From 4c75babf0322da4b5cb07db4645fe85d7ee8f1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 24 May 2024 17:12:57 +0200 Subject: [PATCH] EEVEE-Next: Shadow: Improve shadow tagging debugging The tilemap debug mode now shows updates in the viewport and cached pages in the bottom tilemaps. --- .../engines/eevee_next/eevee_shader_shared.hh | 2 +- .../shaders/eevee_shadow_debug_frag.glsl | 71 +++++++++++-------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh index 64e73807e5c..40157c4ae73 100644 --- a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh +++ b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh @@ -1485,7 +1485,7 @@ static inline ShadowTileDataPacked shadow_tile_pack(ShadowTileData tile) struct ShadowSamplingTile { /** Page inside the virtual shadow map atlas. */ uint3 page; - /** LOD pointed to LOD 0 tile page. */ + /** LOD pointed by LOD 0 tile page. */ uint lod; /** Offset to the texel position to align with the LOD page start. (directional only). */ uint2 lod_offset; diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_debug_frag.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_debug_frag.glsl index 9046c756408..8e1ceca3865 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_debug_frag.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_debug_frag.glsl @@ -63,7 +63,7 @@ vec3 debug_tile_state_color(ShadowTileData tile) return col; } -vec3 debug_tile_state_color(eLightType type, ShadowSamplingTile tile) +vec3 debug_tile_lod(eLightType type, ShadowSamplingTile tile) { if (!tile.is_valid) { return vec3(1, 0, 0); @@ -115,51 +115,59 @@ LightData debug_light_get() } /** Return true if a pixel was written. */ -bool debug_tilemaps(vec3 P, LightData light) +bool debug_tilemaps(vec3 P, LightData light, bool do_debug_sample_tile) { const int debug_tile_size_px = 4; ivec2 px = ivec2(gl_FragCoord.xy) / debug_tile_size_px; int tilemap = px.x / SHADOW_TILEMAP_RES; int tilemap_index = light.tilemap_index + tilemap; if ((px.y < SHADOW_TILEMAP_RES) && (tilemap_index <= light_tilemap_max_get(light))) { -#if 1 - /* Debug values in the tilemap_tx. */ - uvec2 tilemap_texel = shadow_tile_coord_in_atlas(uvec2(px), tilemap_index); - ShadowSamplingTile tile = shadow_sampling_tile_unpack( - texelFetch(shadow_tilemaps_tx, ivec2(tilemap_texel), 0).x); - /* Leave 1 px border between tile-maps. */ - if (!any(equal(ivec2(gl_FragCoord.xy) % (SHADOW_TILEMAP_RES * debug_tile_size_px), ivec2(0)))) - { - gl_FragDepth = 0.0; - out_color_add = vec4(debug_tile_state_color(light.type, tile), 0.0); - out_color_mul = vec4(0.0); + if (do_debug_sample_tile) { + /* Debug values in the tilemap_tx. */ + uvec2 tilemap_texel = shadow_tile_coord_in_atlas(uvec2(px), tilemap_index); + ShadowSamplingTile tile = shadow_sampling_tile_unpack( + texelFetch(shadow_tilemaps_tx, ivec2(tilemap_texel), 0).x); + /* Leave 1 px border between tile-maps. */ + if (!any( + equal(ivec2(gl_FragCoord.xy) % (SHADOW_TILEMAP_RES * debug_tile_size_px), ivec2(0)))) + { + gl_FragDepth = 0.0; + out_color_add = vec4(debug_tile_lod(light.type, tile), 0.0); + out_color_mul = vec4(0.0); - return true; + return true; + } } -#else - /* Debug actual values in the tile-map buffer. */ - ShadowTileMapData tilemap = tilemaps_buf[tilemap_index]; - int tile_index = shadow_tile_offset( - (px + SHADOW_TILEMAP_RES) % SHADOW_TILEMAP_RES, tilemap.tiles_index, 0); - ShadowTileData tile = shadow_tile_unpack(tiles_buf[tile_index]); - /* Leave 1 px border between tile-maps. */ - if (!any(equal(ivec2(gl_FragCoord.xy) % (SHADOW_TILEMAP_RES * debug_tile_size_px), ivec2(0)))) - { - gl_FragDepth = 0.0; - out_color_add = vec4(debug_tile_state_color(tile), 0.0); - out_color_mul = vec4(0.0); + else { + /* Debug actual values in the tile-map buffer. */ + ShadowTileMapData tilemap = tilemaps_buf[tilemap_index]; + int tile_index = shadow_tile_offset( + (px + SHADOW_TILEMAP_RES) % SHADOW_TILEMAP_RES, tilemap.tiles_index, 0); + ShadowTileData tile = shadow_tile_unpack(tiles_buf[tile_index]); + /* Leave 1 px border between tile-maps. */ + if (!any( + equal(ivec2(gl_FragCoord.xy) % (SHADOW_TILEMAP_RES * debug_tile_size_px), ivec2(0)))) + { + gl_FragDepth = 0.0; + out_color_add = vec4(debug_tile_state_color(tile), 0.0); + out_color_mul = vec4(0.0); - return true; + return true; + } } -#endif } return false; } void debug_tile_state(vec3 P, LightData light) { - ShadowSamplingTile tile = debug_tile_get(P, light); - out_color_add = vec4(debug_tile_state_color(light.type, tile), 0) * 0.5; + ShadowSamplingTile tile_samp = debug_tile_get(P, light); + ShadowCoordinates coord = debug_coord_get(P, light); + ShadowTileMapData tilemap = tilemaps_buf[coord.tilemap_index]; + int tile_index = shadow_tile_offset( + ivec2(coord.tilemap_tile >> tile_samp.lod), tilemap.tiles_index, int(tile_samp.lod)); + ShadowTileData tile = shadow_tile_unpack(tiles_buf[tile_index]); + out_color_add = vec4(debug_tile_state_color(tile), 0) * 0.5; out_color_mul = vec4(0.5); } @@ -199,7 +207,8 @@ void main() LightData light = debug_light_get(); - if (debug_tilemaps(P, light)) { + bool do_debug_sample_tile = eDebugMode(debug_mode) != DEBUG_SHADOW_TILEMAPS; + if (debug_tilemaps(P, light, do_debug_sample_tile)) { return; }