Exemplo n.º 1
0
 internal Uniforms(HableCurve parent)
 {
     this.parent = parent;
 }
    void DrawCustomToneCurve(DragonPostProcess.Property.ToneMapProperty property)
    {
        EditorGUILayout.Space();

        Vector3[] m_RectVertices  = new Vector3[4];
        Vector3[] m_LineVertices  = new Vector3[2];
        Vector3[] m_CurveVertices = new Vector3[k_CustomToneCurveResolution];
        Rect      m_CustomToneCurveRect;

        // Reserve GUI space
        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Space(EditorGUI.indentLevel * 15f);
            m_CustomToneCurveRect = GUILayoutUtility.GetRect(128, 80);
        }

        if (Event.current.type != EventType.Repaint)
        {
            return;
        }

        // Prepare curve data
        float      toeStrength      = property.toneCurveToeStrength;
        float      toeLength        = property.toneCurveToeLength;
        float      shoulderStrength = property.toneCurveShoulderStrength;
        float      shoulderLength   = property.toneCurveShoulderLength;
        float      shoulderAngle    = property.toneCurveShoulderAngle;
        float      gamma            = property.toneCurveGamma;
        HableCurve m_HableCurve     = new HableCurve();

        m_HableCurve.Init(
            toeStrength,
            toeLength,
            shoulderStrength,
            shoulderLength,
            shoulderAngle,
            gamma
            );

        float endPoint = m_HableCurve.whitePoint;

        // Background
        m_RectVertices[0] = PointInRect(0f, 0f, endPoint, m_CustomToneCurveRect);
        m_RectVertices[1] = PointInRect(endPoint, 0f, endPoint, m_CustomToneCurveRect);
        m_RectVertices[2] = PointInRect(endPoint, k_CustomToneCurveRangeY, endPoint, m_CustomToneCurveRect);
        m_RectVertices[3] = PointInRect(0f, k_CustomToneCurveRangeY, endPoint, m_CustomToneCurveRect);
        Handles.DrawSolidRectangleWithOutline(m_RectVertices, Color.white * 0.1f, Color.white * 0.4f);

        // Vertical guides
        if (endPoint < m_CustomToneCurveRect.width / 3)
        {
            int steps = Mathf.CeilToInt(endPoint);
            for (var i = 1; i < steps; i++)
            {
                DrawLine(i, 0, i, k_CustomToneCurveRangeY, 0.4f, endPoint, m_CustomToneCurveRect, m_LineVertices);
            }
        }

        // Label
        Handles.Label(m_CustomToneCurveRect.position + Vector2.right, "Custom Tone Curve", EditorStyles.miniLabel);

        // Draw the acual curve
        var vcount = 0;

        while (vcount < k_CustomToneCurveResolution)
        {
            float x = endPoint * vcount / (k_CustomToneCurveResolution - 1);
            float y = m_HableCurve.Eval(x);

            if (y < k_CustomToneCurveRangeY)
            {
                m_CurveVertices[vcount++] = PointInRect(x, y, endPoint, m_CustomToneCurveRect);
            }
            else
            {
                if (vcount > 1)
                {
                    // Extend the last segment to the top edge of the rect.
                    var v1   = m_CurveVertices[vcount - 2];
                    var v2   = m_CurveVertices[vcount - 1];
                    var clip = (m_CustomToneCurveRect.y - v1.y) / (v2.y - v1.y);
                    m_CurveVertices[vcount - 1] = v1 + (v2 - v1) * clip;
                }
                break;
            }
        }

        if (vcount > 1)
        {
            Handles.color = Color.white * 0.9f;
            Handles.DrawAAPolyLine(2f, vcount, m_CurveVertices);
        }
    }