Creating Fog In HDRP

Using particles, post processing, and volumetric fog

When it comes to the High Definition Rendering Pipeline (HDRP) in Unity, we are presented with various different ways of incorporating fog into our scene. Whether its for a smoke-like effect, an overall ambience, or even cloudy light rays, we can do it all!

First, let’s look at using Unity’s built in particle system, something all versions of the Rendering Pipeline contain. The built in particle system, simulates and renders multiple small images to create a larger effect, and is useful for creating dynamic objects such as fire or smoke. Being a component of Unity, the particle system is also capable of interacting with our C# scripts and physics systems such as colliders.

Adding the component to a blank object will generate a default effect depicting various white pixel-like shapes, ready to be manipulated. Instead of trying to build a fog system from scratch, we can grab a premade asset from GameDevHQ’s Filebase as a starting point.

By default, it was built for either the Standard or Universal Rendering Pipeline shaders, but we can get around this by setting the material shader to Sprite.

We now have a solid starting point without creating our own particles from scratch, as the particle system is large and takes a lot of time to learn every element.

At it’s core, this system has replaced the white pixel-like images with animations of our sprite material. We can see these clouds somewhat separated in the image above.

Of course, it also manipulated a bunch of different settings to stray from the defaults, but let’s change these parameters further to bring the effect closer to what we need for our scene.

Our Particle System component shows a window of general settings every system uses at it’s base, with further overrides we can add in and manipulate. To start, lets look at this general window.

We want our system to loop, and we can set the duration of each iteration. Next, we have set our Start Lifetime, which is set to randomize between two values. This sets the initial lifetime for each particle generated.

From here, we have set a Start Speed of next to nothing, which will allow us to have the particles linger almost in place. Start Size simply dictates the size of each particle.

Everything else we’ve kept to the default except for adding a green tint.

For our overrides, I have made use of the Emission, Velocity Over Lifetime, and Size Over Lifetime.

The Emission Override allows us to affect the rate and timing of our system. Within this, I have set up a burst effect, to create puffs of smoke instead of a continuous emission. This pairs excellently with the long lifetime of each particle. In this case, 30 particles are emitted every second.

Velocity Over Lifetime allows us to increase the speed of the particles as they reach the end of their cycle. I’m simply using this to apply an ever so slight increase radially, so the smoke dissipates outwards.

Lastly, I’ve used Size Over Lifetime which allows us to manipulate the size of each particle as they reach the end of their cycle. All particles start with a size of 5, but I’ve set a random range between 0.1 and 2, so that each particle shrinks to different extents, mimicking natural dissipation.

Finished product, dissipating out in bursts with randomized size and speed.

The Post Processing stack allows us to add a Fog Override. This provides a fog effect, that allows for altering fog density, based on the distance from the camera, with an exponential element dependent on height.

Like the other overrides, we can enable this, and then start altering default parameters.

A quick example on what can be achieved

While this could work as something like a night time mist, it doesn’t work well for my indoor scene. I set out with a goal of somewhat inverting the visual effect so it looks like smoke is building in the ceiling space.

Much more subtle!

Our main parameter is the Fog Attenuation Distance, this controls how dense the base fog is, determining how far we can see through. All parameters are measured in meters. In the previous example, it was set to roughly the length of the room, so that we could just see the walls through the fog. To achieve my desired effect, I’ve got it set very high so we get very little fog at ground height.

The Base Height determines the height at which the fog starts to fade exponentially. This is paired with the Maximum Height to control the rate at which the fog fades. This allowed me to set a level of fog starting further up the wall.

The Max Fog Distance allows for applying fog to the skybox or background, so isn’t really applicable in this scene, at least to my eyes.

Next we have a Color Mode, which allows us to set the color either based on the skybox or a manual color. This also pairs with the Albedo setting which tints the emitted light in the fog. This can be used as a stronger effect if we apply Volumetrics.

Within the Post Processing stack’s Fog Override, we can also enable Volumetric Fog. This allows us to add a component to the fog that allows for physically rendered glows and beams of light from our light components. This can be used to really bring out light cones from spotlights, or creating rays of sunlight. To make use of this, we first need to select the desired lights and check the volumetric setting, where we can then set the intensity through a multiplier.

In older versions such as Unity 2019, exponential, linear, and volumetric fog are all bundled into one override. Thus, enabling volumetric fog will significantly change what we created above.

Between our Light Settings, and Post Processing Stack, we can start to create various different rays of light to add effect to our scene. I’ve used my two spotlights focused on the central tubes to really show this off, setting the multiplier to the max to simulate the fog from the particle effect spilling in to the cone.

With my re-tweaks done after adding the volumetric component, I managed to achieve my desired effect using three different types of fog generation! Checkout how much more eerie the vibe of the room is below.

Before and after all fog effects!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to debug Solidity Smart Contracts with Tenderly and Truffle

The Microsoft Linux Desktop

Google Cloud Anthos Series: Anthos Config Management

What is Flutter?

Getting started with open-source Drone CI

How to ace CKAD (Certified Kubernetes Application Developer) Exam

How to use Git-lfs ( Large File Storage ) to push large files to Github

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Calum Slee

Calum Slee

More from Medium

Using Height Maps for Material Displacement

Damage VFX using Animated Sprites in Unity

A Guide to a More Productive Unity Layout

Object Pool Pattern in Unity