private void DrawShadowCascades(int cascadeCount, bool useMetric, float baseMetric) { var cascades = new ShadowCascadeGUI.Cascade[cascadeCount]; float lastCascadePartitionSplit = 0; for (int i = 0; i < cascadeCount - 1; ++i) { cascades[i] = new ShadowCascadeGUI.Cascade() { size = i == 0 ? m_CascadeShadowSplits[i].value.floatValue : m_CascadeShadowSplits[i].value.floatValue - lastCascadePartitionSplit, // Calculate the size of cascade borderSize = m_CascadeShadowBorders[i].value.floatValue, cascadeHandleState = m_CascadeShadowSplits[i].overrideState.boolValue ? ShadowCascadeGUI.HandleState.Enabled : ShadowCascadeGUI.HandleState.Disabled, borderHandleState = m_CascadeShadowBorders[i].overrideState.boolValue ? ShadowCascadeGUI.HandleState.Enabled : ShadowCascadeGUI.HandleState.Disabled, }; lastCascadePartitionSplit = m_CascadeShadowSplits[i].value.floatValue; } // Last cascade is special var lastCascade = cascadeCount - 1; cascades[lastCascade] = new ShadowCascadeGUI.Cascade() { size = lastCascade == 0 ? 1.0f : 1 - m_CascadeShadowSplits[lastCascade - 1].value.floatValue, // Calculate the size of cascade borderSize = m_CascadeShadowBorders[lastCascade].value.floatValue, cascadeHandleState = ShadowCascadeGUI.HandleState.Hidden, borderHandleState = m_CascadeShadowBorders[lastCascade].overrideState.boolValue ? ShadowCascadeGUI.HandleState.Enabled : ShadowCascadeGUI.HandleState.Disabled, }; EditorGUI.BeginChangeCheck(); ShadowCascadeGUI.DrawCascades(ref cascades, useMetric, baseMetric); if (EditorGUI.EndChangeCheck()) { float lastCascadeSize = 0; for (int i = 0; i < cascadeCount - 1; ++i) { m_CascadeShadowSplits[i].value.floatValue = lastCascadeSize + cascades[i].size; lastCascadeSize = m_CascadeShadowSplits[i].value.floatValue; } for (int i = 0; i < cascadeCount; ++i) { m_CascadeShadowBorders[i].value.floatValue = cascades[i].borderSize; } } }
private void DrawCascades(int cascadeCount, bool useMetric, float baseMetric) { var cascades = new ShadowCascadeGUI.Cascade[cascadeCount]; Vector3 shadowCascadeSplit = Vector3.zero; if (cascadeCount == 4) { shadowCascadeSplit = m_ShadowCascade4SplitProp.vector3Value; } else if (cascadeCount == 3) { shadowCascadeSplit = m_ShadowCascade3SplitProp.vector2Value; } else if (cascadeCount == 2) { shadowCascadeSplit.x = m_ShadowCascade2SplitProp.floatValue; } else { shadowCascadeSplit.x = m_ShadowCascade2SplitProp.floatValue; } float lastCascadePartitionSplit = 0; for (int i = 0; i < cascadeCount - 1; ++i) { cascades[i] = new ShadowCascadeGUI.Cascade() { size = i == 0 ? shadowCascadeSplit[i] : shadowCascadeSplit[i] - lastCascadePartitionSplit, // Calculate the size of cascade borderSize = 0, cascadeHandleState = ShadowCascadeGUI.HandleState.Enabled, borderHandleState = ShadowCascadeGUI.HandleState.Hidden, }; lastCascadePartitionSplit = shadowCascadeSplit[i]; } // Last cascade is special var lastCascade = cascadeCount - 1; cascades[lastCascade] = new ShadowCascadeGUI.Cascade() { size = lastCascade == 0 ? 1.0f : 1 - shadowCascadeSplit[lastCascade - 1], // Calculate the size of cascade borderSize = m_ShadowCascadeBorderProp.floatValue, cascadeHandleState = ShadowCascadeGUI.HandleState.Hidden, borderHandleState = ShadowCascadeGUI.HandleState.Enabled, }; EditorGUI.BeginChangeCheck(); ShadowCascadeGUI.DrawCascades(ref cascades, useMetric, baseMetric); if (EditorGUI.EndChangeCheck()) { if (cascadeCount == 4) { m_ShadowCascade4SplitProp.vector3Value = new Vector3( cascades[0].size, cascades[0].size + cascades[1].size, cascades[0].size + cascades[1].size + cascades[2].size ); } else if (cascadeCount == 3) { m_ShadowCascade3SplitProp.vector2Value = new Vector2( cascades[0].size, cascades[0].size + cascades[1].size ); } else if (cascadeCount == 2) { m_ShadowCascade2SplitProp.floatValue = cascades[0].size; } m_ShadowCascadeBorderProp.floatValue = cascades[lastCascade].borderSize; } }