While upgrading versions on DotCam and TK-Master’s Ocean plugin I realized while there are some underwater camera effects in the new version, there isn’t any fog effect, and having previously run into the limitation of a single Exponential Height Fog actor per level in UE4, I realized I would need to buckle down and write a fog shader myself. Not hard, of course, but there are a couple of tricks that should save time and hair pulling.
First, let’s see how the current underwater shader effect in the example level looks:
Not bad – the animated 4-Way Chaos setup combined with the wavy normal map does an admiral job at simulating the effect of looking through clear water.
But what if your ocean has a high amount of plankton, or other debris?
Something like the above is a bit more suited.
To replicate this, create a new material and set it to be a Post Process type.
Then recreate this node layout:
The code for the custom node (ExponentialDepthFog, in the image) is very simple:
// Get the distance from scene depth float dist = length(pixelDist); float fogFactor = 0; // Compute our fog lerp factor fogFactor = exp( -pow(dist * fogDensity, 2)); fogFactor = saturate(1 - fogFactor); // Lerp between fog and scene color. return lerp(sceneColor, fogColor, fogFactor );
Once you’ve created the material, add it to your underwater PostProcessVolume under the blendables section.