diff --git a/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/105_TransparentReceiveShadows.unity b/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/105_TransparentReceiveShadows.unity index b48b44cee5d..56ea8f7bcba 100644 --- a/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/105_TransparentReceiveShadows.unity +++ b/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/105_TransparentReceiveShadows.unity @@ -1752,7 +1752,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_UsePipelineSettings: 0 - m_AdditionalLightsShadowResolutionTier: 1 + m_AdditionalLightsShadowResolutionTier: 2 --- !u!1 &558490757 GameObject: m_ObjectHideFlags: 0 diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs index 13f735ce94b..029651b991b 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs @@ -47,7 +47,7 @@ internal class Styles public static GUIContent perObjectLimit = EditorGUIUtility.TrTextContent("Per Object Limit", "Maximum amount of additional lights. These lights are sorted and culled per-object."); public static GUIContent supportsAdditionalShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled shadows will be supported for spot lights.\n"); public static GUIContent additionalLightsShadowmapResolution = EditorGUIUtility.TrTextContent("Shadow Atlas Resolution", "All additional lights are packed into a single shadowmap atlas. This setting controls the atlas size."); - public static GUIContent additionalLightsShadowResolutionTiers = EditorGUIUtility.TrTextContent("Shadow Resolution Tiers", "Additional Lights Shadow Resolution Tiers. Rounded to the next power of two, and clamped to be at least 128."); + public static GUIContent additionalLightsShadowResolutionTiers = EditorGUIUtility.TrTextContent("Shadow Resolution Tiers", $"Additional Lights Shadow Resolution Tiers. Rounded to the next power of two, and clamped to be at least {UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution}."); public static GUIContent[] additionalLightsShadowResolutionTierNames = { new GUIContent("Low"), @@ -379,7 +379,7 @@ void DrawShadowResolutionTierSettings() { var fieldSlot = new Rect(contentRect.x + pixelShift, contentRect.y, num - labelWidth, contentRect.height); // Define the rectangle for the field int value = EditorGUI.DelayedIntField(fieldSlot, values[index].intValue); - values[index].intValue = Mathf.Max(128, Mathf.NextPowerOfTwo(value)); + values[index].intValue = Mathf.Max(UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution, Mathf.NextPowerOfTwo(value)); } pixelShift += spaceLeft; // Shift by the slot that was left for the field } diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineLightEditor.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineLightEditor.cs index 1432bdb2b58..7bf20c9cba1 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineLightEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineLightEditor.cs @@ -35,7 +35,7 @@ class Styles public static readonly GUIContent ShadowNormalBias = EditorGUIUtility.TrTextContent("Normal", "Controls the distance shadow caster vertices are offset along their normals when rendering shadow maps. Currently ignored for Point Lights."); // Resolution (default or custom) - public static readonly GUIContent ShadowResolution = EditorGUIUtility.TrTextContent("Resolution", "Sets the rendered resolution of the shadow maps. A higher resolution increases the fidelity of shadows at the cost of GPU performance and memory usage. Rounded to the next power of two, and clamped to be at least 128."); + public static readonly GUIContent ShadowResolution = EditorGUIUtility.TrTextContent("Resolution", $"Sets the rendered resolution of the shadow maps. A higher resolution increases the fidelity of shadows at the cost of GPU performance and memory usage. Rounded to the next power of two, and clamped to be at least {UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution}."); public static readonly int[] ShadowResolutionDefaultValues = { UniversalAdditionalLightData.AdditionalLightsShadowResolutionTierCustom, @@ -376,7 +376,7 @@ void DrawShadowsResolutionGUI() { // show the custom value field GUI. var newResolution = EditorGUI.IntField(fieldRect, settings.shadowsResolution.intValue); - settings.shadowsResolution.intValue = Mathf.Max(128, Mathf.NextPowerOfTwo(newResolution)); + settings.shadowsResolution.intValue = Mathf.Max(UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution, Mathf.NextPowerOfTwo(newResolution)); m_AdditionalLightDataSO.ApplyModifiedProperties(); } diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index d24b35eec16..71890049eab 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -104,8 +104,8 @@ public partial class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerial ScriptableRenderer[] m_Renderers = new ScriptableRenderer[1]; // Default values set when a new UniversalRenderPipeline asset is created - [SerializeField] int k_AssetVersion = 8; - [SerializeField] int k_AssetPreviousVersion = 8; + [SerializeField] int k_AssetVersion = 9; + [SerializeField] int k_AssetPreviousVersion = 9; // Deprecated settings for upgrading sakes [SerializeField] RendererType m_RendererType = RendererType.UniversalRenderer; @@ -139,9 +139,9 @@ public partial class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerial [SerializeField] bool m_AdditionalLightShadowsSupported = false; [SerializeField] ShadowResolution m_AdditionalLightsShadowmapResolution = ShadowResolution._2048; - [SerializeField] int m_AdditionalLightsShadowResolutionTierLow = 256; - [SerializeField] int m_AdditionalLightsShadowResolutionTierMedium = 512; - [SerializeField] int m_AdditionalLightsShadowResolutionTierHigh = 1024; + [SerializeField] int m_AdditionalLightsShadowResolutionTierLow = AdditionalLightsDefaultShadowResolutionTierLow; + [SerializeField] int m_AdditionalLightsShadowResolutionTierMedium = AdditionalLightsDefaultShadowResolutionTierMedium; + [SerializeField] int m_AdditionalLightsShadowResolutionTierHigh = AdditionalLightsDefaultShadowResolutionTierHigh; // Shadows Settings [SerializeField] float m_ShadowDistance = 50.0f; @@ -186,6 +186,10 @@ public partial class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerial internal const int k_ShadowCascadeMinCount = 1; internal const int k_ShadowCascadeMaxCount = 4; + public static readonly int AdditionalLightsDefaultShadowResolutionTierLow = 256; + public static readonly int AdditionalLightsDefaultShadowResolutionTierMedium = 512; + public static readonly int AdditionalLightsDefaultShadowResolutionTierHigh = 1024; + #if UNITY_EDITOR [NonSerialized] internal UniversalRenderPipelineEditorResources m_EditorResourcesAsset; @@ -934,6 +938,25 @@ public void OnAfterDeserialize() k_AssetVersion = 8; } + if (k_AssetVersion < 9) + { + bool assetContainsCustomAdditionalLightShadowResolutions = + m_AdditionalLightsShadowResolutionTierHigh != AdditionalLightsDefaultShadowResolutionTierHigh || + m_AdditionalLightsShadowResolutionTierMedium != AdditionalLightsDefaultShadowResolutionTierMedium || + m_AdditionalLightsShadowResolutionTierLow != AdditionalLightsDefaultShadowResolutionTierLow; + + if (!assetContainsCustomAdditionalLightShadowResolutions) + { + // if all resolutions are still the default values, we assume that they have never been customized and that it is safe to upgrade them to fit better the Additional Lights Shadow Atlas size + m_AdditionalLightsShadowResolutionTierHigh = (int)m_AdditionalLightsShadowmapResolution; + m_AdditionalLightsShadowResolutionTierMedium = Mathf.Max(m_AdditionalLightsShadowResolutionTierHigh / 2, UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution); + m_AdditionalLightsShadowResolutionTierLow = Mathf.Max(m_AdditionalLightsShadowResolutionTierMedium / 2, UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution); + } + + k_AssetPreviousVersion = k_AssetVersion; + k_AssetVersion = 9; + } + #if UNITY_EDITOR if (k_AssetPreviousVersion != k_AssetVersion) { @@ -964,10 +987,10 @@ static void UpgradeAsset(UniversalRenderPipelineAsset asset) asset.k_AssetPreviousVersion = 5; } - if (asset.k_AssetPreviousVersion < 8) + if (asset.k_AssetPreviousVersion < 9) { // The added feature was reverted, we keep this version to avoid breakage in case somebody already has version 7 - asset.k_AssetPreviousVersion = 8; + asset.k_AssetPreviousVersion = 9; } EditorUtility.SetDirty(asset); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalLightData.cs b/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalLightData.cs index 37363dac78c..3053fce9acd 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalLightData.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalLightData.cs @@ -29,8 +29,9 @@ public bool usePipelineSettings public static readonly int AdditionalLightsShadowResolutionTierLow = 0; public static readonly int AdditionalLightsShadowResolutionTierMedium = 1; public static readonly int AdditionalLightsShadowResolutionTierHigh = 2; - public static readonly int AdditionalLightsShadowDefaultResolutionTier = AdditionalLightsShadowResolutionTierLow; + public static readonly int AdditionalLightsShadowDefaultResolutionTier = AdditionalLightsShadowResolutionTierHigh; public static readonly int AdditionalLightsShadowDefaultCustomResolution = 128; + public static readonly int AdditionalLightsShadowMinimumResolution = 128; [Tooltip("Controls if light shadow resolution uses pipeline settings.")] [SerializeField] int m_AdditionalLightsShadowResolutionTier = AdditionalLightsShadowDefaultResolutionTier;