Parameters
Name | Type | Description |
---|---|---|
position | vec3<f32> | 3D position to evaluate. |
radius | f32 | Base radius of the cone. |
height | f32 | Height of the cone. |
Returns
WGSL Code
fn sdfCone(position: vec3<f32>, radius: f32, height: f32) -> f32 {let q = vec2<f32>(length(position.xz), position.y);let h = height;let r = radius;// Calculate distancelet d1 = -q.y - h;let d2 = max(q.x * h - q.y * r, q.y * h + q.x * r);return length(max(vec2<f32>(d1, d2), vec2<f32>(0.0))) + min(max(d1, d2), 0.0);}