From da87e2b5c8985d164eabf128f00e6f5e67a2569f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 11 Jan 2023 12:27:29 +0100 Subject: [PATCH] volumetric directional light: don't early exit when out of shadow cascade --- .../volumetricLight_DirectionalPS.hlsl | 34 ++++++++----------- WickedEngine/wiVersion.cpp | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/WickedEngine/shaders/volumetricLight_DirectionalPS.hlsl b/WickedEngine/shaders/volumetricLight_DirectionalPS.hlsl index 5cc4408ab..1caa579ce 100644 --- a/WickedEngine/shaders/volumetricLight_DirectionalPS.hlsl +++ b/WickedEngine/shaders/volumetricLight_DirectionalPS.hlsl @@ -39,7 +39,8 @@ float4 main(VertexToPixel input) : SV_TARGET for (uint i = 0; i < sampleCount; ++i) { bool valid = false; - + + float3 shadow = 1; for (uint cascade = 0; cascade < GetFrame().shadow_cascade_count; ++cascade) { float3 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + cascade), float4(P, 1)).xyz; // ortho matrix, no divide by .w @@ -48,31 +49,24 @@ float4 main(VertexToPixel input) : SV_TARGET [branch] if (is_saturated(shadow_uv)) { - float3 attenuation = shadow_2D(light, shadow_pos, shadow_uv.xy, cascade); - - if (GetFrame().options & OPTION_BIT_VOLUMETRICCLOUDS_SHADOWS) - { - attenuation *= shadow_2D_volumetricclouds(P); - } - - // Evaluate sample height for height fog calculation, given 0 for V: - attenuation *= GetFogAmount(cameraDistance - marchedDistance, P, float3(0.0, 0.0, 0.0)); - attenuation *= scattering; - - accumulation += attenuation; - - marchedDistance += stepSize; - P = P + V * stepSize; - - valid = true; + shadow *= shadow_2D(light, shadow_pos, shadow_uv.xy, cascade); break; } } - if (!valid) + if (GetFrame().options & OPTION_BIT_VOLUMETRICCLOUDS_SHADOWS) { - break; + shadow *= shadow_2D_volumetricclouds(P); } + + // Evaluate sample height for height fog calculation, given 0 for V: + shadow *= GetFogAmount(cameraDistance - marchedDistance, P, 0); + shadow *= scattering; + + accumulation += shadow; + + marchedDistance += stepSize; + P = P + V * stepSize; } accumulation /= sampleCount; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 61b80bf74..01fb6a7e8 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 133; + const int revision = 134; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);