diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-06 08:46:20 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-06 08:46:20 +0100 |
| commit | 7d60a8a9ece368e365b5c857600004298cb89526 (patch) | |
| tree | aa394cb9823939c561b8fb09897f1e192a4059ad /assets/final/shaders/render/scene_query_bvh.wgsl | |
| parent | 180b0961a2216279024b4d35229d105d95a61878 (diff) | |
fix: Correct mesh normal transformation and floor shadow rendering
Diffstat (limited to 'assets/final/shaders/render/scene_query_bvh.wgsl')
| -rw-r--r-- | assets/final/shaders/render/scene_query_bvh.wgsl | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/assets/final/shaders/render/scene_query_bvh.wgsl b/assets/final/shaders/render/scene_query_bvh.wgsl index c7dfdf4..d040c1b 100644 --- a/assets/final/shaders/render/scene_query_bvh.wgsl +++ b/assets/final/shaders/render/scene_query_bvh.wgsl @@ -10,11 +10,13 @@ struct BVHNode { @group(0) @binding(2) var<storage, read> bvh_nodes: array<BVHNode>; -fn get_dist(p: vec3<f32>, obj_type: f32) -> f32 { +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; } @@ -40,7 +42,14 @@ fn map_scene(p: vec3<f32>, skip_idx: u32) -> f32 { 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))); - d = min(d, get_dist(q, obj.params.x) * s); + // IMPORTANT: Plane (type 4.0) should not be scaled by 's' in this way. + // The sdPlane function expects its own scale/offset implicitly handled by the model matrix. + // The 's' factor is meant for primitives whose SDFs are defined relative to a unit size. + if (obj.params.x != 4.0) { // Only scale if not a plane + 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; |
