Skip to content

Commit e92ba39

Browse files
eh-unityEvergreen
authored andcommitted
Fix black screen when TAA is enabled on the 2D renderer.
Correctly handle missing motion vectors for TAA. Fixes black screen on the 2D renderer when TAA is enabled. Does not implement TAA for 2D.
1 parent bb8432b commit e92ba39

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/FrameData/UniversalCameraData.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,13 @@ internal bool IsTemporalAAEnabled()
423423
UniversalAdditionalCameraData additionalCameraData;
424424
camera.TryGetComponent(out additionalCameraData);
425425

426-
return (antialiasing == AntialiasingMode.TemporalAntiAliasing) // Enabled
427-
&& (taaPersistentData != null) // Initialized
428-
&& (cameraTargetDescriptor.msaaSamples == 1) // No MSAA
429-
&& !(additionalCameraData?.renderType == CameraRenderType.Overlay || additionalCameraData?.cameraStack.Count > 0) // No Camera stack
430-
&& !camera.allowDynamicResolution // No Dynamic Resolution
431-
&& postProcessEnabled; // No Postprocessing
426+
return (antialiasing == AntialiasingMode.TemporalAntiAliasing) // Enabled
427+
&& postProcessEnabled // Postprocessing Enabled
428+
&& (taaPersistentData != null) // Initialized
429+
&& (cameraTargetDescriptor.msaaSamples == 1) // No MSAA
430+
&& !(additionalCameraData?.renderType == CameraRenderType.Overlay || additionalCameraData?.cameraStack.Count > 0) // No Camera stack
431+
&& !camera.allowDynamicResolution // No Dynamic Resolution
432+
&& renderer.SupportsMotionVectors(); // Motion Vectors implemented
432433
}
433434

434435
/// <summary>

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,9 @@ void Swap(ref ScriptableRenderer r)
518518
{
519519
using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.TemporalAA)))
520520
{
521+
Debug.Assert(m_MotionVectors != null, "MotionVectors are invalid. TAA requires a motion vector texture.");
521522

522-
TemporalAA.ExecutePass(cmd, m_Materials.temporalAntialiasing, ref renderingData.cameraData, source, destination, m_MotionVectors.rt);
523+
TemporalAA.ExecutePass(cmd, m_Materials.temporalAntialiasing, ref renderingData.cameraData, source, destination, m_MotionVectors?.rt);
523524
Swap(ref renderer);
524525
}
525526
}
@@ -766,8 +767,8 @@ void DoSubpixelMorphologicalAntialiasing(ref CameraData cameraData, CommandBuffe
766767
material, 0);
767768

768769
// Pass 2: Blend weights
769-
RenderingUtils.Blit(cmd, m_EdgeColorTexture, pixelRect,
770-
m_BlendTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
770+
RenderingUtils.Blit(cmd, m_EdgeColorTexture, pixelRect,
771+
m_BlendTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
771772
stencil, RenderBufferLoadAction.Load, RenderBufferStoreAction.DontCare,
772773
ClearFlag.Color, Color.clear, material, 1);
773774

@@ -1215,6 +1216,7 @@ void DoMotionBlur(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHa
12151216
var mode = m_MotionBlur.mode.value;
12161217
if (mode == MotionBlurMode.CameraAndObjects)
12171218
{
1219+
Debug.Assert(motionVectors != null, "Motion vectors are invalid. Per-object motion blur requires a motion vector texture.");
12181220
pass += 3;
12191221
material.SetTexture(MotionVectorRenderPass.k_MotionVectorTextureName, motionVectors);
12201222
}

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPassRenderGraph.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ private void RenderTemporalAA(RenderGraph renderGraph, UniversalResourceData res
999999

10001000
TextureHandle cameraDepth = resourceData.cameraDepth;
10011001
TextureHandle motionVectors = resourceData.motionVectorColor;
1002+
1003+
Debug.Assert(motionVectors.IsValid(), "MotionVectors are invalid. TAA requires a motion vector texture.");
1004+
10021005
TemporalAA.Render(renderGraph, m_Materials.temporalAntialiasing, cameraData, ref source, ref cameraDepth, ref motionVectors, ref destination);
10031006
}
10041007
#endregion
@@ -1012,6 +1015,8 @@ private void RenderSTP(RenderGraph renderGraph, UniversalResourceData resourceDa
10121015
TextureHandle cameraDepth = resourceData.cameraDepth;
10131016
TextureHandle motionVectors = resourceData.motionVectorColor;
10141017

1018+
Debug.Assert(motionVectors.IsValid(), "MotionVectors are invalid. STP requires a motion vector texture.");
1019+
10151020
var desc = GetCompatibleDescriptor(cameraData.cameraTargetDescriptor,
10161021
cameraData.pixelWidth,
10171022
cameraData.pixelHeight,
@@ -1061,13 +1066,13 @@ public void RenderMotionBlur(RenderGraph renderGraph, UniversalResourceData reso
10611066

10621067
destination = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "_MotionBlurTarget", true, FilterMode.Bilinear);
10631068

1069+
TextureHandle motionVectorColor = resourceData.motionVectorColor;
1070+
TextureHandle cameraDepthTexture = resourceData.cameraDepthTexture;
1071+
10641072
var mode = m_MotionBlur.mode.value;
10651073
int passIndex = (int)m_MotionBlur.quality.value;
10661074
passIndex += (mode == MotionBlurMode.CameraAndObjects) ? 3 : 0;
10671075

1068-
TextureHandle motionVectorColor = resourceData.motionVectorColor;
1069-
TextureHandle cameraDepthTexture = resourceData.cameraDepthTexture;
1070-
10711076
using (var builder = renderGraph.AddRasterRenderPass<MotionBlurPassData>("Motion Blur", out var passData, ProfilingSampler.Get(URPProfileId.RG_MotionBlur)))
10721077
{
10731078
builder.AllowGlobalStateModification(true);
@@ -1078,6 +1083,8 @@ public void RenderMotionBlur(RenderGraph renderGraph, UniversalResourceData reso
10781083

10791084
if (mode == MotionBlurMode.CameraAndObjects)
10801085
{
1086+
Debug.Assert(motionVectorColor.IsValid(), "Motion vectors are invalid. Per-object motion blur requires a motion vector texture.");
1087+
10811088
passData.motionVectors = motionVectorColor;
10821089
builder.UseTexture(motionVectorColor, AccessFlags.Read);
10831090
}

Packages/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ public bool SupportsCameraStackingType(CameraRenderType cameraRenderType)
8888
return (SupportedCameraStackingTypes() & 1 << (int)cameraRenderType) != 0;
8989
}
9090

91+
92+
// NOTE: This is a temporary solution until ScriptableRenderer has a system for partially shared features.
93+
// TAA (and similar) affect the whole pipe. The code is split into two parts in terms of ownership.
94+
// The ScriptableRenderer "shared" code (Camera) and the ScriptableRenderer "specific" code (the ScriptableRenderPasses).
95+
// For example: TAA is enabled and configured from the Camera, which is used by any ScriptableRenderer.
96+
// TAA also jitters the Camera matrix for all ScriptableRenderers.
97+
// However a Renderer might not implement a motion vector pass, which the TAA needs to function correctly.
98+
//
99+
/// <summary>
100+
/// Check if the ScriptableRenderer implements a motion vector pass for temporal techniques.
101+
/// The Camera will check this to enable/disable features and/or apply jitter when required.
102+
///
103+
/// For example, Temporal Anti-aliasing in the Camera settings is enabled only if the ScriptableRenderer can support motion vectors.
104+
/// </summary>
105+
/// <returns>Returns true if the ScriptableRenderer implements a motion vector pass. False otherwise.</returns>
106+
protected internal virtual bool SupportsMotionVectors()
107+
{
108+
return false;
109+
}
110+
91111
/// <summary>
92112
/// Override to provide a custom profiling name
93113
/// </summary>

Packages/com.unity.render-pipelines.universal/Runtime/TemporalAA.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ internal static string ValidateAndWarn(UniversalCameraData cameraData)
323323
{
324324
string warning = null;
325325

326+
if(warning == null && !cameraData.postProcessEnabled)
327+
warning = "Disabling TAA because camera has post-processing disabled.";
328+
326329
if (cameraData.taaPersistentData == null)
327330
{
328331
warning = "Disabling TAA due to invalid persistent data.";
@@ -348,8 +351,8 @@ internal static string ValidateAndWarn(UniversalCameraData cameraData)
348351
if (warning == null && cameraData.camera.allowDynamicResolution)
349352
warning = "Disabling TAA because camera has dynamic resolution enabled. You can use a constant render scale instead.";
350353

351-
if(warning == null && !cameraData.postProcessEnabled)
352-
warning = "Disabling TAA because camera has post-processing disabled.";
354+
if(warning == null && !cameraData.renderer.SupportsMotionVectors())
355+
warning = "Disabling TAA because the renderer does not implement motion vectors. Motion vectors are required for TAA.";
353356

354357
const int warningThrottleFrames = 60 * 1; // 60 FPS * 1 sec
355358
if(Time.frameCount % warningThrottleFrames == 0)

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public override int SupportedCameraStackingTypes()
7373
}
7474
}
7575

76+
/// <inheritdoc/>
77+
protected internal override bool SupportsMotionVectors()
78+
{
79+
// Motion vector pass for TAA and per-object motion blur (etc.) is available.
80+
return true;
81+
}
82+
7683
// Rendering mode setup from UI. The final rendering mode used can be different. See renderingModeActual.
7784
internal RenderingMode renderingModeRequested => m_RenderingMode;
7885

0 commit comments

Comments
 (0)