Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        void DrawWheel(ref Vector4 value, bool overrideState, TrackballAttribute attr)
        {
            var   wheelRect = GUILayoutUtility.GetAspectRect(1f);
            float size      = wheelRect.width;
            float hsize     = size / 2f;
            float radius    = 0.38f * size;

            Vector3 hsv;

            Color.RGBToHSV(value, out hsv.x, out hsv.y, out hsv.z);
            float offset = value.w;

            // Thumb
            var   thumbPos = Vector2.zero;
            float theta    = hsv.x * (Mathf.PI * 2f);

            thumbPos.x = Mathf.Cos(theta + (Mathf.PI / 2f));
            thumbPos.y = Mathf.Sin(theta - (Mathf.PI / 2f));
            thumbPos  *= hsv.y * radius;

            // Draw the wheel
            if (Event.current.type == EventType.Repaint)
            {
                // Retina support
                float scale = EditorGUIUtility.pixelsPerPoint;

                if (s_Material == null)
                {
                    s_Material = new Material(Shader.Find("Hidden/PostProcessing/Editor/Trackball"))
                    {
                        hideFlags = HideFlags.HideAndDontSave
                    }
                }
                ;

                // Wheel texture
            #if UNITY_2018_1_OR_NEWER
                const RenderTextureReadWrite kReadWrite = RenderTextureReadWrite.sRGB;
            #else
                const RenderTextureReadWrite kReadWrite = RenderTextureReadWrite.Linear;
            #endif

                var oldRT = RenderTexture.active;
                var rt    = RenderTexture.GetTemporary((int)(size * scale), (int)(size * scale), 0, RenderTextureFormat.ARGB32, kReadWrite);
                s_Material.SetFloat("_Offset", offset);
                s_Material.SetFloat("_DisabledState", overrideState ? 1f : 0.5f);
                s_Material.SetVector("_Resolution", new Vector2(size * scale, size * scale / 2f));
                Graphics.Blit(null, rt, s_Material, EditorGUIUtility.isProSkin ? 0 : 1);
                RenderTexture.active = oldRT;

                GUI.DrawTexture(wheelRect, rt);
                RenderTexture.ReleaseTemporary(rt);

                var thumbSize  = Styling.wheelThumbSize;
                var thumbSizeH = thumbSize / 2f;
                Styling.wheelThumb.Draw(new Rect(wheelRect.x + hsize + thumbPos.x - thumbSizeH.x, wheelRect.y + hsize + thumbPos.y - thumbSizeH.y, thumbSize.x, thumbSize.y), false, false, false, false);
            }

            // Input
            var bounds = wheelRect;
            bounds.x    += hsize - radius;
            bounds.y    += hsize - radius;
            bounds.width = bounds.height = radius * 2f;
            hsv          = GetInput(bounds, hsv, thumbPos, radius);
            value        = Color.HSVToRGB(hsv.x, hsv.y, 1f);
            value.w      = offset;

            // Offset
            var   sliderRect = GUILayoutUtility.GetRect(1f, 17f);
            float padding    = sliderRect.width * 0.05f; // 5% padding
            sliderRect.xMin += padding;
            sliderRect.xMax -= padding;
            value.w          = GUI.HorizontalSlider(sliderRect, value.w, -1f, 1f);

            if (attr.mode == TrackballAttribute.Mode.None)
            {
                return;
            }

            // Values
            var displayValue = Vector3.zero;

            switch (attr.mode)
            {
            case TrackballAttribute.Mode.Lift: displayValue = ColorUtilities.ColorToLift(value);
                break;

            case TrackballAttribute.Mode.Gamma: displayValue = ColorUtilities.ColorToInverseGamma(value);
                break;

            case TrackballAttribute.Mode.Gain: displayValue = ColorUtilities.ColorToGain(value);
                break;
            }

            using (new EditorGUI.DisabledGroupScope(true))
            {
                var valuesRect = GUILayoutUtility.GetRect(1f, 17f);
                valuesRect.width /= 3f;
                GUI.Label(valuesRect, displayValue.x.ToString("F2"), EditorStyles.centeredGreyMiniLabel);
                valuesRect.x += valuesRect.width;
                GUI.Label(valuesRect, displayValue.y.ToString("F2"), EditorStyles.centeredGreyMiniLabel);
                valuesRect.x += valuesRect.width;
                GUI.Label(valuesRect, displayValue.z.ToString("F2"), EditorStyles.centeredGreyMiniLabel);
                valuesRect.x += valuesRect.width;
            }
        }

        void DrawLabelAndOverride(GUIContent title, SerializedProperty overrideState)
        {
            // Title
            var areaRect  = GUILayoutUtility.GetRect(1f, 17f);
            var labelSize = Styling.wheelLabel.CalcSize(title);
            var labelRect = new Rect(areaRect.x + areaRect.width / 2 - labelSize.x / 2, areaRect.y, labelSize.x, labelSize.y);

            GUI.Label(labelRect, title, Styling.wheelLabel);

            // Override checkbox
            var overrideRect = new Rect(labelRect.x - 17, labelRect.y + 3, 17f, 17f);

            EditorUtilities.DrawOverrideCheckbox(overrideRect, overrideState);
        }

        Vector3 GetInput(Rect bounds, Vector3 hsv, Vector2 thumbPos, float radius)
        {
            var e        = Event.current;
            var id       = GUIUtility.GetControlID(k_ThumbHash, FocusType.Passive, bounds);
            var mousePos = e.mousePosition;

            if (e.type == EventType.MouseDown && GUIUtility.hotControl == 0 && bounds.Contains(mousePos))
            {
                if (e.button == 0)
                {
                    var   center = new Vector2(bounds.x + radius, bounds.y + radius);
                    float dist   = Vector2.Distance(center, mousePos);

                    if (dist <= radius)
                    {
                        e.Use();
                        m_CursorPos           = new Vector2(thumbPos.x + radius, thumbPos.y + radius);
                        GUIUtility.hotControl = id;
                        GUI.changed           = true;
                    }
                }
                else if (e.button == 1)
                {
                    e.Use();
                    GUI.changed  = true;
                    m_ResetState = true;
                }
            }
            else if (e.type == EventType.MouseDrag && e.button == 0 && GUIUtility.hotControl == id)
            {
                e.Use();
                GUI.changed  = true;
                m_CursorPos += e.delta * GlobalSettings.trackballSensitivity;
                GetWheelHueSaturation(m_CursorPos.x, m_CursorPos.y, radius, out hsv.x, out hsv.y);
            }
            else if (e.rawType == EventType.MouseUp && e.button == 0 && GUIUtility.hotControl == id)
            {
                e.Use();
                GUIUtility.hotControl = 0;
            }

            return(hsv);
        }

        void GetWheelHueSaturation(float x, float y, float radius, out float hue, out float saturation)
        {
            float dx = (x - radius) / radius;
            float dy = (y - radius) / radius;
            float d  = Mathf.Sqrt(dx * dx + dy * dy);

            hue        = Mathf.Atan2(dx, -dy);
            hue        = 1f - ((hue > 0) ? hue : (Mathf.PI * 2f) + hue) / (Mathf.PI * 2f);
            saturation = Mathf.Clamp01(d);
        }
    }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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));
        }