From 85aba2e1dab9e1d0fde071e15f1395ea05a5016a Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 28 Jun 2018 17:24:36 +0100 Subject: [PATCH] Add toggleable shadow debug overlay. --- components/sceneutil/shadow.cpp | 7 +++++ .../reference/modding/settings/shadows.rst | 10 +++++++ files/settings-default.cfg | 2 ++ files/shaders/objects_fragment.glsl | 2 ++ files/shaders/shadows_fragment.glsl | 27 +++++++++++++++++++ files/shaders/terrain_fragment.glsl | 2 ++ files/shaders/water_fragment.glsl | 2 ++ 7 files changed, 52 insertions(+) diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index 374faee8c..6e45bdd22 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -101,6 +101,11 @@ namespace SceneUtil else definesWithShadows["shadowMapsOverlap"] = "0"; + if (Settings::Manager::getBool("enable debug overlay", "Shadows")) + definesWithShadows["useShadowDebugOverlay"] = "1"; + else + definesWithShadows["useShadowDebugOverlay"] = "0"; + return definesWithShadows; } @@ -112,6 +117,8 @@ namespace SceneUtil definesWithShadows["shadowMapsOverlap"] = "0"; + definesWithShadows["useShadowDebugOverlay"] = "0"; + return definesWithShadows; } void ShadowManager::enableIndoorMode() diff --git a/docs/source/reference/modding/settings/shadows.rst b/docs/source/reference/modding/settings/shadows.rst index f9ebd1f63..271ecac20 100644 --- a/docs/source/reference/modding/settings/shadows.rst +++ b/docs/source/reference/modding/settings/shadows.rst @@ -49,6 +49,16 @@ enable debug hud Enable or disable the debug hud to see what the shadow map(s) contain. This setting is only recommended for developers, bug reporting and advanced users performing fine-tuning of shadow settings. +enable debug overlay +---------------- + +:Type: boolean +:Range: True/False +:Default: False + +Enable or disable the debug overlay to see the area covered by each shadow map. +This setting is only recommended for developers, bug reporting and advanced users performing fine-tuning of shadow settings. + compute tight scene bounds -------------------------- diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 6cee10e05..277b5dd08 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -530,6 +530,8 @@ split point uniform logarithmic ratio = 0.5 split point bias = 0.0 # Enable the debug hud to see what the shadow map(s) contain. enable debug hud = false +# Enable the debug overlay to see where each shadow map affects. +enable debug overlay = false # Attempt to better use the shadow map by making them cover a smaller area. Especially helpful when looking downwards with a high viewing distance. The performance impact of this may be very large. compute tight scene bounds = false # How large to make the shadow map(s). Higher values increase GPU load, but can produce better-looking results. Power-of-two values may turn out to be faster on some GPU/driver combinations. diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index fffb9c83b..64435f001 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -155,4 +155,6 @@ void main() float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0); gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue); + + applyShadowDebugOverlay(); } diff --git a/files/shaders/shadows_fragment.glsl b/files/shaders/shadows_fragment.glsl index cc1b38b59..ce9e958d1 100644 --- a/files/shaders/shadows_fragment.glsl +++ b/files/shaders/shadows_fragment.glsl @@ -33,4 +33,31 @@ float unshadowedLightRatio() #endif #endif // SHADOWS return shadowing; +} + +void applyShadowDebugOverlay() +{ +#if SHADOWS && @useShadowDebugOverlay + bool doneOverlay = false; + float colourIndex = 0.0; + @foreach shadow_texture_unit_index @shadow_texture_unit_list + if (!doneOverlay) + { + vec2 shadowXY = shadowSpaceCoords@shadow_texture_unit_index.xy / shadowSpaceCoords@shadow_texture_unit_index.w; + if (all(lessThan(shadowXY, vec2(1.0, 1.0))) && all(greaterThan(shadowXY, vec2(0.0, 0.0)))) + { + colourIndex = mod(@shadow_texture_unit_index.0, 3.0); + if (colourIndex < 1.0) + gl_FragData[0].x += 0.1; + else if (colourIndex < 2.0) + gl_FragData[0].y += 0.1; + else + gl_FragData[0].z += 0.1; + + if (all(lessThan(shadowXY, vec2(0.95, 0.95))) && all(greaterThan(shadowXY, vec2(0.05, 0.05)))) + doneOverlay = true; + } + } + @endforeach +#endif // SHADOWS } \ No newline at end of file diff --git a/files/shaders/terrain_fragment.glsl b/files/shaders/terrain_fragment.glsl index 219b92c99..c946777bb 100644 --- a/files/shaders/terrain_fragment.glsl +++ b/files/shaders/terrain_fragment.glsl @@ -86,4 +86,6 @@ void main() float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0); gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue); + + applyShadowDebugOverlay(); } diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index a227e1e68..0102a6eb9 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -280,4 +280,6 @@ void main(void) #else gl_FragData[0].w = clamp(fresnel*6.0 + specular, 0.0, 1.0); //clamp(fresnel*2.0 + specular, 0.0, 1.0); #endif + + applyShadowDebugOverlay(); }