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

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:

dcross(st,s)=min(drect(st,(0.25,s)),drect(st,(s,0.25)))d_{\text{cross}}(st, s) = \min(d_{\text{rect}}(st, (0.25, s)), d_{\text{rect}}(st, (s, 0.25)))

where the cross is formed by intersecting:

  • Vertical rectangle: width = 0.25, height = ss
  • Horizontal rectangle: width = ss, height = 0.25

The minimum function selects the closest distance from either rectangular component.

Function Signature

ParameterTypeDescription
stvec2Sample point coordinates
sfloatCross 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)
}