@@ -23,6 +23,7 @@ public enum Antialiasing
2323 // Settings
2424 public Transform volumeTrigger ;
2525 public LayerMask volumeLayer ;
26+ public bool stopNaNPropagation = true ;
2627
2728 // Builtins / hardcoded effects that don't benefit from volume blending
2829 public Antialiasing antialiasingMode = Antialiasing . None ;
@@ -39,7 +40,7 @@ public enum Antialiasing
3940 PostProcessResources m_Resources ;
4041
4142 // UI states
42- [ SerializeField ] bool m_ShowDebugLayer ;
43+ [ SerializeField ] bool m_ShowRenderingFeatures ;
4344 [ SerializeField ] bool m_ShowToolkit ;
4445 [ SerializeField ] bool m_ShowCustomSorter ;
4546
@@ -94,6 +95,8 @@ public sealed class SerializedBundleRef
9495
9596 TargetPool m_TargetPool ;
9697
98+ bool m_NaNKilled = false ;
99+
97100 // Recycled list - used to reduce GC stress when gathering active effects in a bundle list
98101 // on each frame
99102 readonly List < PostProcessEffectRenderer > m_ActiveEffects = new List < PostProcessEffectRenderer > ( ) ;
@@ -157,7 +160,7 @@ public void InitBundles()
157160 UpdateBundleSortList ( m_BeforeStackBundles , PostProcessEvent . BeforeStack ) ;
158161 UpdateBundleSortList ( m_AfterStackBundles , PostProcessEvent . AfterStack ) ;
159162
160- // Push all sorted lists in a dictionary for easier access
163+ // Push all sorted lists in a dictionary for easier access
161164 sortedBundles = new Dictionary < PostProcessEvent , List < SerializedBundleRef > > ( new PostProcessEventComparer ( ) )
162165 {
163166 { PostProcessEvent . BeforeTransparent , m_BeforeTransparentBundles } ,
@@ -275,10 +278,10 @@ void OnPreCull()
275278 {
276279 opaqueOnlyEffects ++ ;
277280 }
278-
281+
279282 opaqueOnlyEffects += isFogActive ? 1 : 0 ;
280283 opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0 ;
281-
284+
282285 var cameraTarget = new RenderTargetIdentifier ( BuiltinRenderTextureType . CameraTarget ) ;
283286
284287 if ( opaqueOnlyEffects > 0 )
@@ -336,13 +339,18 @@ void OnPreCull()
336339
337340 cmd . ReleaseTemporaryRT ( tempTarget0 ) ;
338341 }
339-
342+
340343 // Post-transparency stack
344+ // Same as before, first blit needs to use the builtin Blit command to properly handle
345+ // tiled GPUs
341346 int tempRt = m_TargetPool . Get ( ) ;
347+
342348 m_LegacyCmdBuffer . GetTemporaryRT ( tempRt , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
343- m_LegacyCmdBuffer . Blit ( cameraTarget , tempRt ) ;
349+ m_LegacyCmdBuffer . Blit ( cameraTarget , tempRt , RuntimeUtilities . copyMaterial , stopNaNPropagation ? 3 : 2 ) ;
350+ m_NaNKilled = stopNaNPropagation ;
351+
344352 context . command = m_LegacyCmdBuffer ;
345- context . source = new RenderTargetIdentifier ( tempRt ) ;
353+ context . source = tempRt ;
346354 context . destination = cameraTarget ;
347355 Render ( context ) ;
348356 m_LegacyCmdBuffer . ReleaseTemporaryRT ( tempRt ) ;
@@ -514,8 +522,18 @@ public void Render(PostProcessRenderContext context)
514522 // hasn't been called this frame.
515523 UpdateSettingsIfNeeded ( context ) ;
516524
517- // Do temporal anti-aliasing first
525+ // Do a NaN killing pass if needed
518526 int lastTarget = - 1 ;
527+ if ( stopNaNPropagation && ! m_NaNKilled )
528+ {
529+ lastTarget = m_TargetPool . Get ( ) ;
530+ cmd . GetTemporaryRT ( lastTarget , context . width , context . height , 24 , FilterMode . Bilinear , context . sourceFormat ) ;
531+ cmd . BlitFullscreenTriangle ( context . source , lastTarget , RuntimeUtilities . copySheet , 1 ) ;
532+ context . source = lastTarget ;
533+ m_NaNKilled = true ;
534+ }
535+
536+ // Do temporal anti-aliasing first
519537 if ( context . IsTemporalAntialiasingActive ( ) )
520538 {
521539 if ( ! RuntimeUtilities . scriptableRenderPipelineActive )
@@ -526,13 +544,18 @@ public void Render(PostProcessRenderContext context)
526544 camera . useJitteredProjectionMatrixForTransparentRendering = false ;
527545 }
528546
529- lastTarget = m_TargetPool . Get ( ) ;
547+ var taaTarget = m_TargetPool . Get ( ) ;
530548 var finalDestination = context . destination ;
531- cmd . GetTemporaryRT ( lastTarget , context . width , context . height , 24 , FilterMode . Bilinear , context . sourceFormat ) ;
532- context . destination = lastTarget ;
549+ cmd . GetTemporaryRT ( taaTarget , context . width , context . height , 24 , FilterMode . Bilinear , context . sourceFormat ) ;
550+ context . destination = taaTarget ;
533551 temporalAntialiasing . Render ( context ) ;
534- context . source = lastTarget ;
552+ context . source = taaTarget ;
535553 context . destination = finalDestination ;
554+
555+ if ( lastTarget > - 1 )
556+ cmd . ReleaseTemporaryRT ( lastTarget ) ;
557+
558+ lastTarget = taaTarget ;
536559 }
537560
538561 bool hasBeforeStackEffects = HasActiveEffects ( PostProcessEvent . BeforeStack , context ) ;
@@ -561,6 +584,7 @@ public void Render(PostProcessRenderContext context)
561584
562585 TextureLerper . instance . EndFrame ( ) ;
563586 m_SettingsUpdateNeeded = true ;
587+ m_NaNKilled = false ;
564588 }
565589
566590 int RenderInjectionPoint ( PostProcessEvent evt , PostProcessRenderContext context , string marker , int releaseTargetAfterUse = - 1 )
@@ -599,7 +623,7 @@ void RenderList(List<SerializedBundleRef> list, PostProcessRenderContext context
599623 }
600624
601625 int count = m_ActiveEffects . Count ;
602-
626+
603627 // If there's only one active effect, we can simply execute it and skip the rest
604628 if ( count == 1 )
605629 {
@@ -630,7 +654,7 @@ void RenderList(List<SerializedBundleRef> list, PostProcessRenderContext context
630654 context . destination = m_Targets [ i + 1 ] ;
631655 m_ActiveEffects [ i ] . Render ( context ) ;
632656 }
633-
657+
634658 cmd . ReleaseTemporaryRT ( tempTarget1 ) ;
635659 if ( count > 2 )
636660 cmd . ReleaseTemporaryRT ( tempTarget2 ) ;
@@ -705,7 +729,7 @@ int RenderBuiltins(PostProcessRenderContext context, bool isFinalPass, int relea
705729 if ( releaseTargetAfterUse > - 1 ) cmd . ReleaseTemporaryRT ( releaseTargetAfterUse ) ;
706730 if ( motionBlurTarget > - 1 ) cmd . ReleaseTemporaryRT ( motionBlurTarget ) ;
707731 if ( depthOfFieldTarget > - 1 ) cmd . ReleaseTemporaryRT ( motionBlurTarget ) ;
708-
732+
709733 cmd . EndSample ( "BuiltinStack" ) ;
710734
711735 return tempTarget ;
0 commit comments