Cheap Water Caustics in UE4
The idea for this post was to cover WorldPositionBehindTranslucency in an interesting fashion, and provide a tangible example on how to utilize this technique to render behind translucent objects.
Using this method, it allows us to project the caustics below the water plane in world space. As a bonus because the projection is below the water plane, physically the caustics will be influenced by your water flow refraction.
The caustics themselves add 49 instructions and 1 texture sample to your translucent water shader.
Effect Breakdown
The key here is the clever usage of WorldPositionBehindTranslucency. By subtracting the actor position from it, we get UV positions which allow us to project the caustics below the water plane in world space. Attach this at the end of your water shader, adding to the Base Color.
The caustics extension to the water shader
There is no procedural methodologies at play here, the material function is an extension to the Motion_4waychaos found in the engine. The panning is equal in all 4 axes, as it is addictive. You can add a general direction to the pan by blending it with SoftLight, and then rotate the panners towards the desired direction
Towards the end, you can see the RGB split implementation. It requires the base texture to have RBG spit on it, and then it de-saturates that using a sine wave. I used a free Substance generator for this one, but you easily can split a black and white texture in Photoshop.
And getting back to the water shader, we lerp the caustics with a simple depth fade :) This prevents caustics from being drawn below a certain point. Everything is multiplied by the scene colour, so that brightly lit areas have more visible caustics and shadowed areas have little to no caustics.
This approach is not without its downsides:
- If the camera is below the water plane, the caustics are gone, but it shouldn’t be hard to use a similar approach in a PP material active below the water plane, or disable depth checking on the water material to keep the caustics (which comes with its own issues as then you need to make depth fading yourself)
- Another issue is flat 90-degree surfaces, which can be solved by sampling the world normal and generating triplanar coordinates for the caustics
If I do get back to this I will update the article with fixes for these issues.
So there you go, a cheap and entirely fake solution for water caustics. A big thank you to Ales Rajar for making the “Modular Cliffs” environment and its base water shader.
You can find the original post on my twitter here.