Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ In the URP, you can configure settings for:
- [__Shadows__](#shadows)
- [__Post-processing__](#post-processing)
- [__Advanced__](#advanced)
- [__Adaptive Performance__](#adaptive-performance)



Expand Down Expand Up @@ -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:<br />**Disabled**: Debugging is disabled. This is the default.<br />**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:<br /> **Disabled**: Unity doesn’t log anything.<br />**Only Universal**: Unity logs information for all of the [URP Shaders](shaders-in-universalrp.md).<br />**All**: Unity logs information for all Shaders in your build.<br /> 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. |
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"GUID:3eae0364be2026648bf74846acb8a731",
"GUID:be0903cd8e1546f498710afdc59db5eb",
"GUID:b75d3cd3037d383a8d1e2f9a26d73d8a",
"GUID:329b4ccd385744985bf3f83cfd77dfe7"
"GUID:329b4ccd385744985bf3f83cfd77dfe7",
"GUID:9604b18aafdbc9346bceb5e19ac9c746"
],
"includePlatforms": [
"Editor"
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -133,6 +138,8 @@ internal class Styles
SerializedProperty m_ColorGradingMode;
SerializedProperty m_ColorGradingLutSize;

SerializedProperty m_UseAdaptivePerformance;

public override void OnInspectorGUI()
{
serializedObject.Update();
Expand All @@ -143,6 +150,9 @@ public override void OnInspectorGUI()
DrawShadowSettings();
DrawPostProcessingSettings();
DrawAdvancedSettings();
#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
DrawAdaptivePerformance();
#endif

serializedObject.ApplyModifiedProperties();
}
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -622,6 +625,16 @@ public int colorGradingLutSize
set { m_ColorGradingLutSize = Mathf.Clamp(value, k_MinLutSize, k_MaxLutSize); }
}

/// <summary>
/// Set to true to allow Adaptive performance to modify graphics quality settings during runtime.
/// Only applicable when Adaptive performance package is available.
/// </summary>
public bool useAdaptivePerformance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
get { return m_UseAdaptivePerformance; }
set { m_UseAdaptivePerformance = value; }
}

public override Material defaultMaterial
{
get { return GetMaterial(DefaultMaterialType.Standard); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"references": [
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
"GUID:ab67fb10353d84448ac887a7367cbda8",
"GUID:7dbf32976982c98448af054f2512cb79",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:2665a8d13d1b3f18800f46e256720795"
],
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be careful with render scaling, as this kind of RT scale recreates render textures. The render scale in URP is meant to be done once to select your game resolution (720p, 1080p, 1440p... )

for something dynamic as adaptive performance is probably better to have a different scaling system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! For GLES I'd have though that might be the case, it this also on Vulcan? It's currently used as fall-back if dynamic resolution would not be available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for all platforms. I'm not sure this is a valid fallback for dynamic resolution, HDRP and XR has a system to scale based on viewport, that would be a suitable fallback but sadly URP doesn't support it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to not use this render scale with adaptive performance, it will possibly allocate textures per-frame and cause issues.

}

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
}
}