Three.js Fractal Explorer (Mandelbrot, Julia, Burning Ship)
Interactive GPU fractal explorer in Three.js with smooth-colored Mandelbrot, Julia and Burning Ship sets, pointer-anchored zoom, drag to pan, preset locations and a live Julia constant.
Key topics: three.js mandelbrot, julia set, fractal explorer, burning ship, glsl, escape time, smooth coloring
Game Over
What this code does
- Escape-Time Iteration: every pixel iterates z → z² + c in a fragment shader until |z|² > 256 or the iteration cap is reached.
- Smooth Coloring: the continuous count `n − log₂(log₂|z|²)` removes banding before it is mapped through a cosine palette.
- Julia vs Mandelbrot: Mandelbrot varies c per pixel with z₀ = 0, while Julia fixes c and varies z₀; try "follow pointer" to sweep c.
- Pointer-Anchored Zoom: the wheel rescales the view around the complex coordinate under the cursor.
- Precision Limit: GPU 32-bit floats start to pixelate around 10⁵× zoom, which is why deep zooms need perturbation techniques.
- Controls: preset, fractal type, max iterations, palette, color cycling, auto zoom and the Julia constant.
Related Demos
Continue Learning
JavaScript Implementation
const renderer = new THREE.WebGLRenderer()
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)
const scene = new THREE.Scene()
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1)
const uniforms = {
uCenter: { value: new THREE.Vector2(-0.6, 0) },
uScale: { value: 3 },
uAspect: { value: width / height }
}
const material = new THREE.ShaderMaterial({
uniforms,
vertexShader: 'varying vec2 vUv; void main () { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }',
fragmentShader: `
uniform vec2 uCenter; uniform float uScale; uniform float uAspect; varying vec2 vUv;
void main () {
vec2 c = uCenter + (vUv - 0.5) * vec2(uAspect, 1.0) * uScale;
vec2 z = vec2(0.0);
float i = 0.0;
for (int k = 0; k < 300; k++) {
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
if (dot(z, z) > 256.0) break;
i += 1.0;
}
float s = i - log2(log2(dot(z, z))) + 4.0;
vec3 col = i >= 300.0 ? vec3(0.0) : 0.5 + 0.5 * cos(6.2831853 * (s * 0.025 + vec3(0.0, 0.1, 0.2)));
gl_FragColor = vec4(col, 1.0);
}`
})
const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), material)
scene.add(quad)
renderer.domElement.addEventListener('wheel', (e) => {
e.preventDefault()
uniforms.uScale.value *= Math.exp(e.deltaY * 0.0015)
}, { passive: false })
function animate () {
requestAnimationFrame(animate)
renderer.render(scene, camera)
}
animate()