Beispiel #1
0
        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (shader == null)
            {
                Graphics.Blit(source, destination);
                return;
            }

            if (bloom == null)
            {
                bloom = new Bloom(shader);
            }

            bloom.iterations = iterations;
            bloom.intensity  = intensity;
            bloom.threshold  = threshold;
            bloom.softKnee   = softKnee;

            var res         = RenderTextureUtils.GetScreenResolution(resolution);
            var bloomTarget = RenderTexture.GetTemporary(res.x, res.y, 0, Ext.argbHalf);

            bloomTarget.filterMode = FilterMode.Bilinear;
            bloomTarget.wrapMode   = TextureWrapMode.Clamp;

            bloom.Apply(source, bloomTarget, res);
            bloom.Combine(source, destination, bloomTarget, noise);

            RenderTexture.ReleaseTemporary(bloomTarget);
        }
        void LateUpdate()
        {
            Init();
            if (!inited)
            {
                return;
            }

            var camera = GetCamera();

            if (camera == null)
            {
                return;
            }

            if (bloom == null)
            {
                bloom = new Bloom(bloomShader);
            }

            bloom.iterations = iterations;
            bloom.intensity  = intensity;
            bloom.threshold  = threshold;
            bloom.softKnee   = softKnee;

            var res = RenderTextureUtils.GetScreenResolution(resolution);

            var sourceTarget = GetTarget(res, Ext.argbHalf);

            camera.targetTexture = sourceTarget;
            var mask = camera.cullingMask;

            camera.cullingMask ^= layerMask.value;
            camera.Render();
            camera.cullingMask   = mask;
            camera.targetTexture = null;

            RenderTexture.ReleaseTemporary(bloomTarget);
            bloomTarget = GetTarget(res, Ext.argbHalf);
            bloom.Apply(sourceTarget, bloomTarget, res);

            displayMaterial.SetTexture(_BloomTex, bloomTarget);
            displayMaterial.SetTexture(_NoiseTex, noise);
            displayMaterial.SetVector(_NoiseTexScale, RenderTextureUtils.GetTextureScreenScale(noise));

            RenderTexture.ReleaseTemporary(sourceTarget);
        }