示例#1
0
        private void PerformBlur(RenderTexture src, RenderTexture dest)
        {
            float off = BlurSpread;

            BlurMaterial.SetTexture("_MainTex", src);
            BlurMaterial.SetFloat("_Shift", off);
            Graphics.Blit(src, dest, BlurMaterial);
        }
示例#2
0
        private void PerformBlur(RenderTexture src, RenderTexture dest, int iteration)
        {
            float offset = iteration * BlurSpread;

            offset *= gaussFilter[iteration];

            BlurMaterial.SetTexture("_MainTex", src);
            BlurMaterial.SetFloat("_Shift", offset);
            Graphics.Blit(src, dest, BlurMaterial);
        }
示例#3
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        ConvolveFogVolume();
        GetRT(ref _source, new int2(Screen.width, Screen.height), "_source");
        Graphics.Blit(source, _source);
        fastBloomMaterial.SetTexture("_source", _source);
        BlurMaterial.SetTexture("_source", _source);
        //Graphics.Blit(_source, destination, BlurMaterial);
        // RT_Format = source.format;
        #region Density convolution
        UniformFogCamera.cullingMask = 1 << instance.FogVolumeLayer;
        //UniformFogCamera.cullingMask |= 1 << LayerMask.NameToLayer("FogVolumeUniform");//add Fog volume uniforms
        FOV_compensation = initFOV / SceneCamera.fieldOfView;
        Shader.SetGlobalFloat("FOV_compensation", FOV_compensation);
        fastBloomMaterial.SetFloat("_Falloff", _Falloff);
        // BlurMaterial.SetFloat("_Dither", _Dither);
        // BlurMaterial.SetFloat("_Distortion", ImageDistortion * -.08f);

        RenderTexture RT_DensityBlur = RenderTexture.GetTemporary(screenX / Downsample, screenY / Downsample, 0, RT_Format);


        DownSample4x(source, RT_DensityBlur);

        for (int i = 0; i < iterations; i++)
        {
            RenderTexture RT_DensityBlur2 = RenderTexture.GetTemporary(screenX / Downsample, screenY / Downsample, 0, RT_Format);
            FourTapCone(RT_DensityBlur, RT_DensityBlur2, i);
            RenderTexture.ReleaseTemporary(RT_DensityBlur);
            RT_DensityBlur = RT_DensityBlur2;
        }
        // Graphics.Blit(RT_DensityBlur, destination);

        #endregion

        #region Bloom
        if (intensity > 0)
        {
            Rendering.EnsureKeyword(fastBloomMaterial, "BLOOM", true);
            float widthMod = 2.0f / (float)_BloomDowsample;
            fastBloomMaterial.SetFloat("_Saturation", _Saturation);
            fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod, 0.0f, threshold, intensity));
            var rtW = source.width / _BloomDowsample;
            var rtH = source.height / _BloomDowsample;

            // downsample
            RenderTexture rt = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
            rt.filterMode = FilterMode.Bilinear;

            if (SceneBloom)
            {
                Graphics.Blit(source, rt, fastBloomMaterial, 1);
            }
            else
            {
                Graphics.Blit(RT_DensityBlur, rt, fastBloomMaterial, 1);
            }

            var passOffs = blurType == BlurType.Standard ? 0 : 2;

            for (int i = 1; i < blurIterations; i++)
            {
                fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod + (i * 1.0f), 0.0f, threshold, intensity));

                // vertical blur
                RenderTexture rt2 = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, fastBloomMaterial, 2 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;

                // horizontal blur
                rt2            = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, fastBloomMaterial, 3 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;
            }

            fastBloomMaterial.SetTexture("_Bloom", rt);
            RenderTexture.ReleaseTemporary(rt);
        }
        else
        {
            Rendering.EnsureKeyword(fastBloomMaterial, "BLOOM", false);
        }
        #endregion
        Graphics.Blit(RT_DensityBlur, destination, fastBloomMaterial, 0);
        RenderTexture.ReleaseTemporary(RT_DensityBlur);
    }