- Home /
 
How to use CommandBuffer with RenderPipelineManager to draw a material to fullscreen?
I'm trying to have a fullscreen shader in URP (10.5). One solution that I saw people use is to have a custom camera that uses RenderPipelineManager.beginCameraRendering with command buffer. What I want is to draw the material on top of what the camera has already drawn. Here's is what I currently have:
 public class ForwardCamera : MonoBehaviour
 {
     public Shader blitShader;
     public Camera cam;
     public UnityEngine.UI.RawImage debugImage;
 
     private Material blitMat;
     private RenderTexture texture;
 
     private void Awake()
     {
         blitMat = CoreUtils.CreateEngineMaterial(blitShader);
         texture = RenderTexture.GetTemporary(
                 cam.pixelWidth,
                 cam.pixelHeight,
                 0,
                 GraphicsFormat.R16G16B16A16_SFloat
             );
 
         // Debug purpose
         debugImage.texture = texture;
     }
 
     private void OnEnable()
     {
         RenderPipelineManager.beginCameraRendering += HandleBeginCameraRendering;
     }
 
     private void OnDisable()
     {
         RenderPipelineManager.beginCameraRendering -= HandleBeginCameraRendering;
         RenderTexture.ReleaseTemporary(texture);
     }
 
     private void HandleBeginCameraRendering(ScriptableRenderContext context, Camera currentCamera)
     {
         if (!ReferenceEquals(cam, currentCamera)) return;
 
         var cmd = CommandBufferPool.Get();
         cmd.Clear();
 
         int id = Shader.PropertyToID("_Test_Color");
         cmd.SetGlobalColor(id, Color.red);
 
         cmd.SetRenderTarget(texture);
         cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
         cmd.SetViewport(new Rect(0, 0, cam.pixelWidth, cam.pixelHeight));
         cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, blitMat, 0);
 
         context.ExecuteCommandBuffer(cmd);
         cmd.Release();
     }
 }
 
               Here's the inspector view:

Here's the simple test shader: 
I don't know why but there is nothing on the debug raw image that I had.
 
                 
                picture1.png 
                (65.9 kB) 
               
 
                
                 
                picture2.png 
                (66.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer