浏览代码

- Split shadow setting relevant to the scene from the HDRenderLoop ShadowSettings structure to the CommonSettings component.

- Made sure everything worked fine with multi-editing.
/main
Julien Ignace 8 年前
当前提交
d3f35f1a
共有 4 个文件被更改,包括 146 次插入28 次删除
  1. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  2. 25
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 37
      Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/CommonSettings.cs
  4. 98
      Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/Editor/CommonSettingsEditor.cs

14
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent shadowsAtlasWidth = new GUIContent("Atlas width");
public readonly GUIContent shadowsAtlasHeight = new GUIContent("Atlas height");
public readonly GUIContent shadowsMaxShadowDistance = new GUIContent("Maximum shadow distance");
public readonly GUIContent shadowsDirectionalLightCascadeCount = new GUIContent("Directional cascade count");
public readonly GUIContent[] shadowsCascadeCounts = new GUIContent[] { new GUIContent("1"), new GUIContent("2"), new GUIContent("3"), new GUIContent("4") };
public readonly int[] shadowsCascadeCountValues = new int[] { 1, 2, 3, 4 };
public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop Settings");
public readonly string[] tileLightLoopDebugTileFlagStrings = new string[] { "Punctual Light", "Area Light", "Env Light"};
public readonly GUIContent splitLightEvaluation = new GUIContent("Split light and reflection evaluation", "Toggle");

shadowParameters.enabled = EditorGUILayout.Toggle(styles.shadowsEnabled, shadowParameters.enabled);
shadowParameters.shadowAtlasWidth = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasWidth, shadowParameters.shadowAtlasWidth));
shadowParameters.shadowAtlasHeight = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasHeight, shadowParameters.shadowAtlasHeight));
shadowParameters.maxShadowDistance = Mathf.Max(0, EditorGUILayout.FloatField(styles.shadowsMaxShadowDistance, shadowParameters.maxShadowDistance));
shadowParameters.directionalLightCascadeCount = EditorGUILayout.IntPopup(styles.shadowsDirectionalLightCascadeCount, shadowParameters.directionalLightCascadeCount, styles.shadowsCascadeCounts, styles.shadowsCascadeCountValues);
EditorGUI.indentLevel++;
for (int i = 0; i < shadowParameters.directionalLightCascadeCount - 1; i++)
{
shadowParameters.directionalLightCascades[i] = Mathf.Max(0, EditorGUILayout.FloatField(shadowParameters.directionalLightCascades[i]));
}
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint

25
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public Matrix4x4 invViewProjectionMatrix;
}
CommonSettings m_CommonSettings = null;
public CommonSettings commonSettings
{
set { m_CommonSettings = value; }
get { return m_CommonSettings; }
}
public override void Build()
{
#if UNITY_EDITOR

m_lightLoop.PushGlobalParams(hdCamera.camera, renderLoop);
}
void UpdateCommonSettings()
{
if(m_CommonSettings == null)
{
m_ShadowSettings.maxShadowDistance = ShadowSettings.Default.maxShadowDistance;
m_ShadowSettings.directionalLightCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
m_ShadowSettings.directionalLightCascades = ShadowSettings.Default.directionalLightCascades;
}
else
{
m_ShadowSettings.directionalLightCascadeCount = m_CommonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(m_CommonSettings.shadowCascadeSplit0, m_CommonSettings.shadowCascadeSplit1, m_CommonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
}
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
if (!m_LitRenderLoop.isInit)

// Do anything we need to do upon a new frame.
m_lightLoop.NewFrame();
UpdateCommonSettings();
// Set Frame constant buffer
// TODO...

37
Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/CommonSettings.cs


public class CommonSettings
: MonoBehaviour
{
[SerializeField]
private string m_SkyRendererTypeName = "";
[SerializeField] private string m_SkyRendererTypeName = ""; // Serialize a string because serialize a Type.
[SerializeField] float m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance;
[SerializeField] int m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
[SerializeField] float m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x;
[SerializeField] float m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y;
[SerializeField] float m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z;
public Type skyRendererType
{
set { m_SkyRendererTypeName = value != null ? value.FullName : ""; OnSkyRendererChanged(); }

public float shadowMaxDistance { set { m_ShadowMaxDistance = value; OnValidate(); } get { return m_ShadowMaxDistance; } }
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }
public float shadowCascadeSplit0 { set { m_ShadowCascadeSplit0 = value; OnValidate(); } get { return m_ShadowCascadeSplit0; } }
public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
void OnEnable()
{

return;
}
if (renderLoop.commonSettings == null)
renderLoop.commonSettings = this;
else if (renderLoop.commonSettings != this)
Debug.LogWarning("Only one CommonSettings can be setup at a time.");
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
{
return;
}
if (renderLoop.commonSettings == this)
renderLoop.commonSettings = null;
}
void OnValidate()
{
m_ShadowMaxDistance = Mathf.Max(0.0f, m_ShadowMaxDistance);
m_ShadowCascadeCount = Math.Min(4, Math.Max(1, m_ShadowCascadeCount));
m_ShadowCascadeSplit0 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit0));
m_ShadowCascadeSplit1 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit1));
m_ShadowCascadeSplit2 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit2));
}
void OnSkyRendererChanged()

98
Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/Editor/CommonSettingsEditor.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[CustomEditor(typeof(CommonSettings))]
[CanEditMultipleObjects]
public class CommonSettingsEditor
: Editor
{

public readonly GUIContent sky = new GUIContent("Sky");
public readonly GUIContent shadows = new GUIContent("Shadows");
public readonly GUIContent maxShadowDistance = new GUIContent("Maximum shadow distance");
public readonly GUIContent shadowsDirectionalLightCascadeCount = new GUIContent("Directional cascade count");
public readonly GUIContent[] shadowsCascadeCounts = new GUIContent[] { new GUIContent("1"), new GUIContent("2"), new GUIContent("3"), new GUIContent("4") };
public readonly int[] shadowsCascadeCountValues = new int[] { 1, 2, 3, 4 };
public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent[] shadowSplits = new GUIContent[] { new GUIContent("Split 0"), new GUIContent("Split 1"), new GUIContent("Split 2") };
}
private static Styles s_Styles = null;

}
}
private List<Type> m_SkyRendererTypes;
// Sky renderer
List<Type> m_SkyRendererTypes = new List<Type>();
private List<string> m_SkyRendererFullTypeNames = new List<string>();
private bool multipleEditing { get { return targets.Length > 1; } }
private SerializedProperty m_SkyRenderer;
private SerializedProperty m_ShadowMaxDistance;
private SerializedProperty m_ShadowCascadeCount;
private SerializedProperty[] m_ShadowCascadeSplits = new SerializedProperty[3];
m_SkyRenderer = serializedObject.FindProperty("m_SkyRendererTypeName");
m_ShadowMaxDistance = serializedObject.FindProperty("m_ShadowMaxDistance");
m_ShadowCascadeCount = serializedObject.FindProperty("m_ShadowCascadeCount");
for (int i = 0; i < 3; ++i)
m_ShadowCascadeSplits[i] = serializedObject.FindProperty(string.Format("m_ShadowCascadeSplit{0}", i));
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(SkyRenderer)) && !t.IsGenericType)
.ToList();
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(SkyRenderer)) && !t.IsGenericType)
.ToList();
m_SkyRendererFullTypeNames.Clear();
for(int i = 0 ; i < m_SkyRendererTypes.Count ; ++i)
for (int i = 0; i < m_SkyRendererTypes.Count; ++i)
m_SkyRendererFullTypeNames.Add(longName);
char[] separators = {'.'};
string[] tokens = longName.Split(separators);
m_SkyRendererTypeNames.Add(new GUIContent(tokens[tokens.Length - 1]));

// Add default null value.
m_SkyRendererTypeNames.Add(styles.none);
m_SkyRendererFullTypeNames.Add("");
public override void OnInspectorGUI()
void OnSkyInspectorGUI()
serializedObject.Update();
EditorGUILayout.LabelField(styles.sky);
EditorGUI.indentLevel++;
CommonSettings settings = target as CommonSettings;
// Retrieve the index of the current SkyRenderer
// Retrieve the index of the current SkyRenderer. Won't be used in case of multiple editing with different values
for(int i = 0 ; i < m_SkyRendererTypeValues.Count ; ++i )
for (int i = 0; i < m_SkyRendererTypeNames.Count; ++i)
if(m_SkyRendererTypes[i] == settings.skyRendererType)
if (m_SkyRendererFullTypeNames[i] == m_SkyRenderer.stringValue)
{
index = i;
break;

EditorGUI.showMixedValue = m_SkyRenderer.hasMultipleDifferentValues;
if (EditorGUI.EndChangeCheck())
{
m_SkyRenderer.stringValue = m_SkyRendererFullTypeNames[newValue];
}
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;
}
void OnShadowInspectorGUI()
{
EditorGUILayout.LabelField(styles.shadows);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_ShadowMaxDistance, styles.maxShadowDistance);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = m_ShadowCascadeCount.hasMultipleDifferentValues;
int newCascadeCount = EditorGUILayout.IntPopup(styles.shadowsDirectionalLightCascadeCount, m_ShadowCascadeCount.intValue, styles.shadowsCascadeCounts, styles.shadowsCascadeCountValues);
settings.skyRendererType = m_SkyRendererTypes[newValue];
m_ShadowCascadeCount.intValue = newCascadeCount;
}
// Compute max cascade count.
int maxCascadeCount = 0;
for (int i = 0; i < targets.Length; ++i)
{
CommonSettings settings = targets[i] as CommonSettings;
maxCascadeCount = Math.Max(maxCascadeCount, settings.shadowCascadeCount);
EditorGUI.indentLevel++;
for (int i = 0; i < maxCascadeCount - 1; i++)
{
EditorGUILayout.PropertyField(m_ShadowCascadeSplits[i], styles.shadowSplits[i]);
}
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
OnSkyInspectorGUI();
OnShadowInspectorGUI();
serializedObject.ApplyModifiedProperties();
}
正在加载...
取消
保存