GLSL shader example

Ray-Marched Tunnel with Repeating Arches

Fold z into a repeating cell containing an arch; camera translation moves the repeated structure past the viewer.

Live example

Edit the code and the preview updates as you type.

What to observe

Ray-Marched Tunnel with Repeating Arches.

Mechanism

Fold z into a repeating cell containing an arch; camera translation moves the repeated structure past the viewer.

The controlling code

p.z=mod(p.z+1.,2.)-1.;vec2 q=abs(p.xy)-vec2(1.2,1.);return max(abs(length(vec2(max(q.x,0.),p.y))-1.)-.08,abs(p.z)-.07);

Experiment

Change the forward motion u_time*.6 in ro to u_time*1.2. Repeated arches pass the camera twice as fast, while their z spacing remains two units.

Debugging and cost

The repeat fold mod(p.z+1.,2.)-1. makes infinitely many cells, but rays still stop after distance 12 or 80 steps. Change the arch slab half-thickness abs(p.z)-.07 to abs(p.z)-.12 to make each repeated slice thicker without raising the cell count.

Built-in functions used

Learn it step by step