Hello,
I am currently attempting to customize the Universal Render Pipeline (URP) version 14.0.10 on Unity 2022.3.20f1 to render in an auxiliary buffer for the opaque object.
My approach is based on the principles outlined in the following Unity forum post: Implemeting color-based object selection in URP
In the frame debugger, it is working as expected.
RT0:
RT1:
I obtain the correct render target in the full screen shader, but the value does not seem to be cleared correctly between frames.

// Graphics\Packages\com.unity.render-pipelines.universal\Runtime\Passes\DrawObjectsPass.cs
RTHandle[] mrt;
RTHandle secondaryColorRT;
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
mrt[0] = renderingData.cameraData.renderer.cameraColorTargetHandle;
RenderTextureDescriptor desc = renderingData.cameraData.cameraTargetDescriptor;
desc.depthBufferBits = 0;
int selectBufId = Shader.PropertyToID("_SecondaryColorRT");
cmd.GetTemporaryRT(selectBufId, desc);
secondaryColorRT = RTHandles.Alloc(selectBufId);
//cmd.SetGlobalTexture("_SecondaryColorRT", secondaryColorRT.nameID);
mrt[1] = secondaryColorRT;
ConfigureTarget(mrt, renderingData.cameraData.renderer.cameraDepthTargetHandle);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
RTHandles.Release(secondaryColorRT);
}
The legacy way of doing it gave me the same result:
RenderTargetIdentifier[] mrtId;
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
mrtId[0] = renderingData.cameraData.renderer.cameraColorTarget;
RenderTextureDescriptor desc = renderingData.cameraData.cameraTargetDescriptor;
desc.depthBufferBits = 0;
int selectBufId = Shader.PropertyToID("_SecondaryColorRT");
cmd.GetTemporaryRT(selectBufId, desc);
mrtId[1] = new RenderTargetIdentifier(selectBufId);
ConfigureTarget(mrtId, renderingData.cameraData.renderer.cameraDepthTarget);
}
With a simple shader:
Shader "Custom/MRTExample"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Name "MRT Blue & Red"
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings vert(Attributes input)
{
Varyings output;
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
return output;
}
struct FragmentOutput
{
half4 baseColor : SV_Target0;
half4 customData : SV_Target1;
};
FragmentOutput frag(Varyings input)
{
FragmentOutput output;
output.baseColor = half4(0.0, 0.0, 1.0, 1.0); // Blue color
output.customData = half4(1.0, 0.0, 0.0, 1.0); // Red color
return output;
}
ENDHLSL
}
}
}
FullScreenShader.cs (via the FullScreenRendererFeature)
Shader "Custom/MRTFullScreenShader"
{
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
Pass
{
Name "MRTFullScreenShader"
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#pragma vertex Vert
#pragma fragment frag
SAMPLER(sampler_BlitTexture);
TEXTURE2D(_SecondaryColorRT);
SAMPLER(sampler_SecondaryColorRT);
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
//return SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, input.texcoord);
return SAMPLE_TEXTURE2D_X(_SecondaryColorRT, sampler_SecondaryColorRT, input.texcoord);
}
ENDHLSL
}
}
}
I’ve tried different clear methods, but they just make the screen black.
Does anyone have any suggestions on how to resolve this issue?


