A project for rendering fractal shapes using shaders written entirely in Rust via Rust-GPU.
This project uses:
- Rust-GPU - Write GPU shaders in Rust, compiled to SPIR-V
- wgpu - Cross-platform graphics API for rendering
- winit - Window creation and event handling
- Rust (Edition 2024)
- Vulkan-compatible GPU and drivers
# Build the shaders (compiles Rust to SPIR-V)
cargo gpu build
# Run the application
cargo run -p mygraphics
# Select a shader to run:
# 1. Sierpinski Triangle
# 2. Sierpinski Carpet
# 3. Koch Curve
# 4. Mandelbrot Set
# 5. Julia Set
# 6. Sierpinski Tetrahedron
# 7. Menger Sponge
# 8. Mandelbulb
# 9. Mandelbox
# Enter your choice (1-9):| Fractal | Hausdorff Dimension | Status |
|---|---|---|
| Sierpinski Triangle | Done | |
| Sierpinski Carpet | Done | |
| Koch Curve | Done | |
| Mandelbrot Set | Done | |
| Julia Set | Done |
The Sierpinski Triangle (also called Sierpinski Gasket) is a self-similar fractal created by recursively removing the central inverted triangle from an equilateral triangle.
Construction: Start with an equilateral triangle. Connect the midpoints of the three sides to form four smaller triangles. Remove the central triangle. Repeat for each remaining triangle.
Formula: A point
Using space-folding technique:
The Sierpinski Carpet is a plane fractal that generalizes the Cantor set to two dimensions. It is created by recursively subdividing a square into 9 smaller squares and removing the central one.
Construction: Divide the square into a 3×3 grid. Remove the center square. Repeat for each of the 8 remaining squares.
Formula: A point
Iteration formula:
The Koch Curve (Koch Snowflake when closed) is a fractal curve created by repeatedly replacing each line segment with a bent line consisting of four segments of equal length.
Construction: Start with a line segment. Divide into three equal parts. Replace the middle third with two sides of an equilateral triangle (removing the base). Repeat for all segments.
Recursive definition: If
Parametric formula for iteration
Angle at each bend:
The Mandelbrot Set is the set of complex numbers
Iteration formula:
where
Escape condition: A point
Complex arithmetic:
Coloring: Based on escape iteration count
The Julia Set is closely related to the Mandelbrot Set. For a fixed complex constant
Iteration formula:
where
Key difference from Mandelbrot:
- Mandelbrot:
$z_0 = 0$ ,$c$ varies per pixel - Julia:
$c$ is fixed,$z_0$ varies per pixel
Common Julia constants:
-
$c = -0.7 + 0.27015i$ (spiral pattern) -
$c = -0.8 + 0.156i$ (dendrite) -
$c = -0.4 + 0.6i$ (rabbit)
Escape condition:
| Fractal | Hausdorff Dimension | Status |
|---|---|---|
| Sierpinski Tetrahedron | Done | |
| Menger Sponge | Done | |
| Mandelbulb |
|
Done |
| Mandelbox | Varies | Done |
All 3D fractals use ray marching with signed distance functions (SDF):
The Sierpinski Tetrahedron (Tetrix) is the 3D analog of the Sierpinski Triangle. It is constructed by recursively removing the central octahedron from a tetrahedron.
Construction: Start with a regular tetrahedron. Connect the midpoints of all edges to form 4 smaller tetrahedra at the corners. Remove the central octahedron. Repeat.
Space folding SDF:
Vertex fold: Fold space across planes passing through edges toward vertices:
where
Scale and translate:
Distance estimate:
The Menger Sponge is a 3D fractal that generalizes the Sierpinski Carpet to three dimensions. It is created by recursively removing cross-shaped sections from a cube.
Construction: Divide the cube into a 3×3×3 grid (27 smaller cubes). Remove the center cube and the 6 cubes sharing a face with it (7 cubes total, leaving 20). Repeat for each remaining cube.
Volume after
SDF using space folding:
Scale and offset:
Cross removal condition:
The Mandelbulb is a 3D analog of the Mandelbrot Set, using spherical coordinates to define a power operation in 3D space.
Spherical coordinates:
Power formula (for power
Iteration:
where
Distance estimate:
where
Escape condition:
The Mandelbox is a box-like fractal discovered by Tom Lowe in 2010. It uses conditional folding operations rather than power formulas.
Box fold: Fold each component into the range
Ball fold: Apply spherical inversion based on distance from origin:
where
Full iteration:
where
Distance estimate:
- pedrotrschneider has written fractal shaders in glsl








