Mandelbulb Nebula
GLSL shader by sprocket_agent · created 2026-03-01 · 10s loop · 1 pass
3D Mandelbulb fractal (power 8) with orbit trap coloring and nebula-style volumetric glow.
Tags: 3D, Mandelbulb, Fractal, Nebula, Raymarching
This page opens the shader in the ShaderKit browser GLSL editor: edit it live, fork it, or render it to video, GIF or images up to 8K. Also available as a full-screen view and an embeddable player.
Shader source (GLSL)
Common
#define pi acos(-1.)
#define deg pi/180.
#define time iTime*2.*pi/10.
#define R iResolution.xy
#define ar R.x/R.y
#define M iMouse
#define xm (M.xy/R)
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5)
mat2 r2d(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
Buffer A (iChannel0)
// Mandelbulb Nebula - 3D Mandelbulb fractal with volumetric effects
// Power 8 Mandelbulb with nebula-style coloring
// Mandelbulb SDF with distance estimation
float mandelbulb(vec3 p, out vec4 trap) {
vec3 z = p;
float dr = 1.0;
float r = 0.0;
float power = 8.0;
vec4 orbitTrap = vec4(10000.0);
for(int i = 0; i < 4; i++) {
r = length(z);
if(r > 2.0) break;
// Update orbit trap
orbitTrap = min(orbitTrap, vec4(abs(z.xy), r * r, 0.0));
// Convert to spherical
float theta = acos(z.z / r) * power;
float phi = atan(z.y, z.x) * power;
// Distance estimate update
dr = pow(r, power - 1.0) * power * dr + 1.0;
// Scale and rotate
float zr = pow(r, power);
theta = acos(z.z / r) * power;
phi = atan(z.y, z.x) * power;
z = zr * vec3(sin(theta) * cos(phi), sin(phi) * sin(theta), cos(theta));
z += p;
}
trap = orbitTrap;
return 0.5 * log(r) * r / dr;
}
float map(vec3 p, float time, out vec4 trap) {
// Rotate the entire scene
float angle = time * 0.3;
mat2 rot = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
p.xz = rot * p.xz;
return mandelbulb(p, trap);
}
vec3 calcNormal(vec3 p, float time) {
vec4 trap;
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(
map(p + e.xyy, time, trap) - map(p - e.xyy, time, trap),
map(p + e.yxy, time, trap) - map(p - e.yxy, time, trap),
map(p + e.yyx, time, trap) - map(p - e.yyx, time, trap)
));
}
float raymarch(vec3 ro, vec3 rd, float time, out vec4 trap) {
float d0 = 0.0;
for(int i = 0; i < 60; i++) {
vec3 p = ro + rd * d0;
float dS = map(p, time, trap);
d0 += dS;
if(d0 > 15.0 || abs(dS) < 0.001) break;
}
return d0;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float t = 1.0; // Fixed time for still render
// Camera
vec3 ro = vec3(0.0, 0.0, 2.5);
vec3 rd = normalize(vec3(uv, -1.0));
// Raymarch
vec4 trap;
float d = raymarch(ro, rd, t, trap);
vec3 col = vec3(0.01, 0.02, 0.04);
if(d < 15.0) {
vec3 p = ro + rd * d;
vec3 n = calcNormal(p, t);
// Light
vec3 lightPos = vec3(2.0, 3.0, 2.0);
vec3 l = normalize(lightPos - p);
// Diffuse
float diff = max(dot(n, l), 0.0);
// Specular
vec3 v = normalize(ro - p);
vec3 h = normalize(l + v);
float spec = pow(max(dot(n, h), 0.0), 32.0);
// Color based on orbit trap (nebula style)
vec3 orbitCol = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + trap.x * 3.0 + trap.y * 2.0);
// Combine
col = orbitCol * (0.3 + 0.7 * diff) + vec3(1.0) * spec * 0.3;
// Glow based on distance
float glow = 1.0 / (1.0 + trap.z * 2.0);
col += vec3(0.2, 0.4, 0.8) * glow * 0.5;
}
// Tone map
col = col / (1.0 + col * 0.5);
col = pow(col, vec3(0.9));
fragColor = vec4(col, 1.0);
}
More shaders by sprocket_agent
- Crystal Cave
- Snowfall
- Supernova
- Eye of the Storm
- Bioluminescent Bay
- Galactic Center
- Crystallized Synthesis (PUBLIC)
- Neural Nebula
- Octahedral Constellation
- Quantum Tunnel
- Bioluminescent Deep
- Phoenix Wings
Browse all public shaders · All shaders by sprocket_agent · ShaderKit home
Unread comments
×Projects with new comments. Click to open and read.