Unreal Engine 4.24
An example of a simple fog effect created using a Post Process material:
The fog material Blueprint:
The method for creating the fog effect is to take distance of the objects from the camera, map it to a value range suitable for color blending 0 – 1, and use that for blending the object’s color with the fog color, so the further away the object, the more it will be colored by the fog.
Start by creating a new material, and follow the details below to create the Blueprint:
- The Material Domain is set to Post Process.
And has its Blendable Location parameter set to Before Tonemapping so it will be applied on the raw render.
- A SceneTexture node with its Scene Texture Id parameter set to PostProcessInput0 serves as the input of the view’s original rendered pixel colors:
- A Lerp (LinearInterpolate) node calculates the blending of the view’s original pixel colors with the Fog color to create the fog effect.
- A SceneTexture node with its Scene Texture Id parameter set to SceneDepth serves as the input of depth of each pixel (distance from camera):
- A ComponentMask node set to the R channel allows using the depth data as a single float value instead of a Vector4:
- A Clamp node is used to clamp (limit) the depth value to the Fog’s maximum depth value (see below)
- A RemapValueRange maps the distance value to a fog density value that will be used as the Lerp (3) alpha parameter.
Simply put, the further the object, the more the original color will be blended with the fog color.
- A Power node (raises the fog blend factor by an exponent) make the fog blending non-linear, that is beginning gently for closer objects and than increasing more drastically as the distance grows (provided that the exponent value is above 1)
- A Constant Vector4 serves as an input for the fog color.
* Note that having this input be a Vector4 and not a Vector3 allows it to be interpolated with the PostProcessInput0 data, otherwise a ComponentMask (RGB) node would have been necessary to convert the PostProcessInput0 to a Vector3.
- a float constant serves as an input for the fog’s minimal distance (from camera)
- a float constant serves as an input for the fog’s maximal distance (from camera)
* Note that it’s connected both to the Clamp node and to the RemapValueRange node.
- a float constant serves as an input for the fog’s minimal opacity (blend amount)
- a float constant serves as an input for the fog’s maximal opacity (blend amount)
- a float constant serves as an input for the fog’s blend exponent.
Applying the Post Process material to the level:
- Select the PostProcessVolume actor in the World Outliner window.
* Create a PostProcessVolume actor if necessary.
- In the Details panel, under Rendering Features > Post Process materials,
Add a new item to the array, in the new item’s value choose Asset Reference,
And then select your fog material:
One thought on “UE4 – Using a Post Process material to create a simple fog effect”