4 namespace UnityStandardAssets.ImageEffects
7 [RequireComponent(typeof(Camera))]
8 [AddComponentMenu(
"Image Effects/Color Adjustments/Contrast Enhance (Unsharp Mask)")]
12 public float intensity = 0.5f;
14 public float threshold = 0.0f;
16 private Material separableBlurMaterial;
17 private Material contrastCompositeMaterial;
20 public float blurSpread = 1.0f;
22 public Shader separableBlurShader = null;
23 public Shader contrastCompositeShader = null;
26 public override bool CheckResources ()
30 contrastCompositeMaterial = CheckShaderAndCreateMaterial (contrastCompositeShader, contrastCompositeMaterial);
31 separableBlurMaterial = CheckShaderAndCreateMaterial (separableBlurShader, separableBlurMaterial);
38 void OnRenderImage (RenderTexture source, RenderTexture destination)
40 if (CheckResources()==
false)
42 Graphics.Blit (source, destination);
46 int rtW = source.width;
47 int rtH = source.height;
49 RenderTexture color2 = RenderTexture.GetTemporary (rtW/2, rtH/2, 0);
53 Graphics.Blit (source, color2);
54 RenderTexture color4a = RenderTexture.GetTemporary (rtW/4, rtH/4, 0);
55 Graphics.Blit (color2, color4a);
56 RenderTexture.ReleaseTemporary (color2);
60 separableBlurMaterial.SetVector (
"offsets",
new Vector4 (0.0f, (blurSpread * 1.0f) / color4a.height, 0.0f, 0.0f));
61 RenderTexture color4b = RenderTexture.GetTemporary (rtW/4, rtH/4, 0);
62 Graphics.Blit (color4a, color4b, separableBlurMaterial);
63 RenderTexture.ReleaseTemporary (color4a);
65 separableBlurMaterial.SetVector (
"offsets",
new Vector4 ((blurSpread * 1.0f) / color4a.width, 0.0f, 0.0f, 0.0f));
66 color4a = RenderTexture.GetTemporary (rtW/4, rtH/4, 0);
67 Graphics.Blit (color4b, color4a, separableBlurMaterial);
68 RenderTexture.ReleaseTemporary (color4b);
72 contrastCompositeMaterial.SetTexture (
"_MainTexBlurred", color4a);
73 contrastCompositeMaterial.SetFloat (
"intensity", intensity);
74 contrastCompositeMaterial.SetFloat (
"threshold", threshold);
75 Graphics.Blit (source, destination, contrastCompositeMaterial);
77 RenderTexture.ReleaseTemporary (color4a);