Skip to content

Commit 58e958d

Browse files
authored
Add a test for Dynamic Resolution (#127)
Add a test for Dynamic Resolution
1 parent caec0f2 commit 58e958d

8 files changed

Lines changed: 483 additions & 87 deletions

Tests/HDRPTests/Assets/Settings/HDRenderPipelineAsset.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ MonoBehaviour:
135135
lutFormat: 48
136136
bufferFormat: 74
137137
dynamicResolutionSettings:
138-
enabled: 0
138+
enabled: 1
139139
useMipBias: 0
140140
enableDLSS: 0
141141
DLSSPerfQualitySetting: 0
@@ -145,7 +145,7 @@ MonoBehaviour:
145145
fsrOverrideSharpness: 0
146146
fsrSharpness: 0.92
147147
maxPercentage: 100
148-
minPercentage: 100
148+
minPercentage: 50
149149
dynResType: 1
150150
upsampleFilter: 1
151151
forceResolution: 0

Tests/HDRPTests/Assets/Tests/Basic.unity

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RenderSettings:
2424
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
2525
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
2626
m_AmbientIntensity: 1
27-
m_AmbientMode: 0
27+
m_AmbientMode: 4
2828
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
2929
m_SkyboxMaterial: {fileID: 0}
3030
m_HaloStrength: 0.5
@@ -137,6 +137,7 @@ GameObject:
137137
- component: {fileID: 90829606}
138138
- component: {fileID: 90829612}
139139
- component: {fileID: 90829608}
140+
- component: {fileID: 90829613}
140141
m_Layer: 0
141142
m_Name: Camera
142143
m_TagString: MainCamera
@@ -274,6 +275,53 @@ MonoBehaviour:
274275
m_Script: {fileID: 11500000, guid: 23c1ce4fb46143f46bc5cb5224c934f6, type: 3}
275276
m_Name:
276277
m_EditorClassIdentifier:
278+
m_Version: 9
279+
m_ObsoleteRenderingPath: 0
280+
m_ObsoleteFrameSettings:
281+
overrides: 0
282+
enableShadow: 0
283+
enableContactShadows: 0
284+
enableShadowMask: 0
285+
enableSSR: 0
286+
enableSSAO: 0
287+
enableSubsurfaceScattering: 0
288+
enableTransmission: 0
289+
enableAtmosphericScattering: 0
290+
enableVolumetrics: 0
291+
enableReprojectionForVolumetrics: 0
292+
enableLightLayers: 0
293+
enableExposureControl: 1
294+
diffuseGlobalDimmer: 0
295+
specularGlobalDimmer: 0
296+
shaderLitMode: 0
297+
enableDepthPrepassWithDeferredRendering: 0
298+
enableTransparentPrepass: 0
299+
enableMotionVectors: 0
300+
enableObjectMotionVectors: 0
301+
enableDecals: 0
302+
enableRoughRefraction: 0
303+
enableTransparentPostpass: 0
304+
enableDistortion: 0
305+
enablePostprocess: 0
306+
enableOpaqueObjects: 0
307+
enableTransparentObjects: 0
308+
enableRealtimePlanarReflection: 0
309+
enableMSAA: 0
310+
enableAsyncCompute: 0
311+
runLightListAsync: 0
312+
runSSRAsync: 0
313+
runSSAOAsync: 0
314+
runContactShadowsAsync: 0
315+
runVolumeVoxelizationAsync: 0
316+
lightLoopSettings:
317+
overrides: 0
318+
enableDeferredTileAndCluster: 0
319+
enableComputeLightEvaluation: 0
320+
enableComputeLightVariants: 0
321+
enableComputeMaterialVariants: 0
322+
enableFptlForForwardOpaque: 0
323+
enableBigTilePrepass: 0
324+
isFptlEnabled: 0
277325
clearColorMode: 0
278326
backgroundColorHDR: {r: 0.025, g: 0.07, b: 0.19, a: 0}
279327
clearDepth: 1
@@ -344,53 +392,21 @@ MonoBehaviour:
344392
data1: 0
345393
data2: 0
346394
defaultFrameSettings: 0
347-
m_Version: 9
348-
m_ObsoleteRenderingPath: 0
349-
m_ObsoleteFrameSettings:
350-
overrides: 0
351-
enableShadow: 0
352-
enableContactShadows: 0
353-
enableShadowMask: 0
354-
enableSSR: 0
355-
enableSSAO: 0
356-
enableSubsurfaceScattering: 0
357-
enableTransmission: 0
358-
enableAtmosphericScattering: 0
359-
enableVolumetrics: 0
360-
enableReprojectionForVolumetrics: 0
361-
enableLightLayers: 0
362-
enableExposureControl: 1
363-
diffuseGlobalDimmer: 0
364-
specularGlobalDimmer: 0
365-
shaderLitMode: 0
366-
enableDepthPrepassWithDeferredRendering: 0
367-
enableTransparentPrepass: 0
368-
enableMotionVectors: 0
369-
enableObjectMotionVectors: 0
370-
enableDecals: 0
371-
enableRoughRefraction: 0
372-
enableTransparentPostpass: 0
373-
enableDistortion: 0
374-
enablePostprocess: 0
375-
enableOpaqueObjects: 0
376-
enableTransparentObjects: 0
377-
enableRealtimePlanarReflection: 0
378-
enableMSAA: 0
379-
enableAsyncCompute: 0
380-
runLightListAsync: 0
381-
runSSRAsync: 0
382-
runSSAOAsync: 0
383-
runContactShadowsAsync: 0
384-
runVolumeVoxelizationAsync: 0
385-
lightLoopSettings:
386-
overrides: 0
387-
enableDeferredTileAndCluster: 0
388-
enableComputeLightEvaluation: 0
389-
enableComputeLightVariants: 0
390-
enableComputeMaterialVariants: 0
391-
enableFptlForForwardOpaque: 0
392-
enableBigTilePrepass: 0
393-
isFptlEnabled: 0
395+
--- !u!114 &90829613
396+
MonoBehaviour:
397+
m_ObjectHideFlags: 0
398+
m_CorrespondingSourceObject: {fileID: 0}
399+
m_PrefabInstance: {fileID: 0}
400+
m_PrefabAsset: {fileID: 0}
401+
m_GameObject: {fileID: 90829605}
402+
m_Enabled: 1
403+
m_EditorHideFlags: 0
404+
m_Script: {fileID: 11500000, guid: 45f5722020ae4d62ac1550c857c6b37c, type: 3}
405+
m_Name:
406+
m_EditorClassIdentifier:
407+
screenPercentage: 70
408+
overrideUpscaleFilter: 0
409+
upscaleFilter: 0
394410
--- !u!1 &807526207
395411
GameObject:
396412
m_ObjectHideFlags: 0
@@ -898,6 +914,14 @@ MonoBehaviour:
898914
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
899915
m_Name:
900916
m_EditorClassIdentifier:
917+
m_Version: 11
918+
m_ObsoleteShadowResolutionTier: 1
919+
m_ObsoleteUseShadowQualitySettings: 0
920+
m_ObsoleteCustomShadowResolution: 512
921+
m_ObsoleteContactShadows: 0
922+
m_PointlightHDType: 0
923+
m_SpotLightShape: 0
924+
m_AreaLightShape: 0
901925
m_Intensity: 7000
902926
m_EnableSpotReflector: 0
903927
m_LuxAtDistance: 1
@@ -1000,14 +1024,6 @@ MonoBehaviour:
10001024
m_AreaLightEmissiveMeshShadowCastingMode: 0
10011025
m_AreaLightEmissiveMeshMotionVectorGenerationMode: 0
10021026
m_AreaLightEmissiveMeshLayer: -1
1003-
m_Version: 11
1004-
m_ObsoleteShadowResolutionTier: 1
1005-
m_ObsoleteUseShadowQualitySettings: 0
1006-
m_ObsoleteCustomShadowResolution: 512
1007-
m_ObsoleteContactShadows: 0
1008-
m_PointlightHDType: 0
1009-
m_SpotLightShape: 0
1010-
m_AreaLightShape: 0
10111027
--- !u!1 &1803884772
10121028
GameObject:
10131029
m_ObjectHideFlags: 0
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using UnityEngine;
2+
#if UNITY_6000_0_OR_NEWER
3+
using UnityEngine.Rendering;
4+
using UnityEngine.Rendering.HighDefinition;
5+
#endif
6+
7+
[DisallowMultipleComponent]
8+
[RequireComponent(typeof(Camera))]
9+
#if UNITY_6000_0_OR_NEWER
10+
[RequireComponent(typeof(HDAdditionalCameraData))]
11+
#endif
12+
public class HDRPDynamicResolutionController : MonoBehaviour
13+
{
14+
const float DefaultScreenPercentage = 100.0f;
15+
16+
[SerializeField]
17+
[Range(5.0f, 100.0f)]
18+
float screenPercentage = 70.0f;
19+
20+
[SerializeField]
21+
bool overrideUpscaleFilter = false;
22+
23+
[SerializeField]
24+
int upscaleFilter = 0;
25+
26+
#if UNITY_6000_0_OR_NEWER
27+
static HDRPDynamicResolutionController activeInstance;
28+
29+
void OnEnable()
30+
{
31+
if (!Application.isPlaying)
32+
{
33+
return;
34+
}
35+
36+
activeInstance = this;
37+
ApplyCameraSettings();
38+
ApplyDynamicResolution();
39+
}
40+
41+
void Update()
42+
{
43+
if (!Application.isPlaying || activeInstance == this)
44+
{
45+
return;
46+
}
47+
48+
activeInstance = this;
49+
ApplyCameraSettings();
50+
ApplyDynamicResolution();
51+
}
52+
53+
void OnDisable()
54+
{
55+
if (!Application.isPlaying || activeInstance != this)
56+
{
57+
return;
58+
}
59+
60+
activeInstance = null;
61+
DynamicResolutionHandler.SetDynamicResScaler(GetDefaultScreenPercentage, DynamicResScalePolicyType.ReturnsPercentage);
62+
}
63+
64+
void OnValidate()
65+
{
66+
screenPercentage = Mathf.Clamp(screenPercentage, 5.0f, 100.0f);
67+
68+
if (Application.isPlaying && activeInstance == this)
69+
{
70+
ApplyCameraSettings();
71+
ApplyDynamicResolution();
72+
}
73+
}
74+
75+
void ApplyCameraSettings()
76+
{
77+
var targetCamera = GetComponent<Camera>();
78+
if (!targetCamera.allowDynamicResolution)
79+
{
80+
targetCamera.allowDynamicResolution = true;
81+
}
82+
83+
var additionalCameraData = GetComponent<HDAdditionalCameraData>();
84+
if (!additionalCameraData.allowDynamicResolution)
85+
{
86+
additionalCameraData.allowDynamicResolution = true;
87+
}
88+
89+
if (overrideUpscaleFilter)
90+
{
91+
DynamicResolutionHandler.SetUpscaleFilter(targetCamera, (DynamicResUpscaleFilter)upscaleFilter);
92+
}
93+
}
94+
95+
void ApplyDynamicResolution()
96+
{
97+
DynamicResolutionHandler.SetDynamicResScaler(GetActiveScreenPercentage, DynamicResScalePolicyType.ReturnsPercentage);
98+
}
99+
100+
static float GetActiveScreenPercentage()
101+
{
102+
return activeInstance != null ? activeInstance.screenPercentage : DefaultScreenPercentage;
103+
}
104+
105+
static float GetDefaultScreenPercentage()
106+
{
107+
return DefaultScreenPercentage;
108+
}
109+
#else
110+
void OnValidate()
111+
{
112+
screenPercentage = Mathf.Clamp(screenPercentage, 5.0f, 100.0f);
113+
}
114+
#endif
115+
}

Tests/HDRPTests/Assets/Tests/HDRPDynamicResolutionController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)