diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 18:51:54 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 18:51:54 +0100 |
| commit | 7790472dabfa0ecd06f3408d847860ec6072866e (patch) | |
| tree | 5bce7b119f42d131daf746ddc052da2da5ff0650 /workspaces/main/shaders/render/scene_query_bvh.wgsl | |
| parent | 002ab9094f638c46d5db95d478e71c10933aceb2 (diff) | |
feat: Implement workspace system (Task #77)
Self-contained workspaces for parallel demo development.
Structure:
- workspaces/main,test - Demo-specific resources
- assets/common - Shared resources
- workspace.cfg - Configuration per workspace
CMake integration:
- DEMO_WORKSPACE option (defaults to main)
- cmake/ParseWorkspace.cmake - Config parser
- Workspace-relative asset/timeline/music paths
Migration:
- Main demo: demo.seq to workspaces/main/timeline.seq
- Test demo: test_demo.seq to workspaces/test/timeline.seq
- Common shaders: assets/common/shaders
- Workspace shaders: workspaces/*/shaders
Build:
cmake -B build -DDEMO_WORKSPACE=main
cmake -B build_test -DDEMO_WORKSPACE=test
All tests passing (36/36).
handoff(Claude): Task #77 workspace system complete. Both main and test workspaces build and pass all tests.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces/main/shaders/render/scene_query_bvh.wgsl')
| -rw-r--r-- | workspaces/main/shaders/render/scene_query_bvh.wgsl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/workspaces/main/shaders/render/scene_query_bvh.wgsl b/workspaces/main/shaders/render/scene_query_bvh.wgsl new file mode 100644 index 0000000..3e6f895 --- /dev/null +++ b/workspaces/main/shaders/render/scene_query_bvh.wgsl @@ -0,0 +1,67 @@ +#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 + if (obj_type == 2.0) { return sdBox(p, vec3<f32>(1.0)); } // Unit Box + if (obj_type == 3.0) { return sdTorus(p, vec2<f32>(1.0, 0.4)); } // Unit Torus + if (obj_type == 4.0) { return sdPlane(p, vec3<f32>(0.0, 1.0, 0.0), 0.0); } + if (obj_type == 5.0) { return sdBox(p, obj_params.yzw); } // MESH AABB + return 100.0; +} + +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; + + // Extract scale factors from the model matrix + let sx = length(obj.model[0].xyz); + let sy = length(obj.model[1].xyz); + let sz = length(obj.model[2].xyz); + + var s = min(sx, min(sy, sz)); + if (obj.params.x == 4.0) { + s = sy; // Plane normal is (0,1,0) in local space + } + + d = min(d, get_dist(q, obj.params) * s); + } else { // Internal + if (stack_ptr < 31) { + stack[stack_ptr] = node.left_idx; + stack_ptr++; + stack[stack_ptr] = node.obj_idx_or_right; + stack_ptr++; + } + } + } + } + return d; +} |
