@@ -496,31 +496,31 @@ public void Render(PostProcessRenderContext context)
496496 context . destination = finalDestination ;
497497 }
498498
499+ bool hasBeforeStackEffects = HasActiveEffects ( PostProcessEvent . BeforeStack , context ) ;
500+ bool hasAfterStackEffects = HasActiveEffects ( PostProcessEvent . AfterStack , context ) && ! breakBeforeColorGrading ;
501+ bool needsFinalPass = ( hasAfterStackEffects || antialiasingMode == Antialiasing . FastApproximateAntialiasing ) && ! breakBeforeColorGrading ;
502+
499503 // Right before the builtin stack
500- lastTarget = RenderInjectionPoint ( PostProcessEvent . BeforeStack , context , "BeforeStack" , lastTarget ) ;
504+ if ( hasBeforeStackEffects )
505+ lastTarget = RenderInjectionPoint ( PostProcessEvent . BeforeStack , context , "BeforeStack" , lastTarget ) ;
501506
502507 // Builtin stack
503- lastTarget = RenderBuiltins ( context , lastTarget ) ;
508+ lastTarget = RenderBuiltins ( context , ! needsFinalPass , lastTarget ) ;
504509
505510 // After the builtin stack but before the final pass (before FXAA & Dithering)
506- if ( ! breakBeforeColorGrading )
511+ if ( hasAfterStackEffects )
507512 lastTarget = RenderInjectionPoint ( PostProcessEvent . AfterStack , context , "AfterStack" , lastTarget ) ;
508513
509514 // And close with the final pass
510- RenderFinalPass ( context , lastTarget ) ;
515+ if ( needsFinalPass )
516+ RenderFinalPass ( context , lastTarget ) ;
511517
512518 TextureLerper . instance . EndFrame ( ) ;
513519 m_SettingsUpdateNeeded = true ;
514520 }
515521
516522 int RenderInjectionPoint ( PostProcessEvent evt , PostProcessRenderContext context , string marker , int releaseTargetAfterUse = - 1 )
517523 {
518- // Make sure we have active effects in this injection point, skip it otherwise
519- bool hasActiveEffects = HasActiveEffects ( evt , context ) ;
520-
521- if ( ! hasActiveEffects )
522- return releaseTargetAfterUse ;
523-
524524 int tempTarget = m_TargetPool . Get ( ) ;
525525 var finalDestination = context . destination ;
526526
@@ -595,7 +595,7 @@ void RenderList(List<SerializedBundleRef> list, PostProcessRenderContext context
595595 cmd . EndSample ( marker ) ;
596596 }
597597
598- int RenderBuiltins ( PostProcessRenderContext context , int releaseTargetAfterUse = - 1 )
598+ int RenderBuiltins ( PostProcessRenderContext context , bool isFinalPass , int releaseTargetAfterUse = - 1 )
599599 {
600600 var uberSheet = context . propertySheets . Get ( context . resources . shaders . uber ) ;
601601 uberSheet . ClearKeywords ( ) ;
@@ -606,11 +606,16 @@ int RenderBuiltins(PostProcessRenderContext context, int releaseTargetAfterUse =
606606 var cmd = context . command ;
607607 cmd . BeginSample ( "BuiltinStack" ) ;
608608
609- // Render to an intermediate target as this won't be the final pass
610- int tempTarget = m_TargetPool . Get ( ) ;
611- cmd . GetTemporaryRT ( tempTarget , context . width , context . height , 24 , FilterMode . Bilinear , context . sourceFormat ) ;
609+ int tempTarget = - 1 ;
612610 var finalDestination = context . destination ;
613- context . destination = tempTarget ;
611+
612+ if ( ! isFinalPass )
613+ {
614+ // Render to an intermediate target as this won't be the final pass
615+ tempTarget = m_TargetPool . Get ( ) ;
616+ cmd . GetTemporaryRT ( tempTarget , context . width , context . height , 24 , FilterMode . Bilinear , context . sourceFormat ) ;
617+ context . destination = tempTarget ;
618+ }
614619
615620 // Depth of field final combination pass used to be done in Uber which led to artifacts
616621 // when used at the same time as Bloom (because both effects used the same source, so
@@ -636,7 +641,13 @@ int RenderBuiltins(PostProcessRenderContext context, int releaseTargetAfterUse =
636641
637642 if ( ! breakBeforeColorGrading )
638643 RenderEffect < ColorGrading > ( context ) ;
639-
644+
645+ if ( isFinalPass )
646+ {
647+ uberSheet . EnableKeyword ( "FINALPASS" ) ;
648+ dithering . Render ( context ) ;
649+ }
650+
640651 cmd . BlitFullscreenTriangle ( context . source , context . destination , uberSheet , 0 ) ;
641652
642653 context . source = context . destination ;
0 commit comments