using UnityEngine; namespace uNature.Demo.UnityStandardAssets { [AddComponentMenu("Image Effects/Bloom and Glow/Bloom (Optimized)")] [RequireComponent(typeof(Camera))] [ExecuteInEditMode] public class StandardAssets_BloomOptimized : StandardAssets_PostEffectsBase { public enum Resolution { Low = 0, High = 1 } public enum BlurType { Standard = 0, Sgx = 1 } [Range(0f, 1.5f)] public float threshold = 0.25f; [Range(0f, 2.5f)] public float intensity = 0.75f; [Range(0.25f, 5.5f)] public float blurSize = 1f; private Resolution resolution; [Range(1f, 4f)] public int blurIterations = 1; public BlurType blurType; public Shader fastBloomShader; private Material fastBloomMaterial; public override bool CheckResources() { CheckSupport(false); fastBloomMaterial = CheckShaderAndCreateMaterial(fastBloomShader, fastBloomMaterial); if (!isSupported) { ReportAutoDisable(); } return isSupported; } private void OnDisable() { if ((bool)fastBloomMaterial) { Object.DestroyImmediate(fastBloomMaterial); } } private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!CheckResources()) { Graphics.Blit(source, destination); return; } int num = ((resolution != Resolution.Low) ? 2 : 4); float num2 = ((resolution != Resolution.Low) ? 1f : 0.5f); fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * num2, 0f, threshold, intensity)); source.filterMode = FilterMode.Bilinear; int width = source.width / num; int height = source.height / num; RenderTexture renderTexture = RenderTexture.GetTemporary(width, height, 0, source.format); renderTexture.filterMode = FilterMode.Bilinear; Graphics.Blit(source, renderTexture, fastBloomMaterial, 1); int num3 = ((blurType != BlurType.Standard) ? 2 : 0); for (int i = 0; i < blurIterations; i++) { fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * num2 + (float)i * 1f, 0f, threshold, intensity)); RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, source.format); temporary.filterMode = FilterMode.Bilinear; Graphics.Blit(renderTexture, temporary, fastBloomMaterial, 2 + num3); RenderTexture.ReleaseTemporary(renderTexture); renderTexture = temporary; temporary = RenderTexture.GetTemporary(width, height, 0, source.format); temporary.filterMode = FilterMode.Bilinear; Graphics.Blit(renderTexture, temporary, fastBloomMaterial, 3 + num3); RenderTexture.ReleaseTemporary(renderTexture); renderTexture = temporary; } fastBloomMaterial.SetTexture("_Bloom", renderTexture); Graphics.Blit(source, destination, fastBloomMaterial, 0); RenderTexture.ReleaseTemporary(renderTexture); } } }