Skip to main content

spiralSDF: Logarithmic Spiral Pattern Generator

Mathematical Spiral Construction in 2D Space

The spiralSDF function creates intricate spiral patterns by combining logarithmic radius transformation with angular positioning. This function generates distance fields that follow logarithmic spiral mathematics, producing visually appealing rotational patterns.

Mathematical Foundation

The spiral function operates through polar coordinate transformation:

dspiral=sin(fract(log(r)t+θk))d_{\text{spiral}} = |\sin(\text{fract}(\log(r) \cdot t + \theta \cdot k))|

where:

  • r=stcenter2r = ||\mathbf{st} - \mathbf{center}||^2 represents the squared distance from center
  • θ=arctan(y,x)\theta = \arctan(y, x) provides angular position
  • tt controls spiral tightness and frequency
  • k=0.15912πk = 0.159 \approx \frac{1}{2\pi} normalizes angular scaling

The logarithmic transformation creates exponentially expanding spiral arms, while the fractional component generates periodic repetition.

Function Signature

ParameterTypeDescription
stvec22D coordinate position
tfloatSpiral frequency and tightness control

Implementation Demonstrations

Live Editor
const fragment = () => {
      const coord = uv.mul(2).sub(1)
      const time = iTime.mul(0.1)
      const spiral1 = spiralSDF(coord.mul(0.5).add(0.5), time.add(2))
      const spiral2 = spiralSDF(coord.mul(0.7).add(0.5), time.mul(1.3).add(4))
      const pattern = spiral1.mul(spiral2)
      const color = pattern.pow(0.5).mul(vec3(1, 0.7, 0.4))
      return vec4(color, 1)
}