diff options
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..61efe49 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) 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; |
