Parameters
Name | Type | Description |
---|---|---|
position | vec3<f32> | 3D position to evaluate. |
size | f32 | Size of the tetrahedron. |
Returns
WGSL Code
fn sdfTetrahedron(position: vec3<f32>, size: f32) -> f32 {var p = position;let s = size;// Set initial valueslet signVal = sign(p.x + p.y + p.z);p.x = abs(p.x);p.y = abs(p.y);p.z = abs(p.z);// Calculate the distanceif (p.x < p.y) {let t = p.x;p.x = p.y;p.y = t;}if (p.x < p.z) {let t = p.x;p.x = p.z;p.z = t;}if (p.y < p.z) {let t = p.y;p.y = p.z;p.z = t;}let k = clamp((p.x + p.z - p.y) * 0.5, 0.0, p.z);return signVal * (length(vec3<f32>(p.x, p.y - s, p.z - k)) - s);}