-
Notifications
You must be signed in to change notification settings - Fork 856
Adding adaptive performance as optional dependency #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b2847d2
622b6b6
2889f7c
37aac27
44bc34c
0675734
95a7082
daec92c
bf99d9c
b812bf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add public API docs. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/