Skip to content

Commit

Permalink
[Fogbugz # 1365368] Fixing debug views for drs #5948
Browse files Browse the repository at this point in the history
  • Loading branch information
kecho authored and sebastienlagarde committed Dec 8, 2021
1 parent 018f746 commit 181334c
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 120 deletions.
3 changes: 2 additions & 1 deletion com.unity.render-pipelines.high-definition/CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fixed some XR devices: Pulling camera world space position from mainViewConstants instead of transform.
- Fixed Xbox Series X compilation issue with DoF shader
- Fixed references to reflection probes that wouldn't be cleared when unloading a scene. (case 1357459)
- Fixed broken debug views when dynamic resolution was enabled (case 1365368).

## [12.1.2] - 2021-10-22

Expand Down Expand Up @@ -37,7 +39,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed light unit conversion after changing mid gray value.
- Fixed Focus distance in path traced depth of field now takes into account the focus mode setting (volume vs camera).
- Fixed stencil buffer resolve when MSAA is enabled so that OR operator is used instead of picking the last sample.
- Fixed references to reflection probes that wouldn't be cleared when unloading a scene. (case 1357459)

### Changed
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.
Expand Down
@@ -0,0 +1,21 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#pragma kernel clearMain
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl"

float4 _QuadOverdrawClearBuffParams;
#define _BufferOffset _QuadOverdrawClearBuffParams.x

[numthreads(64, 1, 1)]
void clearMain(uint dispatchThreadID : SV_DispatchThreadID)
{
const uint totalPixels = (uint)_DebugViewportSize.x * (uint) _DebugViewportSize.y;
if (dispatchThreadID.x > totalPixels)
return;

_FullScreenDebugBuffer[(int)_BufferOffset + dispatchThreadID.x] = 0.0;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -29,6 +29,7 @@ unsafe struct ShaderVariablesDebugDisplay
public int _DebugMipMapModeTerrainTexture; // Match enum DebugMipMapModeTerrainTexture
public int _ColorPickerMode; // Match enum ColorPickerDebugMode

public Vector4 _DebugViewportSize; //Frame viewport size used during rendering.
public Vector4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse
public Vector4 _DebugLightingSmoothness; // x == bool override, y == override value
public Vector4 _DebugLightingNormal; // x == bool override
Expand Down
Expand Up @@ -58,6 +58,7 @@ CBUFFER_START(ShaderVariablesDebugDisplay)
float _DebugTransparencyOverdrawWeight;
int _DebugMipMapModeTerrainTexture;
int _ColorPickerMode;
float4 _DebugViewportSize;
float4 _DebugLightingAlbedo;
float4 _DebugLightingSmoothness;
float4 _DebugLightingNormal;
Expand Down
Expand Up @@ -59,6 +59,8 @@ Shader "Hidden/HDRP/DebugFullScreen"
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);

//Texcoord holds the coordinates of the original rendering before post processing.
output.texcoord = GetNormalizedFullScreenTriangleTexCoord(input.vertexID);
return output;
}
Expand Down Expand Up @@ -199,22 +201,22 @@ Shader "Hidden/HDRP/DebugFullScreen"
}
if ( _FullScreenDebugMode == FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE)
{
float4 color = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)input.positionCS.xy);
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
return color;
}
if ( _FullScreenDebugMode == FULLSCREENDEBUGMODE_VOLUMETRIC_CLOUDS)
{
float4 color = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)(input.positionCS.xy));
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
return float4(color.xyz * color.w, 1.0);
}
if ( _FullScreenDebugMode == FULLSCREENDEBUGMODE_VOLUMETRIC_CLOUDS_SHADOW)
{
float4 color = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)(input.positionCS.xy));
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
return float4(color.xxx, 1.0);
}
if ( _FullScreenDebugMode == FULLSCREENDEBUGMODE_SCREEN_SPACE_SHADOWS)
{
float4 color = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)input.positionCS.xy);
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
return color;
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_MOTION_VECTORS)
Expand Down Expand Up @@ -287,12 +289,12 @@ Shader "Hidden/HDRP/DebugFullScreen"
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_COLOR_LOG)
{
float4 color = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)input.positionCS.xy);
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
return color;
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC)
{
float coc = LOAD_TEXTURE2D_X(_DebugFullScreenTexture, (uint2)input.positionCS.xy).x;
float coc = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);

float3 color = lerp(float3(1.0, 0.0, 0.0), float3(1.0, 1.0, 1.0), saturate(-coc));
color = lerp(color, float3(1.0, 1.0, 1.0), saturate(coc));
Expand All @@ -305,7 +307,8 @@ Shader "Hidden/HDRP/DebugFullScreen"
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_CONTACT_SHADOWS)
{
uint contactShadowData = LOAD_TEXTURE2D_X(_ContactShadowTexture, (uint2)input.positionCS.xy).r;
uint2 samplePosition = (uint2)((input.texcoord.xy / _RTHandleScale.xy) * _DebugViewportSize.xy);
uint contactShadowData = LOAD_TEXTURE2D_X(_ContactShadowTexture, samplePosition).r;

// when the index is -1 we display all contact shadows
uint mask = (_DebugContactShadowLightIndex == -1) ? -1 : 1 << _DebugContactShadowLightIndex;
Expand All @@ -315,7 +318,8 @@ Shader "Hidden/HDRP/DebugFullScreen"
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_CONTACT_SHADOWS_FADE)
{
uint contactShadowData = LOAD_TEXTURE2D_X(_ContactShadowTexture, (uint2)input.positionCS.xy).r;
uint2 samplePosition = (uint2)((input.texcoord.xy / _RTHandleScale.xy) * _DebugViewportSize.xy);
uint contactShadowData = LOAD_TEXTURE2D_X(_ContactShadowTexture, samplePosition).r;
float fade = float((contactShadowData >> 24)) / 255.0;

return float4(fade.xxx, 0.0);
Expand All @@ -338,7 +342,8 @@ Shader "Hidden/HDRP/DebugFullScreen"
{
// Reuse depth display function from DebugViewMaterial
int2 mipOffset = _DebugDepthPyramidOffsets[_DebugDepthPyramidMip];
uint2 pixCoord = (uint2)input.positionCS.xy >> _DebugDepthPyramidMip;
uint2 remappedPos = (uint2)(input.texcoord.xy * _DebugViewportSize.xy);
uint2 pixCoord = (uint2)remappedPos.xy >> _DebugDepthPyramidMip;
float depth = LOAD_TEXTURE2D_X(_CameraDepthTexture, pixCoord + mipOffset).r;
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);

Expand Down Expand Up @@ -371,30 +376,27 @@ Shader "Hidden/HDRP/DebugFullScreen"
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW)
{
uint2 quad = (uint2)input.positionCS.xy & ~1;
uint quad0_idx = _ScreenSize.x * (_ScreenSize.y * SLICE_ARRAY_INDEX + quad.y) + quad.x;
uint quad1_idx = _ScreenSize.x * (_ScreenSize.y * SLICE_ARRAY_INDEX + quad.y) + quad.x + 1;
uint2 samplePosition = (uint2)((input.texcoord / _RTHandleScale.xy) * _DebugViewportSize.xy);
uint2 quad = (uint2)samplePosition.xy & ~1;
uint2 renderScreenSize = (uint2)_DebugViewportSize.xy;
uint quad0_idx = renderScreenSize.x * (renderScreenSize.y * SLICE_ARRAY_INDEX + quad.y) + quad.x;
float4 color = (float4)0;

float quadCost = (float)_FullScreenDebugBuffer[quad0_idx];
if (all(((uint2)input.positionCS.xy & 1) == 0)) // Write only once per quad
{
_FullScreenDebugBuffer[quad0_idx] = 0; // Overdraw
_FullScreenDebugBuffer[quad1_idx] = 0; // Lock
}
if ((quadCost > 0.001))
color.rgb = HsvToRgb(float3(0.66 * saturate(1.0 - (1.0 / _QuadOverdrawMaxQuadCost) * quadCost), 1.0, 1.0));

return color;
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_VERTEX_DENSITY)
{
uint2 quad = (uint2)input.positionCS;
uint quad_idx = _ScreenSize.x * (_ScreenSize.y * SLICE_ARRAY_INDEX + quad.y) + quad.x;
uint2 samplePosition = (uint2)((input.texcoord / _RTHandleScale.xy) * _DebugViewportSize.xy);
uint2 quad = (uint2)samplePosition.xy;
uint2 renderScreenSize = (uint2)_DebugViewportSize.xy;
uint quad_idx = renderScreenSize.x * (renderScreenSize.y * SLICE_ARRAY_INDEX + quad.y) + quad.x;
float4 color = (float4)0;

float density = (float)_FullScreenDebugBuffer[quad_idx];
_FullScreenDebugBuffer[quad_idx] = 0;
if ((density > 0.001))
color.rgb = HsvToRgb(float3(0.66 * saturate(1.0 - (1.0 / _VertexDensityMaxPixelCost) * density), 1.0, 1.0));

Expand Down Expand Up @@ -432,7 +434,8 @@ Shader "Hidden/HDRP/DebugFullScreen"

if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_LENS_FLARE_DATA_DRIVEN)
{
return SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
uint2 samplePosition = (uint2)((input.texcoord / _RTHandleScale.xy) * _DebugViewportSize.xy);
return LOAD_TEXTURE2D_X(_DebugFullScreenTexture, samplePosition);
}

return float4(0.0, 0.0, 0.0, 0.0);
Expand Down
Expand Up @@ -48,6 +48,8 @@ Shader "Hidden/HDRP/DebugViewTiles"
uint _NumTiles;
float _ClusterDebugDistance;
int _ClusterDebugMode;
float4 _ClusterDebugLightViewportSize;


StructuredBuffer<uint> g_TileList;
Buffer<uint> g_DispatchIndirectBuffer;
Expand Down Expand Up @@ -120,7 +122,7 @@ Shader "Hidden/HDRP/DebugViewTiles"
variant = -1;
#endif

float2 clipCoord = (pixelCoord * _ScreenSize.zw) * 2.0 - 1.0;
float2 clipCoord = (pixelCoord * _ClusterDebugLightViewportSize.zw) * 2.0 - 1.0;
clipCoord.y *= -1;

Varyings output;
Expand Down Expand Up @@ -157,14 +159,15 @@ Shader "Hidden/HDRP/DebugViewTiles"
// For debug shaders, Viewport can be at a non zero (x,y) but the pipeline render targets all starts at (0,0)
// input.positionCS in in pixel coordinate relative to the render target origin so they will be offsted compared to internal render textures
// To solve that, we compute pixel coordinates from full screen quad texture coordinates which start correctly at (0,0)
uint2 pixelCoord = uint2(input.texcoord.xy * _ScreenSize.xy);
uint2 pixelCoord = uint2(input.texcoord.xy * _ClusterDebugLightViewportSize.xy);

float depth = GetTileDepth(pixelCoord);

PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, pixelCoord / GetTileSize());
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ClusterDebugLightViewportSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, pixelCoord / GetTileSize());

float2 debugViewportScaling = _ClusterDebugLightViewportSize.xy / _ScreenSize.xy;
int2 tileCoord = (float2)pixelCoord / GetTileSize();
int2 mouseTileCoord = _MousePixelCoord.xy / GetTileSize();
int2 mouseTileCoord = (_MousePixelCoord.xy * debugViewportScaling) / GetTileSize();
int2 offsetInTile = pixelCoord - tileCoord * GetTileSize();

int n = 0;
Expand Down Expand Up @@ -223,43 +226,52 @@ Shader "Hidden/HDRP/DebugViewTiles"
result = AlphaBlend(result, result2);
}

// Print light lists for selected tile at the bottom of the screen
int maxAreaWidth = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT + 4;
if (tileCoord.y < LIGHTCATEGORY_COUNT && tileCoord.x < maxAreaWidth)
{
float depthMouse = GetTileDepth(_MousePixelCoord.xy);

PositionInputs mousePosInput = GetPositionInput(_MousePixelCoord.xy, _ScreenSize.zw, depthMouse, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, mouseTileCoord);

uint category = (LIGHTCATEGORY_COUNT - 1) - tileCoord.y;
uint start;
uint count;

GetCountAndStart(mousePosInput, category, start, count);
float catMenuScale = max(debugViewportScaling.x,debugViewportScaling.y);
float scaledTileSize = GetTileSize() * catMenuScale;
int2 catTileCoord = (int2)((pixelCoord) / scaledTileSize);
float2 catPixelCoordUnscaled = input.texcoord.xy * _ClusterDebugLightViewportSize.xy;
int2 catPixelCoord = (int2)((catPixelCoordUnscaled - 0.5) / catMenuScale);
int2 catOffsetInTile = catPixelCoord - catTileCoord * GetTileSize();

// Print light lists for selected tile at the bottom of the screen
int maxAreaWidth = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT + 4;
if (catTileCoord.y < LIGHTCATEGORY_COUNT && catTileCoord.x < maxAreaWidth)
{
float depthMouse = GetTileDepth(_MousePixelCoord.xy);

float4 result2 = float4(.1,.1,.1,.9);
int2 fontCoord = int2(pixelCoord.x, offsetInTile.y);
int lightListIndex = tileCoord.x - 2;
PositionInputs mousePosInput = GetPositionInput(_MousePixelCoord.xy, _ClusterDebugLightViewportSize.zw, depthMouse, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, mouseTileCoord);

int n = -1;
if(tileCoord.x == 0)
{
n = (int)count;
}
else if(lightListIndex >= 0 && lightListIndex < (int)count)
{
n = FetchIndex(start, lightListIndex);
}
uint category = (LIGHTCATEGORY_COUNT - 1) - catTileCoord.y;
uint start;
uint count;

if (n >= 0)
{
if (SampleDebugFontNumber(offsetInTile, n))
result2 = float4(0.0, 0.0, 0.0, 1.0);
if (SampleDebugFontNumber(offsetInTile + 1, n))
result2 = float4(1.0, 1.0, 1.0, 1.0);
GetCountAndStart(mousePosInput, category, start, count);

float4 result2 = float4(.1,.1,.1,.9);
int2 fontCoord = int2(catPixelCoord.x, catOffsetInTile.y);
int lightListIndex = catTileCoord.x - 2;

int n = -1;
if(catTileCoord.x == 0)
{
n = (int)count;
}
else if(lightListIndex >= 0 && lightListIndex < (int)count)
{
n = FetchIndex(start, lightListIndex);
}

if (n >= 0)
{
if (SampleDebugFontNumber(catOffsetInTile, n))
result2 = float4(0.0, 0.0, 0.0, 1.0);
if (SampleDebugFontNumber(catOffsetInTile + 1, n))
result2 = float4(1.0, 1.0, 1.0, 1.0);
}

result = AlphaBlend(result, result2);
}

result = AlphaBlend(result, result2);
}
#endif
#endif
Expand Down

0 comments on commit 181334c

Please sign in to comment.