Parameters
Name | Type | Description |
---|---|---|
position | vec3<f32> | 3D position to evaluate. |
size | f32 | Size of the icosahedron. |
Returns
WGSL Code
fn sdfIcosahedron(position: vec3<f32>, size: f32) -> f32 {var p = position;let s = size;// Constants for icosahedronlet phi = 1.618033988749895;let a = s;let b = s * phi;// Compute distance to icosahedronp = abs(p / s);let d = p.x * p.y * p.z;let m = max(max(p.x, p.y), p.z);let n = min(min(p.x, p.y), p.z);let mid = p.x + p.y + p.z - m - n;// Calculate the signed distancelet q = select(mid, d, m < phi * n);return (length(p) - phi) * s;}