diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md
index a46047a7ce9..7f5060b1dd1 100644
--- a/com.unity.render-pipelines.universal/CHANGELOG.md
+++ b/com.unity.render-pipelines.universal/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
+### Added
+- Added option to enable/disable Adaptive Performance when it's package is available.
+
### Changed
- The 2D Renderer now supports camera stacking.
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 9b647c6acbc..0a79a4f0217 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
@@ -17,5 +17,11 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
- "versionDefines": []
+ "versionDefines": [
+ {
+ "name": "com.unity.adaptiveperformance",
+ "expression": "2.0.0-preview.7",
+ "define": "ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER"
+ }
+ ]
}
\ 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 4455a549d0a..0732bbe932f 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;
}
@@ -381,6 +394,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 c5f5ceda457..828b0763f89 100644
--- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs
+++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs
@@ -155,6 +155,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;
@@ -618,6 +621,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 7cb5802784f..577d3bf02eb 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,7 +3,8 @@
"references": [
"GUID:d60799ab2a985554ea1a39cd38695018",
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
- "GUID:ab67fb10353d84448ac887a7367cbda8"
+ "GUID:ab67fb10353d84448ac887a7367cbda8",
+ "GUID:7dbf32976982c98448af054f2512cb79"
],
"includePlatforms": [],
"excludePlatforms": [],
@@ -18,6 +19,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 cdb9b3f3ec0..1935c2a579f 100644
--- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs
+++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs
@@ -185,6 +185,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);
}
@@ -231,6 +235,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);
}
@@ -321,6 +330,10 @@ static void RenderCameraStack(ScriptableRenderContext context, Camera baseCamera
#endif
UpdateVolumeFramework(baseCamera, baseCameraAdditionalData);
InitializeCameraData(baseCamera, baseCameraAdditionalData, !isStackedRendering, out var baseCameraData);
+#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
+ if (asset.useAdaptivePerformance)
+ ApplyAdaptivePerformance(ref baseCameraData);
+#endif
RenderSingleCamera(context, baseCameraData, anyPostProcessingEnabled);
EndCameraRendering(context, baseCamera);
@@ -808,5 +821,71 @@ static void SetupPerFrameShaderConstants()
// Used when subtractive mode is selected
Shader.SetGlobalVector(PerFrameBuffer._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.isStereoEnabled)
+ {
+ 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
}
}