GLSL shader example

Procedural Water Caustics

Domain-warped cell edges produce moving pool-floor patterns. This procedural approximation does not solve light focusing.

Live example

Edit the code and the preview updates as you type.

What to observe

Procedural Water Caustics.

Mechanism

Domain-warped cell edges produce moving pool-floor patterns. This procedural approximation does not solve light focusing.

The controlling code

vec2 q=p*6.+vec2(sin(u_time*.3),cos(u_time*.4));float d=cellEdge(q+vec2(fbm(q+u_time*.15),fbm(q-u_time*.12)));c=vec3(.02,.22,.3)+vec3(.3,.9,.95)*exp(-d*18.);

Experiment

Change the brightness falloff exp(-d*18.) to exp(-d*35.). The bright pool-floor lines become narrower while the warped cell boundaries continue moving along the same paths.

Debugging and cost

Two four-octave fbm calls warp q before the nine-neighbor cellEdge search. Replace q+vec2(fbm(q+u_time*.15),fbm(q-u_time*.12)) with q to remove that warp and its noise cost, leaving a more rigid sliding cell pattern.

Built-in functions used

Learn it step by step