improve PCF
This commit is contained in:
parent
dab82367f0
commit
057240acc1
2 changed files with 16 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
const PI = 3.14159;
|
const PI = 3.14159;
|
||||||
const INV_SQRT_2 = 0.70710678118654752440; // 1 / sqrt(2)
|
const INV_SQRT_2 = 0.70710678118654752440; // 1 / sqrt(2)
|
||||||
const INV_SQRT_3 = 0.57735026918962576451; // 1 / sqrt(3)
|
const INV_SQRT_3 = 0.57735026918962576451; // 1 / sqrt(3)
|
||||||
const SHADOW_SAMPLES = 8;
|
// in every direction from 0,0
|
||||||
const INV_SHADOW_SAMPLES = 1.0 / 8.0;
|
// total = (2n + 1)^2
|
||||||
const SHADOW_SAMPLE_DIST = 0.001;
|
const SHADOW_SAMPLES = 2;
|
||||||
|
const INV_SHADOW_SAMPLES = 1.0 / 25.0;
|
||||||
|
|
|
@ -78,23 +78,19 @@ fn sample_direct_light(index: i32, light_coords: vec4<f32>) -> f32 {
|
||||||
let reference_depth = light_coords.z * proj_correction - bias;
|
let reference_depth = light_coords.z * proj_correction - bias;
|
||||||
|
|
||||||
var total_sample = 0.0;
|
var total_sample = 0.0;
|
||||||
for (var i: i32 = 0; i < SHADOW_SAMPLES; i++) {
|
for (var x: i32 = -SHADOW_SAMPLES; x < SHADOW_SAMPLES; x++) {
|
||||||
let phase = i % 4;
|
for (var y: i32 = -SHADOW_SAMPLES; y < SHADOW_SAMPLES; y++) {
|
||||||
var offset = vec2<f32>(f32(i / 4) * SHADOW_SAMPLE_DIST);
|
let texelSize = vec2<f32>(textureDimensions(t_light_depth));
|
||||||
if (phase == 1 || phase == 3) {
|
let offset = vec2<f32>(f32(x), f32(y)) / texelSize.xy;
|
||||||
offset.x = -offset.x;
|
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;
|
return total_sample;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue