Parameters
Name | Type | Description |
---|---|---|
position | vec3<f32> | 3D position to evaluate. |
radius | f32 | Radius of the capsule. |
height | f32 | Height of the cylindrical portion. |
Returns
WGSL Code
fn sdfCapsule(position: vec3<f32>, radius: f32, height: f32) -> f32 {let d = abs(length(position.xz)) - radius;let p = vec2<f32>(d, abs(position.y) - height * 0.5);return length(max(p, vec2<f32>(0.0))) + min(max(p.x, p.y), 0.0) - radius;}