From abc0643f5c8afa1e2f53199d8a27dfece0666a53 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 11 Aug 2019 16:50:07 +0100 Subject: [PATCH] directional volumetric light fix --- .../volumetricLight_DirectionalPS.hlsl | 35 ++++++++++++------- WickedEngine/wiVersion.cpp | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/WickedEngine/volumetricLight_DirectionalPS.hlsl b/WickedEngine/volumetricLight_DirectionalPS.hlsl index e6e6ccf8c..009bea7c7 100644 --- a/WickedEngine/volumetricLight_DirectionalPS.hlsl +++ b/WickedEngine/volumetricLight_DirectionalPS.hlsl @@ -34,22 +34,33 @@ float4 main(VertexToPixel input) : SV_TARGET [loop] for (uint i = 0; i < sampleCount; ++i) { - float3 attenuation = 1; + bool valid = false; - float3 ShPos = mul(float4(P, 1), MatrixArray[light.GetShadowMatrixIndex() + 0]).xyz; // ortho matrix, no divide by .w - float3 ShTex = ShPos.xyz * float3(0.5f, -0.5f, 0.5f) + 0.5f; - - [branch]if ((saturate(ShTex.x) == ShTex.x) && (saturate(ShTex.y) == ShTex.y) && (saturate(ShTex.z) == ShTex.z)) + for (uint cascade = 0; cascade < g_xFrame_ShadowCascadeCount; ++cascade) { - attenuation *= shadowCascade(ShPos, ShTex.xy, light.shadowKernel, light.shadowBias, light.GetShadowMapIndex() + 0); + float3 ShPos = mul(float4(P, 1), MatrixArray[light.GetShadowMatrixIndex() + cascade]).xyz; // ortho matrix, no divide by .w + float3 ShTex = ShPos.xyz * float3(0.5f, -0.5f, 0.5f) + 0.5f; + + [branch]if (is_saturated(ShTex)) + { + float3 attenuation = shadowCascade(ShPos, ShTex.xy, light.shadowKernel, light.shadowBias, light.GetShadowMapIndex() + cascade); + + attenuation *= GetFog(cameraDistance - marchedDistance); + + accumulation += attenuation; + + marchedDistance += stepSize; + P = P + V * stepSize; + + valid = true; + break; + } } - attenuation *= GetFog(cameraDistance - marchedDistance); - - accumulation += attenuation; - - marchedDistance += stepSize; - P = P + V * stepSize; + if (!valid) + { + break; + } } accumulation /= sampleCount; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 977aba63a..da09f288e 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 28; // minor bug fixes, alterations, refactors, updates - const int revision = 0; + const int revision = 1; long GetVersion()