少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using System;
using System.Collections.Generic;
using UnityEngine;
 
namespace UnityStandardAssets.ImageEffects
{
    [ExecuteAlways]
    [RequireComponent (typeof(Camera))]
    public class PostEffectsBase : MonoBehaviour
    {
        protected bool  supportHDRTextures = true;
        protected bool  supportDX11 = false;
        protected bool  isSupported = true;
 
        private List<Material> createdMaterials = new List<Material> ();
 
        protected Material CheckShaderAndCreateMaterial ( Shader s, Material m2Create)
        {
            if (!s)
            {
                Debug.Log("Missing shader in " + ToString ());
                enabled = false;
                return null;
            }
 
            if (s.isSupported && m2Create && m2Create.shader == s)
                return m2Create;
 
            if (!s.isSupported)
            {
                NotSupported ();
                Debug.Log("The shader " + s.ToString() + " on effect "+ToString()+" is not supported on this platform!");
                return null;
            }
 
            m2Create = new Material (s);
            createdMaterials.Add (m2Create);
            m2Create.hideFlags = HideFlags.DontSave;
 
            return m2Create;
        }
 
 
        protected Material CreateMaterial (Shader s, Material m2Create)
        {
            if (!s)
            {
                Debug.Log ("Missing shader in " + ToString ());
                return null;
            }
 
            if (m2Create && (m2Create.shader == s) && (s.isSupported))
                return m2Create;
 
            if (!s.isSupported)
            {
                return null;
            }
 
            m2Create = new Material (s);
            createdMaterials.Add (m2Create);
            m2Create.hideFlags = HideFlags.DontSave;
                
            return m2Create;
        }
 
        void OnEnable ()
        {
            isSupported = true;
        }
 
        void OnDestroy ()
        {
            RemoveCreatedMaterials ();    
        }
 
        private void RemoveCreatedMaterials ()
        {
            while (createdMaterials.Count > 0)
            {
                Material mat = createdMaterials[0];
                createdMaterials.RemoveAt (0);
#if UNITY_EDITOR
                DestroyImmediate (mat);
#else
                Destroy(mat);
#endif
            }
        }
 
        protected bool CheckSupport ()
        {
            return CheckSupport (false);
        }
 
 
        public virtual bool CheckResources ()
        {
            Debug.LogWarning ("CheckResources () for " + ToString() + " should be overwritten.");
            return isSupported;
        }
 
 
        protected void Start ()
        {
            CheckResources ();
        }
 
        protected bool CheckSupport (bool needDepth)
        {
            isSupported = true;
            supportHDRTextures = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf);
            supportDX11 = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders;
 
   //         if (!SystemInfo.supportsImageEffects)
            //{
   //             NotSupported ();
   //             return false;
   //         }
 
            if (needDepth && !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth))
            {
                NotSupported ();
                return false;
            }
 
            if (needDepth)
                GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
 
            return true;
        }
 
        protected bool CheckSupport (bool needDepth,  bool needHdr)
        {
            if (!CheckSupport(needDepth))
                return false;
 
            if (needHdr && !supportHDRTextures)
            {
                NotSupported ();
                return false;
            }
 
            return true;
        }
 
 
        public bool Dx11Support ()
        {
            return supportDX11;
        }
 
 
        protected void ReportAutoDisable ()
        {
            Debug.LogWarning ("The image effect " + ToString() + " has been disabled as it's not supported on the current platform.");
        }
 
        // deprecated but needed for old effects to survive upgrading
        bool CheckShader (Shader s)
        {
            Debug.Log("The shader " + s.ToString () + " on effect "+ ToString () + " is not part of the Unity 3.2+ effects suite anymore. For best performance and quality, please ensure you are using the latest Standard Assets Image Effects (Pro only) package.");
            if (!s.isSupported)
            {
                NotSupported ();
                return false;
            }
            else
            {
                return false;
            }
        }
 
 
        protected void NotSupported ()
        {
            enabled = false;
            isSupported = false;
            return;
        }
 
 
        protected void DrawBorder (RenderTexture dest, Material material)
        {
            float x1;
            float x2;
            float y1;
            float y2;
 
            RenderTexture.active = dest;
            bool  invertY = true; // source.texelSize.y < 0.0ff;
            // Set up the simple Matrix
            GL.PushMatrix();
            GL.LoadOrtho();
 
            for (int i = 0; i < material.passCount; i++)
            {
                material.SetPass(i);
 
                float y1_; float y2_;
                if (invertY)
                {
                    y1_ = 1.0f; y2_ = 0.0f;
                }
                else
                {
                    y1_ = 0.0f; y2_ = 1.0f;
                }
 
                // left
                x1 = 0.0f;
                x2 = 0.0f + 1.0f/(dest.width*1.0f);
                y1 = 0.0f;
                y2 = 1.0f;
                GL.Begin(GL.QUADS);
 
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
 
                // right
                x1 = 1.0f - 1.0f/(dest.width*1.0f);
                x2 = 1.0f;
                y1 = 0.0f;
                y2 = 1.0f;
 
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
 
                // top
                x1 = 0.0f;
                x2 = 1.0f;
                y1 = 0.0f;
                y2 = 0.0f + 1.0f/(dest.height*1.0f);
 
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
 
                // bottom
                x1 = 0.0f;
                x2 = 1.0f;
                y1 = 1.0f - 1.0f/(dest.height*1.0f);
                y2 = 1.0f;
 
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
 
                GL.End();
            }
 
            GL.PopMatrix();
        }
    }
}