Parameters
| Name | Type | Description |
|---|---|---|
| position | vec3<f32> | 3D position to evaluate. |
| radius1 | f32 | Bottom radius of the cone. |
| radius2 | f32 | Top radius of the cone. |
| height | f32 | Height of the cone. |
| roundness | f32 | Rounding factor for the edges. |
Returns
WGSL Code
fn sdfRoundedCone(position: vec3<f32>, radius1: f32, radius2: f32, height: f32, roundness: f32) -> f32 { // Calculate distances let p = position; let r1 = radius1 - roundness; let r2 = radius2 - roundness; let h = height; // Squared distance from axis let q = length(p.xz); // Project into 2D space let k1 = (r2 - r1) / h; let k2 = h / (r1 - r2); let projected = vec2<f32>(q - r1 + r1 * (p.y / h) * (r1 - r2) / r1, p.y - h); let ca = p.y * k1 - q; let cb = p.y - r1 * k2 + q * k2; var s: f32; if (ca < 0.0 && projected.y < 0.0) { s = length(projected) - roundness; } else if (ca > 0.0 && cb < 0.0) { s = -ca - roundness; } else { s = length(vec2<f32>(max(ca, 0.0), max(projected.y, 0.0))) - roundness; } return s; }