Parameters
| Name | Type | Description |
|---|---|---|
| position | vec3<f32> | 3D position to evaluate. |
| radius | f32 | Radius of the hexagon. |
| height | f32 | Height of the prism. |
Returns
WGSL Code
fn sdfHexagonalPrism(position: vec3<f32>, radius: f32, height: f32) -> f32 { // Project into 2D var p = abs(position); let k = vec3<f32>(-0.866025404, 0.5, 0.577350269); // Hexagon in xy-plane p = vec3<f32>(p.x + p.y * k.x, p.y * k.y, p.z); p = vec3<f32>(p.x - min(p.x, p.y), p.y, p.z); let d = vec2<f32>(length(vec2<f32>(p.x, p.y - radius * k.z)) - radius, abs(p.z) - height * 0.5); return min(max(d.x, d.y), 0.0) + length(max(d, vec2<f32>(0.0))); }