Skip to content

Commit

Permalink
shadow fix
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jul 28, 2024
1 parent 228dd86 commit 112d03d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions WickedEngine/shaders/shadowHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

// "Vogel disk" sampling pattern based on: https://github.com/corporateshark/poisson-disk-generator/blob/master/PoissonGenerator.h
// Baked values are remapped from [0, 1] range into [-1, 1] range by doing: value * 2 - 1
static const float2 vogel_points[] = {
float2(0.353553, 0.000000),
float2(-0.451560, 0.413635),
float2(0.069174, -0.787537),
float2(0.569060, 0.742409),
static const half2 vogel_points[] = {
half2(0.353553, 0.000000),
half2(-0.451560, 0.413635),
half2(0.069174, -0.787537),
half2(0.569060, 0.742409),
};

static const min16uint soft_shadow_sample_count = arraysize(vogel_points);
static const half soft_shadow_sample_count_rcp = rcp((half)soft_shadow_sample_count);

inline half3 sample_shadow(float2 uv, float cmp, float4 uv_clamping, float spread, uint2 pixel)
inline half3 sample_shadow(float2 uv, float cmp, float4 uv_clamping, half radius, uint2 pixel)
{
Texture2D texture_shadowatlas = bindless_textures[GetFrame().texture_shadowatlas_index];
Texture2D texture_shadowatlas_transparent = bindless_textures[GetFrame().texture_shadowatlas_transparent_index];

half3 shadow = 0;

#ifndef DISABLE_SOFT_SHADOWMAP
const float2 spread_offset = GetFrame().shadow_atlas_resolution_rcp.xy * (2 + spread * 8); // remap spread to try to match ray traced shadow result
const float2 spread = GetFrame().shadow_atlas_resolution_rcp.xy * (2 + radius * 8); // remap radius to try to match ray traced shadow result
const half2x2 rot = dither_rot2x2(pixel + GetTemporalAASampleRotation()); // per pixel rotation for every sample
for (min16uint i = 0; i < soft_shadow_sample_count; ++i)
{
float2 sample_uv = uv + mul(vogel_points[i], rot) * spread_offset;
float2 sample_uv = uv + mul(vogel_points[i], rot) * spread;
#else
float2 sample_uv = uv;
#endif // DISABLE_SOFT_SHADOWMAP
Expand All @@ -35,13 +35,15 @@ inline half3 sample_shadow(float2 uv, float cmp, float4 uv_clamping, float sprea
half3 pcf = texture_shadowatlas.SampleCmpLevelZero(sampler_cmp_depth, sample_uv, cmp).rrr;
if(pcf.x > 0)
{
#ifndef DISABLE_TRANSPARENT_SHADOWMAP
half4 transparent_shadow = texture_shadowatlas_transparent.SampleLevel(sampler_linear_clamp, sample_uv, 0);
#ifdef TRANSPARENT_SHADOWMAP_SECONDARY_DEPTH_CHECK
if (transparent_shadow.a > cmp)
#endif // TRANSPARENT_SHADOWMAP_SECONDARY_DEPTH_CHECK
{
pcf *= transparent_shadow.rgb;
}
#endif // DISABLE_TRANSPARENT_SHADOWMAP
shadow += pcf;
}

Expand Down

0 comments on commit 112d03d

Please sign in to comment.