diff --git a/res/shaders/constants.wgsl b/res/shaders/constants.wgsl index ad50ca7..c84912f 100644 --- a/res/shaders/constants.wgsl +++ b/res/shaders/constants.wgsl @@ -1,6 +1,7 @@ const PI = 3.14159; const INV_SQRT_2 = 0.70710678118654752440; // 1 / sqrt(2) const INV_SQRT_3 = 0.57735026918962576451; // 1 / sqrt(3) -const SHADOW_SAMPLES = 8; -const INV_SHADOW_SAMPLES = 1.0 / 8.0; -const SHADOW_SAMPLE_DIST = 0.001; +// in every direction from 0,0 +// total = (2n + 1)^2 +const SHADOW_SAMPLES = 2; +const INV_SHADOW_SAMPLES = 1.0 / 25.0; diff --git a/res/shaders/pbr.wgsl b/res/shaders/pbr.wgsl index bfd5114..89d4a27 100644 --- a/res/shaders/pbr.wgsl +++ b/res/shaders/pbr.wgsl @@ -78,23 +78,19 @@ fn sample_direct_light(index: i32, light_coords: vec4) -> f32 { let reference_depth = light_coords.z * proj_correction - bias; var total_sample = 0.0; - for (var i: i32 = 0; i < SHADOW_SAMPLES; i++) { - let phase = i % 4; - var offset = vec2(f32(i / 4) * SHADOW_SAMPLE_DIST); - if (phase == 1 || phase == 3) { - offset.x = -offset.x; + for (var x: i32 = -SHADOW_SAMPLES; x < SHADOW_SAMPLES; x++) { + for (var y: i32 = -SHADOW_SAMPLES; y < SHADOW_SAMPLES; y++) { + let texelSize = vec2(textureDimensions(t_light_depth)); + let offset = vec2(f32(x), f32(y)) / texelSize.xy; + let s = textureSampleCompare( + t_light_depth, + s_light_depth, + light_local + offset, + index, + reference_depth + ); + total_sample += s * INV_SHADOW_SAMPLES; } - if (phase == 2 || phase == 3) { - offset.y = -offset.y; - } - let s = textureSampleCompare( - t_light_depth, - s_light_depth, - light_local + offset, - index, - reference_depth - ); - total_sample += s * INV_SHADOW_SAMPLES; } return total_sample;