Mandelbulb
Video Lecture
Section | Video Links |
---|---|
Mandelbulb | ![]() ![]() |
(Pay Per View)
You can use PayPal to purchase a one time viewing of this video for $1.49 USD.
Description
We will practice concepts that we've already scene, but use a fractal algorithm known as the Mandelbulb.
Working Example
The Mandelbulb Algorithm
-
Start with a 3D position (x, y, z).
This is the position we are testing to see if it belongs to the fractal.
-
Initialize variables
- Make a copy of this position.
- Set a "derivative accumulator" (
dr
) to 1. This keeps track of how distances stretch as we iterate.
-
Repeat for several iterations. (usually 8–12 times, or until we "escape")
- Measure the distance from the origin.
r = length(z)
- Escape check. If
r > 2
, we know we are outside the fractal and can stop early. - Update the derivative accumulator. This step is used later to estimate how far we are from the fractal surface.
- Convert to spherical coordinates. Think a point on a sphere:
- r = how far from the center
- θ =
theta
. The angle from the vertical axis (like latitude) - φ =
phi
. The angle around the vertical axis (like longitude)
- Scale by the fractal power
- Raise
r
to a power (e.g. r^8) - Multiply the angles θ and φ by the same power.
- Raise
- Convert the scaled (r, θ, φ) back into 3D (cartesian) coordinates (x, y, z)
- Add to the original position.
p.addAssign(position)
- Measure the distance from the origin.
-
After the loop, calculate the final distance estimate.
return log(r).mul(r).div(dr).mul(0.5)
This gives us a good guess of how far we are from the nearest surface of the Mandelbulb, which lets us raymarch efficiently.
Start Scripts
./src/SDFScene.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
./src/Mandelbulb.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
./src/main.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
ShadowMarcher Settings
Property | Value |
---|---|
softness | 10 |
intensity | 0.15 |
maxSteps | 32 |
near | 0.01 |
far | 64 |
surfaceDistance | 0.001 |
Ambient Occlusion Settings
Property | Value |
---|---|
samples | 4 |
spread | 0.015 |
factor | 0.005 |