Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 0d5fc87

Browse files
committed
Added debug overlays
1 parent 5a16935 commit 0d5fc87

22 files changed

Lines changed: 828 additions & 143 deletions

PostProcessing/Editor/PostProcessDebugEditor.cs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEngine;
1+
using UnityEngine;
22
using UnityEngine.Rendering.PostProcessing;
33

44
namespace UnityEditor.Rendering.PostProcessing
@@ -11,12 +11,17 @@ public sealed class PostProcessDebugEditor : BaseEditor<PostProcessDebug>
1111
SerializedProperty m_HistogramEnabled;
1212
SerializedProperty m_WaveformEnabled;
1313
SerializedProperty m_VectorscopeEnabled;
14+
SerializedProperty m_Overlay;
15+
16+
SerializedObject m_LayerObject;
1417

15-
SerializedObject m_Monitors;
1618
SerializedProperty m_LightMeterShowCurves;
1719
SerializedProperty m_HistogramChannel;
1820
SerializedProperty m_WaveformExposure;
1921
SerializedProperty m_VectorscopeExposure;
22+
23+
SerializedProperty m_MotionColorIntensity;
24+
SerializedProperty m_MotionGridSize;
2025

2126
void OnEnable()
2227
{
@@ -25,6 +30,7 @@ void OnEnable()
2530
m_HistogramEnabled = FindProperty(x => x.histogram);
2631
m_WaveformEnabled = FindProperty(x => x.waveform);
2732
m_VectorscopeEnabled = FindProperty(x => x.vectorscope);
33+
m_Overlay = FindProperty(x => x.debugOverlay);
2834

2935
if (m_PostProcessLayer.objectReferenceValue != null)
3036
RebuildProperties();
@@ -35,12 +41,15 @@ void RebuildProperties()
3541
if (m_PostProcessLayer.objectReferenceValue == null)
3642
return;
3743

38-
m_Monitors = new SerializedObject(m_Target.postProcessLayer);
44+
m_LayerObject = new SerializedObject(m_Target.postProcessLayer);
45+
46+
m_LightMeterShowCurves = m_LayerObject.FindProperty("debugLayer.lightMeter.showCurves");
47+
m_HistogramChannel = m_LayerObject.FindProperty("debugLayer.histogram.channel");
48+
m_WaveformExposure = m_LayerObject.FindProperty("debugLayer.waveform.exposure");
49+
m_VectorscopeExposure = m_LayerObject.FindProperty("debugLayer.vectorscope.exposure");
3950

40-
m_LightMeterShowCurves = m_Monitors.FindProperty("monitors.lightMeter.showCurves");
41-
m_HistogramChannel = m_Monitors.FindProperty("monitors.histogram.channel");
42-
m_WaveformExposure = m_Monitors.FindProperty("monitors.waveform.exposure");
43-
m_VectorscopeExposure = m_Monitors.FindProperty("monitors.vectorscope.exposure");
51+
m_MotionColorIntensity = m_LayerObject.FindProperty("debugLayer.overlaySettings.motionColorIntensity");
52+
m_MotionGridSize = m_LayerObject.FindProperty("debugLayer.overlaySettings.motionGridSize");
4453
}
4554

4655
public override void OnInspectorGUI()
@@ -50,21 +59,41 @@ public override void OnInspectorGUI()
5059
using (var changed = new EditorGUI.ChangeCheckScope())
5160
{
5261
EditorGUILayout.PropertyField(m_PostProcessLayer);
62+
serializedObject.ApplyModifiedProperties(); // Needed to rebuild properties after a change
63+
serializedObject.Update();
5364

5465
if (changed.changed)
5566
RebuildProperties();
5667
}
5768

5869
if (m_PostProcessLayer.objectReferenceValue != null)
5970
{
60-
m_Monitors.Update();
71+
m_LayerObject.Update();
72+
73+
// Overlays
74+
EditorGUILayout.Space();
75+
EditorGUILayout.LabelField(EditorUtilities.GetContent("Overlay"), EditorStyles.boldLabel);
76+
EditorGUI.indentLevel++;
77+
EditorGUILayout.PropertyField(m_Overlay);
78+
DoOverlayGUI(DebugOverlay.MotionVectors, m_MotionColorIntensity, m_MotionGridSize);
79+
80+
// Special cases
81+
if (m_Overlay.intValue == (int)DebugOverlay.NANTracker && m_Target.postProcessLayer.stopNaNPropagation)
82+
EditorGUILayout.HelpBox("Disable \"Stop NaN Propagation\" in the Post-process layer or NaNs will be overwritten!", MessageType.Warning);
6183

84+
EditorGUI.indentLevel--;
85+
86+
// Monitors
87+
EditorGUILayout.Space();
88+
EditorGUILayout.LabelField(EditorUtilities.GetContent("Monitors"), EditorStyles.boldLabel);
89+
EditorGUI.indentLevel++;
6290
DoMonitorGUI(EditorUtilities.GetContent("Light Meter"), m_LightMeterEnabled, m_LightMeterShowCurves);
6391
DoMonitorGUI(EditorUtilities.GetContent("Histogram"), m_HistogramEnabled, m_HistogramChannel);
6492
DoMonitorGUI(EditorUtilities.GetContent("Waveform"), m_WaveformEnabled, m_WaveformExposure);
6593
DoMonitorGUI(EditorUtilities.GetContent("Vectoscope"), m_VectorscopeEnabled, m_VectorscopeExposure);
94+
EditorGUI.indentLevel--;
6695

67-
m_Monitors.ApplyModifiedProperties();
96+
m_LayerObject.ApplyModifiedProperties();
6897
}
6998

7099
serializedObject.ApplyModifiedProperties();
@@ -83,8 +112,19 @@ void DoMonitorGUI(GUIContent content, SerializedProperty prop, params Serialized
83112
foreach (var p in settings)
84113
EditorGUILayout.PropertyField(p);
85114
EditorGUI.indentLevel--;
86-
EditorGUILayout.Space();
87115
}
88116
}
117+
118+
void DoOverlayGUI(DebugOverlay overlay, params SerializedProperty[] settings)
119+
{
120+
if (m_Overlay.intValue != (int)overlay)
121+
return;
122+
123+
if (settings == null || settings.Length == 0)
124+
return;
125+
126+
foreach (var p in settings)
127+
EditorGUILayout.PropertyField(p);
128+
}
89129
}
90130
}
124 Bytes
Binary file not shown.

PostProcessing/Runtime/Effects/Bloom.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ enum Pass
5353
Downsample13,
5454
Downsample4,
5555
UpsampleTent,
56-
UpsampleBox
56+
UpsampleBox,
57+
DebugOverlayThreshold,
58+
DebugOverlayTent,
59+
DebugOverlayBox
5760
}
5861

5962
// [down,up]
@@ -146,12 +149,20 @@ public override void Render(PostProcessRenderContext context)
146149
last = mipUp;
147150
}
148151

149-
var shaderSettings = new Vector4(
150-
sampleScale,
151-
RuntimeUtilities.Exp2(settings.intensity.value / 10f) - 1f,
152-
settings.lensIntensity.value,
153-
iterations
154-
);
152+
var linearColor = settings.color.value.linear;
153+
float intensity = RuntimeUtilities.Exp2(settings.intensity.value / 10f) - 1f;
154+
var shaderSettings = new Vector4(sampleScale, intensity, settings.lensIntensity.value, iterations);
155+
156+
// Debug overlays
157+
if (context.IsDebugOverlayEnabled(DebugOverlay.BloomThreshold))
158+
{
159+
context.PushDebugOverlay(cmd, context.source, sheet, (int)Pass.DebugOverlayThreshold);
160+
}
161+
else if (context.IsDebugOverlayEnabled(DebugOverlay.BloomBuffer))
162+
{
163+
sheet.properties.SetVector(ShaderIDs.ColorIntensity, new Vector4(linearColor.r, linearColor.g, linearColor.b, intensity));
164+
context.PushDebugOverlay(cmd, m_Pyramid[0].up, sheet, (int)Pass.DebugOverlayTent + qualityOffset);
165+
}
155166

156167
// Lens dirtiness
157168
// Keep the aspect ratio correct & center the dirt texture, we don't want it to be
@@ -180,7 +191,7 @@ public override void Render(PostProcessRenderContext context)
180191
uberSheet.EnableKeyword("BLOOM");
181192
uberSheet.properties.SetVector(ShaderIDs.Bloom_DirtTileOffset, dirtTileOffset);
182193
uberSheet.properties.SetVector(ShaderIDs.Bloom_Settings, shaderSettings);
183-
uberSheet.properties.SetColor(ShaderIDs.Bloom_Color, settings.color.value.linear);
194+
uberSheet.properties.SetColor(ShaderIDs.Bloom_Color, linearColor);
184195
uberSheet.properties.SetTexture(ShaderIDs.Bloom_DirtTex, dirtTexture);
185196
cmd.SetGlobalTexture(ShaderIDs.BloomTex, m_Pyramid[0].up);
186197

PostProcessing/Runtime/Effects/DepthOfField.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ enum Pass
4444
BokehLargeKernel,
4545
BokehVeryLargeKernel,
4646
PostFilter,
47-
Combine
47+
Combine,
48+
DebugOverlay
4849
}
4950

5051
// Ping-pong between two history textures as we can't read & write the same target in the
@@ -165,6 +166,10 @@ public override void Render(PostProcessRenderContext context)
165166
cmd.BlitFullscreenTriangle(ShaderIDs.DepthOfFieldTemp, ShaderIDs.DepthOfFieldTex, sheet, (int)Pass.PostFilter);
166167
cmd.ReleaseTemporaryRT(ShaderIDs.DepthOfFieldTemp);
167168

169+
// Debug overlay pass
170+
if (context.IsDebugOverlayEnabled(DebugOverlay.DepthOfField))
171+
context.PushDebugOverlay(cmd, context.source, sheet, (int)Pass.DebugOverlay);
172+
168173
// Combine pass
169174
cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, (int)Pass.Combine);
170175
cmd.ReleaseTemporaryRT(ShaderIDs.DepthOfFieldTex);

PostProcessing/Runtime/Effects/MultiScaleVO.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ enum Pass
3838
{
3939
DepthCopy,
4040
CompositionDeferred,
41-
CompositionForward
41+
CompositionForward,
42+
DebugOverlay
4243
}
4344

4445
PropertySheet m_PropertySheet;
@@ -311,6 +312,9 @@ void RebuildCommandBuffers(PostProcessRenderContext context)
311312
PushUpsampleCommands(context, cmd, m_LowDepth3, m_Combined3, m_LowDepth2, m_Occlusion2, m_Combined2);
312313
PushUpsampleCommands(context, cmd, m_LowDepth2, m_Combined2, m_LowDepth1, m_Occlusion1, m_Combined1);
313314
PushUpsampleCommands(context, cmd, m_LowDepth1, m_Combined1, m_LinearDepth, null, m_Result);
315+
316+
if (context.IsDebugOverlayEnabled(DebugOverlay.AmbientOcclusion))
317+
context.PushDebugOverlay(cmd, m_Result.id, m_PropertySheet, (int)Pass.DebugOverlay);
314318
}
315319

316320
// Calculate values in _ZBuferParams (built-in shader variable)

PostProcessing/Runtime/Effects/ScalableAO.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace UnityEngine.Rendering.PostProcessing
44
{
@@ -48,7 +48,8 @@ enum Pass
4848
HorizontalBlurDeferred,
4949
VerticalBlur,
5050
CompositionForward,
51-
CompositionDeferred
51+
CompositionDeferred,
52+
DebugOverlay
5253
}
5354

5455
public DepthTextureMode GetCameraFlags()
@@ -147,6 +148,9 @@ void Render(PostProcessRenderContext context, CommandBuffer cmd, int occlusionSo
147148
// Separable blur (vertical pass)
148149
cmd.BlitFullscreenTriangle(rtBlur, m_Result, sheet, (int)Pass.VerticalBlur);
149150
cmd.ReleaseTemporaryRT(rtBlur);
151+
152+
if (context.IsDebugOverlayEnabled(DebugOverlay.AmbientOcclusion))
153+
context.PushDebugOverlay(cmd, m_Result, sheet, (int)Pass.DebugOverlay);
150154
}
151155

152156
public void RenderAfterOpaque(PostProcessRenderContext context)

PostProcessing/Runtime/PostProcessDebug.cs

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,113 @@
1-
namespace UnityEngine.Rendering.PostProcessing
1+
namespace UnityEngine.Rendering.PostProcessing
22
{
33
[ExecuteInEditMode]
44
public sealed class PostProcessDebug : MonoBehaviour
55
{
66
public PostProcessLayer postProcessLayer;
7+
PostProcessLayer m_PreviousPostProcessLayer;
78

89
public bool lightMeter;
910
public bool histogram;
1011
public bool waveform;
1112
public bool vectorscope;
1213

14+
public DebugOverlay debugOverlay = DebugOverlay.None;
15+
16+
Camera m_CurrentCamera;
17+
CommandBuffer m_CmdAfterEverything;
18+
19+
void OnEnable()
20+
{
21+
m_CmdAfterEverything = new CommandBuffer { name = "Post-processing Debug Overlay" };
22+
23+
#if UNITY_EDITOR
24+
// Update is only called on object change when ExecuteInEditMode is set, but we need it
25+
// to execute on every frame no matter what when not in play mode, so we'll use the
26+
// editor update loop instead...
27+
UnityEditor.EditorApplication.update += UpdateStates;
28+
#endif
29+
}
30+
31+
void OnDisable()
32+
{
33+
#if UNITY_EDITOR
34+
UnityEditor.EditorApplication.update -= UpdateStates;
35+
#endif
36+
37+
if (m_CurrentCamera != null)
38+
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
39+
40+
m_CurrentCamera = null;
41+
m_PreviousPostProcessLayer = null;
42+
}
43+
44+
#if !UNITY_EDITOR
45+
void Update()
46+
{
47+
UpdateStates();
48+
}
49+
#endif
50+
1351
void Reset()
1452
{
1553
postProcessLayer = GetComponent<PostProcessLayer>();
1654
}
1755

18-
void Update()
56+
void UpdateStates()
1957
{
20-
if (lightMeter) postProcessLayer.monitors.RequestMonitorPass(MonitorType.LightMeter);
21-
if (histogram) postProcessLayer.monitors.RequestMonitorPass(MonitorType.Histogram);
22-
if (waveform) postProcessLayer.monitors.RequestMonitorPass(MonitorType.Waveform);
23-
if (vectorscope) postProcessLayer.monitors.RequestMonitorPass(MonitorType.Vectorscope);
58+
if (m_PreviousPostProcessLayer != postProcessLayer)
59+
{
60+
// Remove cmdbuffer from previously set camera
61+
if (m_CurrentCamera != null)
62+
{
63+
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
64+
m_CurrentCamera = null;
65+
}
66+
67+
m_PreviousPostProcessLayer = postProcessLayer;
68+
69+
// Add cmdbuffer to the currently set camera
70+
if (postProcessLayer != null)
71+
{
72+
m_CurrentCamera = postProcessLayer.GetComponent<Camera>();
73+
m_CurrentCamera.AddCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
74+
}
75+
}
76+
77+
if (postProcessLayer == null || !postProcessLayer.enabled)
78+
return;
79+
80+
// Monitors
81+
if (lightMeter) postProcessLayer.debugLayer.RequestMonitorPass(MonitorType.LightMeter);
82+
if (histogram) postProcessLayer.debugLayer.RequestMonitorPass(MonitorType.Histogram);
83+
if (waveform) postProcessLayer.debugLayer.RequestMonitorPass(MonitorType.Waveform);
84+
if (vectorscope) postProcessLayer.debugLayer.RequestMonitorPass(MonitorType.Vectorscope);
85+
86+
// Overlay
87+
postProcessLayer.debugLayer.RequestDebugOverlay(debugOverlay);
88+
}
89+
90+
void OnPostRender()
91+
{
92+
m_CmdAfterEverything.Clear();
93+
94+
if (postProcessLayer == null || !postProcessLayer.enabled || !postProcessLayer.debugLayer.debugOverlayActive)
95+
return;
96+
97+
m_CmdAfterEverything.Blit(postProcessLayer.debugLayer.debugOverlayTarget, BuiltinRenderTextureType.CameraTarget);
2498
}
2599

26100
void OnGUI()
27101
{
28102
if (postProcessLayer == null || !postProcessLayer.enabled)
29103
return;
30104

31-
var monitors = postProcessLayer.monitors;
32105
var rect = new Rect(5, 5, 0, 0);
33-
34-
DrawMonitor(ref rect, monitors.lightMeter, lightMeter);
35-
DrawMonitor(ref rect, monitors.histogram, histogram);
36-
DrawMonitor(ref rect, monitors.waveform, waveform);
37-
DrawMonitor(ref rect, monitors.vectorscope, vectorscope);
106+
var debugLayer = postProcessLayer.debugLayer;
107+
DrawMonitor(ref rect, debugLayer.lightMeter, lightMeter);
108+
DrawMonitor(ref rect, debugLayer.histogram, histogram);
109+
DrawMonitor(ref rect, debugLayer.waveform, waveform);
110+
DrawMonitor(ref rect, debugLayer.vectorscope, vectorscope);
38111
}
39112

40113
void DrawMonitor(ref Rect rect, Monitor monitor, bool enabled)
@@ -49,4 +122,3 @@ void DrawMonitor(ref Rect rect, Monitor monitor, bool enabled)
49122
}
50123
}
51124
}
52-

0 commit comments

Comments
 (0)