@@ -311,10 +311,7 @@ This section demonstrates how to implement the settings for the custom blur rend
311
311
312
312
// Blit from the camera color to the render graph texture,
313
313
// 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 ));
318
315
}
319
316
```
320
317
@@ -324,33 +321,25 @@ This section demonstrates how to implement the settings for the custom blur rend
324
321
private Vector4 m_ScaleBias = new Vector4(1f, 1f, 0f, 0f);
325
322
```
326
323
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 .
328
325
329
326
```C #
330
327
// 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 ))
333
329
{
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 ;
338
332
passData .material = material ;
339
333
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
+
344
337
// Use the input texture of the previous pass as the output
345
338
builder .SetRenderAttachment (srcCamColor , 0 );
346
339
347
340
// 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 ));
354
343
}
355
344
```
356
345
@@ -513,7 +502,7 @@ public class BlurRendererFeature : ScriptableRendererFeature
513
502
material = new Material (shader );
514
503
blurRenderPass = new BlurRenderPass (material , settings );
515
504
516
- blurRenderPass .renderPassEvent = RenderPassEvent .AfterRenderingSkybox ;
505
+ blurRenderPass .renderPassEvent = RenderPassEvent .BeforeRenderingPostProcessing ;
517
506
}
518
507
519
508
public override void AddRenderPasses (ScriptableRenderer renderer ,
@@ -569,7 +558,7 @@ public class BlurRenderPass : ScriptableRenderPass
569
558
private const string k_VerticalPassName = " VerticalBlurRenderPass" ;
570
559
private const string k_HorizontalPassName = " HorizontalBlurRenderPass" ;
571
560
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 );
573
562
574
563
private BlurSettings defaultSettings ;
575
564
private Material material ;
@@ -606,6 +595,11 @@ public class BlurRenderPass : ScriptableRenderPass
606
595
internal Material material ;
607
596
}
608
597
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
+
609
603
public override void RecordRenderGraph (RenderGraph renderGraph ,
610
604
ContextContainer frameData )
611
605
{
@@ -648,36 +642,25 @@ public class BlurRenderPass : ScriptableRenderPass
648
642
649
643
// Blit from the camera color to the render graph texture,
650
644
// 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 ));
655
646
}
656
-
647
+
657
648
// 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 ))
660
650
{
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 ;
665
653
passData .material = material ;
666
654
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
+
671
658
// Use the input texture of the previous pass as the output
672
659
builder .SetRenderAttachment (srcCamColor , 0 );
673
660
674
661
// 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 ));
681
664
}
682
665
}
683
666
}
@@ -735,6 +718,23 @@ Shader "CustomEffects/Blur"
735
718
736
719
return float4(color.rgb / (BLUR_SAMPLES + 1), 1);
737
720
}
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
+ }
738
738
739
739
ENDHLSL
740
740
@@ -757,30 +757,12 @@ Shader "CustomEffects/Blur"
757
757
758
758
Pass
759
759
{
760
- Name "BlurPassHorizontal_FrameBufferFetch "
760
+ Name "BlurPassHorizontal "
761
761
762
762
HLSLPROGRAM
763
763
764
764
#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
784
766
785
767
ENDHLSL
786
768
}
0 commit comments