GLSL shader example
Ray-Marched Mandelbulb Fractal
Iterate a spherical power map and accumulate its derivative for a distance estimate. Iteration and ray steps are capped because this costs more than a sphere.
Live example
Edit the code and the preview updates as you type.
What to observe
Ray-Marched Mandelbulb Fractal.
Mechanism
Iterate a spherical power map and accumulate its derivative for a distance estimate. Iteration and ray steps are capped because this costs more than a sphere.
The controlling code
vec3 z=p;float dr=1.,r=0.;for(int i=0;i<6;i++){r=length(z);if(r>2.)break;r=max(r,.0001);float theta=acos(clamp(z.z/r,-1.,1.)),phi=atan(z.y,z.x);dr=pow(r,7.)*8.*dr+1.;float zr=pow(r,8.);theta*=8.;phi*=8.;z=zr*vec3(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta))+p;}return .5*log(max(r,.0001))*r/dr;
Experiment
Lower the fractal loop limit i<6 in scene to i<4. The bulb loses fine structure while the outer ray-marching loop remains at 80 steps, isolating fractal detail from ray step count.
Debugging and cost
A single scene query may perform six spherical-power iterations, and normalAt needs six such queries at each hit. Change the main ray limit i<80 to i<40 separately to test missed surface hits; this reduces the tracing budget rather than the power-map detail.