diff --git a/CoreRP/Editor/Debugging/DebugState.cs b/CoreRP/Editor/Debugging/DebugState.cs index dc0d485..b76c2e6 100644 --- a/CoreRP/Editor/Debugging/DebugState.cs +++ b/CoreRP/Editor/Debugging/DebugState.cs @@ -10,6 +10,12 @@ public abstract class DebugState : ScriptableObject [SerializeField] protected string m_QueryPath; + // We need this to keep track of the state modified in the current frame. + // This helps reduces the cost of re-applying states to original widgets and is also needed + // when two states point to the same value (e.g. when using split enums like HDRP does for + // the `fullscreenDebugMode`. + internal static DebugState m_CurrentDirtyState; + public string queryPath { get { return m_QueryPath; } diff --git a/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs b/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs index e564c60..5a9230e 100644 --- a/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs +++ b/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; using UnityEngine.Experimental.Rendering; @@ -44,7 +45,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); var rect = PrepareControlRect(); - bool value = EditorGUI.Toggle(rect, CoreEditorUtils.GetContent(w.displayName), s.value); + bool value = EditorGUI.Toggle(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -65,8 +66,8 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) var rect = PrepareControlRect(); int value = w.min != null && w.max != null - ? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.min(), w.max()) - : EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), s.value); + ? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.min(), w.max()) + : EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -88,8 +89,8 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) // No UIntField so we need to max to 0 ourselves or the value will wrap around var rect = PrepareControlRect(); int tmp = w.min != null && w.max != null - ? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)s.value), Mathf.Max(0, (int)w.min()), Mathf.Max(0, (int)w.max())) - : EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)s.value)); + ? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)w.GetValue()), Mathf.Max(0, (int)w.min()), Mathf.Max(0, (int)w.max())) + : EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)w.GetValue())); uint value = (uint)Mathf.Max(0, tmp); @@ -112,8 +113,8 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) var rect = PrepareControlRect(); float value = w.min != null && w.max != null - ? EditorGUI.Slider(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.min(), w.max()) - : EditorGUI.FloatField(rect, CoreEditorUtils.GetContent(w.displayName), s.value); + ? EditorGUI.Slider(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.min(), w.max()) + : EditorGUI.FloatField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -132,7 +133,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); - int value = s.value; + int value = w.GetValue(); if (w.enumNames == null || w.enumValues == null) { EditorGUILayout.LabelField("Can't draw an empty enumeration."); @@ -140,7 +141,14 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) else { var rect = PrepareControlRect(); - value = EditorGUI.IntPopup(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.enumNames, w.enumValues); + + int index = Array.IndexOf(w.enumValues, w.GetValue()); + + // Fallback just in case, we may be handling sub/sectionned enums here + if (index < 0) + value = w.enumValues[0]; + + value = EditorGUI.IntPopup(rect, CoreEditorUtils.GetContent(w.displayName), value, w.enumNames, w.enumValues); } if (EditorGUI.EndChangeCheck()) @@ -160,7 +168,7 @@ public override void Begin(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); - bool value = EditorGUILayout.Foldout(s.value, CoreEditorUtils.GetContent(w.displayName), true); + bool value = EditorGUILayout.Foldout(w.GetValue(), CoreEditorUtils.GetContent(w.displayName), true); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -191,7 +199,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); var rect = PrepareControlRect(); - var value = EditorGUI.ColorField(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.showPicker, w.showAlpha, w.hdr); + var value = EditorGUI.ColorField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.showPicker, w.showAlpha, w.hdr); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -210,7 +218,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); - var value = EditorGUILayout.Vector2Field(w.displayName, s.value); + var value = EditorGUILayout.Vector2Field(w.displayName, w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -229,7 +237,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); - var value = EditorGUILayout.Vector3Field(w.displayName, s.value); + var value = EditorGUILayout.Vector3Field(w.displayName, w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); @@ -248,7 +256,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state) EditorGUI.BeginChangeCheck(); - var value = EditorGUILayout.Vector4Field(w.displayName, s.value); + var value = EditorGUILayout.Vector4Field(w.displayName, w.GetValue()); if (EditorGUI.EndChangeCheck()) Apply(w, s, value); diff --git a/CoreRP/Editor/Debugging/DebugUIDrawer.cs b/CoreRP/Editor/Debugging/DebugUIDrawer.cs index e006adc..8455c49 100644 --- a/CoreRP/Editor/Debugging/DebugUIDrawer.cs +++ b/CoreRP/Editor/Debugging/DebugUIDrawer.cs @@ -45,6 +45,7 @@ protected void Apply(DebugUI.IValueField widget, DebugState state, object value) state.SetValue(value, widget); widget.SetValue(value); EditorUtility.SetDirty(state); + DebugState.m_CurrentDirtyState = state; UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); } diff --git a/CoreRP/Editor/Debugging/DebugWindow.cs b/CoreRP/Editor/Debugging/DebugWindow.cs index ab41f4d..3939432 100644 --- a/CoreRP/Editor/Debugging/DebugWindow.cs +++ b/CoreRP/Editor/Debugging/DebugWindow.cs @@ -137,6 +137,7 @@ void OnEnable() void OnDestroy() { DebugManager.instance.onSetDirty -= MarkDirty; + Undo.ClearUndo(m_Settings); if (m_WidgetStates != null) { @@ -210,17 +211,29 @@ void UpdateWidgetStates(DebugUI.IContainer container) } } - public void ApplyStates() + public void ApplyStates(bool forceApplyAll = false) { - foreach (var state in m_WidgetStates) + if (!forceApplyAll && DebugState.m_CurrentDirtyState != null) { - var widget = DebugManager.instance.GetItem(state.Key) as DebugUI.IValueField; + ApplyState(DebugState.m_CurrentDirtyState.queryPath, DebugState.m_CurrentDirtyState); + DebugState.m_CurrentDirtyState = null; + return; + } - if (widget == null) - continue; + foreach (var state in m_WidgetStates) + ApplyState(state.Key, state.Value); - widget.SetValue(state.Value.GetValue()); - } + DebugState.m_CurrentDirtyState = null; + } + + void ApplyState(string queryPath, DebugState state) + { + var widget = DebugManager.instance.GetItem(queryPath) as DebugUI.IValueField; + + if (widget == null) + return; + + widget.SetValue(state.GetValue()); } void OnUndoRedoPerformed() @@ -230,7 +243,7 @@ void OnUndoRedoPerformed() // Something has been undone / redone, re-apply states to the debug tree if (stateHash != m_Settings.currentStateHash) { - ApplyStates(); + ApplyStates(true); m_Settings.currentStateHash = stateHash; } @@ -330,9 +343,11 @@ void OnGUI() if (m_Settings.selectedPanel == i && Event.current.type == EventType.Repaint) s_Styles.selected.Draw(elementRect, false, false, false, false); - if (GUI.Toggle(elementRect, m_Settings.selectedPanel == i, panel.displayName, s_Styles.sectionElement)) + EditorGUI.BeginChangeCheck(); + GUI.Toggle(elementRect, m_Settings.selectedPanel == i, panel.displayName, s_Styles.sectionElement); + if (EditorGUI.EndChangeCheck()) { - Undo.RecordObject(m_Settings, "Debug Panel Selection"); + Undo.RegisterCompleteObjectUndo(m_Settings, "Debug Panel Selection"); m_Settings.selectedPanel = i; } } diff --git a/CoreRP/ShaderLibrary/Packing.hlsl b/CoreRP/ShaderLibrary/Packing.hlsl index 567f661..53f1897 100644 --- a/CoreRP/ShaderLibrary/Packing.hlsl +++ b/CoreRP/ShaderLibrary/Packing.hlsl @@ -169,6 +169,11 @@ real3 UnpackNormalRGB(real4 packedNormal, real scale = 1.0) return normalize(normal); } +real3 UnpackNormalRGBNoScale(real4 packedNormal) +{ + return packedNormal.rgb * 2.0 - 1.0; +} + real3 UnpackNormalAG(real4 packedNormal, real scale = 1.0) { real3 normal; diff --git a/package.json b/package.json index d411ae7..8abc7e3 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "com.unity.render-pipelines.core", "description": "Core library for Unity render pipelines.", - "version": "1.1.1-preview", + "version": "1.1.2-preview", "unity": "2018.1", "dependencies": { - "com.unity.postprocessing": "2.0.2-preview" + "com.unity.postprocessing": "2.0.3-preview" } } \ No newline at end of file