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

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

cmd.GetTemporaryRT(mRT_ID,512,512, (int) DepthBits.Depth24);

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

RTHandles.Initialize(512,512); //Init somewhere before a call Alloc
...
var mRT_Handler = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth24);

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


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

1 Like

Did you ever find out a solution? I am having some question

Am I losing my mind or this piece of code is peak insanity? Why setting format to RenderTextureFormat.Depth? Why do we can only have color OR depth with RTHandle when we can have both color AND depth in the good old temporary RT since forever?

And if it’s intentional, why this huge change is mentioned nowhere in Using the RTHandle system | Core RP Library | 14.0.11 (unity3d.com)? What’s even going on with Unity lol