crossSDF: Cross-Shaped Distance Field Composition
Geometric Intersection of Perpendicular Rectangles
The crossSDF
function generates a cross-shaped signed distance field by computing the minimum distance between two perpendicular rectangular strips. This composite primitive demonstrates SDF combination techniques through geometric intersection.
Mathematical Foundation
The cross SDF operates through rectangular composition and minimum distance selection:
where the cross is formed by intersecting:
- Vertical rectangle: width = 0.25, height =
- Horizontal rectangle: width = , height = 0.25
The minimum function selects the closest distance from either rectangular component.
Function Signature
Parameter | Type | Description |
---|---|---|
st | vec2 | Sample point coordinates |
s | float | Cross arm length parameter |
Implementation Demonstrations
ライブエディター
const fragment = () => { const dist = crossSDF(uv, iTime.sin().mul(0.5).add(0.5)) const inside = dist.step(0.5) const edge = float(0.02).smoothstep(0, dist.abs()) const color = inside.mul(0.7).add(edge.mul(0.4)) return vec4(color.mul(vec3(1, 0.3, 0.5)), 1) }