diff --git a/res/shaders/constants.wgsl b/res/shaders/constants.wgsl index aee97ba..4be90be 100644 --- a/res/shaders/constants.wgsl +++ b/res/shaders/constants.wgsl @@ -1 +1,3 @@ -const PI = 3.14159; \ No newline at end of file +const PI = 3.14159; +const INV_SQRT_2 = 0.70710678118654752440; // 1 / sqrt(2) +const INV_SQRT_3 = 0.57735026918962576451; // 1 / sqrt(3) \ No newline at end of file diff --git a/res/shaders/pbr.wgsl b/res/shaders/pbr.wgsl index 812c541..e7adea2 100644 --- a/res/shaders/pbr.wgsl +++ b/res/shaders/pbr.wgsl @@ -125,8 +125,24 @@ fn fs_main(vert: VertexOutput) -> @location(0) vec4 { var total_radiance: vec3; var in_light = 0.0; - for (var i: i32 = 0; i < 1; i++) { - in_light = sample_direct_light(i, light.matrices[i] * vert.world_position); + for (var i: i32 = 0; i < 6; i++) { + let light_coords = light.matrices[i] * vert.world_position; + + let light_dir = normalize(light_coords.xyz); + let bias = 0.005; + // z can never be smaller than this inside 90 degree frustum + if (light_dir.z < INV_SQRT_3 - bias) { + continue; + } + // x and y can never be larger than this inside frustum + if (abs(light_dir.y) > INV_SQRT_2 + bias) { + continue; + } + if (abs(light_dir.x) > INV_SQRT_2 + bias) { + continue; + } + + in_light = sample_direct_light(i, light_coords); if (in_light > 0.0) { break; }