Search Unity

Question How can I get a regular format RT with depth by RTHandles.Alloc ?

Discussion in 'Universal Render Pipeline' started by OldKing_Wang, Aug 26, 2022.

  1. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    Hi

    I wrote a render feature request three pass

    the first two pass need render target to a RenderTexutre , and the third pass blit the RT back to main camera.

    I need depth buffer for the RT (for z-test)

    so what I used to do is request a temporary RT with code

    Code (CSharp):
    1.            
    2. cmd.GetTemporaryRT(mRT_ID,512,512, (int) DepthBits.Depth24);
    3.  
    with URP 13.1(Unity 2022.1.14f1) , unity give me a warning


    [CS0618] 'ScriptableRenderPass.Blit(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Material, int)' is obsolete:
    'Use RTHandles for source and destination'


    so I try to change my code with RTHandles

    Code (CSharp):
    1.    
    2. RTHandles.Initialize(512,512); //Init somewhere before a call Alloc
    3. ...
    4. var mRT_Handler = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth24);
    5.  
    -------

    the issue is, I can't Sample the right info from the RT (alloc by RTHandles).

    I check the RTHandleSystem.cs file. seem , if I request depth with Alloc function , the RT create by RTHandles will use RenderTextureFormat.Depth format

    iShot2022-08-26 22.30.47.jpg

    ----

    I use


    TEXTURE2D(_MainTex);
    SAMPLER(sampler_MainTex);


    to sampler the RT info in the third pass . it worked for cmd.GetTemporaryRT. but not can't get the right info with RTHandles.Alloc();

    so . what should I to fix this issue?

    thanks
     
  2. JSmithIR

    JSmithIR

    Joined:
    Apr 13, 2023
    Posts:
    111
    Did you ever find out a solution? I am having some question