From 7c5c6503227f770c577ebf9cf1729e12fbfc9ff9 Mon Sep 17 00:00:00 2001 From: nigeljw-unity <72749964+nigeljw-unity@users.noreply.github.com> Date: Fri, 17 Sep 2021 17:14:04 +0200 Subject: [PATCH 1/4] Minimal enclosing sphere fix Backport of minimal enclosing sphere solution for shadow frustum culling. https://github.com/Unity-Technologies/Graphics/pull/4436 Co-authored-by: Erik Hakala Co-authored-by: Oleksandr Kokoshyn --- .../CHANGELOG.md | 1 + .../Documentation~/universalrp-asset.md | 3 +-- .../SerializedUniversalRenderPipelineAsset.cs | 3 ++- .../UniversalRenderPipelineAssetUI.Drawers.cs | 9 ++++++++- .../UniversalRenderPipelineAssetUI.Skin.cs | 1 + .../Data/UniversalRenderPipelineAsset.cs | 17 +++++++++++++++++ .../Runtime/UniversalRenderPipeline.cs | 5 +++++ .../Runtime/UniversalRenderer.cs | 4 ++++ 8 files changed, 39 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 76c7029df88..e42a4bf315a 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -178,6 +178,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting. - Fixed an issue where _AfterPostProcessTexture was no longer being assigned in UniversalRenderer. - Fixed UniversalRenderPipelineAsset now being able to use multiedit +- 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) ### Changed - Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph diff --git a/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md b/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md index ea610d4a65c..50d7542b2d4 100644 --- a/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md +++ b/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md @@ -87,8 +87,7 @@ The **Shadows** section has the following properties. | **Depth Bias** | Use this setting to reduce [shadow acne](https://docs.unity3d.com/Manual/ShadowPerformance.html). | | **Normal Bias** | Use this setting to reduce [shadow acne](https://docs.unity3d.com/Manual/ShadowPerformance.html). | | __Soft Shadows__ | Select this check box to enable extra processing of the shadow maps to give them a smoother look.
When enabled, Unity uses the following shadow map filtering method:
Desktop platforms: 5x5 tent filter, mobile platforms: 4 tap filter.
**Performance impact**: high.
When this option is disabled, Unity samples the shadow map once with the default hardware filtering. | - - +| **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.
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.
**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. | ### Post-processing diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs index b4a3c1dbaf2..71103e44ba1 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs @@ -45,8 +45,8 @@ internal class SerializedUniversalRenderPipelineAsset public SerializedProperty shadowCascadeBorderProp { get; } public SerializedProperty shadowDepthBiasProp { get; } public SerializedProperty shadowNormalBiasProp { get; } - public SerializedProperty softShadowsSupportedProp { get; } + public SerializedProperty conservativeEnclosingSphereProp { get; } public SerializedProperty srpBatcher { get; } public SerializedProperty supportsDynamicBatching { get; } @@ -111,6 +111,7 @@ public SerializedUniversalRenderPipelineAsset(SerializedObject serializedObject) shadowDepthBiasProp = serializedObject.FindProperty("m_ShadowDepthBias"); shadowNormalBiasProp = serializedObject.FindProperty("m_ShadowNormalBias"); softShadowsSupportedProp = serializedObject.FindProperty("m_SoftShadowsSupported"); + conservativeEnclosingSphereProp = serializedObject.FindProperty("m_ConservativeEnclosingSphere"); srpBatcher = serializedObject.FindProperty("m_UseSRPBatcher"); supportsDynamicBatching = serializedObject.FindProperty("m_SupportsDynamicBatching"); diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs index b1c7ceb13b9..5ed4f8566d0 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs @@ -25,6 +25,7 @@ enum ExpandableAdditional Rendering = 1 << 1, Lighting = 1 << 2, PostProcessing = 1 << 3, + Shadows = 1 << 4, } internal static void RegisterEditor(UniversalRenderPipelineAssetEditor editor) @@ -103,7 +104,7 @@ static bool ValidateRendererGraphicsAPIs(UniversalRenderPipelineAsset pipelineAs CED.AdditionalPropertiesFoldoutGroup(Styles.renderingSettingsText, Expandable.Rendering, k_ExpandedState, ExpandableAdditional.Rendering, k_AdditionalPropertiesState, DrawRendering, DrawRenderingAdditional), CED.FoldoutGroup(Styles.qualitySettingsText, Expandable.Quality, k_ExpandedState, CED.Group(DrawQuality)), CED.AdditionalPropertiesFoldoutGroup(Styles.lightingSettingsText, Expandable.Lighting, k_ExpandedState, ExpandableAdditional.Lighting, k_AdditionalPropertiesState, DrawLighting, DrawLightingAdditional), - CED.FoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, CED.Group(DrawShadows)), + CED.AdditionalPropertiesFoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, ExpandableAdditional.Shadows, k_AdditionalPropertiesState, DrawShadows, DrawShadowsAdditional), CED.AdditionalPropertiesFoldoutGroup(Styles.postProcessingSettingsText, Expandable.PostProcessing, k_ExpandedState, ExpandableAdditional.PostProcessing, k_AdditionalPropertiesState, DrawPostProcessing, DrawPostProcessingAdditional) #if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER , CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdvanced)), @@ -293,9 +294,15 @@ static void DrawShadows(SerializedUniversalRenderPipelineAsset serialized, Edito serialized.shadowDepthBiasProp.floatValue = EditorGUILayout.Slider(Styles.shadowDepthBias, serialized.shadowDepthBiasProp.floatValue, 0.0f, UniversalRenderPipeline.maxShadowBias); serialized.shadowNormalBiasProp.floatValue = EditorGUILayout.Slider(Styles.shadowNormalBias, serialized.shadowNormalBiasProp.floatValue, 0.0f, UniversalRenderPipeline.maxShadowBias); EditorGUILayout.PropertyField(serialized.softShadowsSupportedProp, Styles.supportsSoftShadows); + EditorGUI.indentLevel--; } + static void DrawShadowsAdditional(SerializedUniversalRenderPipelineAsset serialized, Editor ownerEditor) + { + EditorGUILayout.PropertyField(serialized.conservativeEnclosingSphereProp, Styles.conservativeEnclosingSphere); + } + static void DrawCascadeSliders(SerializedUniversalRenderPipelineAsset serialized, int splitCount, bool useMetric, float baseMetric) { Vector4 shadowCascadeSplit = Vector4.one; diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs index 5d177b67a67..629e0ece74b 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs @@ -74,6 +74,7 @@ public static class Styles 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."); 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."); 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."); + 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."); // Post-processing public static GUIContent colorGradingMode = EditorGUIUtility.TrTextContent("Grading Mode", "Defines how color grading will be applied. Operators will react differently depending on the mode."); diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index 8ab25abcf7d..8e14cca2516 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -198,6 +198,8 @@ public partial class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerial [SerializeField] float m_ShadowDepthBias = 1.0f; [SerializeField] float m_ShadowNormalBias = 1.0f; [SerializeField] bool m_SoftShadowsSupported = false; + [SerializeField] bool m_ConservativeEnclosingSphere = false; + [SerializeField] int m_NumIterationsEnclosingSphere = 64; // Light Cookie Settings [SerializeField] LightCookieResolution m_AdditionalLightsCookieResolution = LightCookieResolution._2048; @@ -260,6 +262,9 @@ public static UniversalRenderPipelineAsset Create(ScriptableRendererData rendere // Initialize default Renderer instance.m_EditorResourcesAsset = instance.editorResources; + // Only enable for new URP assets by default + instance.m_ConservativeEnclosingSphere = true; + return instance; } @@ -913,6 +918,18 @@ public bool useAdaptivePerformance set { m_UseAdaptivePerformance = value; } } + public bool conservativeEnclosingSphere + { + get { return m_ConservativeEnclosingSphere; } + set { m_ConservativeEnclosingSphere = value; } + } + + public int numItertionsEnclosingSphere + { + get { return m_NumIterationsEnclosingSphere; } + set { m_NumIterationsEnclosingSphere = value; } + } + public override Material defaultMaterial { get { return GetMaterial(DefaultMaterialType.Standard); } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 32222f9be1e..0884579e406 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -103,6 +103,11 @@ public static float maxRenderScale get => 2.0f; } + public static int maxNumIterationsEnclosingSphere + { + get => 1000; + } + // Amount of Lights that can be shaded per object (in the for loop in the shader) public static int maxPerObjectLights { diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index 7abb3d146a1..7efecda071c 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -887,6 +887,10 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull cullingParameters.maximumVisibleLights = UniversalRenderPipeline.maxVisibleAdditionalLights + 1; } cullingParameters.shadowDistance = cameraData.maxShadowDistance; + + cullingParameters.conservativeEnclosingSphere = UniversalRenderPipeline.asset.conservativeEnclosingSphere; + + cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numItertionsEnclosingSphere; } /// From 60efdc9e06be4335df33222622cc6dedc36edd16 Mon Sep 17 00:00:00 2001 From: Nigel Williams Date: Fri, 24 Sep 2021 17:10:23 +0200 Subject: [PATCH 2/4] Fixed API typo, added docs, and bumped min version --- .../Runtime/Data/UniversalRenderPipelineAsset.cs | 9 ++++++++- .../Runtime/UniversalRenderer.cs | 2 +- com.unity.render-pipelines.universal/package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index 8e14cca2516..deeb5266008 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -918,13 +918,20 @@ public bool useAdaptivePerformance set { m_UseAdaptivePerformance = value; } } + /// + /// 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. + /// public bool conservativeEnclosingSphere { get { return m_ConservativeEnclosingSphere; } set { m_ConservativeEnclosingSphere = value; } } - public int numItertionsEnclosingSphere + /// + /// 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. + /// This parameter is used only when conservativeEnclosingSphere is set to true. Default value is 64. + /// + public int numIterationsEnclosingSphere { get { return m_NumIterationsEnclosingSphere; } set { m_NumIterationsEnclosingSphere = value; } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index 7efecda071c..2691fbe56da 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -890,7 +890,7 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull cullingParameters.conservativeEnclosingSphere = UniversalRenderPipeline.asset.conservativeEnclosingSphere; - cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numItertionsEnclosingSphere; + cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numIterationsEnclosingSphere; } /// diff --git a/com.unity.render-pipelines.universal/package.json b/com.unity.render-pipelines.universal/package.json index d64f88ec9a6..13a5505be8b 100644 --- a/com.unity.render-pipelines.universal/package.json +++ b/com.unity.render-pipelines.universal/package.json @@ -3,7 +3,7 @@ "description": "The Universal Render Pipeline (URP) is a prebuilt Scriptable Render Pipeline, made by Unity. URP provides artist-friendly workflows that let you quickly and easily create optimized graphics across a range of platforms, from mobile to high-end consoles and PCs.", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b12", + "unityRelease": "0b15", "displayName": "Universal RP", "dependencies": { "com.unity.mathematics": "1.2.1", From f7d99fde549a65c52c21a92a9988812a0f66c6bf Mon Sep 17 00:00:00 2001 From: Nigel Williams Date: Fri, 24 Sep 2021 17:19:59 +0200 Subject: [PATCH 3/4] Removed dead code --- .../Runtime/UniversalRenderPipeline.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 0884579e406..32222f9be1e 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -103,11 +103,6 @@ public static float maxRenderScale get => 2.0f; } - public static int maxNumIterationsEnclosingSphere - { - get => 1000; - } - // Amount of Lights that can be shaded per object (in the for loop in the shader) public static int maxPerObjectLights { From 00b46f7c16427073f7a7772faeb99147105e023d Mon Sep 17 00:00:00 2001 From: Nigel Williams Date: Wed, 29 Sep 2021 15:39:06 +0200 Subject: [PATCH 4/4] Missing package bumps --- com.unity.render-pipelines.core/package.json | 2 +- com.unity.render-pipelines.high-definition-config/package.json | 2 +- com.unity.render-pipelines.high-definition/package.json | 2 +- com.unity.shadergraph/package.json | 2 +- com.unity.visualeffectgraph/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.core/package.json b/com.unity.render-pipelines.core/package.json index 2482b6384c3..6a58012784e 100644 --- a/com.unity.render-pipelines.core/package.json +++ b/com.unity.render-pipelines.core/package.json @@ -3,7 +3,7 @@ "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.", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b14", + "unityRelease": "0b15", "displayName": "Core RP Library", "dependencies": { "com.unity.ugui": "1.0.0", diff --git a/com.unity.render-pipelines.high-definition-config/package.json b/com.unity.render-pipelines.high-definition-config/package.json index 4bb0b79bd28..c038ac9c40d 100644 --- a/com.unity.render-pipelines.high-definition-config/package.json +++ b/com.unity.render-pipelines.high-definition-config/package.json @@ -3,7 +3,7 @@ "description": "Configuration files for the High Definition Render Pipeline.", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b14", + "unityRelease": "0b15", "displayName": "High Definition RP Config", "dependencies": { "com.unity.render-pipelines.core": "12.0.0" diff --git a/com.unity.render-pipelines.high-definition/package.json b/com.unity.render-pipelines.high-definition/package.json index 17b99009127..33d74ee2cde 100644 --- a/com.unity.render-pipelines.high-definition/package.json +++ b/com.unity.render-pipelines.high-definition/package.json @@ -3,7 +3,7 @@ "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.", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b14", + "unityRelease": "0b15", "displayName": "High Definition RP", "dependencies": { "com.unity.mathematics": "1.2.1", diff --git a/com.unity.shadergraph/package.json b/com.unity.shadergraph/package.json index 09caffe704f..bc40936c23a 100644 --- a/com.unity.shadergraph/package.json +++ b/com.unity.shadergraph/package.json @@ -3,7 +3,7 @@ "description": "The Shader Graph package adds a visual Shader editing tool to Unity. You can use this tool to create Shaders in a visual way instead of writing code. Specific render pipelines can implement specific graph features. Currently, both the High Definition Rendering Pipeline and the Universal Rendering Pipeline support Shader Graph.", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b14", + "unityRelease": "0b15", "displayName": "Shader Graph", "dependencies": { "com.unity.render-pipelines.core": "12.0.0", diff --git a/com.unity.visualeffectgraph/package.json b/com.unity.visualeffectgraph/package.json index e85af77331f..e2b13f9432d 100644 --- a/com.unity.visualeffectgraph/package.json +++ b/com.unity.visualeffectgraph/package.json @@ -3,7 +3,7 @@ "displayName": "Visual Effect Graph", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0b14", + "unityRelease": "0b15", "description": "The Visual Effect Graph is a node based visual effect editor. It allows you to author next generation visual effects that Unity simulates directly on the GPU. The Visual Effect Graph is production-ready for the High Definition Render Pipeline and runs on all platforms supported by it. Full support for the Universal Render Pipeline and compatible mobile devices is still in development.", "keywords": [ "vfx",