Skip to content

Commit b6d2c3a

Browse files
eh-unityEvergreen
authored andcommitted
Graphics/urp/bugfix/uum 68008
Various fixes for Rendering Debugger "Map Overlays" for URP Render Graph and non-RenderGraph paths.
1 parent ddfa20d commit b6d2c3a

File tree

8 files changed

+176
-43
lines changed

8 files changed

+176
-43
lines changed

Packages/com.unity.render-pipelines.universal/Documentation~/features/rendering-debugger.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ The properties in this section let you visualize different rendering features.
147147

148148
| **Property** | **Description** |
149149
| ------------------------------ | ------------------------------------------------------------ |
150-
| **Map Overlays** | Specifies which render pipeline texture to overlay on the screen. The options are:<ul><li>**None**: Renders the scene normally without a texture overlay.</li><li>**Depth**: Overlays the camera's depth texture on the screen.</li><li>**Additional Lights Shadow Map**: Overlays the [shadow map](https://docs.unity3d.com/Manual/shadow-mapping.html) that contains shadows cast by lights other than the main directional light.</li><li>**Main Light Shadow Map**: Overlays the shadow map that contains shadows cast by the main directional light.</li></ul> |
150+
| **Map Overlays** | Specifies which render pipeline texture to overlay on the screen. The options are:<ul><li>**None**: Renders the scene normally without a texture overlay.</li><li>**Depth**: Overlays the camera's depth texture on the screen.</li><li>**Motion Vector**: Overlays the camera's motion vector texture on the screen.</li><li>**Additional Lights Shadow Map**: Overlays the [shadow map](https://docs.unity3d.com/Manual/shadow-mapping.html) that contains shadows cast by lights other than the main directional light.</li><li>**Main Light Shadow Map**: Overlays the shadow map that contains shadows cast by the main directional light.</li><li>**Additional Lights Cookie Atlas**: Overlays the light cookie atlas texture that contains patterns cast by lights other than the main directional light.</li><li>**Reflection Probe Atlas**: Overlays the reflection probe atlas texture that contains the reflection textures at the probe locations.</li></ul> |
151151
| **&nbsp;&nbsp;Map Size** | The width and height of the overlay texture as a percentage of the view window URP displays it in. For example, a value of **50** fills up a quarter of the screen (50% of the width and 50% of the height). |
152152
| **HDR** | Indicates whether to use [high dynamic range (HDR)](https://docs.unity3d.com/Manual/HDR.html) to render the scene. Enabling this property only has an effect if you enable **HDR** in your URP Asset. |
153153
| **MSAA** | Indicates whether to use [Multisample Anti-aliasing (MSAA)](./../anti-aliasing.md#msaa) to render the scene. Enabling this property only has an effect if:<ul><li>You set **Anti Aliasing (MSAA)** to a value other than **Disabled** in your URP Asset.</li><li>You use the Game View. MSAA has no effect in the Scene View.</li></ul> |
154+
| **TAA Debug Mode** | Specifies which Temporal Anti-aliasing debug mode to use. The options are:<ul><li>**None**: Renders the scene normally without a debug mode.</li><li>**Show Raw Frame**: Renders the screen with the color input Temporal Anti-aliasing currently uses.</li><li>**Show Raw Frame No Jitter**: Renders the screen with the color input TAA currently uses, and disables camera jitter.</li><li>**Show Clamped History**: Renders the screen with the color history that TAA has accumulated and corrected.</li></ul> |
154155
| **Post-processing** | Specifies how URP applies post-processing. The options are:<ul><li>**Disabled**: Disables post-processing.</li><li>**Auto**: Unity enables or disables post-processing depending on the currently active debug modes. If color changes from post-processing would change the meaning of a debug mode's pixel, Unity disables post-processing. If no debug modes are active, or if color changes from post-processing don't change the meaning of the active debug modes' pixels, Unity enables post-processing.</li><li>**Enabled**: Applies post-processing to the image that the camera captures.</li></ul> |
155156
| **Additional Wireframe Modes** | Specifies whether and how to render wireframes for meshes in your scene. The options are:<ul><li>**None**: Doesn't render wireframes.</li><li>**Wireframe**: Exclusively renders edges for meshes in your scene. In this mode, you can see the wireframe for meshes through the wireframe for closer meshes.</li><li>**Solid Wireframe**: Exclusively renders edges and faces for meshes in your scene. In this mode, the faces of each wireframe mesh hide edges behind them.</li><li>**Shaded Wireframe**: Renders edges for meshes as an overlay. In this mode, Unity renders the scene in color and overlays the wireframe over the top.</li></ul> |
156157
| **Overdraw** | Indicates whether to render the overdraw debug view. This is useful to check where Unity draws pixels over one other. |

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class DebugHandler : IDebugDisplaySettingsQuery
2121
static readonly int k_DebugTextureNoStereoPropertyId = Shader.PropertyToID("_DebugTextureNoStereo");
2222
static readonly int k_DebugTextureDisplayRect = Shader.PropertyToID("_DebugTextureDisplayRect");
2323
static readonly int k_DebugRenderTargetSupportsStereo = Shader.PropertyToID("_DebugRenderTargetSupportsStereo");
24+
static readonly int k_DebugRenderTargetRangeRemap = Shader.PropertyToID("_DebugRenderTargetRangeRemap");
2425

2526
// Material settings...
2627
static readonly int k_DebugMaterialModeId = Shader.PropertyToID("_DebugMaterialMode");
@@ -83,6 +84,7 @@ class DebugHandler : IDebugDisplaySettingsQuery
8384
bool m_HasDebugRenderTarget;
8485
bool m_DebugRenderTargetSupportsStereo;
8586
Vector4 m_DebugRenderTargetPixelRect;
87+
Vector4 m_DebugRenderTargetRangeRemap;
8688
RTHandle m_DebugRenderTarget;
8789

8890
RTHandle m_DebugFontTexture;
@@ -295,12 +297,13 @@ internal void SetupShaderProperties(RasterCommandBuffer cmd, int passIndex = 0)
295297
}
296298
}
297299

298-
internal void SetDebugRenderTarget(RTHandle renderTarget, Rect displayRect, bool supportsStereo)
300+
internal void SetDebugRenderTarget(RTHandle renderTarget, Rect displayRect, bool supportsStereo, Vector4 dataRangeRemap)
299301
{
300302
m_HasDebugRenderTarget = true;
301303
m_DebugRenderTargetSupportsStereo = supportsStereo;
302304
m_DebugRenderTarget = renderTarget;
303305
m_DebugRenderTargetPixelRect = new Vector4(displayRect.x, displayRect.y, displayRect.width, displayRect.height);
306+
m_DebugRenderTargetRangeRemap = dataRangeRemap;
304307
}
305308

306309
internal void ResetDebugRenderTarget()
@@ -320,6 +323,7 @@ class DebugFinalValidationPassData
320323

321324
public Vector4 debugRenderTargetPixelRect;
322325
public int debugRenderTargetSupportsStereo;
326+
public Vector4 debugRenderTargetRangeRemap;
323327

324328
public TextureHandle debugFontTextureHandle;
325329

@@ -341,6 +345,7 @@ DebugFinalValidationPassData InitDebugFinalValidationPassData(DebugFinalValidati
341345

342346
passData.debugRenderTargetPixelRect = m_DebugRenderTargetPixelRect;
343347
passData.debugRenderTargetSupportsStereo = m_DebugRenderTargetSupportsStereo ? 1 : 0;
348+
passData.debugRenderTargetRangeRemap = m_DebugRenderTargetRangeRemap;
344349

345350
passData.debugFontTextureHandle = TextureHandle.nullHandle;
346351

@@ -375,6 +380,7 @@ static void UpdateShaderGlobalPropertiesForFinalValidationPass(RasterCommandBuff
375380

376381
cmd.SetGlobalVector(k_DebugTextureDisplayRect, data.debugRenderTargetPixelRect);
377382
cmd.SetGlobalInteger(k_DebugRenderTargetSupportsStereo, data.debugRenderTargetSupportsStereo);
383+
cmd.SetGlobalVector(k_DebugRenderTargetRangeRemap, data.debugRenderTargetRangeRemap);
378384
}
379385

380386
var renderingSettings = data.renderingSettings;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ public void Clear(CommandBuffer cmd)
275275

276276
internal bool IsKeywordLightCookieEnabled { get; private set; }
277277

278+
internal RTHandle AdditionalLightsCookieAtlasTexture => m_AdditionalLightsCookieAtlas?.AtlasTexture;
279+
278280
public LightCookieManager(ref Settings settings)
279281
{
280282
m_Settings = settings;

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ internal override void ReleaseRenderTargets()
453453

454454
private void SetupFinalPassDebug(UniversalCameraData cameraData)
455455
{
456+
//NOTE: See SetupRenderGraphFinalPassDebug for RG.
457+
456458
if ((DebugHandler != null) && DebugHandler.IsActiveForCamera(cameraData.isPreviewCamera))
457459
{
458460
if (DebugHandler.TryGetFullscreenDebugMode(out DebugFullScreenMode fullScreenDebugMode, out int textureHeightPercent) &&
@@ -466,46 +468,68 @@ private void SetupFinalPassDebug(UniversalCameraData cameraData)
466468
var height = relativeSize * screenHeight;
467469
var width = relativeSize * screenWidth;
468470

471+
RenderTexture tex = null;
469472
if (fullScreenDebugMode == DebugFullScreenMode.ReflectionProbeAtlas)
470473
{
471-
// Ensure that atlas is not stretched, but doesn't take up more than the percentage in any dimension.
472-
var texture = m_ForwardLights.reflectionProbeManager.atlasRT;
473-
var targetWidth = height * texture.width / texture.height;
474-
if (targetWidth > width)
475-
{
476-
height = width * texture.height / texture.width;
477-
}
478-
else
479-
{
480-
width = targetWidth;
481-
}
474+
tex = m_ForwardLights.reflectionProbeManager.atlasRT;
475+
}
476+
else if (fullScreenDebugMode == DebugFullScreenMode.MainLightShadowMap)
477+
{
478+
tex = m_MainLightShadowCasterPass.m_MainLightShadowmapTexture.rt;
479+
}
480+
else if (fullScreenDebugMode == DebugFullScreenMode.AdditionalLightsShadowMap)
481+
{
482+
tex = m_AdditionalLightsShadowCasterPass.m_AdditionalLightsShadowmapHandle.rt;
482483
}
484+
else if (fullScreenDebugMode == DebugFullScreenMode.AdditionalLightsCookieAtlas && m_LightCookieManager != null)
485+
{
486+
tex = m_LightCookieManager?.AdditionalLightsCookieAtlasTexture?.rt;
487+
}
488+
489+
if(tex != null) CorrectForTextureAspectRatio(ref width, ref height, tex.width, tex.height);
483490

484491
float normalizedSizeX = width / screenWidth;
485492
float normalizedSizeY = height / screenHeight;
486493

487494
Rect normalizedRect = new Rect(1 - normalizedSizeX, 1 - normalizedSizeY, normalizedSizeX, normalizedSizeY);
495+
Vector4 dataRangeRemap = Vector4.zero; // zero = off, .x = old min, .y = old max, .z = new min, .w = new max
488496

489497
switch (fullScreenDebugMode)
490498
{
491499
case DebugFullScreenMode.Depth:
492500
{
493-
DebugHandler.SetDebugRenderTarget(m_DepthTexture, normalizedRect, true);
501+
DebugHandler.SetDebugRenderTarget(m_DepthTexture, normalizedRect, true, dataRangeRemap);
502+
break;
503+
}
504+
case DebugFullScreenMode.MotionVector:
505+
{
506+
// Motion vectors are in signed UV space, zoom in for visualization. (note: another option is to use (dir.xy, mag) visualization)
507+
const float zoom = 0.01f;
508+
dataRangeRemap.x = -zoom;
509+
dataRangeRemap.y = zoom;
510+
dataRangeRemap.z = 0;
511+
dataRangeRemap.w = 1.0f;
512+
DebugHandler.SetDebugRenderTarget(m_MotionVectorColor, normalizedRect, true, dataRangeRemap);
494513
break;
495514
}
496515
case DebugFullScreenMode.AdditionalLightsShadowMap:
497516
{
498-
DebugHandler.SetDebugRenderTarget(m_AdditionalLightsShadowCasterPass.m_AdditionalLightsShadowmapHandle, normalizedRect, false);
517+
DebugHandler.SetDebugRenderTarget(m_AdditionalLightsShadowCasterPass.m_AdditionalLightsShadowmapHandle, normalizedRect, false, dataRangeRemap);
499518
break;
500519
}
501520
case DebugFullScreenMode.MainLightShadowMap:
502521
{
503-
DebugHandler.SetDebugRenderTarget(m_MainLightShadowCasterPass.m_MainLightShadowmapTexture, normalizedRect, false);
522+
DebugHandler.SetDebugRenderTarget(m_MainLightShadowCasterPass.m_MainLightShadowmapTexture, normalizedRect, false, dataRangeRemap);
523+
break;
524+
}
525+
case DebugFullScreenMode.AdditionalLightsCookieAtlas:
526+
{
527+
DebugHandler.SetDebugRenderTarget(m_LightCookieManager?.AdditionalLightsCookieAtlasTexture, normalizedRect, false, dataRangeRemap);
504528
break;
505529
}
506530
case DebugFullScreenMode.ReflectionProbeAtlas:
507531
{
508-
DebugHandler.SetDebugRenderTarget(m_ForwardLights.reflectionProbeManager.atlasRTHandle, normalizedRect, false);
532+
DebugHandler.SetDebugRenderTarget(m_ForwardLights.reflectionProbeManager.atlasRTHandle, normalizedRect, false, dataRangeRemap);
509533
break;
510534
}
511535
default:

0 commit comments

Comments
 (0)