4 namespace UnityStandardAssets.ImageEffects
7 [RequireComponent (typeof(Camera))]
10 protected bool supportHDRTextures =
true;
11 protected bool supportDX11 =
false;
12 protected bool isSupported =
true;
14 protected Material CheckShaderAndCreateMaterial ( Shader s, Material m2Create)
18 Debug.Log(
"Missing shader in " + ToString ());
23 if (s.isSupported && m2Create && m2Create.shader == s)
29 Debug.Log(
"The shader " + s.ToString() +
" on effect "+ToString()+
" is not supported on this platform!");
34 m2Create =
new Material (s);
35 m2Create.hideFlags = HideFlags.DontSave;
43 protected Material CreateMaterial (Shader s, Material m2Create)
47 Debug.Log (
"Missing shader in " + ToString ());
51 if (m2Create && (m2Create.shader == s) && (s.isSupported))
60 m2Create =
new Material (s);
61 m2Create.hideFlags = HideFlags.DontSave;
73 protected bool CheckSupport ()
75 return CheckSupport (
false);
79 public virtual bool CheckResources ()
81 Debug.LogWarning (
"CheckResources () for " + ToString() +
" should be overwritten.");
86 protected void Start ()
91 protected bool CheckSupport (
bool needDepth)
94 supportHDRTextures = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf);
95 supportDX11 = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders;
97 if (!SystemInfo.supportsImageEffects || !SystemInfo.supportsRenderTextures)
103 if (needDepth && !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth))
110 GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
115 protected bool CheckSupport (
bool needDepth,
bool needHdr)
117 if (!CheckSupport(needDepth))
120 if (needHdr && !supportHDRTextures)
130 public bool Dx11Support ()
136 protected void ReportAutoDisable ()
138 Debug.LogWarning (
"The image effect " + ToString() +
" has been disabled as it's not supported on the current platform.");
142 bool CheckShader (Shader s)
144 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.");
157 protected void NotSupported ()
165 protected void DrawBorder (RenderTexture dest, Material material)
172 RenderTexture.active = dest;
178 for (
int i = 0; i < material.passCount; i++)
182 float y1_;
float y2_;
185 y1_ = 1.0f; y2_ = 0.0f;
189 y1_ = 0.0f; y2_ = 1.0f;
194 x2 = 0.0f + 1.0f/(dest.width*1.0f);
199 GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
200 GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
201 GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
202 GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
205 x1 = 1.0f - 1.0f/(dest.width*1.0f);
210 GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
211 GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
212 GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
213 GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
219 y2 = 0.0f + 1.0f/(dest.height*1.0f);
221 GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
222 GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
223 GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
224 GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
229 y1 = 1.0f - 1.0f/(dest.height*1.0f);
232 GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
233 GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
234 GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
235 GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);