Skip to content

Commit

Permalink
com.unity.render-pipelines.core@1.1.2-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Jul 10, 2019
1 parent 6a0d3c5 commit 5406e86
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CoreRP/Editor/Debugging/DebugState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
36 changes: 22 additions & 14 deletions CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -132,15 +133,22 @@ 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.");
}
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())
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions CoreRP/Editor/Debugging/DebugUIDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
35 changes: 25 additions & 10 deletions CoreRP/Editor/Debugging/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void OnEnable()
void OnDestroy()
{
DebugManager.instance.onSetDirty -= MarkDirty;
Undo.ClearUndo(m_Settings);

if (m_WidgetStates != null)
{
Expand Down Expand Up @@ -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()
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions CoreRP/ShaderLibrary/Packing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 5406e86

Please sign in to comment.