@@ -311,10 +311,7 @@ This section demonstrates how to implement the settings for the custom blur rend
311311
312312 // Blit from the camera color to the render graph texture,
313313 // using the first shader pass.
314- builder .SetRenderFunc ((PassData data , RasterGraphContext context ) =>
315- {
316- Blitter .BlitTexture (context .cmd , data .src , m_ScaleBias , data .material , 0 );
317- });
314+ builder .SetRenderFunc ((PassData data , RasterGraphContext context ) => ExecutePass (data , context , 0 ));
318315 }
319316 ```
320317
@@ -324,33 +321,25 @@ This section demonstrates how to implement the settings for the custom blur rend
324321 private Vector4 m_ScaleBias = new Vector4(1f, 1f, 0f, 0f);
325322 ```
326323
327- 2 . In the `RecordRenderGraph ` method , using the `builder ` variable , add the render pass for the horizontal blur . This pass uses the output of the previous pass as its input , it does that using the ` FrameBufferFetch ` method . In this example , using this method lets URP merge two blur passes into a single render pass . Refer to the complete shader code for the implementation details .
324+ 2 . In the `RecordRenderGraph ` method , using the `builder ` variable , add the render pass for the horizontal blur . This pass uses the output of the previous pass as its input . Refer to the complete shader code for the implementation details .
328325
329326 ```C #
330327 // Horizontal blur pass
331- using (var builder = renderGraph .AddRasterRenderPass <PassData >(k_HorizontalPassName ,
332- out var passData ))
328+ using (var builder = renderGraph .AddRasterRenderPass <PassData >(k_HorizontalPassName , out var passData ))
333329 {
334- // Reset unused passData fields
335- passData .src = TextureHandle .nullHandle ;
336-
337- // Use the same material as the previous pass
330+ // Configure pass data
331+ passData .src = dst ;
338332 passData .material = material ;
339333
340- // Use the output of the previous pass as the input,
341- // and bind it as FrameBufferFetch input
342- builder .SetInputAttachment (dst , 0 );
343-
334+ // Use the output of the previous pass as the input
335+ builder .UseTexture (passData .src );
336+
344337 // Use the input texture of the previous pass as the output
345338 builder .SetRenderAttachment (srcCamColor , 0 );
346339
347340 // Blit from the render graph texture to the camera color,
348- // using the second shader pass,
349- // which reads the input texture using the FrameBufferFetch method.
350- builder .SetRenderFunc ((PassData data , RasterGraphContext context ) =>
351- {
352- Blitter .BlitTexture (context .cmd , m_ScaleBias , data .material , 1 );
353- });
341+ // using the second shader pass.
342+ builder .SetRenderFunc ((PassData data , RasterGraphContext context ) => ExecutePass (data , context , 1 ));
354343 }
355344 ```
356345
@@ -513,7 +502,7 @@ public class BlurRendererFeature : ScriptableRendererFeature
513502 material = new Material (shader );
514503 blurRenderPass = new BlurRenderPass (material , settings );
515504
516- blurRenderPass .renderPassEvent = RenderPassEvent .AfterRenderingSkybox ;
505+ blurRenderPass .renderPassEvent = RenderPassEvent .BeforeRenderingPostProcessing ;
517506 }
518507
519508 public override void AddRenderPasses (ScriptableRenderer renderer ,
@@ -569,7 +558,7 @@ public class BlurRenderPass : ScriptableRenderPass
569558 private const string k_VerticalPassName = " VerticalBlurRenderPass" ;
570559 private const string k_HorizontalPassName = " HorizontalBlurRenderPass" ;
571560
572- private Vector4 m_ScaleBias = new Vector4 (1 f , 1 f , 0 f , 0 f );
561+ private static Vector4 m_ScaleBias = new Vector4 (1 f , 1 f , 0 f , 0 f );
573562
574563 private BlurSettings defaultSettings ;
575564 private Material material ;
@@ -606,6 +595,11 @@ public class BlurRenderPass : ScriptableRenderPass
606595 internal Material material ;
607596 }
608597
598+ private static void ExecutePass (PassData data , RasterGraphContext context , int pass )
599+ {
600+ Blitter .BlitTexture (context .cmd , data .src , m_ScaleBias , data .material , pass );
601+ }
602+
609603 public override void RecordRenderGraph (RenderGraph renderGraph ,
610604 ContextContainer frameData )
611605 {
@@ -648,36 +642,25 @@ public class BlurRenderPass : ScriptableRenderPass
648642
649643 // Blit from the camera color to the render graph texture,
650644 // using the first shader pass.
651- builder .SetRenderFunc ((PassData data , RasterGraphContext context ) =>
652- {
653- Blitter .BlitTexture (context .cmd , data .src , m_ScaleBias , data .material , 0 );
654- });
645+ builder .SetRenderFunc ((PassData data , RasterGraphContext context ) => ExecutePass (data , context , 0 ));
655646 }
656-
647+
657648 // Horizontal blur pass
658- using (var builder = renderGraph .AddRasterRenderPass <PassData >(k_HorizontalPassName ,
659- out var passData ))
649+ using (var builder = renderGraph .AddRasterRenderPass <PassData >(k_HorizontalPassName , out var passData ))
660650 {
661- // Reset unused passData fields
662- passData .src = TextureHandle .nullHandle ;
663-
664- // Use the same material as the previous pass
651+ // Configure pass data
652+ passData .src = dst ;
665653 passData .material = material ;
666654
667- // Use the output of the previous pass as the input,
668- // and bind it as FrameBufferFetch input
669- builder .SetInputAttachment (dst , 0 );
670-
655+ // Use the output of the previous pass as the input
656+ builder .UseTexture (passData .src );
657+
671658 // Use the input texture of the previous pass as the output
672659 builder .SetRenderAttachment (srcCamColor , 0 );
673660
674661 // Blit from the render graph texture to the camera color,
675- // using the second shader pass,
676- // which reads the input texture using the FrameBufferFetch method.
677- builder .SetRenderFunc ((PassData data , RasterGraphContext context ) =>
678- {
679- Blitter .BlitTexture (context .cmd , m_ScaleBias , data .material , 1 );
680- });
662+ // using the second shader pass.
663+ builder .SetRenderFunc ((PassData data , RasterGraphContext context ) => ExecutePass (data , context , 1 ));
681664 }
682665 }
683666}
@@ -735,6 +718,23 @@ Shader "CustomEffects/Blur"
735718
736719 return float4(color.rgb / (BLUR_SAMPLES + 1), 1);
737720 }
721+
722+ float4 BlurHorizontal (Varyings input) : SV_Target
723+ {
724+ const float BLUR_SAMPLES = 64;
725+ const float BLUR_SAMPLES_RANGE = BLUR_SAMPLES / 2;
726+
727+ UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX (input);
728+ float3 color = 0;
729+ float blurPixels = _ HorizontalBlur * _ ScreenParams.x;
730+ for(float i = -BLUR_SAMPLES_RANGE; i <= BLUR_SAMPLES_RANGE; i++)
731+ {
732+ float2 sampleOffset =
733+ float2 ((blurPixels / _ BlitTexture_TexelSize.z) * (i / BLUR_SAMPLES_RANGE), 0);
734+ color += SAMPLE_TEXTURE2D(_ BlitTexture, sampler_LinearClamp, input.texcoord + sampleOffset).rgb;
735+ }
736+ return float4(color / (BLUR_SAMPLES + 1), 1);
737+ }
738738
739739 ENDHLSL
740740
@@ -757,30 +757,12 @@ Shader "CustomEffects/Blur"
757757
758758 Pass
759759 {
760- Name "BlurPassHorizontal_FrameBufferFetch "
760+ Name "BlurPassHorizontal "
761761
762762 HLSLPROGRAM
763763
764764 #pragma vertex Vert
765- #pragma fragment Frag
766-
767- FRAMEBUFFER_INPUT_X_HALF (0);
768-
769- float4 Frag(Varyings input) : SV_Target
770- {
771- const float BLUR_SAMPLES = 64;
772- const float BLUR_SAMPLES_RANGE = BLUR_SAMPLES / 2;
773-
774- UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX (input);
775- float3 color = 0;
776- float blurPixels = _ HorizontalBlur * _ ScreenParams.x;
777- for(float i = -BLUR_SAMPLES_RANGE; i <= BLUR_SAMPLES_RANGE; i++)
778- {
779- float2 sampleOffset = float2 ((blurPixels / 1) * (i / BLUR_SAMPLES_RANGE), 0);
780- color += LOAD_FRAMEBUFFER_X_INPUT(0, input.positionCS.xy + sampleOffset).rgb;
781- }
782- return float4(color / (BLUR_SAMPLES + 1), 1);
783- }
765+ #pragma fragment BlurHorizontal
784766
785767 ENDHLSL
786768 }
0 commit comments