Parameters
| Name | Type | Description |
|---|---|---|
| position | vec3<f32> | 3D position to evaluate. |
| radius | f32 | Radius of the cylinder. |
| height | f32 | Height of the cylinder. |
| roundness | f32 | Rounding factor for the edges. |
Returns
WGSL Code
fn sdfRoundedCylinder(position: vec3<f32>, radius: f32, height: f32, roundness: f32) -> f32 { // Calculate distances let radiusOffset = radius - roundness; let heightOffset = height * 0.5 - roundness; // Generate rounded cylinder let d = vec2<f32>(length(position.xz) - radiusOffset, abs(position.y) - heightOffset); return min(max(d.x, d.y), 0.0) + length(max(d, vec2<f32>(0.0))) - roundness; }