Hi, we have encountered a batch related problem. We use RenderFeature in URP with
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GetDepthTextureFeature : ScriptableRendererFeature
{
class GetDepthTexture : ScriptableRenderPass
{
private RenderTargetHandle m_TemporaryColorTexture { get; set; }
internal RenderTextureDescriptor descriptor { get; set; }
private FilteringSettings m_FilteringSettings;
private Material DepthNormalMaterial ;
string m_ProfilerTag = "DepthNormals Prepass";
private int Layer ;
private string textureName ;
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
// When empty this render pass will render to the active camera render target.
// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
// The render pipeline will ensure target setup and clearing happens in an performance manner.
public void Setup(RenderTargetHandle m_TemporaryColorTexture , RenderTextureDescriptor dsp)
{
this.descriptor = dsp;
this.m_TemporaryColorTexture = m_TemporaryColorTexture;
dsp.colorFormat = RenderTextureFormat.ARGB32;
}
public GetDepthTexture( Material mat , int layer , string textureName )
{
this.DepthNormalMaterial = mat;
this.Layer = layer;
this.textureName = textureName;
m_FilteringSettings = new FilteringSettings(RenderQueueRange.opaque, layer = (layer != -1)? 1 << layer : -1);
}
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
cmd.GetTemporaryRT(m_TemporaryColorTexture.id, descriptor);
ConfigureTarget(m_TemporaryColorTexture.Identifier());
ConfigureClear(ClearFlag.All , Color.black);
}
// Here you can implement the rendering logic.
// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
using (new ProfilingScope(cmd, new ProfilingSampler(m_ProfilerTag)))
{
cmd.Clear();
var sortFlag = renderingData.cameraData.defaultOpaqueSortFlags;
var drawSetting = CreateDrawingSettings( new ShaderTagId("DepthOnly") , ref renderingData, sortFlag);
drawSetting.overrideMaterial = DepthNormalMaterial;
context.DrawRenderers(renderingData.cullResults, ref drawSetting , ref m_FilteringSettings);
cmd.SetGlobalTexture( textureName , m_TemporaryColorTexture.id);
context.ExecuteCommandBuffer(cmd);
}
CommandBufferPool.Release(cmd);
}
/// Cleanup any allocated resources that were created during the execution of this render pass.
public override void FrameCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id);
}
}
[System.Serializable]
public class Setting
{
public int Layer ;
public string textureName = "_tmpTexture" ;
}
public Setting setting = new Setting();
GetDepthTexture m_ScriptablePass;
RenderTargetHandle m_RenderTextureHandle ;
RenderTargetHandle m_DepthNormalTextureHandle ;
Material depthNormalMat;
public override void Create()
{
// Configures where the render pass should be injected.
depthNormalMat = CoreUtils.CreateEngineMaterial("Hidden/Internal-DepthNormalsTexture");
m_ScriptablePass = new GetDepthTexture( depthNormalMat , setting.Layer , setting.textureName);
m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingOpaques ;
m_RenderTextureHandle.Init(setting.textureName);
}
// Here you can inject one or multiple render passes in the renderer.
// This method is called when setting up the renderer once per-camera.
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
m_ScriptablePass.Setup(m_RenderTextureHandle , renderingData.cameraData.cameraTargetDescriptor);
renderer.EnqueuePass(m_ScriptablePass);
}
}
to retrieve Model’s Normal depth in the scene.
We have successfully batched all the models. Yet when it failed, we couldn’t figure out what went wrong.
The error thrown out was 「Objects are affected by different reflection probes.」If we disable renderer’s probe, it will still fail to batch.
We are wondering if someone could explain Unity SRP Batcher’s rule to us or direct us to articles where we can find the SRP Batcher’s more in depth explaination. Thanks


