diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index b1e9172ba5e..2002e6a26d0 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added additional steps to the 2D Renderer setup page for quality and platform settings. - Added support for clear coat material feature in the Lit shader. - Added option to disable XR autotests on test settings. +- Added option to enable/disable Adaptive Performance when it's package is available. ### Changed diff --git a/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md b/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md index 1b704512706..17c386a4755 100644 --- a/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md +++ b/com.unity.render-pipelines.universal/Documentation~/universalrp-asset.md @@ -16,6 +16,7 @@ In the URP, you can configure settings for: - [__Shadows__](#shadows) - [__Post-processing__](#post-processing) - [__Advanced__](#advanced) +- [__Adaptive Performance__](#adaptive-performance) @@ -100,3 +101,13 @@ This section allows you to fine-tune less commonly changed settings, which impac | __Mixed Lighting__ | Enable [Mixed Lighting](https://docs.unity3d.com/Manual/LightMode-Mixed.html), to tell the pipeline to include mixed lighting shader variants in the build. | | __Debug Level__ | Set the level of debug information that the render pipeline generates. The values are:
**Disabled**: Debugging is disabled. This is the default.
**Profiling**: Makes the render pipeline provide detailed information tags, which you can see in the FrameDebugger. | | __Shader Variant Log Level__ | Set the level of information about Shader Stripping and Shader Variants you want to display when Unity finishes a build. Values are:
**Disabled**: Unity doesn’t log anything.
**Only Universal**: Unity logs information for all of the [URP Shaders](shaders-in-universalrp.md).
**All**: Unity logs information for all Shaders in your build.
You can see the information in Console panel when your build has finished. | + + + +### Adaptive Performance + +This section appears if Adaptive Performance package is installed. It allows to change settings how Adaptive performance and render pipeline interact. + +| __Property__ | __Description__ | +| ----------------------- | ------------------------------------------------------------ | +| __Use adaptive performance__ | Allows Adaptive Performance to adjust rendering quality during runtime. | \ No newline at end of file diff --git a/com.unity.render-pipelines.universal/Editor/Unity.RenderPipelines.Universal.Editor.asmdef b/com.unity.render-pipelines.universal/Editor/Unity.RenderPipelines.Universal.Editor.asmdef index e2d1de76ce1..e7805d69672 100644 --- a/com.unity.render-pipelines.universal/Editor/Unity.RenderPipelines.Universal.Editor.asmdef +++ b/com.unity.render-pipelines.universal/Editor/Unity.RenderPipelines.Universal.Editor.asmdef @@ -8,7 +8,8 @@ "GUID:3eae0364be2026648bf74846acb8a731", "GUID:be0903cd8e1546f498710afdc59db5eb", "GUID:b75d3cd3037d383a8d1e2f9a26d73d8a", - "GUID:329b4ccd385744985bf3f83cfd77dfe7" + "GUID:329b4ccd385744985bf3f83cfd77dfe7", + "GUID:9604b18aafdbc9346bceb5e19ac9c746" ], "includePlatforms": [ "Editor" @@ -19,6 +20,12 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.adaptiveperformance", + "expression": "2.0.0-preview.7", + "define": "ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER" + } + ], "noEngineReferences": false } \ No newline at end of file diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs index 2c51c676e52..ab5ef1ced66 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs @@ -18,6 +18,7 @@ internal class Styles public static GUIContent shadowSettingsText = EditorGUIUtility.TrTextContent("Shadows"); public static GUIContent postProcessingSettingsText = EditorGUIUtility.TrTextContent("Post-processing"); public static GUIContent advancedSettingsText = EditorGUIUtility.TrTextContent("Advanced"); + public static GUIContent adaptivePerformanceText = EditorGUIUtility.TrTextContent("Adaptive Performance"); // General public static GUIContent rendererHeaderText = EditorGUIUtility.TrTextContent("Renderer List", "Lists all the renderers available to this Render Pipeline Asset."); @@ -68,6 +69,9 @@ internal class Styles public static GUIContent debugLevel = EditorGUIUtility.TrTextContent("Debug Level", "Controls the level of debug information generated by the render pipeline. When Profiling is selected, the pipeline provides detailed profiling tags."); public static GUIContent shaderVariantLogLevel = EditorGUIUtility.TrTextContent("Shader Variant Log Level", "Controls the level logging in of shader variants information is outputted when a build is performed. Information will appear in the Unity console when the build finishes."); + // Adaptive performance settings + public static GUIContent useAdaptivePerformance = EditorGUIUtility.TrTextContent("Use adaptive performance", "Allows Adaptive Performance to adjust rendering quality during runtime"); + // Renderer List Messages public static GUIContent rendererListDefaultMessage = EditorGUIUtility.TrTextContent("Cannot remove Default Renderer", @@ -90,6 +94,7 @@ internal class Styles SavedBool m_ShadowSettingsFoldout; SavedBool m_PostProcessingSettingsFoldout; SavedBool m_AdvancedSettingsFoldout; + SavedBool m_AdaptivePerformanceFoldout; SerializedProperty m_RendererDataProp; SerializedProperty m_DefaultRendererProp; @@ -133,6 +138,8 @@ internal class Styles SerializedProperty m_ColorGradingMode; SerializedProperty m_ColorGradingLutSize; + SerializedProperty m_UseAdaptivePerformance; + public override void OnInspectorGUI() { serializedObject.Update(); @@ -143,6 +150,9 @@ public override void OnInspectorGUI() DrawShadowSettings(); DrawPostProcessingSettings(); DrawAdvancedSettings(); +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER + DrawAdaptivePerformance(); +#endif serializedObject.ApplyModifiedProperties(); } @@ -155,6 +165,7 @@ void OnEnable() m_ShadowSettingsFoldout = new SavedBool($"{target.GetType()}.ShadowSettingsFoldout", false); m_PostProcessingSettingsFoldout = new SavedBool($"{target.GetType()}.PostProcessingSettingsFoldout", false); m_AdvancedSettingsFoldout = new SavedBool($"{target.GetType()}.AdvancedSettingsFoldout", false); + m_AdaptivePerformanceFoldout = new SavedBool($"{target.GetType()}.AdaptivePerformanceFoldout", false); m_RendererDataProp = serializedObject.FindProperty("m_RendererDataList"); m_DefaultRendererProp = serializedObject.FindProperty("m_DefaultRendererIndex"); @@ -198,6 +209,8 @@ void OnEnable() m_ColorGradingMode = serializedObject.FindProperty("m_ColorGradingMode"); m_ColorGradingLutSize = serializedObject.FindProperty("m_ColorGradingLutSize"); + m_UseAdaptivePerformance = serializedObject.FindProperty("m_UseAdaptivePerformance"); + selectedLightRenderingMode = (LightRenderingMode)m_AdditionalLightsRenderingModeProp.intValue; } @@ -379,6 +392,20 @@ void DrawAdvancedSettings() EditorGUILayout.EndFoldoutHeaderGroup(); } + void DrawAdaptivePerformance() + { + m_AdaptivePerformanceFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_AdaptivePerformanceFoldout.value, Styles.adaptivePerformanceText); + if (m_AdaptivePerformanceFoldout.value) + { + EditorGUI.indentLevel++; + EditorGUILayout.PropertyField(m_UseAdaptivePerformance, Styles.useAdaptivePerformance); + EditorGUI.indentLevel--; + EditorGUILayout.Space(); + EditorGUILayout.Space(); + } + EditorGUILayout.EndFoldoutHeaderGroup(); + } + void DrawRendererListLayout(ReorderableList list, SerializedProperty prop) { list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index 905b040e548..e2c666b8ee7 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -158,6 +158,9 @@ public class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerializationC [SerializeField] bool m_MixedLightingSupported = true; [SerializeField] PipelineDebugLevel m_DebugLevel = PipelineDebugLevel.Disabled; + // Adaptive performance settings + [SerializeField] bool m_UseAdaptivePerformance = true; + // Post-processing settings [SerializeField] ColorGradingMode m_ColorGradingMode = ColorGradingMode.LowDynamicRange; [SerializeField] int m_ColorGradingLutSize = 32; @@ -622,6 +625,16 @@ public int colorGradingLutSize set { m_ColorGradingLutSize = Mathf.Clamp(value, k_MinLutSize, k_MaxLutSize); } } + /// + /// Set to true to allow Adaptive performance to modify graphics quality settings during runtime. + /// Only applicable when Adaptive performance package is available. + /// + public bool useAdaptivePerformance + { + get { return m_UseAdaptivePerformance; } + set { m_UseAdaptivePerformance = value; } + } + public override Material defaultMaterial { get { return GetMaterial(DefaultMaterialType.Standard); } diff --git a/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef b/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef index b7db4aeafb2..de9342a90fa 100644 --- a/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef +++ b/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef @@ -3,6 +3,7 @@ "references": [ "GUID:df380645f10b7bc4b97d4f5eb6303d95", "GUID:ab67fb10353d84448ac887a7367cbda8", + "GUID:7dbf32976982c98448af054f2512cb79", "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:2665a8d13d1b3f18800f46e256720795" ], @@ -19,6 +20,11 @@ "expression": "0.0.1", "define": "VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER" }, + { + "name": "com.unity.adaptiveperformance", + "expression": "2.0.0-preview.7", + "define": "ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER" + }, { "name": "com.unity.modules.vr", "expression": "1.0.0", diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 3de4f4613c4..7e60e4ccdd2 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -170,6 +170,10 @@ public static void RenderSingleCamera(ScriptableRenderContext context, Camera ca } InitializeCameraData(camera, additionalCameraData, true, out var cameraData); +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER + if (asset.useAdaptivePerformance) + ApplyAdaptivePerformance(ref cameraData); +#endif RenderSingleCamera(context, cameraData, cameraData.postProcessEnabled); } @@ -229,6 +233,11 @@ static void RenderSingleCamera(ScriptableRenderContext context, CameraData camer var cullResults = context.Cull(ref cullingParameters); InitializeRenderingData(asset, ref cameraData, ref cullResults, anyPostProcessingEnabled, out var renderingData); +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER + if (asset.useAdaptivePerformance) + ApplyAdaptivePerformance(ref renderingData); +#endif + renderer.Setup(context, ref renderingData); renderer.Execute(context, ref renderingData); } // When ProfilingSample goes out of scope, an "EndSample" command is enqueued into CommandBuffer cmd @@ -338,7 +347,10 @@ static void RenderCameraStack(ScriptableRenderContext context, Camera baseCamera VFX.VFXManager.PrepareCamera(baseCamera); #endif UpdateVolumeFramework(baseCamera, baseCameraAdditionalData); - +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER + if (asset.useAdaptivePerformance) + ApplyAdaptivePerformance(ref baseCameraData); +#endif RenderSingleCamera(context, baseCameraData, anyPostProcessingEnabled); EndCameraRendering(context, baseCamera); @@ -849,5 +861,71 @@ static void SetupPerFrameShaderConstants() // Used when subtractive mode is selected Shader.SetGlobalVector(ShaderPropertyId.subtractiveShadowColor, CoreUtils.ConvertSRGBToActiveColorSpace(RenderSettings.subtractiveShadowColor)); } + +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER + static void ApplyAdaptivePerformance(ref CameraData cameraData) + { + var noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder; + if (AdaptivePerformance.AdaptivePerformanceRenderSettings.SkipFrontToBackSorting) + cameraData.defaultOpaqueSortFlags = noFrontToBackOpaqueFlags; + + var MaxShadowDistanceMultiplier = AdaptivePerformance.AdaptivePerformanceRenderSettings.MaxShadowDistanceMultiplier; + cameraData.maxShadowDistance *= MaxShadowDistanceMultiplier; + + var RenderScaleMultiplier = AdaptivePerformance.AdaptivePerformanceRenderSettings.RenderScaleMultiplier; + cameraData.renderScale *= RenderScaleMultiplier; + + // TODO + if (!cameraData.xr.enabled) + { + cameraData.cameraTargetDescriptor.width = (int)(cameraData.camera.pixelWidth * cameraData.renderScale); + cameraData.cameraTargetDescriptor.height = (int)(cameraData.camera.pixelHeight * cameraData.renderScale); + } + + var antialiasingQualityIndex = (int)cameraData.antialiasingQuality - AdaptivePerformance.AdaptivePerformanceRenderSettings.AntiAliasingQualityBias; + if (antialiasingQualityIndex < 0) + cameraData.antialiasing = AntialiasingMode.None; + cameraData.antialiasingQuality = (AntialiasingQuality)Mathf.Clamp(antialiasingQualityIndex, (int)AntialiasingQuality.Low, (int)AntialiasingQuality.High); + } + static void ApplyAdaptivePerformance(ref RenderingData renderingData) + { + if (AdaptivePerformance.AdaptivePerformanceRenderSettings.SkipDynamicBatching) + renderingData.supportsDynamicBatching = false; + + var MainLightShadowmapResultionMultiplier = AdaptivePerformance.AdaptivePerformanceRenderSettings.MainLightShadowmapResultionMultiplier; + renderingData.shadowData.mainLightShadowmapWidth = (int)(renderingData.shadowData.mainLightShadowmapWidth * MainLightShadowmapResultionMultiplier); + renderingData.shadowData.mainLightShadowmapHeight = (int)(renderingData.shadowData.mainLightShadowmapHeight * MainLightShadowmapResultionMultiplier); + + var MainLightShadowCascadesCountBias = AdaptivePerformance.AdaptivePerformanceRenderSettings.MainLightShadowCascadesCountBias; + renderingData.shadowData.mainLightShadowCascadesCount = Mathf.Clamp(renderingData.shadowData.mainLightShadowCascadesCount - MainLightShadowCascadesCountBias, 0, 4); + + var shadowQualityIndex = AdaptivePerformance.AdaptivePerformanceRenderSettings.ShadowQualityBias; + for (int i = 0; i < shadowQualityIndex; i++) + { + if (renderingData.shadowData.supportsSoftShadows) + { + renderingData.shadowData.supportsSoftShadows = false; + continue; + } + + if (renderingData.shadowData.supportsAdditionalLightShadows) + { + renderingData.shadowData.supportsAdditionalLightShadows = false; + continue; + } + + if (renderingData.shadowData.supportsMainLightShadows) + { + renderingData.shadowData.supportsMainLightShadows = false; + continue; + } + + break; + } + + if (AdaptivePerformance.AdaptivePerformanceRenderSettings.LutBias >= 1 && renderingData.postProcessingData.lutSize == 32) + renderingData.postProcessingData.lutSize = 16; + } +#endif } }