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

Anti-Aliased Mirror Function

Function Overview

The aamirror function creates a mirrored pattern that automatically applies anti-aliasing to eliminate visual artifacts. This function transforms input values into smooth, symmetric waves that repeat with perfect mirroring.

Mathematical Foundation

The anti-aliased mirror function creates symmetric patterns through mathematical transformation and filtering:

v=xx+0.52v = \left| x - \lfloor x + 0.5 \rfloor \right| \cdot 2

The anti-aliasing width calculation: afwidth=ddx(x),ddy(x)\text{afwidth} = \left\|\frac{d}{dx}(x), \frac{d}{dy}(x)\right\|

The result is processed through Nyquist filtering for smooth transitions: aamirror(x)=nyquist(v,afwidth)\text{aamirror}(x) = \text{nyquist}(v, \text{afwidth})

Where the Nyquist filter applies: nyquist(v,w)=smoothstep(0,w,v)\text{nyquist}(v, w) = \text{smoothstep}(0, w, v)

This creates perfect mirror symmetry with automatic anti-aliasing that adapts to screen pixel density.

Core Implementation Logic

ComponentPurposeMathematical Expression
Mirror TransformCreates symmetric patternabs(x - floor(x + 0.5)) * 2
Anti-aliasing WidthCalculates smoothing factorvec2(dFdx(x), dFdy(x)).length()
Nyquist FilterPrevents aliasing artifactsmix(0.5, pattern, smoothstep(...))

Basic Mirror Pattern

Create fundamental mirrored waves that repeat seamlessly across space.

ライブエディター
const fragment = () => {
      const x = uv.x.mul(8)
      const mirror = aamirror(x)
      const color = vec3(mirror)
      return vec4(color, 1)
}

Distorted Mirror Field

Apply spatial distortions to mirror patterns for organic, fluid effects.

ライブエディター
const fragment = () => {
      const distortion = uv.y.mul(8).sin().mul(0.3)
      const x = uv.x.mul(6).add(distortion)
      const mirror = aamirror(x)
      const intensity = mirror.pow(2)
      const color = vec3(intensity.mul(0.9).add(0.1))
      return vec4(color, 1)
}