Local Volumetric Fog
You may want to have fog effects in your Scene that global fog can not produce by itself. In these cases you can use local fog. To add localized fog, use a Local Volumetric Fog component. Local Volumetric Fog is a volume of fog represented as an oriented bounding box. By default, fog is constant (homogeneous), but you can alter it by assigning a Density Mask 3D texture to the Texture field under the Density Mask Texture section.
Create a Local Volumetric Fog component
You can create a Local Volumetric Fog component in one of the following ways:
In the menu bar, select GameObject > Rendering > Local Volumetric Fog.
Right-click in the Hierarchy window and select Volume > Local Volumetric Fog.
Set up Volumetric fog
To use volumetric fog, enable it in the all of the following locations:
Enable Volumetric Fog in Project Settings
To enable Volumetric Fog in the Project Settings window, open the Project settings window (menu: Edit > Project Settings) and enable the following properties**:**
- Go to Quality > HDRP > Lighting > Volumetrics and enable Volumetric Fog.
- Go to Graphics > HDRP Global Settings.
- Under Frame Settings (Default Values), in the Camera section:
- Select Lighting.
- Enable Fog.
- Enable Volumetrics.
Enable Volumetric Fog in the HDRP Asset
To enable Volumetric Fog in the HDRP Asset:
- In the Project window, select the HDRenderPipelineAsset to open it in the Inspector**.**
- Go to Lighting > Volumetrics.
- Enable Volumetric Fog.
Enable Volumetric Fog in a Global Volume
To use volumetric fog in your scene, create a Global volume with a Fog component. To do this:
- Create a new GameObject (menu: GameObject > Create Empty).
- In the Inspector window, select Add Component.
- In the search box that appears, enter “volume”.
- Select the Volume Component.
- Go to Profile and select New to create a volume profile.
- Select Add Override.
- In the search box that appears, select Fog.
To enable volumetric fog in the Fog component:
- Select the Fog dropdown
- Select the Enable toggle, and enable it.
- Change the State setting to Enabled.
- Select the Volumetric Fog toggle, and enable it.
To see more properties you can use to control Volumetric Fog, expose the hidden Fog settings:
- In the Volume component, go to the Fog override and select the More (⋮) dropdown.
- Select Show All Additional Properties to open the Preferences window.
- In the Preferences window, under Additional Properties, open the Visibility dropdown and select All Visible.
Properties
Property | Description |
---|---|
Single Scattering Albedo | Sets the fog color. Volumetric Fog tints lighting as the light scatters to appear this color. It only tints lighting emitted by Lights behind or within the fog. This means that it does not tint lighting that reflects off GameObjects behind or within the fog. Reflected lighting gets dimmer (fades to black) as fog density increases. For example, if you shine a Light at a white wall behind fog with red Single Scattering Albedo, the fog looks red. If you shine a Light at a white wall and view it from the other side of the fog, the fog darkens the light but doesn’t tint it red. |
Fog Distance | Controls the density at the base of the fog and determines how far you can see through the fog in meters. At this distance, the fog has absorbed and out-scattered 63% of background light. |
Mask Mode | Select a mask type to apply to the fog: •Texture: Applies a 3D texture to the fog volume. •Material: Applies a Material to the fog which updates every frame. You can use this to create dynamic fog effects. |
Blending Mode | Determines how this fog volume blends with existing fog in the scene: •Overwrite: Replaces existing fog in the volume area with this fog volume. •Additive: Adds the color and density of this fog volume to other fog in the scene. This is the default value. •Multiply: Multiplies the color and density of this fog volume with other fog in the scene. You can use this to create effects relative to a specific fog density. •Min: Determines the minimum density value of this fog volume and the scene fog inside its bounding box. For example, a value of 0 appears to remove fog in a certain area. •Max: Determines the maximum density value of this fog volume and the scene fog inside its bounding box. |
Priority | Determined the order in which HDRP blends fog volumes. HDRP renders the lowest priority volume first and the highest priority last. |
Size | Controls the dimensions of the Volume. |
Per Axis Control | Controls the blend distance based on each axis. |
Blend Distance | Blend Distance fades from this fog volume's level to the fog level outside it. This value indicates the absolute distance from the edge of the Volume bounds, defined by the Size property, where the fade starts. Unity clamps this value between 0 and half of the lowest axis value in the Size property. If you use the Normal tab, you can alter a single float value named Blend Distance, which gives a uniform fade in every direction. If you open the Advanced tab, you can use two fades per axis, one for each direction. For example, on the X-axis you could have one for left-to-right and one for right-to-left. A value of 0 hides the fade, and a value of 1 creates a fade. |
Falloff Mode | Controls the falloff function applied to the blending of Blend Distance. By default the falloff is linear but you can change it to exponential for a more realistic look. |
Invert Blend | Reverses the direction of the fade. Setting the Blend Distances on each axis to its maximum possible value preserves the fog at the center of the Volume and fades the edges. Inverting the blend fades the center and preserves the edges instead. |
Distance Fade Start | Distance from the camera at which the Local Volumetric Fog starts to fade out. Use this property to optimize a scene with a lot of Local Volumetric Fog. |
Distance Fade End | Distance from the camera at which the Local Volumetric Fog completely fades out. Use this property to optimize a scene with a lot of Local Volumetric Fog. |
Density Mask Texture | Specifies a 3D texture mapped to the interior of the Volume. Local Volumetric Fog only uses the RGB channels of the texture for the fog color and A for the fog density multiplier. A value of 0 in the Texture alpha channel results in a Volume of 0 density, and the value of 1 results in the original constant (homogeneous) volume. |
Scroll Speed | Specifies the speed (per-axis) at which the Local Volumetric Fog scrolls the texture. If you set every axis to 0, the Local Volumetric Fog doesn't scroll the texture and the fog is static. |
Tiling | Specifies the per-axis tiling rate of the texture. For example, setting the x-axis component to 2 means that the texture repeats 2 times on the x-axis within the interior of the volume. |
Material | The volumetric material mask, this material needs to have a Shader Graph with the material type Fog Volume. |
Volumetric Fog properties in the HDRP Asset
The HDRP Asset contains the following properties that relate to Local Volumetric Fog (menu: Project > Assets > HD Render Pipeline Asset > Lighting > Volumetrics):
Property | Description |
---|---|
Volumetric Fog | Enable or disable volumetric fog. |
Max Local Volumetric Fog On Screen | Control how many Local Volumetric Fog components can appear on-screen at once. This setting has an impact on performance which increases at high values. |
Mask textures
A mask texture is a 3D texture that controls the shape and appearance of the local volumetric fog in your scene. Unity does not limit the size of this 3D texture, and its size doesn't affect the amount of memory a local volumetric fog uses.
Use a built-in Mask Texture
HDRP includes 3D Density Mask Textures with different noise values and shapes that you can use in your scene. To use these Textures, import them from the High Definition RP package samples:
- Open the Package Manager window (menu: Window > Package Manager).
- Find the High Definition RP package.
- Expand the Samples drop-down.
- Find the Local Volumetric Fog 3D Texture Samples and click on the Import button.
Create a Density Mask Texture
To create a 3D texture to apply to a local volumetric fog component:
- In the image-editing software of your choice, create an RGBA flipbook texture and import it as a 3D texture. For example, a texture of size 1024 x 32 describes a 3D Texture of size 32 x 32 x 32 with 32 slices laid out one after another.
- Open a Local Volumetric Fog component and in its Density Mask Texture section assign the 3D Texture you imported to the Texture field .
Limitations
HDRP voxelizes Local Volumetric Fog at 64 or 128 slices along the camera's focal axis to improve performance. This causes the following limitations:
- Local Volumetric Fog doesn't support volumetric shadowing. If you place Local Volumetric Fog between a Light and a surface, the Volume does not decrease the intensity of light that reaches the surface.
- Noticeable aliasing can appear at the boundary of the fog Volume. To hide aliasing artifacts, use Local Volumetric Fog with global fog. You can also use a Density Mask and a Blend Distance value above 0 to decrease the hardness of the edge.