示例#1
0
 private void PushDebug(PostProcessRenderContext context)
 {
     if (context.IsDebugOverlayEnabled(DebugOverlay.AmbientOcclusion))
     {
         context.PushDebugOverlay(context.command, AmbientOnlyAO, PropertySheet, (int)Pass.DebugOverlay);
     }
 }
        public override void Render(PostProcessRenderContext context)
        {
            RenderTextureFormat colorFormat         = RenderTextureFormat.DefaultHDR;
            RenderTextureFormat renderTextureFormat = SelectFormat(RenderTextureFormat.R8, RenderTextureFormat.RHalf);
            float         num           = 0.024f * ((float)context.height / 1080f);
            float         num2          = base.settings.focalLength.value / 1000f;
            float         num3          = Mathf.Max(base.settings.focusDistance.value, num2);
            float         num4          = (float)context.screenWidth / (float)context.screenHeight;
            float         value         = num2 * num2 / (base.settings.aperture.value * (num3 - num2) * num * 2f);
            float         num5          = CalculateMaxCoCRadius(context.screenHeight);
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.depthOfField);

            propertySheet.properties.Clear();
            propertySheet.properties.SetFloat(ShaderIDs.Distance, num3);
            propertySheet.properties.SetFloat(ShaderIDs.LensCoeff, value);
            propertySheet.properties.SetFloat(ShaderIDs.MaxCoC, num5);
            propertySheet.properties.SetFloat(ShaderIDs.RcpMaxCoC, 1f / num5);
            propertySheet.properties.SetFloat(ShaderIDs.RcpAspect, 1f / num4);
            CommandBuffer command = context.command;

            command.BeginSample("DepthOfField");
            context.GetScreenSpaceTemporaryRT(command, ShaderIDs.CoCTex, 0, renderTextureFormat, RenderTextureReadWrite.Linear);
            command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, ShaderIDs.CoCTex, propertySheet, 0);
            if (context.IsTemporalAntialiasingActive())
            {
                float   motionBlending = context.temporalAntialiasing.motionBlending;
                float   z      = (!m_ResetHistory) ? motionBlending : 0f;
                Vector2 jitter = context.temporalAntialiasing.jitter;
                propertySheet.properties.SetVector(ShaderIDs.TaaParams, new Vector3(jitter.x, jitter.y, z));
                int           num6 = m_HistoryPingPong[context.xrActiveEye];
                RenderTexture tex  = CheckHistory(context.xrActiveEye, ++num6 % 2, context, renderTextureFormat);
                RenderTexture tex2 = CheckHistory(context.xrActiveEye, ++num6 % 2, context, renderTextureFormat);
                m_HistoryPingPong[context.xrActiveEye] = ++num6 % 2;
                command.BlitFullscreenTriangle(tex, tex2, propertySheet, 1);
                command.ReleaseTemporaryRT(ShaderIDs.CoCTex);
                command.SetGlobalTexture(ShaderIDs.CoCTex, tex2);
            }
            context.GetScreenSpaceTemporaryRT(command, ShaderIDs.DepthOfFieldTex, 0, colorFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);
            command.BlitFullscreenTriangle(context.source, ShaderIDs.DepthOfFieldTex, propertySheet, 2);
            context.GetScreenSpaceTemporaryRT(command, ShaderIDs.DepthOfFieldTemp, 0, colorFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);
            command.BlitFullscreenTriangle(ShaderIDs.DepthOfFieldTex, ShaderIDs.DepthOfFieldTemp, propertySheet, (int)(3 + base.settings.kernelSize.value));
            command.BlitFullscreenTriangle(ShaderIDs.DepthOfFieldTemp, ShaderIDs.DepthOfFieldTex, propertySheet, 7);
            command.ReleaseTemporaryRT(ShaderIDs.DepthOfFieldTemp);
            if (context.IsDebugOverlayEnabled(DebugOverlay.DepthOfField))
            {
                context.PushDebugOverlay(command, context.source, propertySheet, 9);
            }
            command.BlitFullscreenTriangle(context.source, context.destination, propertySheet, 8);
            command.ReleaseTemporaryRT(ShaderIDs.DepthOfFieldTex);
            if (!context.IsTemporalAntialiasingActive())
            {
                command.ReleaseTemporaryRT(ShaderIDs.CoCTex);
            }
            command.EndSample("DepthOfField");
            m_ResetHistory = false;
        }
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer command = context.command;

            command.BeginSample("BloomPyramid");
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.bloom);

            propertySheet.properties.SetTexture(ShaderIDs.AutoExposureTex, context.autoExposureTexture);
            float num   = Mathf.Clamp(base.settings.anamorphicRatio, -1f, 1f);
            float num2  = (!(num < 0f)) ? 0f : (0f - num);
            float num3  = (!(num > 0f)) ? 0f : num;
            int   num4  = Mathf.FloorToInt((float)context.screenWidth / (2f - num2));
            int   num5  = Mathf.FloorToInt((float)context.screenHeight / (2f - num3));
            int   num6  = Mathf.Max(num4, num5);
            float num7  = Mathf.Log(num6, 2f) + Mathf.Min(base.settings.diffusion.value, 10f) - 10f;
            int   num8  = Mathf.FloorToInt(num7);
            int   num9  = Mathf.Clamp(num8, 1, 16);
            float num10 = 0.5f + num7 - (float)num8;

            propertySheet.properties.SetFloat(ShaderIDs.SampleScale, num10);
            float   num11 = Mathf.GammaToLinearSpace(base.settings.threshold.value);
            float   num12 = num11 * base.settings.softKnee.value + 1E-05f;
            Vector4 value = new Vector4(num11, num11 - num12, num12 * 2f, 0.25f / num12);

            propertySheet.properties.SetVector(ShaderIDs.Threshold, value);
            float x = Mathf.GammaToLinearSpace(base.settings.clamp.value);

            propertySheet.properties.SetVector(ShaderIDs.Params, new Vector4(x, 0f, 0f, 0f));
            int num13 = base.settings.fastMode ? 1 : 0;
            RenderTargetIdentifier source = context.source;

            for (int i = 0; i < num9; i++)
            {
                int down = m_Pyramid[i].down;
                int up   = m_Pyramid[i].up;
                int pass = (i != 0) ? (2 + num13) : num13;
                context.GetScreenSpaceTemporaryRT(command, down, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, num4, num5);
                context.GetScreenSpaceTemporaryRT(command, up, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, num4, num5);
                command.BlitFullscreenTriangle(source, down, propertySheet, pass);
                source = down;
                num4   = Mathf.Max(num4 / 2, 1);
                num5   = Mathf.Max(num5 / 2, 1);
            }
            int num14 = m_Pyramid[num9 - 1].down;

            for (int num15 = num9 - 2; num15 >= 0; num15--)
            {
                int down2 = m_Pyramid[num15].down;
                int up2   = m_Pyramid[num15].up;
                command.SetGlobalTexture(ShaderIDs.BloomTex, down2);
                command.BlitFullscreenTriangle(num14, up2, propertySheet, 4 + num13);
                num14 = up2;
            }
            Color   linear = base.settings.color.value.linear;
            float   num16  = RuntimeUtilities.Exp2(base.settings.intensity.value / 10f) - 1f;
            Vector4 value2 = new Vector4(num10, num16, base.settings.dirtIntensity.value, num9);

            if (context.IsDebugOverlayEnabled(DebugOverlay.BloomThreshold))
            {
                context.PushDebugOverlay(command, context.source, propertySheet, 6);
            }
            else if (context.IsDebugOverlayEnabled(DebugOverlay.BloomBuffer))
            {
                propertySheet.properties.SetVector(ShaderIDs.ColorIntensity, new Vector4(linear.r, linear.g, linear.b, num16));
                context.PushDebugOverlay(command, m_Pyramid[0].up, propertySheet, 7 + num13);
            }
            Texture texture = (!(base.settings.dirtTexture.value == null)) ? base.settings.dirtTexture.value : RuntimeUtilities.blackTexture;
            float   num17   = (float)texture.width / (float)texture.height;
            float   num18   = (float)context.screenWidth / (float)context.screenHeight;
            Vector4 value3  = new Vector4(1f, 1f, 0f, 0f);

            if (num17 > num18)
            {
                value3.x = num18 / num17;
                value3.z = (1f - value3.x) * 0.5f;
            }
            else if (num18 > num17)
            {
                value3.y = num17 / num18;
                value3.w = (1f - value3.y) * 0.5f;
            }
            PropertySheet uberSheet = context.uberSheet;

            if ((bool)base.settings.fastMode)
            {
                uberSheet.EnableKeyword("BLOOM_LOW");
            }
            else
            {
                uberSheet.EnableKeyword("BLOOM");
            }
            uberSheet.properties.SetVector(ShaderIDs.Bloom_DirtTileOffset, value3);
            uberSheet.properties.SetVector(ShaderIDs.Bloom_Settings, value2);
            uberSheet.properties.SetColor(ShaderIDs.Bloom_Color, linear);
            uberSheet.properties.SetTexture(ShaderIDs.Bloom_DirtTex, texture);
            command.SetGlobalTexture(ShaderIDs.BloomTex, num14);
            for (int j = 0; j < num9; j++)
            {
                if (m_Pyramid[j].down != num14)
                {
                    command.ReleaseTemporaryRT(m_Pyramid[j].down);
                }
                if (m_Pyramid[j].up != num14)
                {
                    command.ReleaseTemporaryRT(m_Pyramid[j].up);
                }
            }
            command.EndSample("BloomPyramid");
            context.bloomBufferNameID = num14;
        }