Skip to content

Commit 2b3474f

Browse files
Fix for some post effects not scaling correctly when dynamic resolution is enabled on a camera's target texture (#7383)
* Fix bug in com.unity.postprocessing package where dynamic resolution was not handled properly if the camera has a target texture that has dynamic resolution enabled * Update changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 8fe453b commit 2b3474f

File tree

8 files changed

+66
-52
lines changed

8 files changed

+66
-52
lines changed

Diff for: com.unity.postprocessing/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [3.2.3] - 2022-07-19
7+
## [3.2.3] - 2022-04-27
88

99
### Fixed
10+
- Fixed some post effects not scaling correctly when dynamic resolution is enabled on a camera's target texture (case 1166603)
1011
- Fixed obsolete API call GetScriptingDefineSymbolsForGroup
1112

1213
## [3.2.2] - 2022-04-05

Diff for: com.unity.postprocessing/PostProcessing/Editor/PostProcessLayerEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void DoAntialiasing()
166166
EditorGUILayout.HelpBox("TAA requires Unity 2017.3+ for Single-pass stereo rendering support.", MessageType.Warning);
167167
#endif
168168
#if UNITY_2017_3_OR_NEWER
169-
if (m_TargetCameraComponent != null && m_TargetCameraComponent.allowDynamicResolution)
169+
if (m_TargetCameraComponent != null && RuntimeUtilities.IsDynamicResolutionEnabled(m_TargetCameraComponent))
170170
EditorGUILayout.HelpBox("TAA is not supported with Dynamic Resolution.", MessageType.Warning);
171171
#endif
172172

Diff for: com.unity.postprocessing/PostProcessing/Runtime/Effects/MotionBlur.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void CreateTemporaryRT(PostProcessRenderContext context, int nameID, int
6969
#if UNITY_2019_1_OR_NEWER
7070
cmd.GetTemporaryRT(nameID, rtDesc, FilterMode.Point);
7171
#elif UNITY_2017_3_OR_NEWER
72-
cmd.GetTemporaryRT(nameID, rtDesc.width, rtDesc.height, rtDesc.depthBufferBits, FilterMode.Point, rtDesc.colorFormat, RenderTextureReadWrite.Linear, rtDesc.msaaSamples, rtDesc.enableRandomWrite, rtDesc.memoryless, context.camera.allowDynamicResolution);
72+
cmd.GetTemporaryRT(nameID, rtDesc.width, rtDesc.height, rtDesc.depthBufferBits, FilterMode.Point, rtDesc.colorFormat, RenderTextureReadWrite.Linear, rtDesc.msaaSamples, rtDesc.enableRandomWrite, rtDesc.memoryless, RuntimeUtilities.IsDynamicResolutionEnabled(context.camera));
7373
#else
7474
cmd.GetTemporaryRT(nameID, rtDesc.width, rtDesc.height, rtDesc.depthBufferBits, FilterMode.Point, rtDesc.colorFormat, RenderTextureReadWrite.Linear, rtDesc.msaaSamples, rtDesc.enableRandomWrite, rtDesc.memoryless);
7575
#endif

Diff for: com.unity.postprocessing/PostProcessing/Runtime/Effects/MultiScaleVO.cs

+45-43
Original file line numberDiff line numberDiff line change
@@ -211,51 +211,52 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
211211

212212
void PushAllocCommands(CommandBuffer cmd, bool isMSAA, Camera camera)
213213
{
214+
bool dynamicResolutionEnabled = RuntimeUtilities.IsDynamicResolutionEnabled(camera);
214215
if (isMSAA)
215216
{
216-
Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution);
217-
218-
Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution);
219-
Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution);
220-
Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution);
221-
Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution);
222-
223-
AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution);
224-
AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution);
225-
AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution);
226-
AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution);
227-
228-
Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
229-
Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
230-
Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
231-
Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
232-
233-
Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
234-
Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
235-
Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true, camera.allowDynamicResolution);
217+
Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true, dynamicResolutionEnabled);
218+
219+
Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true, dynamicResolutionEnabled);
220+
Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true, dynamicResolutionEnabled);
221+
Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true, dynamicResolutionEnabled);
222+
Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true, dynamicResolutionEnabled);
223+
224+
AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true, dynamicResolutionEnabled);
225+
AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true, dynamicResolutionEnabled);
226+
AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true, dynamicResolutionEnabled);
227+
AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true, dynamicResolutionEnabled);
228+
229+
Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
230+
Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
231+
Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
232+
Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
233+
234+
Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
235+
Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
236+
Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicResolutionEnabled);
236237
}
237238
else
238239
{
239-
Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution);
240-
241-
Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution);
242-
Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution);
243-
Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution);
244-
Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution);
245-
246-
AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution);
247-
AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution);
248-
AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution);
249-
AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution);
250-
251-
Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
252-
Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
253-
Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
254-
Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
255-
256-
Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
257-
Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
258-
Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true, camera.allowDynamicResolution);
240+
Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true, dynamicResolutionEnabled);
241+
242+
Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true, dynamicResolutionEnabled);
243+
Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true, dynamicResolutionEnabled);
244+
Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true, dynamicResolutionEnabled);
245+
Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true, dynamicResolutionEnabled);
246+
247+
AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true, dynamicResolutionEnabled);
248+
AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true, dynamicResolutionEnabled);
249+
AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true, dynamicResolutionEnabled);
250+
AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true, dynamicResolutionEnabled);
251+
252+
Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
253+
Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
254+
Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
255+
Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
256+
257+
Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
258+
Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
259+
Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicResolutionEnabled);
259260
}
260261
}
261262

@@ -274,7 +275,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
274275
// buffer (it's only available in some specific situations).
275276
if (!RuntimeUtilities.IsResolvedDepthAvailable(camera))
276277
{
277-
Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false, camera.allowDynamicResolution);
278+
Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false, RuntimeUtilities.IsDynamicResolutionEnabled(camera));
278279
depthMapId = new RenderTargetIdentifier(ShaderIDs.DepthCopy);
279280
cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, depthMapId, m_PropertySheet, (int)Pass.DepthCopy);
280281
needDepthMapRelease = true;
@@ -484,7 +485,8 @@ void CheckAOTexture(PostProcessRenderContext context)
484485
{
485486
bool AOUpdateNeeded = m_AmbientOnlyAO == null || !m_AmbientOnlyAO.IsCreated() || m_AmbientOnlyAO.width != context.width || m_AmbientOnlyAO.height != context.height;
486487
#if UNITY_2017_3_OR_NEWER
487-
AOUpdateNeeded = AOUpdateNeeded || m_AmbientOnlyAO.useDynamicScale != context.camera.allowDynamicResolution;
488+
bool dynamicResolutionEnabled = RuntimeUtilities.IsDynamicResolutionEnabled(context.camera);
489+
AOUpdateNeeded = AOUpdateNeeded || m_AmbientOnlyAO.useDynamicScale != dynamicResolutionEnabled;
488490
#endif
489491
if (AOUpdateNeeded)
490492
{
@@ -496,7 +498,7 @@ void CheckAOTexture(PostProcessRenderContext context)
496498
filterMode = FilterMode.Point,
497499
enableRandomWrite = true,
498500
#if UNITY_2017_3_OR_NEWER
499-
useDynamicScale = context.camera.allowDynamicResolution
501+
useDynamicScale = dynamicResolutionEnabled
500502
#endif
501503
};
502504
m_AmbientOnlyAO.Create();

Diff for: com.unity.postprocessing/PostProcessing/Runtime/Effects/SubpixelMorphologicalAntialiasing.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ internal void Render(PostProcessRenderContext context)
6262
cmd.BeginSample("SubpixelMorphologicalAntialiasing");
6363

6464
#if UNITY_2017_3_OR_NEWER
65-
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flip, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, context.camera.allowDynamicResolution);
66-
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flop, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, context.camera.allowDynamicResolution);
65+
bool dynamicResolutionEnabled = RuntimeUtilities.IsDynamicResolutionEnabled(context.camera);
66+
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flip, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, dynamicResolutionEnabled);
67+
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flop, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, dynamicResolutionEnabled);
6768
#else
6869
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flip, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false);
6970
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flop, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false);

Diff for: com.unity.postprocessing/PostProcessing/Runtime/PostProcessLayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void InitLegacy()
257257
#if UNITY_2019_1_OR_NEWER
258258
bool DynamicResolutionAllowsFinalBlitToCameraTarget()
259259
{
260-
return (!m_Camera.allowDynamicResolution || (ScalableBufferManager.heightScaleFactor == 1.0 && ScalableBufferManager.widthScaleFactor == 1.0));
260+
return (!RuntimeUtilities.IsDynamicResolutionEnabled(m_Camera) || (ScalableBufferManager.heightScaleFactor == 1.0 && ScalableBufferManager.widthScaleFactor == 1.0));
261261
}
262262

263263
#endif

Diff for: com.unity.postprocessing/PostProcessing/Runtime/PostProcessRenderContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ internal RenderTextureDescriptor GetDescriptor(int depthBufferBits = 0, RenderTe
319319
modifiedDesc.shadowSamplingMode = m_sourceDescriptor.shadowSamplingMode;
320320

321321
#if UNITY_2019_1_OR_NEWER
322-
if (m_Camera.allowDynamicResolution)
322+
if (RuntimeUtilities.IsDynamicResolutionEnabled(m_Camera))
323323
modifiedDesc.useDynamicScale = true;
324324
#endif
325325

@@ -368,7 +368,7 @@ public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,
368368
#if UNITY_2019_1_OR_NEWER
369369
cmd.GetTemporaryRT(nameID, desc, filter);
370370
#elif UNITY_2017_3_OR_NEWER
371-
cmd.GetTemporaryRT(nameID, desc.width, desc.height, desc.depthBufferBits, filter, desc.colorFormat, readWrite, desc.msaaSamples, desc.enableRandomWrite, desc.memoryless, m_Camera.allowDynamicResolution);
371+
cmd.GetTemporaryRT(nameID, desc.width, desc.height, desc.depthBufferBits, filter, desc.colorFormat, readWrite, desc.msaaSamples, desc.enableRandomWrite, desc.memoryless, RuntimeUtilities.IsDynamicResolutionEnabled(m_Camera));
372372
#else
373373
cmd.GetTemporaryRT(nameID, desc.width, desc.height, desc.depthBufferBits, filter, desc.colorFormat, readWrite, desc.msaaSamples, desc.enableRandomWrite, desc.memoryless);
374374
#endif

Diff for: com.unity.postprocessing/PostProcessing/Runtime/Utils/RuntimeUtilities.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,17 @@ public static bool IsTemporalAntialiasingActive(PostProcessLayer layer)
10091009
&& layer.antialiasingMode == PostProcessLayer.Antialiasing.TemporalAntialiasing
10101010
&& layer.temporalAntialiasing.IsSupported();
10111011
}
1012-
1012+
#if UNITY_2017_3_OR_NEWER
1013+
/// <summary>
1014+
/// Checks if dynamic resolution is enabled on a given camera.
1015+
/// </summary>
1016+
/// <param name="camera">The camera to check</param>
1017+
/// <returns><c>true</c> if dynamic resolution is enabled, <c>false</c> otherwise</returns>
1018+
public static bool IsDynamicResolutionEnabled(Camera camera)
1019+
{
1020+
return camera.allowDynamicResolution || (camera.targetTexture != null && camera.targetTexture.useDynamicScale);
1021+
}
1022+
#endif
10131023
/// <summary>
10141024
/// Gets all scene objects in the hierarchy, including inactive objects. This method is slow
10151025
/// on large scenes and should be used with extreme caution.

0 commit comments

Comments
 (0)