summaryrefslogtreecommitdiff
path: root/assets/final/shaders/render
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 14:08:09 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 14:08:09 +0100
commit1e3e3f54a4f80bd05d168c9ae749ed32e1275868 (patch)
tree88ecf1aaa8c22d64079d45081c96f318a3dd3766 /assets/final/shaders/render
parentb00d1cd351ec6c960ef957950e95930344f75dcc (diff)
fix(shaders): Resolve WGSL validation errors and add shader compilation tests
Fixed three critical WGSL shader issues causing demo64k and test_3d_render to crash: 1. **renderer_3d.wgsl**: Removed dead code using non-existent `inverse()` function - WGSL doesn't have `inverse()` for matrices - Dead code was unreachable but still validated by shader compiler - Also removed reference to undefined `in.normal` vertex input 2. **sdf_utils.wgsl & lighting.wgsl**: Fixed `get_normal_basic()` signature mismatch - Changed parameter from `obj_type: f32` to `obj_params: vec4<f32>` - Now correctly matches `get_dist()` function signature 3. **scene_query_linear.wgsl**: Fixed incorrect BVH binding declaration - Linear mode was incorrectly declaring binding 2 (BVH buffer) - Replaced BVH traversal with simple linear object loop - Root cause: Both BVH and Linear shaders were identical (copy-paste error) Added comprehensive shader compilation test (test_shader_compilation.cc): - Tests all production shaders compile successfully through WebGPU - Validates both BVH and Linear composition modes - Catches WGSL syntax errors, binding mismatches, and type errors - Would have caught all three bugs fixed in this commit Why tests didn't catch this: - Existing test_shader_assets only checked for keywords, not compilation - No test actually created WebGPU shader modules from composed code - New test fills this gap with real GPU validation Results: - demo64k runs without WebGPU errors - test_3d_render no longer crashes - All 22/23 tests pass (FftTest unrelated issue from FFT Phase 1) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'assets/final/shaders/render')
-rw-r--r--assets/final/shaders/render/scene_query_linear.wgsl58
1 files changed, 13 insertions, 45 deletions
diff --git a/assets/final/shaders/render/scene_query_linear.wgsl b/assets/final/shaders/render/scene_query_linear.wgsl
index ab3845a..b61a7e4 100644
--- a/assets/final/shaders/render/scene_query_linear.wgsl
+++ b/assets/final/shaders/render/scene_query_linear.wgsl
@@ -1,15 +1,6 @@
#include "math/sdf_shapes"
#include "math/sdf_utils"
-struct BVHNode {
- min: vec3<f32>,
- left_idx: i32,
- max: vec3<f32>,
- obj_idx_or_right: i32,
-};
-
-@group(0) @binding(2) var<storage, read> bvh_nodes: array<BVHNode>;
-
fn get_dist(p: vec3<f32>, obj_params: vec4<f32>) -> f32 {
let obj_type = obj_params.x;
if (obj_type == 1.0) { return length(p) - 1.0; } // Unit Sphere
@@ -22,42 +13,19 @@ fn get_dist(p: vec3<f32>, obj_params: vec4<f32>) -> f32 {
fn map_scene(p: vec3<f32>, skip_idx: u32) -> f32 {
var d = 1000.0;
- var stack: array<i32, 32>;
- var stack_ptr = 0;
-
- if (arrayLength(&bvh_nodes) > 0u) {
- stack[stack_ptr] = 0;
- stack_ptr++;
- }
-
- while (stack_ptr > 0) {
- stack_ptr--;
- let node_idx = stack[stack_ptr];
- let node = bvh_nodes[node_idx];
-
- if (aabb_sdf(p, node.min, node.max) < d) {
- if (node.left_idx < 0) { // Leaf
- let obj_idx = u32(node.obj_idx_or_right);
- if (obj_idx == skip_idx) { continue; }
- let obj = object_data.objects[obj_idx];
- let q = (obj.inv_model * vec4<f32>(p, 1.0)).xyz;
- let s = min(length(obj.model[0].xyz), min(length(obj.model[1].xyz), length(obj.model[2].xyz)));
- // IMPORTANT: Plane (type 4.0) and Mesh (type 5.0) should not be scaled by 's'.
- // The 's' factor is meant for unit primitives (sphere, box, torus) that are
- // scaled by the model matrix. Meshes already have correct local-space extents.
- if (obj.params.x != 4.0 && obj.params.x != 5.0) { // Not plane, not mesh
- d = min(d, get_dist(q, obj.params) * s);
- } else {
- d = min(d, get_dist(q, obj.params));
- }
- } else { // Internal
- if (stack_ptr < 31) {
- stack[stack_ptr] = node.left_idx;
- stack_ptr++;
- stack[stack_ptr] = node.obj_idx_or_right;
- stack_ptr++;
- }
- }
+ let num_objects = arrayLength(&object_data.objects);
+ for (var i = 0u; i < num_objects; i++) {
+ if (i == skip_idx) { continue; }
+ let obj = object_data.objects[i];
+ let q = (obj.inv_model * vec4<f32>(p, 1.0)).xyz;
+ let s = min(length(obj.model[0].xyz), min(length(obj.model[1].xyz), length(obj.model[2].xyz)));
+ // IMPORTANT: Plane (type 4.0) and Mesh (type 5.0) should not be scaled by 's'.
+ // The 's' factor is meant for unit primitives (sphere, box, torus) that are
+ // scaled by the model matrix. Meshes already have correct local-space extents.
+ if (obj.params.x != 4.0 && obj.params.x != 5.0) { // Not plane, not mesh
+ d = min(d, get_dist(q, obj.params) * s);
+ } else {
+ d = min(d, get_dist(q, obj.params));
}
}
return d;