Skip to content

Commit 5c2ac6a

Browse files
CalChiuEvergreen
authored andcommitted
[Port] [6000.4] [UUM-126982] Fixed STP and Reflection Probe Atlas rendering debug overlay behavior
1 parent 3429031 commit 5c2ac6a

2 files changed

Lines changed: 115 additions & 106 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsRendering.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ public enum TaaDebugMode
194194
/// </summary>
195195
public TaaDebugMode taaDebugMode { get; set; } = TaaDebugMode.None;
196196

197+
/// <summary>
198+
/// Whether to block the Reflection Probe Atlas overlay display. Returns true when the relevant overlay is selected
199+
/// but the main camera's rendering mode doesn't support displaying the Reflection Probe Atlas.
200+
/// </summary>
201+
internal bool blockReflectionProbeAtlasOverlay
202+
{
203+
get
204+
{
205+
var camera = Camera.main;
206+
return camera == null ? false :
207+
(fullScreenDebugMode == DebugFullScreenMode.ReflectionProbeAtlas && !(camera.GetUniversalAdditionalCameraData().scriptableRenderer as UniversalRenderer).usesClusterLightLoop);
208+
}
209+
}
210+
197211
#region Pixel validation
198212

199213
/// <summary>
@@ -223,6 +237,7 @@ static class Strings
223237
public const string RangeValidationSettingsContainerName = "Pixel Range Settings";
224238

225239
public static readonly NameAndTooltip MapOverlays = new() { name = "Map Overlays", tooltip = "Overlays render pipeline textures to validate the scene." };
240+
public static readonly NameAndTooltip ReflectionProbeAtlasDebugWarning = new() { name = "Warning: Reflection Probe Atlas visualization not supported for the current rendering path. Switch to Forward+ or Deferred+ to use this debug view.", tooltip = "Switch to Forward+ or Deferred+ in the main camera's Universal Renderer Data asset to use this debug overlay." };
226241
public static readonly NameAndTooltip StpDebugViews = new() { name = "STP Debug Views", tooltip = "Debug visualizations provided by STP." };
227242
public static readonly NameAndTooltip MapSize = new() { name = "Map Size", tooltip = "Set the size of the render pipeline texture in the scene." };
228243
public static readonly NameAndTooltip AdditionalWireframeModes = new() { name = "Additional Wireframe Modes", tooltip = "Debug the scene with additional wireframe shader views that are different from those in the scene view." };
@@ -277,9 +292,16 @@ internal static class WidgetFactory
277292
{
278293
children =
279294
{
295+
new DebugUI.MessageBox
296+
{
297+
nameAndTooltip = Strings.ReflectionProbeAtlasDebugWarning,
298+
style = DebugUI.MessageBox.Style.Warning,
299+
isHiddenCallback = () => !panel.data.blockReflectionProbeAtlasOverlay,
300+
},
280301
new DebugUI.IntField
281302
{
282303
nameAndTooltip = Strings.MapSize,
304+
isHiddenCallback = () => panel.data.blockReflectionProbeAtlasOverlay,
283305
getter = () => panel.data.fullScreenDebugModeOutputSizeScreenPercent,
284306
setter = value => panel.data.fullScreenDebugModeOutputSizeScreenPercent = value,
285307
incStep = 10,

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRendererDebug.cs

Lines changed: 93 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ private Rect CalculateUVRect(UniversalCameraData cameraData, float width, float
3838
return new Rect(1 - normalizedSizeX, 1 - normalizedSizeY, normalizedSizeX, normalizedSizeY);
3939
}
4040

41-
private Rect CalculateUVRect(UniversalCameraData cameraData, int textureHeightPercent)
42-
{
43-
var relativeSize = Mathf.Clamp01(textureHeightPercent / 100f);
44-
var width = relativeSize * cameraData.pixelWidth;
45-
var height = relativeSize * cameraData.pixelHeight;
46-
47-
return CalculateUVRect(cameraData, width, height);
48-
}
49-
5041
private void CorrectForTextureAspectRatio(ref float width, ref float height, float sourceWidth, float sourceHeight)
5142
{
5243
if (sourceWidth != 0 && sourceHeight != 0)
@@ -72,9 +63,20 @@ private void SetupRenderGraphFinalPassDebug(RenderGraph renderGraph, ContextCont
7263
if ((DebugHandler != null) && DebugHandler.IsActiveForCamera(cameraData.isPreviewCamera))
7364
{
7465
if (DebugHandler.TryGetFullscreenDebugMode(out DebugFullScreenMode fullScreenDebugMode, out int textureHeightPercent) &&
75-
(fullScreenDebugMode != DebugFullScreenMode.ReflectionProbeAtlas || usesClusterLightLoop) &&
76-
(fullScreenDebugMode != DebugFullScreenMode.STP))
66+
(fullScreenDebugMode != DebugFullScreenMode.ReflectionProbeAtlas || usesClusterLightLoop))
7767
{
68+
// if we want to visualize RG internal resources, we need to create an RTHandle external to RG and copy to it the textures to visualize
69+
// this is required because the lifetime of these resources is limited to the RenderGraph execution, and we cannot access the actual resources here
70+
71+
// we also copy external resources into the debug texture below to make them "read only". CreateDebugTexture() can lead to (external) texture reallocation.
72+
73+
var debugDescriptor = cameraData.cameraTargetDescriptor;
74+
// Ensure target can hold all source values. Source can be signed for example.
75+
if (SystemInfo.IsFormatSupported(GraphicsFormat.R16G16B16A16_SFloat, GraphicsFormatUsage.Linear | GraphicsFormatUsage.Render))
76+
debugDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat;
77+
78+
CreateDebugTexture(debugDescriptor);
79+
7880
float screenWidth = cameraData.pixelWidth;
7981
float screenHeight = cameraData.pixelHeight;
8082

@@ -85,107 +87,98 @@ private void SetupRenderGraphFinalPassDebug(RenderGraph renderGraph, ContextCont
8587
bool supportsStereo = false;
8688
Vector4 dataRangeRemap = Vector4.zero; // zero = off, .x = old min, .y = old max, .z = new min, .w = new max
8789

88-
// visualize RG internal resources
90+
// The debug texture for STP is filled later during post-process rendering so we cannot assign the resource now or it will be invalid
91+
if (fullScreenDebugMode != DebugFullScreenMode.STP)
8992
{
90-
// if we want to visualize RG internal resources, we need to create an RTHandle external to RG and copy to it the textures to visualize
91-
// this is required because the lifetime of these resources is limited to the RenderGraph execution, and we cannot access the actual resources here
92-
93-
// we also copy external resources to make them "read only". CreateDebugTexture() can lead to (external) texture reallocation.
94-
95-
var debugDescriptor = cameraData.cameraTargetDescriptor;
96-
// Ensure target can hold all source values. Source can be signed for example.
97-
if(SystemInfo.IsFormatSupported(GraphicsFormat.R16G16B16A16_SFloat, GraphicsFormatUsage.Linear | GraphicsFormatUsage.Render))
98-
debugDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat;
99-
100-
CreateDebugTexture(debugDescriptor);
101-
102-
ImportResourceParams importParams = new ImportResourceParams();
103-
importParams.clearOnFirstUse = false;
104-
importParams.discardOnLastUse = false;
105-
TextureHandle debugTexture = renderGraph.ImportTexture(s_RenderGraphDebugTextureHandle, importParams);
93+
// Render into the debug texture
94+
{
95+
ImportResourceParams importParams = new ImportResourceParams();
96+
importParams.clearOnFirstUse = false;
97+
importParams.discardOnLastUse = false;
98+
TextureHandle debugTexture = renderGraph.ImportTexture(s_RenderGraphDebugTextureHandle, importParams);
10699

107100

108-
switch (fullScreenDebugMode)
109-
{
110-
case DebugFullScreenMode.Depth:
111-
{
112-
BlitToDebugTexture(renderGraph, resourceData.cameraDepthTexture, debugTexture);
113-
supportsStereo = true;
114-
break;
115-
}
116-
case DebugFullScreenMode.MotionVector:
117-
{
118-
BlitToDebugTexture(renderGraph, resourceData.motionVectorColor, debugTexture, isSourceTextureColor: true);
119-
supportsStereo = true;
120-
// Motion vectors are in signed UV space, zoom in and normalize for visualization. (note: maybe add an option to use (angle, mag) visualization)
121-
const float zoom = 0.01f;
122-
dataRangeRemap.x = -zoom;
123-
dataRangeRemap.y = zoom;
124-
dataRangeRemap.z = 0;
125-
dataRangeRemap.w = 1.0f;
126-
break;
127-
}
128-
case DebugFullScreenMode.AdditionalLightsShadowMap:
129-
{
130-
BlitToDebugTexture(renderGraph, resourceData.additionalShadowsTexture, debugTexture);
131-
break;
132-
}
133-
case DebugFullScreenMode.MainLightShadowMap:
134-
{
135-
BlitToDebugTexture(renderGraph, resourceData.mainShadowsTexture, debugTexture);
136-
break;
137-
}
138-
case DebugFullScreenMode.AdditionalLightsCookieAtlas:
101+
switch (fullScreenDebugMode)
139102
{
140-
// Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
141-
var textureHandle =
142-
m_LightCookieManager is { AdditionalLightsCookieAtlasTexture: not null }
143-
? renderGraph.ImportTexture(m_LightCookieManager
144-
.AdditionalLightsCookieAtlasTexture)
145-
: TextureHandle.nullHandle;
146-
147-
BlitToDebugTexture(renderGraph, textureHandle, debugTexture);
148-
break;
103+
case DebugFullScreenMode.Depth:
104+
{
105+
BlitToDebugTexture(renderGraph, resourceData.cameraDepthTexture, debugTexture);
106+
supportsStereo = true;
107+
break;
108+
}
109+
case DebugFullScreenMode.MotionVector:
110+
{
111+
BlitToDebugTexture(renderGraph, resourceData.motionVectorColor, debugTexture, isSourceTextureColor: true);
112+
supportsStereo = true;
113+
// Motion vectors are in signed UV space, zoom in and normalize for visualization. (note: maybe add an option to use (angle, mag) visualization)
114+
const float zoom = 0.01f;
115+
dataRangeRemap.x = -zoom;
116+
dataRangeRemap.y = zoom;
117+
dataRangeRemap.z = 0;
118+
dataRangeRemap.w = 1.0f;
119+
break;
120+
}
121+
case DebugFullScreenMode.AdditionalLightsShadowMap:
122+
{
123+
BlitToDebugTexture(renderGraph, resourceData.additionalShadowsTexture, debugTexture);
124+
break;
125+
}
126+
case DebugFullScreenMode.MainLightShadowMap:
127+
{
128+
BlitToDebugTexture(renderGraph, resourceData.mainShadowsTexture, debugTexture);
129+
break;
130+
}
131+
case DebugFullScreenMode.AdditionalLightsCookieAtlas:
132+
{
133+
// Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
134+
var textureHandle =
135+
m_LightCookieManager is { AdditionalLightsCookieAtlasTexture: not null }
136+
? renderGraph.ImportTexture(m_LightCookieManager
137+
.AdditionalLightsCookieAtlasTexture)
138+
: TextureHandle.nullHandle;
139+
140+
BlitToDebugTexture(renderGraph, textureHandle, debugTexture);
141+
break;
142+
}
143+
144+
case DebugFullScreenMode.ReflectionProbeAtlas:
145+
{
146+
// Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
147+
var textureHandle =
148+
m_ForwardLights.reflectionProbeManager.atlasRT != null
149+
? renderGraph.ImportTexture(RTHandles.Alloc(
150+
m_ForwardLights.reflectionProbeManager.atlasRT, transferOwnership: true))
151+
: TextureHandle.nullHandle;
152+
153+
BlitToDebugTexture(renderGraph, textureHandle, debugTexture);
154+
break;
155+
}
156+
default:
157+
{
158+
break;
159+
}
149160
}
161+
}
150162

151-
case DebugFullScreenMode.ReflectionProbeAtlas:
152-
{
153-
// Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
154-
var textureHandle =
155-
m_ForwardLights.reflectionProbeManager.atlasRT != null
156-
? renderGraph.ImportTexture(RTHandles.Alloc(
157-
m_ForwardLights.reflectionProbeManager.atlasRT, transferOwnership: true))
158-
: TextureHandle.nullHandle;
159-
160-
BlitToDebugTexture(renderGraph, textureHandle, debugTexture);
161-
break;
162-
}
163-
default:
163+
// Textures that are not in screen aspect ratio need to be corrected
164+
{
165+
RenderTexture source = null;
166+
switch (fullScreenDebugMode)
164167
{
165-
break;
168+
case DebugFullScreenMode.AdditionalLightsShadowMap: source = m_AdditionalLightsShadowCasterPass?.m_AdditionalLightsShadowmapHandle?.rt; break;
169+
case DebugFullScreenMode.MainLightShadowMap: source = m_MainLightShadowCasterPass?.m_MainLightShadowmapTexture?.rt; break;
170+
case DebugFullScreenMode.AdditionalLightsCookieAtlas: source = m_LightCookieManager?.AdditionalLightsCookieAtlasTexture?.rt; break;
171+
case DebugFullScreenMode.ReflectionProbeAtlas: source = m_ForwardLights?.reflectionProbeManager.atlasRT; break;
172+
default:
173+
break;
166174
}
167-
}
168-
}
169175

170-
// Textures that are not in screen aspect ratio need to be corrected
171-
{
172-
RenderTexture source = null;
173-
switch (fullScreenDebugMode)
174-
{
175-
case DebugFullScreenMode.AdditionalLightsShadowMap: source = m_AdditionalLightsShadowCasterPass?.m_AdditionalLightsShadowmapHandle?.rt; break;
176-
case DebugFullScreenMode.MainLightShadowMap: source = m_MainLightShadowCasterPass?.m_MainLightShadowmapTexture?.rt; break;
177-
case DebugFullScreenMode.AdditionalLightsCookieAtlas: source = m_LightCookieManager?.AdditionalLightsCookieAtlasTexture?.rt; break;
178-
case DebugFullScreenMode.ReflectionProbeAtlas: source = m_ForwardLights?.reflectionProbeManager.atlasRT; break;
179-
default:
180-
break;
176+
// Ensure that atlas is not stretched, but doesn't take up more than the percentage in any dimension.
177+
if (source != null)
178+
CorrectForTextureAspectRatio(ref width, ref height, source.width, source.height);
181179
}
182-
183-
// Ensure that atlas is not stretched, but doesn't take up more than the percentage in any dimension.
184-
if (source != null)
185-
CorrectForTextureAspectRatio(ref width, ref height, source.width, source.height);
186180
}
187181

188-
189182
Rect uvRect = CalculateUVRect(cameraData, width, height);
190183
DebugHandler.SetDebugRenderTarget(s_RenderGraphDebugTextureHandle, uvRect, supportsStereo, dataRangeRemap);
191184
}
@@ -221,17 +214,11 @@ private void SetupAfterPostRenderGraphFinalPassDebug(RenderGraph renderGraph, Co
221214
if (DebugHandler.TryGetFullscreenDebugMode(out var debugFullscreenMode, out int textureHeightPercent) &&
222215
(debugFullscreenMode == DebugFullScreenMode.STP))
223216
{
224-
CreateDebugTexture(cameraData.cameraTargetDescriptor);
225-
226217
ImportResourceParams importParams = new ImportResourceParams();
227218
importParams.clearOnFirstUse = false;
228219
importParams.discardOnLastUse = false;
229220
TextureHandle debugTexture = renderGraph.ImportTexture(s_RenderGraphDebugTextureHandle, importParams);
230221
BlitToDebugTexture(renderGraph, resourceData.stpDebugView, debugTexture);
231-
232-
Rect uvRect = CalculateUVRect(cameraData, textureHeightPercent);
233-
Vector4 rangeRemap = Vector4.zero; // Off
234-
DebugHandler.SetDebugRenderTarget(s_RenderGraphDebugTextureHandle, uvRect, true, rangeRemap);
235222
}
236223
}
237224
}

0 commit comments

Comments
 (0)