Skip to content

Commit a1b5f0b

Browse files
Antoine LelièvreEvergreen
authored andcommitted
Add volumetric slider cutoff
1 parent 55e9392 commit a1b5f0b

File tree

7 files changed

+218
-161
lines changed

7 files changed

+218
-161
lines changed

Packages/com.unity.render-pipelines.high-definition/Documentation~/fog-volume-override-reference.md

Lines changed: 29 additions & 28 deletions
Large diffs are not rendered by default.

Packages/com.unity.render-pipelines.high-definition/Documentation~/troubleshoot-fog.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ This document explains how to fix some common visual artifacts that can appear w
66

77
A slice artifact is the appearance of thin layers around the edge of the volumetric fog. To fix this issue, go to the Local Volumetric Fog component and adjust the following settings:
88

9-
- **Blend Distance**: Set this value above 0.
9+
- **Blend Distance**: Set this value above 0 to improve visual transitions at the volume’s border and reduce slice artifacts.
1010
- **Slice Distribution Uniformity**: Increase this value to make the edge of the fog more detailed as it gets closer to the camera.
11-
- **Volumetric Fog Distance**: Set this property between 20 and 100 to reduce the appearance of artifacts.
1211

1312
## Sharp edges
1413

1514
To remove the appearance of sharp areas or corners in a volumetric fog, open the [Global Fog](create-a-global-fog-effect.md) component and set the **Denoising Mode** property to one of the following modes:
1615
- **None**.
17-
- **Reprojection**: This mode can cause edges to have a blurry artifact (ghosting).
18-
- **Gaussian**: Use this setting for blurry fog with no hard shapes.
16+
- **Reprojection**: Disables denoising for fog with sharp edges or hard corners. This option maintains detail, but can introduce ghosting artifacts, and doubles the amount of memory volumetric fog uses.
17+
- **Gaussian**: Creates soft, blurry fog with undefined shapes. This mode smooths out noise but can blur out sharp features.
1918
- **Both**: Applies both Reprojection and Gaussian techniques. This setting significantly increases the volumetric fog's memory usage and GPU time.
2019

20+
For more physically accurate blending between the fog and the environment, set **Falloff Mode** to **Exponential**.
21+
2122
## Light flickering
2223

2324
To stop light from flickering in a fog volume, change the following properties:
@@ -27,3 +28,35 @@ To stop light from flickering in a fog volume, change the following properties:
2728
- **Volumetric Fog Distance**: Set this value between the **Distance Fade Start** and **Distance Fade End** values set in the Local Volumetric Fog component. This makes the fog fade out at the same point as its maximum distance, which reduces light flickering in the distant areas of the fog volume.
2829
- **Radius**: Increase this value in the [Light](Light-Component.md) component. This lowers the intensity of the light source which makes flickering artifacts less visible.
2930

31+
## Optimize fog performance
32+
33+
How to optimize volumetric fog depends on the content of your scene and the quality you want. For more information about fog properties, refer to [Fog Volume Override reference](fog-volume-override-reference.md) and [Local Volumetric Fog Volume reference](local-volumetric-fog-volume-reference.md).
34+
35+
To make sure all parameters are visible in the **Inspector** window, follow these steps in each Local Volumetric Fog Volume:
36+
37+
1. Set **Quality** to **Custom**.
38+
2. Set **Fog Control Mode** to **Manual**.
39+
3. At the top of the **Fog** component, open the **More** (⋮) menu and enable **Advanced Properties**.
40+
41+
Try adjusting the following properties:
42+
43+
- Decrease the **Distance** parameter to reduce the number of fog slices HDRP renders. For long-distance fog, adjust the **Slice Distribution Uniformity** and **Slice Count** instead.
44+
- Decrease **Volume Slice Count** to reduce the number of fog slices along the camera's forward axis, to reduce GPU and memory usage. Or increase **Volume Slice Count** and reduce **Slice Distribution Uniformity** to focus more slices further from the camera.
45+
- Set the near and far clipping planes of the camera, to avoid fog rendering too close to the camera. This is particularly important in scenarios such as top-down views, where there may be a significant distance between the camera and the first visible fog or objects.
46+
- Set **Denoising Mode** to **Gaussian** instead of **Reprojection**, so the fog uses less memory.
47+
- Reduce the **Screen Resolution Percentage** value to a low value, to limit how much memory and computation fog uses, especially if you have highly diffuse fog.
48+
- Enable **Directional Lights Only**, especially if you have a large or outdoor scene where only sunlight should contribute to volumetric effects.
49+
50+
### Skip lighting calculations in areas with low-density fog
51+
52+
To skip lighting calculations for areas where the fog density is below a certain threshold, use the **Volumetric Lighting Density Cutoff** property.
53+
54+
This property can improve performance if you use [Local Volumetric Fog Volumes](local-volumetric-fog-volume-reference.md). It doesn't affect scenes with constant or height-based fog because all areas have the same density.
55+
56+
Follow these steps:
57+
58+
1. To remove global fog from the scene, set a very high **Fog Attenuation Distance**.
59+
2. Add Local Volumetric Fog Volumes where you want fog to appear.
60+
3. Increase the **Volumetric Lighting Density Cutoff** gradually, until important fog features begin to disappear.
61+
62+
**Note**: This property doesn't take into account changes applied by the **Anisotropy** property. The visibility of fog might not correspond directly to the **Volumetric Lighting Density Cutoff** value in scenes with a lot of anisotropic scattering.

Packages/com.unity.render-pipelines.high-definition/Editor/Sky/AtmosphericScattering/FogEditor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FogEditor : VolumeComponentWithQualityEditor
2323

2424
protected SerializedDataParameter m_EnableVolumetricFog;
2525
protected SerializedDataParameter m_Anisotropy;
26+
protected SerializedDataParameter m_VolumetricLightingDensityCutoff;
2627
protected SerializedDataParameter m_MultipleScatteringIntensity;
2728
protected SerializedDataParameter m_DepthExtent;
2829
protected SerializedDataParameter m_GlobalLightProbeDimmer;
@@ -63,6 +64,7 @@ public override void OnEnable()
6364
m_BaseHeight = Unpack(o.Find(x => x.baseHeight));
6465
m_MaximumHeight = Unpack(o.Find(x => x.maximumHeight));
6566
m_Anisotropy = Unpack(o.Find(x => x.anisotropy));
67+
m_VolumetricLightingDensityCutoff = Unpack(o.Find(x => x.volumetricLightingDensityCutoff));
6668
m_MultipleScatteringIntensity = Unpack(o.Find(x => x.multipleScatteringIntensity));
6769
m_GlobalLightProbeDimmer = Unpack(o.Find(x => x.globalLightProbeDimmer));
6870

@@ -173,6 +175,15 @@ public override void OnInspectorGUI()
173175
EndAdditionalPropertiesScope();
174176
}
175177

178+
PropertyField(m_VolumetricLightingDensityCutoff);
179+
if (m_VolumetricLightingDensityCutoff.value.floatValue > 0.0f)
180+
{
181+
using (new IndentLevelScope())
182+
{
183+
float currentMinExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(m_MeanFreePath.value.floatValue);
184+
EditorGUILayout.HelpBox($"The current minimum density for the fog is {currentMinExtinction:F3} (calculated from the Fog Distance).", MessageType.Info, wide: true);
185+
}
186+
}
176187
}
177188
}
178189
PropertyField(m_MultipleScatteringIntensity);

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public float resolutionDepthRatio
157157
[Tooltip("When enabled, HDRP only includes directional Lights when it evaluates volumetric fog.")]
158158
public BoolParameter directionalLightsOnly = new BoolParameter(false);
159159

160+
/// <summary>Indicates at which fog density the lighting should be ignored. Every voxel containing less fog density than this value will be ignored by the volumetric lighting.</summary>
161+
[Tooltip("Improves performance by skipping the lighting evaluation in areas with low-density fog. When the value is above 0, HDRP skips calculating volumetric lighting in areas where the fog density is below this value.")]
162+
public FloatParameter volumetricLightingDensityCutoff = new(0.0f);
163+
160164
internal static bool IsFogEnabled(HDCamera hdCamera)
161165
{
162166
return hdCamera.frameSettings.IsEnabled(FrameSettingsField.AtmosphericScattering) && hdCamera.volumeStack.GetComponent<Fog>().enabled.value;
@@ -177,7 +181,7 @@ internal static bool IsVolumetricFogEnabled(HDCamera hdCamera)
177181
internal static bool IsVolumetricReprojectionEnabled(HDCamera hdCamera)
178182
{
179183
var fog = hdCamera.volumeStack.GetComponent<Fog>();
180-
184+
181185
return (fog.denoisingMode.value & FogDenoisingMode.Reprojection) != 0;
182186
}
183187

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricLighting.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ unsafe struct ShaderVariablesVolumetric
8585
public uint _VolumeCount;
8686
public uint _IsObliqueProjectionMatrix;
8787
public float _HalfVoxelArcLength;
88-
public uint _Padding2;
88+
public float _VolumetricLightingExtinctionCutoff;
8989
}
9090

9191
/// <summary>Falloff mode for the local volumetric fog blend distance.</summary>
@@ -997,6 +997,7 @@ unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb,
997997
// Compute the arc length of a single froxel at 1m from the camera.
998998
// This value can be used to quickly compute the arc length of a single froxel
999999
cb._HalfVoxelArcLength = Mathf.Deg2Rad * hdCamera.camera.fieldOfView / currParams.viewportSize.y / 2.0f;
1000+
cb._VolumetricLightingExtinctionCutoff = fog.volumetricLightingDensityCutoff.value;
10001001

10011002
if (updateVoxelizationFields)
10021003
{

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricLighting.cs.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ CBUFFER_START(ShaderVariablesVolumetric)
6262
uint _VolumeCount;
6363
uint _IsObliqueProjectionMatrix;
6464
float _HalfVoxelArcLength;
65-
uint _Padding2;
65+
float _VolumetricLightingExtinctionCutoff;
6666
CBUFFER_END
6767

6868
// Generated from UnityEngine.Rendering.HighDefinition.VolumetricMaterialDataCBuffer

0 commit comments

Comments
 (0)