Parameters
| Name | Type | Description |
|---|---|---|
| position | vec3<f32> | 3D position to evaluate. |
| size | f32 | Base size of the pyramid. |
| height | f32 | Height of the pyramid. |
Returns
WGSL Code
fn sdfPyramid(position: vec3<f32>, size: f32, height: f32) -> f32 { // Normalize position var p = position; let h = height; let m2 = h * h + size * size; // Project into 2D let q = abs(p); p.y -= h; p.y = max(p.y, 0.0); // Distance calculation var d: f32; if (max(q.x, q.z) < size) { d = length(vec2<f32>(length(p.xz), p.y)) - sqrt(m2); } else { d = length(vec2<f32>(length(max(abs(p.xz) - vec2<f32>(size), vec2<f32>(0.0))), p.y)); } // Account for position below base d = select(d, length(p) - sqrt(m2), p.y < 0.0); return d; }