Disable shadowmapping on WebGL

This commit is contained in:
Lauri Räsänen 2023-11-05 02:27:38 +02:00
parent 2616b2f5c9
commit ccaf9261cc
7 changed files with 67 additions and 45 deletions

View file

@ -13,5 +13,5 @@ fn vs_main(
);
let world_position = model_matrix * vec4<f32>(model.position, 1.0);
return light.matrices[light_matrix_index.value] * world_position;
return light.matrices[global_uniforms.light_matrix_index] * world_position;
}

View file

@ -17,14 +17,14 @@ struct Light {
var<uniform> light: Light;
// Needs to be 16 bytes in WebGL
struct LightMatrixIndex {
value: u32,
_padding: u32,
struct GlobalUniforms {
light_matrix_index: u32,
use_shadowmaps: u32,
_padding1: u32,
_padding2: u32,
}
@group(1) @binding(1)
var<uniform> light_matrix_index: LightMatrixIndex;
var<uniform> global_uniforms: GlobalUniforms;
struct VertexInput {
@location(0) position: vec3<f32>,

View file

@ -116,29 +116,36 @@ fn fs_main(vert: VertexOutput) -> @location(0) vec4<f32> {
var total_radiance: vec3<f32>;
var in_light = 0.0;
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.01;
// 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;
}
// Depth sampling is broken in WebGL...
// TODO: remove once WebGPU
if (global_uniforms.use_shadowmaps > 0u) {
for (var i: i32 = 0; i < 6; i++) {
let light_coords = light.matrices[i] * vert.world_position;
in_light = sample_direct_light(i, light_coords);
// TODO should break even if 0 since we're inside frustum.
// See if causes issues with bias overlap between directions.
if (in_light > 0.0) {
break;
let light_dir = normalize(light_coords.xyz);
let bias = 0.01;
// 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);
// TODO should break even if 0 since we're inside frustum.
// See if causes issues with bias overlap between directions.
if (in_light > 0.0) {
break;
}
}
} else {
in_light = 1.0;
}
if (in_light > 0.0) {