Create a 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.
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.
Refer to Create a local fog effect for more information about applying a Fog Volume shader.
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.
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.