Caustics Shader
From C4 Engine Wiki
WIP.
Contents |
Definition
A caustic is a indirect illuminated light patterns. This sort light patterns are formed when light rays reflected from or transmitted through specular surfaces strikes a diffuse surface. This phenomena can be found at underwater scenes. (Wikipedia)
Principle (underwater caustics)
Underwater caustics are due to dispersion of the light when it hits the water surface. Caustic pattern depends of the waves. Rounded waves will create rounded and slow patterns on the ground contrary to sharpen waves. So define your wave to define your caustics.
Shading
This shader will be approached from a "artistic" point of view (not physically right) First, we gonna add two animated map of caustics to the diffuse. Then we will push a little forward for more realism.
Texture animation is done by translating UVs thanks to the Shader Time box. Multiplying it with a constant permits to speed up and down the speed of the translation.
Here, I used Texcoord 1 as UVs for the caustics, this means a texcoord must be used and generally it will be a Planar from top mapping. (Getting a World Position box would allow to free this texcoord and avoid a mapping.) Multiply the texcoord permits to scale it and calibrate correctly the size of your caustics.
Then Texcoords are rebuild to animate only one it on one axis. the first texture will translate on 't' and the second on 's'. Addition generates animated caustics.
Finally adjust the intensity by multiplying it with a constant. (Saturation can be used)
Add it to the diffuse texture map to achieve the basic shader.
Improvement
- Caustics intensity should depend on the depth. They're highly concentrated on shallow water and disappear when it's getting deeper.
- Caustics sharpness should also depend on the depth. They become more and more blurred as it's getting deeper.
- Scale the caustics textures at different size to avoid repetition, or animate them at different speed (You can also use two different texture for more variation).
- Apply caustics in ambient pass to simulate light reverberation. You can make the intensity dependent of the light direction.
- Pay someone or develop the Shader Editor to get access to the World Position Matrix and so avoid to use a texcoord and get the depth directly.




