A thorough instruction by Ryan Brucks.
Ryan Brucks published a post that demonstrates some ways to create artistic effects using the new Volumetric Fog system in UE4. Some of the methods shown use existing features of Unreal, others leverage the PseudoVolume Texture support in the artist’s GDC Content Plugin. You can get the pulugin here.
First of all, take some time to study this twitch stream:
A Volumetric Fog solution gives you the ability to define fog density using HeightFog and/or ParticleSystems. It also gives fog the ability to receive shadows from the environment by compositing shadowmaps into the volume. You can boost your scenes’ quality and it’s not that difficult.
Modifying Fog with Materials
As of 4.17, in order to use a material to write to the volumetric fog, a Particle System must be used. Any particles using a material with the Material Domain set to Volumetric will render their materials to the volume fog. The material is meant to be set up with a Sphere Mask using WorldPosition, ParticlePosition, and ParticleRadius. The documentation link above has a good example for that, so I am just going to show a few more advanced and customized versions.
When using particles to write to the fog, you must be mindful of the cost as it can get out of control quickly. The cost will be how many voxels each particle overlaps times the material instruction count. If any particle can cover the whole screen view, there better be only one particle contributing, as otherwise you are paying the cost to overdraw many times for the whole volume.
In theory it is better to use smaller localized particles to limit the area of the volume written to, but if the camera can ever go into those localized areas, the overdraw can get pretty expensive. Another approach is to use only one particle large enough to cover the whole volume bounds to just fix the cost at the worst case which is sometimes beneficial.
The easiest way to set that up is by making a Particle System with a spawn rate of 0 and a Burst of 1. Then you need a material with MD_Volumetric.
You might assume that to do cool things with 3D fog, you would need 3D textures. While they do help, plenty of effects can be done using only 2D textures. This fog bank over the water effect is achieved by using the ‘one large particle’ method, using a 2d noise texture:
The material setup for the density looks like this:
This is basically custom, textured heightfog. The worldposition Z uses a linear gradient to define the density. The start of the gradient is offset by the 2D texture. The texture is mapped using simple XY world coordinates. All of the values are in world space. The above graph is for the density only (which is the “Exctinction” material pin). You may notice the fog in the above image has some subtle shading from self shadowing. That is also handled in the material.
Make sure to study the full guide here.