示例#1
0
        private void RenderLDRPipeline2D(PostProcessRenderContext context)
        {
            CheckInternalStripLut();
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.lut2DBaker);

            propertySheet.ClearKeywords();
            propertySheet.properties.SetVector(ShaderIDs.Lut2D_Params, new Vector4(32f, 0.00048828125f, 0.015625f, 1.032258f));
            Vector3 v = ColorUtilities.ComputeColorBalance(base.settings.temperature.value, base.settings.tint.value);

            propertySheet.properties.SetVector(ShaderIDs.ColorBalance, v);
            propertySheet.properties.SetVector(ShaderIDs.ColorFilter, base.settings.colorFilter.value);
            float x = base.settings.hueShift.value / 360f;
            float y = base.settings.saturation.value / 100f + 1f;
            float z = base.settings.contrast.value / 100f + 1f;

            propertySheet.properties.SetVector(ShaderIDs.HueSatCon, new Vector3(x, y, z));
            Vector3 a  = new Vector3(base.settings.mixerRedOutRedIn, base.settings.mixerRedOutGreenIn, base.settings.mixerRedOutBlueIn);
            Vector3 a2 = new Vector3(base.settings.mixerGreenOutRedIn, base.settings.mixerGreenOutGreenIn, base.settings.mixerGreenOutBlueIn);
            Vector3 a3 = new Vector3(base.settings.mixerBlueOutRedIn, base.settings.mixerBlueOutGreenIn, base.settings.mixerBlueOutBlueIn);

            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerRed, a / 100f);
            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerGreen, a2 / 100f);
            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerBlue, a3 / 100f);
            Vector3 v2 = ColorUtilities.ColorToLift(base.settings.lift.value);
            Vector3 v3 = ColorUtilities.ColorToGain(base.settings.gain.value);
            Vector3 v4 = ColorUtilities.ColorToInverseGamma(base.settings.gamma.value);

            propertySheet.properties.SetVector(ShaderIDs.Lift, v2);
            propertySheet.properties.SetVector(ShaderIDs.InvGamma, v4);
            propertySheet.properties.SetVector(ShaderIDs.Gain, v3);
            propertySheet.properties.SetFloat(ShaderIDs.Brightness, (base.settings.brightness.value + 100f) / 100f);
            propertySheet.properties.SetTexture(ShaderIDs.Curves, GetCurveTexture(hdr: false));
            context.command.BeginSample("LdrColorGradingLut2D");
            Texture value = base.settings.ldrLut.value;

            if (value == null)
            {
                context.command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, m_InternalLdrLut, propertySheet, 0);
            }
            else
            {
                propertySheet.properties.SetVector(ShaderIDs.UserLut2D_Params, new Vector4(1f / (float)value.width, 1f / (float)value.height, (float)value.height - 1f, base.settings.ldrLutContribution));
                context.command.BlitFullscreenTriangle(value, m_InternalLdrLut, propertySheet, 1);
            }
            context.command.EndSample("LdrColorGradingLut2D");
            RenderTexture internalLdrLut = m_InternalLdrLut;
            PropertySheet uberSheet      = context.uberSheet;

            uberSheet.EnableKeyword("COLOR_GRADING_LDR_2D");
            uberSheet.properties.SetVector(ShaderIDs.Lut2D_Params, new Vector3(1f / (float)internalLdrLut.width, 1f / (float)internalLdrLut.height, (float)internalLdrLut.height - 1f));
            uberSheet.properties.SetTexture(ShaderIDs.Lut2D, internalLdrLut);
        }
示例#2
0
        private void RenderHDRPipeline3D(PostProcessRenderContext context)
        {
            CheckInternalLogLut();
            ComputeShader lut3DBaker  = context.resources.computeShaders.lut3DBaker;
            int           kernelIndex = 0;

            switch (base.settings.tonemapper.value)
            {
            case Tonemapper.None:
                kernelIndex = lut3DBaker.FindKernel("KGenLut3D_NoTonemap");
                break;

            case Tonemapper.Neutral:
                kernelIndex = lut3DBaker.FindKernel("KGenLut3D_NeutralTonemap");
                break;

            case Tonemapper.ACES:
                kernelIndex = lut3DBaker.FindKernel("KGenLut3D_AcesTonemap");
                break;

            case Tonemapper.Custom:
                kernelIndex = lut3DBaker.FindKernel("KGenLut3D_CustomTonemap");
                break;
            }
            CommandBuffer command = context.command;

            command.SetComputeTextureParam(lut3DBaker, kernelIndex, "_Output", m_InternalLogLut);
            command.SetComputeVectorParam(lut3DBaker, "_Size", new Vector4(33f, 0.03125f, 0f, 0f));
            Vector3 v = ColorUtilities.ComputeColorBalance(base.settings.temperature.value, base.settings.tint.value);

            command.SetComputeVectorParam(lut3DBaker, "_ColorBalance", v);
            command.SetComputeVectorParam(lut3DBaker, "_ColorFilter", base.settings.colorFilter.value);
            float x = base.settings.hueShift.value / 360f;
            float y = base.settings.saturation.value / 100f + 1f;
            float z = base.settings.contrast.value / 100f + 1f;

            command.SetComputeVectorParam(lut3DBaker, "_HueSatCon", new Vector4(x, y, z, 0f));
            Vector4 a  = new Vector4(base.settings.mixerRedOutRedIn, base.settings.mixerRedOutGreenIn, base.settings.mixerRedOutBlueIn, 0f);
            Vector4 a2 = new Vector4(base.settings.mixerGreenOutRedIn, base.settings.mixerGreenOutGreenIn, base.settings.mixerGreenOutBlueIn, 0f);
            Vector4 a3 = new Vector4(base.settings.mixerBlueOutRedIn, base.settings.mixerBlueOutGreenIn, base.settings.mixerBlueOutBlueIn, 0f);

            command.SetComputeVectorParam(lut3DBaker, "_ChannelMixerRed", a / 100f);
            command.SetComputeVectorParam(lut3DBaker, "_ChannelMixerGreen", a2 / 100f);
            command.SetComputeVectorParam(lut3DBaker, "_ChannelMixerBlue", a3 / 100f);
            Vector3 vector  = ColorUtilities.ColorToLift(base.settings.lift.value * 0.2f);
            Vector3 vector2 = ColorUtilities.ColorToGain(base.settings.gain.value * 0.8f);
            Vector3 vector3 = ColorUtilities.ColorToInverseGamma(base.settings.gamma.value * 0.8f);

            command.SetComputeVectorParam(lut3DBaker, "_Lift", new Vector4(vector.x, vector.y, vector.z, 0f));
            command.SetComputeVectorParam(lut3DBaker, "_InvGamma", new Vector4(vector3.x, vector3.y, vector3.z, 0f));
            command.SetComputeVectorParam(lut3DBaker, "_Gain", new Vector4(vector2.x, vector2.y, vector2.z, 0f));
            command.SetComputeTextureParam(lut3DBaker, kernelIndex, "_Curves", GetCurveTexture(hdr: true));
            if (base.settings.tonemapper.value == Tonemapper.Custom)
            {
                m_HableCurve.Init(base.settings.toneCurveToeStrength.value, base.settings.toneCurveToeLength.value, base.settings.toneCurveShoulderStrength.value, base.settings.toneCurveShoulderLength.value, base.settings.toneCurveShoulderAngle.value, base.settings.toneCurveGamma.value);
                command.SetComputeVectorParam(lut3DBaker, "_CustomToneCurve", m_HableCurve.uniforms.curve);
                command.SetComputeVectorParam(lut3DBaker, "_ToeSegmentA", m_HableCurve.uniforms.toeSegmentA);
                command.SetComputeVectorParam(lut3DBaker, "_ToeSegmentB", m_HableCurve.uniforms.toeSegmentB);
                command.SetComputeVectorParam(lut3DBaker, "_MidSegmentA", m_HableCurve.uniforms.midSegmentA);
                command.SetComputeVectorParam(lut3DBaker, "_MidSegmentB", m_HableCurve.uniforms.midSegmentB);
                command.SetComputeVectorParam(lut3DBaker, "_ShoSegmentA", m_HableCurve.uniforms.shoSegmentA);
                command.SetComputeVectorParam(lut3DBaker, "_ShoSegmentB", m_HableCurve.uniforms.shoSegmentB);
            }
            context.command.BeginSample("HdrColorGradingLut3D");
            int num = Mathf.CeilToInt(8.25f);

            command.DispatchCompute(lut3DBaker, kernelIndex, num, num, num);
            context.command.EndSample("HdrColorGradingLut3D");
            RenderTexture internalLogLut = m_InternalLogLut;
            PropertySheet uberSheet      = context.uberSheet;

            uberSheet.EnableKeyword("COLOR_GRADING_HDR_3D");
            uberSheet.properties.SetTexture(ShaderIDs.Lut3D, internalLogLut);
            uberSheet.properties.SetVector(ShaderIDs.Lut3D_Params, new Vector2(1f / (float)internalLogLut.width, (float)internalLogLut.width - 1f));
            uberSheet.properties.SetFloat(ShaderIDs.PostExposure, RuntimeUtilities.Exp2(base.settings.postExposure.value));
            context.logLut = internalLogLut;
        }
示例#3
0
        private void RenderHDRPipeline2D(PostProcessRenderContext context)
        {
            CheckInternalStripLut();
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.lut2DBaker);

            propertySheet.ClearKeywords();
            propertySheet.properties.SetVector(ShaderIDs.Lut2D_Params, new Vector4(32f, 0.00048828125f, 0.015625f, 1.032258f));
            Vector3 v = ColorUtilities.ComputeColorBalance(base.settings.temperature.value, base.settings.tint.value);

            propertySheet.properties.SetVector(ShaderIDs.ColorBalance, v);
            propertySheet.properties.SetVector(ShaderIDs.ColorFilter, base.settings.colorFilter.value);
            float x = base.settings.hueShift.value / 360f;
            float y = base.settings.saturation.value / 100f + 1f;
            float z = base.settings.contrast.value / 100f + 1f;

            propertySheet.properties.SetVector(ShaderIDs.HueSatCon, new Vector3(x, y, z));
            Vector3 a  = new Vector3(base.settings.mixerRedOutRedIn, base.settings.mixerRedOutGreenIn, base.settings.mixerRedOutBlueIn);
            Vector3 a2 = new Vector3(base.settings.mixerGreenOutRedIn, base.settings.mixerGreenOutGreenIn, base.settings.mixerGreenOutBlueIn);
            Vector3 a3 = new Vector3(base.settings.mixerBlueOutRedIn, base.settings.mixerBlueOutGreenIn, base.settings.mixerBlueOutBlueIn);

            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerRed, a / 100f);
            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerGreen, a2 / 100f);
            propertySheet.properties.SetVector(ShaderIDs.ChannelMixerBlue, a3 / 100f);
            Vector3 v2 = ColorUtilities.ColorToLift(base.settings.lift.value * 0.2f);
            Vector3 v3 = ColorUtilities.ColorToGain(base.settings.gain.value * 0.8f);
            Vector3 v4 = ColorUtilities.ColorToInverseGamma(base.settings.gamma.value * 0.8f);

            propertySheet.properties.SetVector(ShaderIDs.Lift, v2);
            propertySheet.properties.SetVector(ShaderIDs.InvGamma, v4);
            propertySheet.properties.SetVector(ShaderIDs.Gain, v3);
            propertySheet.properties.SetTexture(ShaderIDs.Curves, GetCurveTexture(hdr: true));
            switch (base.settings.tonemapper.value)
            {
            case Tonemapper.Custom:
                propertySheet.EnableKeyword("TONEMAPPING_CUSTOM");
                m_HableCurve.Init(base.settings.toneCurveToeStrength.value, base.settings.toneCurveToeLength.value, base.settings.toneCurveShoulderStrength.value, base.settings.toneCurveShoulderLength.value, base.settings.toneCurveShoulderAngle.value, base.settings.toneCurveGamma.value);
                propertySheet.properties.SetVector(ShaderIDs.CustomToneCurve, m_HableCurve.uniforms.curve);
                propertySheet.properties.SetVector(ShaderIDs.ToeSegmentA, m_HableCurve.uniforms.toeSegmentA);
                propertySheet.properties.SetVector(ShaderIDs.ToeSegmentB, m_HableCurve.uniforms.toeSegmentB);
                propertySheet.properties.SetVector(ShaderIDs.MidSegmentA, m_HableCurve.uniforms.midSegmentA);
                propertySheet.properties.SetVector(ShaderIDs.MidSegmentB, m_HableCurve.uniforms.midSegmentB);
                propertySheet.properties.SetVector(ShaderIDs.ShoSegmentA, m_HableCurve.uniforms.shoSegmentA);
                propertySheet.properties.SetVector(ShaderIDs.ShoSegmentB, m_HableCurve.uniforms.shoSegmentB);
                break;

            case Tonemapper.ACES:
                propertySheet.EnableKeyword("TONEMAPPING_ACES");
                break;

            case Tonemapper.Neutral:
                propertySheet.EnableKeyword("TONEMAPPING_NEUTRAL");
                break;
            }
            context.command.BeginSample("HdrColorGradingLut2D");
            context.command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, m_InternalLdrLut, propertySheet, 2);
            context.command.EndSample("HdrColorGradingLut2D");
            RenderTexture internalLdrLut = m_InternalLdrLut;
            PropertySheet uberSheet      = context.uberSheet;

            uberSheet.EnableKeyword("COLOR_GRADING_HDR_2D");
            uberSheet.properties.SetVector(ShaderIDs.Lut2D_Params, new Vector3(1f / (float)internalLdrLut.width, 1f / (float)internalLdrLut.height, (float)internalLdrLut.height - 1f));
            uberSheet.properties.SetTexture(ShaderIDs.Lut2D, internalLdrLut);
            uberSheet.properties.SetFloat(ShaderIDs.PostExposure, RuntimeUtilities.Exp2(base.settings.postExposure.value));
        }