4 namespace UnityStandardAssets.ImageEffects
7 [RequireComponent (typeof(Camera))]
8 [AddComponentMenu (
"Image Effects/Bloom and Glow/Bloom (Optimized)")]
12 public enum Resolution
25 public float threshold = 0.25f;
27 public float intensity = 0.75f;
30 public float blurSize = 1.0f;
32 Resolution resolution = Resolution.Low;
34 public int blurIterations = 1;
36 public BlurType blurType= BlurType.Standard;
38 public Shader fastBloomShader = null;
39 private Material fastBloomMaterial = null;
42 public override bool CheckResources ()
46 fastBloomMaterial = CheckShaderAndCreateMaterial (fastBloomShader, fastBloomMaterial);
55 if (fastBloomMaterial)
56 DestroyImmediate (fastBloomMaterial);
59 void OnRenderImage (RenderTexture source, RenderTexture destination)
61 if (CheckResources() ==
false)
63 Graphics.Blit (source, destination);
67 int divider = resolution == Resolution.Low ? 4 : 2;
68 float widthMod = resolution == Resolution.Low ? 0.5f : 1.0f;
70 fastBloomMaterial.SetVector (
"_Parameter",
new Vector4 (blurSize * widthMod, 0.0f, threshold, intensity));
71 source.filterMode = FilterMode.Bilinear;
73 var rtW= source.width/divider;
74 var rtH= source.height/divider;
77 RenderTexture rt = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
78 rt.filterMode = FilterMode.Bilinear;
79 Graphics.Blit (source, rt, fastBloomMaterial, 1);
81 var passOffs= blurType == BlurType.Standard ? 0 : 2;
83 for(
int i = 0; i < blurIterations; i++)
85 fastBloomMaterial.SetVector (
"_Parameter",
new Vector4 (blurSize * widthMod + (i*1.0f), 0.0f, threshold, intensity));
88 RenderTexture rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
89 rt2.filterMode = FilterMode.Bilinear;
90 Graphics.Blit (rt, rt2, fastBloomMaterial, 2 + passOffs);
91 RenderTexture.ReleaseTemporary (rt);
95 rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
96 rt2.filterMode = FilterMode.Bilinear;
97 Graphics.Blit (rt, rt2, fastBloomMaterial, 3 + passOffs);
98 RenderTexture.ReleaseTemporary (rt);
102 fastBloomMaterial.SetTexture (
"_Bloom", rt);
104 Graphics.Blit (source, destination, fastBloomMaterial, 0);
106 RenderTexture.ReleaseTemporary (rt);