starSDF: Parametric Star Distance Field
Multi-Pointed Star Generation with Angular Precision
The starSDF function generates star-shaped distance fields with precise angular control. This function creates star polygons by dividing angular space into segments and applying alternating radius modulation to create the characteristic pointed and indented star geometry.
Mathematical Foundation
The star pattern is constructed through angular segmentation and polar transformation:
where represents the number of star points and controls the inner scaling factor.
Function Signatures
| Function | Parameters | Description |
|---|---|---|
starSDF(st, V, s) | vec2, int, float | Full control with custom inner scaling |
starSDF(st, V) | vec2, int | Simplified version with default scaling |
Parameters
| Parameter | Type | Description |
|---|---|---|
st | vec2 | 2D coordinate position |
V | int | Number of star points (vertices) |
s | float | Inner scaling factor (default: 0.1) |
Implementation Demonstrations
Live Editor
const fragment = () => { const vertices = iTime.sin().add(3).floor().toInt() const scale = iTime.cos().mul(0.3).add(3) const dist = starSDF(uv, vertices, scale) const brightness = float(0.1).smoothstep(0, dist).mul(0.9) const color = brightness.mul(vec3(1, 0.7, 0.3)) return vec4(color, 1) }