Skip to content

Commit 3639f88

Browse files
nigeljw-unityeh-unityoleks-k
authored
Minimal enclosing sphere backport to 2021.2 (#5722)
Co-authored-by: Erik Hakala <[email protected]> Co-authored-by: Oleksandr Kokoshyn <[email protected]>
1 parent 0a71823 commit 3639f88

File tree

13 files changed

+47
-10
lines changed

13 files changed

+47
-10
lines changed

com.unity.render-pipelines.core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "SRP Core makes it easier to create or customize a Scriptable Render Pipeline (SRP). SRP Core contains reusable code, including boilerplate code for working with platform-specific graphics APIs, utility functions for common rendering operations, and shader libraries. The code in SRP Core is use by the High Definition Render Pipeline (HDRP) and Universal Render Pipeline (URP). If you are creating a custom SRP from scratch or customizing a prebuilt SRP, using SRP Core will save you time.",
44
"version": "12.1.0",
55
"unity": "2021.2",
6-
"unityRelease": "0b14",
6+
"unityRelease": "0b15",
77
"displayName": "Core RP Library",
88
"dependencies": {
99
"com.unity.ugui": "1.0.0",

com.unity.render-pipelines.high-definition-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Configuration files for the High Definition Render Pipeline.",
44
"version": "12.1.0",
55
"unity": "2021.2",
6-
"unityRelease": "0b14",
6+
"unityRelease": "0b15",
77
"displayName": "High Definition RP Config",
88
"dependencies": {
99
"com.unity.render-pipelines.core": "12.1.0"

com.unity.render-pipelines.high-definition/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "The High Definition Render Pipeline (HDRP) is a high-fidelity Scriptable Render Pipeline built by Unity to target modern (Compute Shader compatible) platforms. HDRP utilizes Physically-Based Lighting techniques, linear lighting, HDR lighting, and a configurable hybrid Tile/Cluster deferred/Forward lighting architecture and gives you the tools you need to create games, technical demos, animations, and more to a high graphical standard.",
44
"version": "12.1.0",
55
"unity": "2021.2",
6-
"unityRelease": "0b14",
6+
"unityRelease": "0b15",
77
"displayName": "High Definition RP",
88
"dependencies": {
99
"com.unity.mathematics": "1.2.1",

com.unity.render-pipelines.universal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
188188
- Fixed an issue where _AfterPostProcessTexture was no longer being assigned in UniversalRenderer.
189189
- Fixed UniversalRenderPipelineAsset now being able to use multiedit
190190
- Fixed memory leak with XR combined occlusion meshes. [case 1366173]
191+
- Added "Conservative Enclosing Sphere" setting to fix shadow frustum culling issue where shadows are erroneously culled in corners of cascades [case 1153151](https://issuetracker.unity3d.com/issues/lwrp-shadows-are-being-culled-incorrectly-in-the-corner-of-the-camera-viewport-when-the-far-clip-plane-is-small)
191192

192193
### Changed
193194
- Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph

com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ The **Shadows** section has the following properties.
8787
| **Depth Bias** | Use this setting to reduce [shadow acne](https://docs.unity3d.com/Manual/ShadowPerformance.html). |
8888
| **Normal Bias** | Use this setting to reduce [shadow acne](https://docs.unity3d.com/Manual/ShadowPerformance.html). |
8989
| __Soft Shadows__ | Select this check box to enable extra processing of the shadow maps to give them a smoother look.<br/>When enabled, Unity uses the following shadow map filtering method:<br/>Desktop platforms: 5x5 tent filter, mobile platforms: 4 tap filter.<br/>**Performance impact**: high.<br/>When this option is disabled, Unity samples the shadow map once with the default hardware filtering. |
90-
91-
90+
| **Conservative Enclosing Sphere** | Enable this option to improve shadow frustum culling and prevent Unity from excessively culling shadows in the corners of the shadow cascades.<br/>Disable this option only for compatibility purposes of existing projects created in previous Unity versions.<br/>If you enable this option in an existing project, you might need to adjust the shadows cascade distances because the shadow culling enclosing spheres change their size and position.<br/>**Performance impact**: enabling this option is likely to improve performance, because the option minimizes the overlap of shadow cascades, which reduces the number of redundant static shadow casters. |
9291

9392
### Post-processing
9493

com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ internal class SerializedUniversalRenderPipelineAsset
4545
public SerializedProperty shadowCascadeBorderProp { get; }
4646
public SerializedProperty shadowDepthBiasProp { get; }
4747
public SerializedProperty shadowNormalBiasProp { get; }
48-
4948
public SerializedProperty softShadowsSupportedProp { get; }
49+
public SerializedProperty conservativeEnclosingSphereProp { get; }
5050

5151
public SerializedProperty srpBatcher { get; }
5252
public SerializedProperty supportsDynamicBatching { get; }
@@ -111,6 +111,7 @@ public SerializedUniversalRenderPipelineAsset(SerializedObject serializedObject)
111111
shadowDepthBiasProp = serializedObject.FindProperty("m_ShadowDepthBias");
112112
shadowNormalBiasProp = serializedObject.FindProperty("m_ShadowNormalBias");
113113
softShadowsSupportedProp = serializedObject.FindProperty("m_SoftShadowsSupported");
114+
conservativeEnclosingSphereProp = serializedObject.FindProperty("m_ConservativeEnclosingSphere");
114115

115116
srpBatcher = serializedObject.FindProperty("m_UseSRPBatcher");
116117
supportsDynamicBatching = serializedObject.FindProperty("m_SupportsDynamicBatching");

com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum ExpandableAdditional
2525
Rendering = 1 << 1,
2626
Lighting = 1 << 2,
2727
PostProcessing = 1 << 3,
28+
Shadows = 1 << 4,
2829
}
2930

3031
internal static void RegisterEditor(UniversalRenderPipelineAssetEditor editor)
@@ -103,7 +104,7 @@ static bool ValidateRendererGraphicsAPIs(UniversalRenderPipelineAsset pipelineAs
103104
CED.AdditionalPropertiesFoldoutGroup(Styles.renderingSettingsText, Expandable.Rendering, k_ExpandedState, ExpandableAdditional.Rendering, k_AdditionalPropertiesState, DrawRendering, DrawRenderingAdditional),
104105
CED.FoldoutGroup(Styles.qualitySettingsText, Expandable.Quality, k_ExpandedState, CED.Group(DrawQuality)),
105106
CED.AdditionalPropertiesFoldoutGroup(Styles.lightingSettingsText, Expandable.Lighting, k_ExpandedState, ExpandableAdditional.Lighting, k_AdditionalPropertiesState, DrawLighting, DrawLightingAdditional),
106-
CED.FoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, CED.Group(DrawShadows)),
107+
CED.AdditionalPropertiesFoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, ExpandableAdditional.Shadows, k_AdditionalPropertiesState, DrawShadows, DrawShadowsAdditional),
107108
CED.AdditionalPropertiesFoldoutGroup(Styles.postProcessingSettingsText, Expandable.PostProcessing, k_ExpandedState, ExpandableAdditional.PostProcessing, k_AdditionalPropertiesState, DrawPostProcessing, DrawPostProcessingAdditional)
108109
#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
109110
, CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdvanced)),
@@ -293,9 +294,15 @@ static void DrawShadows(SerializedUniversalRenderPipelineAsset serialized, Edito
293294
serialized.shadowDepthBiasProp.floatValue = EditorGUILayout.Slider(Styles.shadowDepthBias, serialized.shadowDepthBiasProp.floatValue, 0.0f, UniversalRenderPipeline.maxShadowBias);
294295
serialized.shadowNormalBiasProp.floatValue = EditorGUILayout.Slider(Styles.shadowNormalBias, serialized.shadowNormalBiasProp.floatValue, 0.0f, UniversalRenderPipeline.maxShadowBias);
295296
EditorGUILayout.PropertyField(serialized.softShadowsSupportedProp, Styles.supportsSoftShadows);
297+
296298
EditorGUI.indentLevel--;
297299
}
298300

301+
static void DrawShadowsAdditional(SerializedUniversalRenderPipelineAsset serialized, Editor ownerEditor)
302+
{
303+
EditorGUILayout.PropertyField(serialized.conservativeEnclosingSphereProp, Styles.conservativeEnclosingSphere);
304+
}
305+
299306
static void DrawCascadeSliders(SerializedUniversalRenderPipelineAsset serialized, int splitCount, bool useMetric, float baseMetric)
300307
{
301308
Vector4 shadowCascadeSplit = Vector4.one;

com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static class Styles
7474
public static GUIContent shadowDepthBias = EditorGUIUtility.TrTextContent("Depth Bias", "Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts.");
7575
public static GUIContent shadowNormalBias = EditorGUIUtility.TrTextContent("Normal Bias", "Controls distance at which the shadow casting surfaces will be shrunk along the surface normal. Useful for avoiding false self-shadowing artifacts.");
7676
public static GUIContent supportsSoftShadows = EditorGUIUtility.TrTextContent("Soft Shadows", "If enabled pipeline will perform shadow filtering. Otherwise all lights that cast shadows will fallback to perform a single shadow sample.");
77+
public static GUIContent conservativeEnclosingSphere = EditorGUIUtility.TrTextContent("Conservative Enclosing Sphere", "Enable this option to improve shadow frustum culling and prevent Unity from excessively culling shadows in the corners of the shadow cascades. Disable this option only for compatibility purposes of existing projects created in previous Unity versions.");
7778

7879
// Post-processing
7980
public static GUIContent colorGradingMode = EditorGUIUtility.TrTextContent("Grading Mode", "Defines how color grading will be applied. Operators will react differently depending on the mode.");

com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public partial class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerial
198198
[SerializeField] float m_ShadowDepthBias = 1.0f;
199199
[SerializeField] float m_ShadowNormalBias = 1.0f;
200200
[SerializeField] bool m_SoftShadowsSupported = false;
201+
[SerializeField] bool m_ConservativeEnclosingSphere = false;
202+
[SerializeField] int m_NumIterationsEnclosingSphere = 64;
201203

202204
// Light Cookie Settings
203205
[SerializeField] LightCookieResolution m_AdditionalLightsCookieResolution = LightCookieResolution._2048;
@@ -260,6 +262,9 @@ public static UniversalRenderPipelineAsset Create(ScriptableRendererData rendere
260262
// Initialize default Renderer
261263
instance.m_EditorResourcesAsset = instance.editorResources;
262264

265+
// Only enable for new URP assets by default
266+
instance.m_ConservativeEnclosingSphere = true;
267+
263268
return instance;
264269
}
265270

@@ -913,6 +918,25 @@ public bool useAdaptivePerformance
913918
set { m_UseAdaptivePerformance = value; }
914919
}
915920

921+
/// <summary>
922+
/// Set to true to enable a conservative method for calculating the size and position of the minimal enclosing sphere around the frustum cascade corner points for shadow culling.
923+
/// </summary>
924+
public bool conservativeEnclosingSphere
925+
{
926+
get { return m_ConservativeEnclosingSphere; }
927+
set { m_ConservativeEnclosingSphere = value; }
928+
}
929+
930+
/// <summary>
931+
/// Set the number of iterations to reduce the cascade culling enlcosing sphere to be closer to the absolute minimun enclosing sphere, but will also require more CPU computation for increasing values.
932+
/// This parameter is used only when conservativeEnclosingSphere is set to true. Default value is 64.
933+
/// </summary>
934+
public int numIterationsEnclosingSphere
935+
{
936+
get { return m_NumIterationsEnclosingSphere; }
937+
set { m_NumIterationsEnclosingSphere = value; }
938+
}
939+
916940
public override Material defaultMaterial
917941
{
918942
get { return GetMaterial(DefaultMaterialType.Standard); }

com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull
896896
cullingParameters.maximumVisibleLights = UniversalRenderPipeline.maxVisibleAdditionalLights + 1;
897897
}
898898
cullingParameters.shadowDistance = cameraData.maxShadowDistance;
899+
900+
cullingParameters.conservativeEnclosingSphere = UniversalRenderPipeline.asset.conservativeEnclosingSphere;
901+
902+
cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numIterationsEnclosingSphere;
899903
}
900904

901905
/// <inheritdoc />

0 commit comments

Comments
 (0)