UE4 – Using a Post Process material to create a simple fog effect

Software:
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:

Fog_PP_material

  1. 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.
    Annotation 2020-05-04 011312
  2. A SceneTexture node with its Scene Texture Id parameter set to PostProcessInput0 serves as the input of the view’s original rendered pixel colors:
    Annotation 2020-05-04 011050
  3. A Lerp (LinearInterpolate) node calculates the blending of the view’s original pixel colors with the Fog color to create the fog effect.
  4. A SceneTexture node with its Scene Texture Id parameter set to SceneDepth serves as the input of depth of each pixel (distance from camera):
    Annotation 2020-05-04 012256
  5. A ComponentMask node set to the R channel allows using the depth data as a single float value instead of a Vector4:
    Annotation 2020-05-04 012603
  6. A Clamp node is used to clamp (limit) the depth value to the Fog’s maximum depth value (see below)
  7. 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.
  8. 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)
  9. 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.
  10. a float constant serves as an input for the fog’s minimal distance (from camera)
  11. 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.
  12. a float constant serves as an input for the fog’s minimal opacity (blend amount)
  13. a float constant serves as an input for the fog’s maximal opacity (blend amount)
  14. a float constant serves as an input for the fog’s blend exponent.

 

Applying the Post Process material to the level:

Fog_2

  1. Select the PostProcessVolume actor in the World Outliner window.
    * Create a PostProcessVolume actor if necessary.
  2. 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:
    Annotation 2020-05-04 015354
    Annotation 2020-05-04 015831

 

Related:

  1. Material Functions
  2. Blending materials
  3. Blending materials using texture paint

Arnold for 3ds max – Volumetric Fog and ‘God Rays’

Software:
3ds max 2019 | Arnold 5

a

Adding a ‘Volume Light’ effect in Arnold for 3ds max is fairly simple:

  1. In the Render Setup windows > Arnold Renderer tab, under Environment, Background & Atmosphere:
  2. Click the Scene Atmosphere material slot, add an Arnold Atmosphere Volume material to it,
    And drag it as an instance to the Material Editor to edit it’s parameters.
    Untitled-3
  3. Set the Density to a higher than 0.0 value, so the material will have an effect.
  4. You’ll probably need to significantly raise the number of samples in the Atmosphere Volume material, and also the number of Volume samples in the light settings in order to get a clean render.

Untitled-1.jpg

Related:
Arnold for 3ds max Volume Shading

UE4 – Connect a Directional Light to an Atmospheric Fog effect

Software:
Unreal Engine 4.21

UE4‘s Directional Light mimics sun lighting and shadow fairly realistically,
And the Atmospheric Fog visual effect produces a realistic clear sky background that includes the sun’s disk image in the sky.
> The Atmospheric Fog produces a result similar to an implementation of a Preetham physical sky model in common rendering software.

Combined together, these two elements can produce an effective day-light system,
But inorder for this to work the sun’s direction should be controlling the time of day simulated by the Atmospheric Fog.

For the Directional light to control the Atmospheric fog:
In the Directional Light’s details, under light, expend the settings and enable:
Atmosphere / Fog Sun Light

Note:
There is a limitation to this setup’s realism because the sunlight’s color shouldn’t be pure white, but rather yellowish, to orange, depending on the time of day (you can find tables of the sunlight’s color temperature for various time of day on the web)
There is no problem setting the sun’s color, but the problem is that it causes additional coloring of the Atmospheric Fog which isn’t needed since it already is simulating the sky’s color correctly.
The result of this limitation is that we can see a sunset sky with a white sunlight which is wrong.
I didn’t find a workaround for this yet, can’t find a way to set the Atmospheric Fog‘s sun vector without connecting it to a Directional light and can’t find a way to make the Directional Light‘s color not affect the Atmospheric Fog‘s color.

Update:
It seems this limitation can be overcome by disconnecting the Atmospheric Fog from the Directional Light and using the Atmospheric Fog Object’s rotation to control it.

Directional_light_Affect_Atmo_Fog
atmo_fog.gif

Related:

  1. UE4 HDRI Lighting
  2. 3ds max & V-Ray to UE4 Datasmith workflow
  3. Unreal – Architectural glass material
  4. Unreal – Camera animation