Fog Volume shader
Use the Fog Volume shader graph to create volumetric fog and environmental effects. HDRP includes an example scene that demonstrates different volumetric fog effects in the Volumetric Sample scene.
This document describes how to do the following:
For details on the settings in the Fog Volume shader graph, refer to Fog Volume Master Stack
Create a Fog Volume shader
You can create a Fog Volume shader in Shader Graph in one of the following ways:
Create a new Fog Volume Shader Graph:
-
- Go to Assets > Create > Shader Graph > HDRP > Fog Volume Shader Graph.
Change an existing shader graph:
- In the Project window, select a shader graph to open it in the Shader Editor.
- In Graph Settings, select the HDRP Target. If there isn't one, go to Active Targets, click the Plus button, and select HDRP.
- In the Material drop-down, select Fog Volume.
- Open a Fog Volume shader in the volumetric sample scene.
- Open the volumetric sample scene.
- In the Project window, go to Assets > Samples > High Definition RP > HDRP version number > Volumetric samples > Fog Volume Shadergraph.
- Double-click a shader graph asset to open it in Shader Graph.
This creates a shader graph that contains the Fog Volume master stack.
Apply a Fog Volume shader graph
To apply a Fog Volume shader in a scene, assign a Fog Volume material to a Local Volumetric Fog component:
- Create and set up a Local Volumetric Fog component..
- In the Project window, right-click the Fog Volume shader graph asset and select Create > Material.
- In the Hierarchy window, select the Local Volumetric Fog GameObject.
- In the Local Volumetric Fog’s Inspector window, set the Mask Mode property to Material.
- In the Mask Material section, select the material picker (circle).
- Select the Fog Volume material.
If the Fog Volume doesn't appear in your scene, follow the Local Volumetric Fog setup instructions.
Note: The Scale transform doesn't affect the size of the fog in your scene. To do this, change the Size value in the Local Volumetric Fog component. For more information, visit Local Volumetric Fog.
Note: If you use more than one Fog Volume shader in your scene, then the HDRP fog system applies lighting consistently across them all.
Set up a Fog Volume in Shader Graph
Volumetric effects in Shader Graph require a 3D input. To get this 3D input, use one or both of the following nodes:
- UV: Use this node to sample along the local, normalized position inside the volume along the X,Y and Z axes.
- Position: Use this node to sample along the Z and X axes starting at a value of 0 in the center of the fog volume.
You can use these nodes as inputs to the Sample Texture 3D node.
To find an example of a shader graph that uses these nodes, open the volumetric sample scene.
Note: To create a fog effect in world space that isn’t affected by the volume’s position, set the Position node’s Space property to Absolute World. This is because HDRP uses Camera Relative Rendering.
Open the volumetric sample scene
HDRP includes a Volumetric sample scene that demonstrates different ways that you can use Local Volumetric Fog. To import the volumetric samples:
- Go to Window > Package manager and select High Definition RP.
- Select the Samples tab.
- Find Volumetric Samples and select Import.
To set up the Volumetric sample scene:
- Go to the Project window.
- Go to Assets > Samples > High Definition RP > HDRP version number > Volumetric samples > Scenes.
- Select the Volumetric Samples scene.
- Go to Assets > Samples > High Definition RP > HDRP version number > Volumetric samples > Scenes > Resources.
- Drag the Volumetric Samples Collection into the Hierarchy window.
- In the Inspector window, open the Sample List dropdown and select a sample to display it in your scene.
Optimize performance
This section explains how to improve how a Fog Volume shader graph looks and performs. To fix artefacts in a Fog Volume shader, refer to Fix issues with Local Volumetric Fog.
- Keep the number of nodes in a volumetric fog shader graph to a minimum. This is because a high number of Shader graph calculations limit the performance of a volumetric fog shader on the GPU.
- HDRP invokes a pixel for every voxel it executes in a local volumetric fog. To lower the amount of resources this uses, reduce the size of the volumetric fog volume.
- Enable mipmaps in the Texture Importer for any textures you sample in Shader Graph. This reduces the time HDRP takes to fetch textures because the resolution of the V-buffer is often lower than the screen resolution.
- Keep the screen space size of the fog volume as small as possible. To check how much screen space the fog volume takes up, go to Window > Rendering Debugger > Rendering > Fullscreen Debug Mode and use the debug mode LocalVolumetricFogOverdraw.
- If the Fog Volume Mesh Voxelization step is slower than the Volumetric Lighting step in the GPU profiler, this tells you that your scene uses too many fog volumes or that the fog volumes in your scene are too large. To fix this, reduce the number of volumes in your scene or lower the quality of the volumetric fog.
- In the Fog volume override, set the Screen Resolution Percentage to a low value to improve performance. Low values work best with diffuse fog. Values over 30 use a high amount of memory on the GPu.