Skip to content

Commit aedcc5a

Browse files
ApoorvaJpastasfuture
authored andcommitted
10.3.1/dynamic density volumes (#18)
* Apply patch from partner/crazyhunter-10.x.x-dynamic-density-volumes from the main Graphics repo * Fix HLSL truncation warning in shader * Eliminate the possibility of a null atlas texture by always allocating a 1x1x1 texture at minimum * Change from one callback per volume to a single callback * Remove time parameter from PrepareDensityVolumeData * Address review comments bonfirestudios/unity-com.unity.render-pipelines.high-definition#18 * Add UI to control density volume atlas size * Statically allocate the density volume atlas instead of growing it * Log error if density volumes exceed size of the atlas Remove mipmap regeneration. Will be done in user code instead. (#21) Density Volumes: Cleanup to the Density Volume Atlas management / update code. Additionally fixed a few bugs, and added profile markers for static atlas blits, dynamic atlas dispatches, and atlas mipmap generation. Currently we update the whole mip chain via GenerateMipmaps() if any static or dynamic density volumes trigger atlas updates. In the future we should look into generating mip data for only dirty regions of the atlas, probably in compute. (#73) Dynamic Density Volumes: Add HDRenderPipelineResources
1 parent 7e84640 commit aedcc5a

24 files changed

+576
-181
lines changed

com.unity.render-pipelines.high-definition/Editor/Lighting/VolumetricLighting/DensityVolumeUI.Drawer.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static partial class DensityVolumeUI
1313
enum Expandable
1414
{
1515
Volume = 1 << 0,
16-
DensityMaskTexture = 1 << 1
16+
DensityMaskTexture = 1 << 1,
17+
DensityMaskShader = 1 << 2
1718
}
1819

1920
readonly static ExpandedState<Expandable, DensityVolume> k_ExpandedState = new ExpandedState<Expandable, DensityVolume>(Expandable.Volume | Expandable.DensityMaskTexture, "HDRP");
@@ -30,6 +31,10 @@ enum Expandable
3031
CED.FoldoutGroup(
3132
Styles.k_DensityMaskTextureHeader, Expandable.DensityMaskTexture, k_ExpandedState,
3233
Drawer_DensityMaskTextureContent
34+
),
35+
CED.FoldoutGroup(
36+
Styles.k_DensityMaskShaderHeader, Expandable.DensityMaskShader, k_ExpandedState,
37+
Drawer_DensityMaskShaderContent
3338
)
3439
);
3540

@@ -181,5 +186,23 @@ static void Drawer_DensityMaskTextureContent(SerializedDensityVolume serialized,
181186
EditorGUILayout.PropertyField(serialized.textureScroll, Styles.s_TextureScrollLabel);
182187
EditorGUILayout.PropertyField(serialized.textureTile, Styles.s_TextureTileLabel);
183188
}
189+
190+
static void Drawer_DensityMaskShaderContent(SerializedDensityVolume serialized, Editor owner)
191+
{
192+
EditorGUILayout.PropertyField(serialized.volumeShader, Styles.s_VolumeShaderLabel);
193+
194+
EditorGUILayout.BeginHorizontal();
195+
EditorGUILayout.LabelField(Styles.s_VolumeShaderResolutionLabel);
196+
EditorGUI.BeginChangeCheck();
197+
int x = EditorGUILayout.DelayedIntField(serialized.volumeShaderResolution.vector3IntValue.x);
198+
int y = EditorGUILayout.DelayedIntField(serialized.volumeShaderResolution.vector3IntValue.y);
199+
int z = EditorGUILayout.DelayedIntField(serialized.volumeShaderResolution.vector3IntValue.z);
200+
EditorGUILayout.EndHorizontal();
201+
if (EditorGUI.EndChangeCheck())
202+
{
203+
Vector3Int resolutionNext = DensityVolume.FixupDynamicVolumeResolution(new Vector3Int(x, y, z));
204+
serialized.volumeShaderResolution.vector3IntValue = resolutionNext;
205+
}
206+
}
184207
}
185208
}

com.unity.render-pipelines.high-definition/Editor/Lighting/VolumetricLighting/DensityVolumeUI.Skin.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal static class Styles
88
{
99
public static readonly GUIContent k_VolumeHeader = new GUIContent("Volume");
1010
public static readonly GUIContent k_DensityMaskTextureHeader = new GUIContent("Density Mask Texture");
11+
public static readonly GUIContent k_DensityMaskShaderHeader = new GUIContent("Density Mask Shader");
1112

1213
public static readonly GUIContent[] s_Toolbar_Contents = new GUIContent[]
1314
{
@@ -21,6 +22,8 @@ internal static class Styles
2122
public static readonly GUIContent s_VolumeTextureLabel = new GUIContent("Texture", "The fog Texture for the Density Mask. Generate this Texture type using the Density Volume Texture Tool.");
2223
public static readonly GUIContent s_TextureScrollLabel = new GUIContent("Scroll Speed", "Modify the speed for each axis at which HDRP scrolls the fog Texture.");
2324
public static readonly GUIContent s_TextureTileLabel = new GUIContent("Tiling", "Modify the tiling of the fog Texture on each axis individually.");
25+
public static readonly GUIContent s_VolumeShaderLabel = new GUIContent("Shader", "The fog shader for the Density Mask.");
26+
public static readonly GUIContent s_VolumeShaderResolutionLabel = new GUIContent("Resolution", "The resolution of the texture that the shader will write to.");
2427
public static readonly GUIContent s_BlendLabel = new GUIContent("Blend Distance", "Interior distance from the Size where the fog fades in completely.");
2528
public static readonly GUIContent s_InvertFadeLabel = new GUIContent("Invert Blend", "Inverts blend values so 0 becomes the new maximum value and the original maximum value becomes 0.");
2629
public static readonly GUIContent s_ManipulatonTypeContent = EditorGUIUtility.TrTextContent("Per Axis Control", "When checked, each face can be manipulated separatly. This also include fading options.");

com.unity.render-pipelines.high-definition/Editor/Lighting/VolumetricLighting/SerializedDensityVolume.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class SerializedDensityVolume
1111
public SerializedProperty volumeTexture;
1212
public SerializedProperty textureScroll;
1313
public SerializedProperty textureTile;
14+
public SerializedProperty volumeShader;
15+
public SerializedProperty volumeShaderResolution;
1416

1517
public SerializedProperty size;
1618

@@ -39,6 +41,8 @@ public SerializedDensityVolume(SerializedObject serializedObject)
3941
volumeTexture = densityParams.FindPropertyRelative("volumeMask");
4042
textureScroll = densityParams.FindPropertyRelative("textureScrollingSpeed");
4143
textureTile = densityParams.FindPropertyRelative("textureTiling");
44+
volumeShader = densityParams.FindPropertyRelative("volumeShader");
45+
volumeShaderResolution = densityParams.FindPropertyRelative("volumeShaderResolution");
4246

4347
size = densityParams.FindPropertyRelative("size");
4448

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class GeneralSection
3131
public static readonly GUIContent lightingQualitySettings = EditorGUIUtility.TrTextContent("Lighting Quality Settings");
3232

3333
public static readonly GUIContent lightLayerSubTitle = EditorGUIUtility.TrTextContent("Light Layers");
34+
public static readonly GUIContent volumetricsSubTitle = EditorGUIUtility.TrTextContent("Volumetrics");
3435
public static readonly GUIContent cookiesSubTitle = EditorGUIUtility.TrTextContent("Cookies");
3536
public static readonly GUIContent reflectionsSubTitle = EditorGUIUtility.TrTextContent("Reflections");
3637
public static readonly GUIContent skySubTitle = EditorGUIUtility.TrTextContent("Sky");
@@ -94,7 +95,7 @@ public class GeneralSection
9495
public static readonly GUIContent supportSSGIContent = EditorGUIUtility.TrTextContent("Screen Space Global Illumination", "When enabled, HDRP allocates memory for processing screen space global illumination (SSGI). This allows you to use SSGI in your Unity Project.");
9596
public static readonly GUIContent supportedSSSContent = EditorGUIUtility.TrTextContent("Subsurface Scattering", "When enabled, HDRP allocates memory for processing subsurface scattering (SSS). This allows you to use SSS in your Unity Project.");
9697
public static readonly GUIContent sssSampleBudget = EditorGUIUtility.TrTextContent("Sample Budget", "Maximum number of samples the Subsurface Scattering algorithm is allowed to take.");
97-
public static readonly GUIContent supportVolumetricContent = EditorGUIUtility.TrTextContent("Volumetrics", "When enabled, HDRP allocates Shader variants and memory for volumetric effects. This allows you to use volumetric lighting and fog in your Unity Project.");
98+
public static readonly GUIContent supportVolumetricContent = EditorGUIUtility.TrTextContent("Enable", "When enabled, HDRP allocates Shader variants and memory for volumetric effects. This allows you to use volumetric lighting and fog in your Unity Project.");
9899
public static readonly GUIContent volumetricResolutionContent = EditorGUIUtility.TrTextContent("High Quality ", "When enabled, HDRP increases the resolution of volumetric lighting buffers. Warning: There is a high performance cost, do not enable on consoles.");
99100
public static readonly GUIContent supportLightLayerContent = EditorGUIUtility.TrTextContent("Light Layers", "When enabled, HDRP allocates memory for processing Light Layers. This allows you to use Light Layers in your Unity Project. For deferred rendering, this allocation includes an extra render target in memory and extra cost.");
100101
public static readonly GUIContent lightLayerName0 = EditorGUIUtility.TrTextContent("Light Layer Name 0", "The display name for Light Layer 0. This is purely cosmetic, and can be used to articulate intended use of Light Layer 0");
@@ -140,7 +141,7 @@ public class GeneralSection
140141
internal const string probeVolumeInfo = "Warning: Probe Volumes is a highly experimental feature.\nIt is disabled by default for this reason.\nIt's functionality is subject to breaking changes and whole sale removal.\nIt is not recommended for use outside of for providing feedback.\nIt should not be used in production.\nTo enable, set:\nProbeVolumesEvaluationMode = ProbeVolumesEvaluationModes.MaterialPass\ninside of ShaderConfig.cs\and inside of the editor run:\nEdit->Render Pipeline->Generate Shader Includes\nProbe Volumes feature must also be enabled here.";
141142
internal static readonly GUIContent probeVolumeAtlasResolution = EditorGUIUtility.TrTextContent("Atlas Resolution", "Resolution of the 3D texture atlas containing visible ProbeVolumes.");
142143
internal static readonly GUIContent probeVolumeAtlasOctahedralDepthResolution = EditorGUIUtility.TrTextContent("Octahedral Depth Atlas Resolution", "Resolution of the 2D texture atlas containing visible ProbeVolumes octahedral depth data.");
143-
144+
internal static readonly GUIContent densityVolumeAtlasResolution = EditorGUIUtility.TrTextContent("Density Atlas Resolution", "Resolution of the 3D texture atlas containing fog density.");
144145

145146
public const string cacheErrorFormat = "This configuration will lead to more than 2 GB reserved for this cache at runtime! ({0} requested) Only {1} element will be reserved instead.";
146147
public const string cacheInfoFormat = "Reserving {0} in memory at runtime.";

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum Expandable
4343
LightingQuality = 1 << 25,
4444
SSRQuality = 1 << 26,
4545
VirtualTexturing = 1 << 27,
46-
FogQuality = 1 << 28
46+
FogQuality = 1 << 28,
47+
Volumetrics = 1 << 29
4748
}
4849

4950
static readonly ExpandedState<Expandable, HDRenderPipelineAsset> k_ExpandedState = new ExpandedState<Expandable, HDRenderPipelineAsset>(Expandable.CameraFrameSettings | Expandable.General, "HDRP");
@@ -82,6 +83,7 @@ static HDRenderPipelineUI()
8283
),
8384
CED.FoldoutGroup(Styles.lightingSectionTitle, Expandable.Lighting, k_ExpandedState,
8485
CED.Group(GroupOption.Indent, Drawer_SectionLightingUnsorted),
86+
CED.FoldoutGroup(Styles.volumetricsSubTitle, Expandable.Volumetrics, k_ExpandedState, FoldoutOption.Indent | FoldoutOption.SubFoldout, Drawer_SectionVolumetrics),
8587
CED.FoldoutGroup(Styles.cookiesSubTitle, Expandable.Cookie, k_ExpandedState, FoldoutOption.Indent | FoldoutOption.SubFoldout, Drawer_SectionCookies),
8688
CED.FoldoutGroup(Styles.reflectionsSubTitle, Expandable.Reflection, k_ExpandedState, FoldoutOption.Indent | FoldoutOption.SubFoldout, Drawer_SectionReflection),
8789
CED.FoldoutGroup(Styles.skySubTitle, Expandable.Sky, k_ExpandedState, FoldoutOption.Indent | FoldoutOption.SubFoldout, Drawer_SectionSky),
@@ -995,8 +997,6 @@ static void Drawer_SectionLightingUnsorted(SerializedHDRenderPipelineAsset seria
995997
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSSAO, Styles.supportSSAOContent);
996998
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSSGI, Styles.supportSSGIContent);
997999

998-
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetrics, Styles.supportVolumetricContent);
999-
10001000
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportLightLayers, Styles.supportLightLayerContent);
10011001

10021002
if (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled)
@@ -1078,6 +1078,27 @@ static void Drawer_SectionLightingUnsorted(SerializedHDRenderPipelineAsset seria
10781078

10791079
EditorGUILayout.Space(); //to separate with following sub sections
10801080
}
1081+
static void Drawer_SectionVolumetrics(SerializedHDRenderPipelineAsset serialized, Editor owner)
1082+
{
1083+
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetrics, Styles.supportVolumetricContent);
1084+
1085+
++EditorGUI.indentLevel;
1086+
using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportVolumetrics.boolValue))
1087+
{
1088+
EditorGUI.BeginChangeCheck();
1089+
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.densityVolumeSettings.atlasResolution, Styles.densityVolumeAtlasResolution);
1090+
if (EditorGUI.EndChangeCheck())
1091+
serialized.renderPipelineSettings.densityVolumeSettings.atlasResolution.vector3IntValue =
1092+
Vector3Int.Min(
1093+
Vector3Int.Max(
1094+
serialized.renderPipelineSettings.densityVolumeSettings.atlasResolution.vector3IntValue,
1095+
Vector3Int.one
1096+
),
1097+
new Vector3Int(2048, 2048, 2048)
1098+
);
1099+
}
1100+
--EditorGUI.indentLevel;
1101+
}
10811102

10821103
static void Drawer_SectionMaterialUnsorted(SerializedHDRenderPipelineAsset serialized, Editor owner)
10831104
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine.Rendering.HighDefinition;
2+
3+
namespace UnityEditor.Rendering.HighDefinition
4+
{
5+
class SerializedDensityVolumeSettings
6+
{
7+
internal SerializedProperty root;
8+
9+
internal SerializedProperty atlasResolution;
10+
11+
internal SerializedDensityVolumeSettings(SerializedProperty root)
12+
{
13+
this.root = root;
14+
15+
atlasResolution = root.Find((DensityVolumeSettings s) => s.atlasResolution);
16+
}
17+
}
18+
}

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedDensityVolumeSettings.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SerializedRenderPipelineSettings
7979
public SerializedPostProcessingQualitySettings postProcessQualitySettings;
8080
public SerializedLightingQualitySettings lightingQualitySettings;
8181
internal SerializedGlobalProbeVolumeSettings probeVolumeSettings;
82+
internal SerializedDensityVolumeSettings densityVolumeSettings;
8283

8384
public SerializedLightSettings lightSettings;
8485
public SerializedScalableSetting lodBias;
@@ -151,6 +152,8 @@ public SerializedRenderPipelineSettings(SerializedProperty root)
151152
postProcessQualitySettings = new SerializedPostProcessingQualitySettings(root.Find((RenderPipelineSettings s) => s.postProcessQualitySettings));
152153
probeVolumeSettings = new SerializedGlobalProbeVolumeSettings(root.Find((RenderPipelineSettings s) => s.probeVolumeSettings));
153154

155+
densityVolumeSettings = new SerializedDensityVolumeSettings(root.Find((RenderPipelineSettings s) => s.densityVolumeSettings));
156+
154157
lightSettings = new SerializedLightSettings(root.Find((RenderPipelineSettings s) => s.lightSettings));
155158
lodBias = new SerializedScalableSetting(root.Find((RenderPipelineSettings s) => s.lodBias));
156159
maximumLODLevel = new SerializedScalableSetting(root.Find((RenderPipelineSettings s) => s.maximumLODLevel));

0 commit comments

Comments
 (0)