Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to use Blitter to blit a RenderTexture (from Shader.PropertyToID) to another RenderTexture?

Discussion in 'Universal Render Pipeline' started by qtc_Dena, Feb 17, 2023.

?

How to use Blitter to blit a RenderTexture (from Shader.PropertyToID) to another RenderTexture?

  1. Helpful!

    71.4%
  2. Nothing useful.

    28.6%
Multiple votes are allowed.
  1. qtc_Dena

    qtc_Dena

    Joined:
    Aug 12, 2022
    Posts:
    5
    As the URP document says: avoid using CommandBuffer.Blit() to perform blit operation. And it also recommend using SRP Blitter API instead. However, it reported errors when I changed to Blitter.

    I have a _MyTempRTId that is allocated from CommandBuffer.GetTemporaryRT, and a public RenderTexture, targetRT. I want to blit _MyTempRTId to targetRT. So first I converse them to type RTHandle so I can pass them to Blitter API.

    Then it reported errors as I call the Blitter.BlitCameraTexture. The following is pseudocode that explains the sample.

    Code (CSharp):
    1. private static int _MyTempRTId = Shader.PropertyToID("_MyTempRT");
    2.  
    3. public RenderTexture targetRT;
    4.  
    5. public void Blit(CommandBuffer cmd)
    6. {
    7.     var myTempRTIdentifier = new RenderTargetIdentifier(_MyTempRTId);
    8.     var myTempRTHandle = RTHandles.Alloc(myTempRTIdentifier);
    9.  
    10.     var targetRTHandle = RTHandles.Alloc(targetRT);
    11.  
    12.     Blitter.BlitCameraTexture(cmd, myTempRTHandle, targetRTHandle, default, true);
    13. }
     
  2. HajiyevEl

    HajiyevEl

    Joined:
    Feb 19, 2020
    Posts:
    41
    Did you manage to do it?
     
  3. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    216
    What is the error you get?