#include "math/sdf_shapes" fn get_dist(p: vec3, obj_type: f32) -> f32 { if (obj_type == 1.0) { return length(p) - 1.0; } // Unit Sphere if (obj_type == 2.0) { return sdBox(p, vec3(1.0)); } // Unit Box if (obj_type == 3.0) { return sdTorus(p, vec2(1.0, 0.4)); } // Unit Torus if (obj_type == 4.0) { return sdPlane(p, vec3(0.0, 1.0, 0.0), 0.0); } return 100.0; } fn map_scene(p: vec3, skip_idx: u32) -> f32 { var d = 1000.0; let count = u32(globals.params.x); for (var i = 0u; i < count; i = i + 1u) { if (i == skip_idx) { continue; } let obj = object_data.objects[i]; let obj_type = obj.params.x; // Skip rasterized objects (like the floor) in the SDF map if (obj_type <= 0.0) { continue; } let q = (obj.inv_model * vec4(p, 1.0)).xyz; let scale_x = length(obj.model[0].xyz); let scale_y = length(obj.model[1].xyz); let scale_z = length(obj.model[2].xyz); // Use conservative minimum scale to avoid overstepping the distance field let s = min(scale_x, min(scale_y, scale_z)); d = min(d, get_dist(q, obj_type) * s); } return d; }