GLSL shader example

Ray-Marched Torus

Measure distance to the torus major circle and subtract tube radius; inspect occlusion around the inner hole.

Live example

Edit the code and the preview updates as you type.

What to observe

Ray-Marched Torus.

Mechanism

Measure distance to the torus major circle and subtract tube radius; inspect occlusion around the inner hole.

The controlling code

return length(vec2(length(p.xz)-.6,p.y))-.22;

Experiment

In length(vec2(length(p.xz)-.6,p.y))-.22, change the tube radius .22 to .12. The torus becomes thinner and the central hole opens wider, while the major radius remains 0.6.

Debugging and cost

This scene uses an exact torus distance for the primary march, followed by six normal queries. Set the camera's ro.y from 1.5 to 2.0 to inspect more of the hole from above; the ray direction still aims downward through p.y-.9.

Built-in functions used

Learn it step by step