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 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;
|
||||
|
|
|
@ -78,15 +78,10 @@ fn sample_direct_light(index: i32, light_coords: vec4<f32>) -> 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>(f32(i / 4) * SHADOW_SAMPLE_DIST);
|
||||
if (phase == 1 || phase == 3) {
|
||||
offset.x = -offset.x;
|
||||
}
|
||||
if (phase == 2 || phase == 3) {
|
||||
offset.y = -offset.y;
|
||||
}
|
||||
for (var x: i32 = -SHADOW_SAMPLES; x < SHADOW_SAMPLES; x++) {
|
||||
for (var y: i32 = -SHADOW_SAMPLES; y < SHADOW_SAMPLES; y++) {
|
||||
let texelSize = vec2<f32>(textureDimensions(t_light_depth));
|
||||
let offset = vec2<f32>(f32(x), f32(y)) / texelSize.xy;
|
||||
let s = textureSampleCompare(
|
||||
t_light_depth,
|
||||
s_light_depth,
|
||||
|
@ -96,6 +91,7 @@ fn sample_direct_light(index: i32, light_coords: vec4<f32>) -> f32 {
|
|||
);
|
||||
total_sample += s * INV_SHADOW_SAMPLES;
|
||||
}
|
||||
}
|
||||
|
||||
return total_sample;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue