Daniel Gray

Thoughts, Notes, Ideas, Projects

Contact

GLSL 3D Fractals - 3D IFS Fractals

Iterated Function Systems (IFS) are a powerful method for generating fractals using affine transformations. In 3D, IFS fractals can create stunning organic and geometric forms, from ferns and trees to complex geometric structures. The technique applies a set of transformations iteratively, with each transformation having a probability of being applied.

Interactive Demo

Move your mouse to rotate the camera and explore the IFS fractal. Scroll to adjust parameters and see how the structure evolves:

Mathematical Foundation

Affine Transformations

An affine transformation in 3D combines:

  • Rotation: RR3×3R \in \mathbb{R}^{3 \times 3}
  • Scaling: sRs \in \mathbb{R}
  • Translation: tR3\mathbf{t} \in \mathbb{R}^3

The transformation is:

xn+1=sRxn+t\mathbf{x}_{n+1} = s \cdot R \cdot \mathbf{x}_n + \mathbf{t}

IFS Definition

An IFS consists of NN transformations {T1,T2,,TN}\{T_1, T_2, \ldots, T_N\}, each with:

  • A transformation matrix MiM_i
  • A translation vector ti\mathbf{t}_i
  • A probability pip_i (for random IFS)

Deterministic IFS

In deterministic IFS, all transformations are applied:

xn+1=Ti(xn)for all i\mathbf{x}_{n+1} = T_i(\mathbf{x}_n) \quad \text{for all } i

The fractal is the union of all transformed copies.

Random IFS

In random IFS, transformations are chosen probabilistically:

P(Ti)=piwhere i=1Npi=1P(T_i) = p_i \quad \text{where } \sum_{i=1}^{N} p_i = 1

Distance Estimation

For IFS fractals, we can estimate distance by finding the minimum distance to any transformed copy:

d(p)=mini{d(Ti1(p))si}d(\mathbf{p}) = \min_i \left\{ d(T_i^{-1}(\mathbf{p})) \cdot s_i \right\}

Where sis_i is the scale factor of transformation ii.

Classic IFS Examples

Sierpinski Triangle (2D → 3D)

The 3D Sierpinski triangle uses three transformations:

T1(x)=12x+(000)T_1(\mathbf{x}) = \frac{1}{2}\mathbf{x} + \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}

T2(x)=12x+(0.500)T_2(\mathbf{x}) = \frac{1}{2}\mathbf{x} + \begin{pmatrix} 0.5 \\ 0 \\ 0 \end{pmatrix}

T3(x)=12x+(0.250.4330)T_3(\mathbf{x}) = \frac{1}{2}\mathbf{x} + \begin{pmatrix} 0.25 \\ 0.433 \\ 0 \end{pmatrix}

Barnsley Fern (3D Extension)

The famous Barnsley fern can be extended to 3D:

T1(x)=(00000.160000)xT_1(\mathbf{x}) = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0.16 & 0 \\ 0 & 0 & 0 \end{pmatrix}\mathbf{x}

T2(x)=(0.850.0400.040.850000.9)x+(01.60)T_2(\mathbf{x}) = \begin{pmatrix} 0.85 & 0.04 & 0 \\ -0.04 & 0.85 & 0 \\ 0 & 0 & 0.9 \end{pmatrix}\mathbf{x} + \begin{pmatrix} 0 \\ 1.6 \\ 0 \end{pmatrix}

3D Spiral IFS

A 3D spiral IFS creates organic, twisting forms:

Ti(x)=Rz(θi)Ry(ϕi)S(si)x+tiT_i(\mathbf{x}) = R_z(\theta_i) \cdot R_y(\phi_i) \cdot S(s_i) \cdot \mathbf{x} + \mathbf{t}_i

Where RzR_z and RyR_y are rotation matrices, and SS is a scaling matrix.

Implementation Details

The GLSL implementation uses:

  • Ray marching with distance estimation
  • Iterative transformation application
  • Minimum distance calculation across all transformations
  • Normal calculation using finite differences

Key Parameters

Transformation Count

The number of transformations affects:

  • Complexity: More transformations = more detail
  • Performance: More transformations = slower rendering
  • Shape: Different transformations create different forms

Scale Factors

Scale factors control:

  • Self-similarity: Smaller scales = more detail
  • Convergence: Scales < 1.0 ensure convergence
  • Structure: Different scales create different patterns

Probabilities (Random IFS)

In random IFS, probabilities control:

  • Density: Higher probability = more points
  • Shape: Different probabilities emphasize different regions
  • Organic appearance: Non-uniform probabilities create natural forms

Visual Characteristics

3D IFS fractals exhibit:

  • Organic beauty: Natural, plant-like structures
  • Geometric precision: Mathematical perfection
  • Infinite detail: Self-similar at all scales
  • Variety: Can create vastly different forms

References

  • "Fractals Everywhere" by Michael Barnsley
  • "The Algorithmic Beauty of Plants" by Prusinkiewicz and Lindenmayer
  • IFS Fractals

Related Articles

Related Content

GLSL 3D Fractals - Sierpinski Tetrahedron

GLSL 3D Fractals - Sierpinski Tetrahedron The Sierpinski Tetrahedron is the 3D generalization of the classic Sierpinski triangle. It's created by recursively subdividing a regular tetrahedron, removin...

GLSL 3D Fractals Series

GLSL 3D Fractals Series 3D fractals represent some of the most visually stunning and mathematically fascinating objects in computer graphics. This series explores how to render these infinite structur...