メインコンテンツまでスキップ

superShapeSDF: Parametric Superformula Distance Field

Gielis Superformula for Organic Shape Generation

The superShapeSDF function implements the Gielis superformula, a mathematical equation capable of generating a wide variety of natural and geometric shapes through parametric control. This function creates complex organic forms ranging from flowers to starfish through precise mathematical parametrization.

Mathematical Foundation

The superformula is defined in polar coordinates:

r(θ)=[1acos(mθ4)n2+1bsin(mθ4)n3]1/n1r(\theta) = \left[ \left| \frac{1}{a} \cos\left(\frac{m\theta}{4}\right) \right|^{n_2} + \left| \frac{1}{b} \sin\left(\frac{m\theta}{4}\right) \right|^{n_3} \right]^{-1/n_1}

The distance calculation converts the point to polar coordinates, computes the superformula radius, and measures deviation:

d=p5sr(θ)(cosθ,sinθ)d = |p| \cdot 5 - |s \cdot r(\theta) \cdot (\cos\theta, \sin\theta)|

Function Signatures

superShapeSDF

ParameterTypeDescription
stvec2Sample point position
sfloatOverall scale factor
afloatX-axis scaling parameter
bfloatY-axis scaling parameter
n1floatPrimary shape exponent
n2floatCosine term exponent
n3floatSine term exponent
mfloatRotational symmetry order

superShapeSDFCenter

Same parameters as superShapeSDF plus:

ParameterTypeDescription
centervec2Shape center position

Parameter Effects

ParameterRangeEffect
m1-20Rotational symmetry (m=4 creates 4-fold symmetry)
n10.1-10Overall shape roundness/sharpness
n2, n30.1-10Cosine/sine term sharpness
a, b0.1-2Axis scaling ratios

Implementation Demonstrations

ライブエディター
const fragment = () => {
      const p = uv.mul(2).sub(1).mul(0.1)
      const dist = superShapeSDFCenter(p, vec2(0), 0.5, 1, 1, 1, 1, 1, 5)
      const color = float(0).step(dist).oneMinus()
      return vec4(vec3(color), 1)
}