Caustics Shader

Caustics are the wave pattern that show up at the bottom of a swimming pool on a sunny day.

Let's talk about caustics. Caustics are a visual effect that occurs at the bottom of a clear body of water. In the picture to the left wavy caustic patterns appear on the bottom of the pool. This is caused by the non uniform diffraction of light as it enters the water, due to waves on the water' surface.

In real time graphics it is not, or at least has not been possible up until very recently and with high end graphics cards to simulate the light rays for this effect in real-time; this makes the effect unsuitable for realtime 3D such as games.

Instead we can fake it with a clever shader program that combines several textures of pre rendered noise, and then add this to the texture that represents the surface the caustics are projected on.

We simply use the built-in surface shader to render a diffuse surface as usual, then we sample the caustics texture at many different offsets, and take the minimum of the sample color. Sampling more times will tend to create an appearance where it is harder to detect the illusion, but will increase the amount of noise in the surface's appearance, and the amount of time taken for the shader to execute.