Skip to content

Commit

Permalink
volumetric: Use non pcf variant for volumetric shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Jan 14, 2024
1 parent 32bf63d commit c5f1d04
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion data/base/shaders/vk/pointlights.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,61 @@ vec4 iterateOverAllPointLights(
return light;
}


float getShadowVisibilityWithoutPCF(vec3 fragPos)
{
if (WZ_SHADOW_MODE == 0 || WZ_SHADOW_FILTER_SIZE == 0)
{
// no shadow-mapping
return 1.0;
}
else
{
// Shadow Mapping

vec4 fragPosViewSpace = ViewMatrix * vec4(fragPos, 1.0);
float depthValue = abs(fragPosViewSpace.z);

int cascadeIndex = 0;

// unrolled loop, using vec4 swizzles
if (WZ_SHADOW_CASCADES_COUNT > 1)
{
if (depthValue >= ShadowMapCascadeSplits.x)
{
cascadeIndex = 1;
}
}
if (WZ_SHADOW_CASCADES_COUNT > 2)
{
if (depthValue >= ShadowMapCascadeSplits.y)
{
cascadeIndex = 2;
}
}
if (WZ_SHADOW_CASCADES_COUNT > 3)
{
if (depthValue >= ShadowMapCascadeSplits.z)
{
cascadeIndex = 3;
}
}

vec4 shadowPos = ShadowMapMVPMatrix[cascadeIndex] * vec4(fragPos, 1.0);
vec3 pos = shadowPos.xyz / shadowPos.w;

if (pos.z > 1.0f)
{
return 1.0;
}

float bias = 0.0002f;

return texture( shadowMap, vec4(pos.xy, cascadeIndex, (pos.z+bias)) );
}
}


// based on equations found here : https://www.shadertoy.com/view/lstfR7
vec4 volumetricLights(
vec2 clipSpaceCoord,
Expand Down Expand Up @@ -101,7 +156,7 @@ vec4 volumetricLights(

vec3 od = fogColor.xyz * thickness * length(viewLine / STEPS) / 1000;

float sunLightEnergy = getShadowVisibility(posOnViewLine) ;
float sunLightEnergy = getShadowVisibilityWithoutPCF(posOnViewLine) ;
vec3 scatteredLight = vec3(sunLightEnergy) * sunLightColor * od;

for (int i = 0; i < bucketOffsetAndSize[bucketId].y; i++)
Expand Down

0 comments on commit c5f1d04

Please sign in to comment.