public RenderPassEvent injectionPoint = RenderPassEvent.AfterRenderingOpaques;
/*[Header("Output / Sharing")]
public Color clearColor = Color.black;
public bool setGlobalTexture = true;
public string globalTextureName = "_OverrideOpaquesTex";
public bool copyBackToCamera = false; // optional composite*/
public struct OverrideGroup {
public LayerMask layerMask;
public Material material;
public Settings settings = new Settings();
public OverrideGroup[] _groups;
public override void Create()
// Create the render pass that draws the objects, and pass in the override material
materialOverlayPass = new MaterialOverlayPass(settings, _groups);
// Insert render passes after URP's post-processing render pass
materialOverlayPass.renderPassEvent = materialOverlayPass.injectionPoint;// RenderPassEvent.AfterRenderingOpaques;
// You can request URP color texture and depth buffer as inputs by uncommenting the line below,
// URP will ensure copies of these resources are available for sampling before executing the render pass.
// Only uncomment it if necessary, it will have a performance impact, especially on mobiles and other TBDR GPUs where it will break render passes.
//m_ScriptablePass.ConfigureInput(ScriptableRenderPassInput.Color | ScriptableRenderPassInput.Depth);
// You can request URP to render to an intermediate texture by uncommenting the line below.
// Use this option for passes that do not support rendering directly to the backbuffer.
// Only uncomment it if necessary, it will have a performance impact, especially on mobiles and other TBDR GPUs where it will break render passes.
//m_ScriptablePass.requiresIntermediateTexture = true;
// 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)
renderer.EnqueuePass(materialOverlayPass);
class MaterialOverlayPass : ScriptableRenderPass
public RenderPassEvent injectionPoint;
private readonly OverrideGroup[] groups;
public MaterialOverlayPass( Settings settings, OverrideGroup[] overrideGroups/*Material overrideMaterial*/)
injectionPoint = s.injectionPoint;
// This class stores the data needed by the RenderGraph pass.
// It is passed as a parameter to the delegate function that executes the RenderGraph pass.
// Create a field to store the list of objects to draw
//public RendererListHandle rendererListHandle;
public RendererListHandle[] lists;
//public TextureHandle colorOut;
public TextureHandle cameraColor;
// This static method is passed as the RenderFunc delegate to the RenderGraph render pass.
// It is used to execute draw commands.
static void ExecutePass(PassData data, RasterGraphContext context)
// RecordRenderGraph is where the RenderGraph handle can be accessed, through which render passes can be added to the graph.
// FrameData is a context container through which URP resources can be accessed and managed.
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
if (groups == null || groups.Length == 0) return;
var camData = frameData.Get<UniversalCameraData>();
var urpData = frameData.Get<UniversalRenderingData>();
var light = frameData.Get<UniversalLightData>();
var res = frameData.Get<UniversalResourceData>();
// Off-screen color + private depth (same as before)
var colorDesc = camData.cameraTargetDescriptor;
colorDesc.msaaSamples = 1;
colorDesc.depthBufferBits = 0;
var colorTex = UniversalRenderer.CreateRenderGraphTexture(renderGraph, colorDesc, "_RG_MultiOverrideColor", false);
var depthDesc = colorDesc;
depthDesc.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.None;
depthDesc.depthBufferBits = 32;
var depthTex = UniversalRenderer.CreateRenderGraphTexture(renderGraph, depthDesc, "_RG_MultiOverrideDepth", false);
//var depthTex = res.activeDepthTexture; // <- camera depth+stencil
// Build a renderer list per group (opaque range + opaque sorting)
//var tag = new ShaderTagId("UniversalForward");
var shaderTags = new System.Collections.Generic.List<ShaderTagId>
new ShaderTagId("UniversalForward"), // URP Lit
new ShaderTagId("UniversalForwardOnly"), // common SG/Lit variants
new ShaderTagId("SRPDefaultUnlit") // SG Unlit
var sort = camData.defaultOpaqueSortFlags; // CommonOpaque
var lists = new System.Collections.Generic.List<RendererListHandle>(groups.Length);
foreach (var g in groups)
if (g.material == null) continue;
var draw = RenderingUtils.CreateDrawingSettings(shaderTags, urpData, camData, light, sort);
draw.overrideMaterial = g.material;
draw.overrideMaterialPassIndex = g.materialPass;
var filter = new FilteringSettings(RenderQueueRange.opaque, g.layerMask);
var rlp = new RendererListParams(urpData.cullResults, draw, filter);
lists.Add(renderGraph.CreateRendererList(rlp ));
// One raster pass: bind attachments once, draw all lists
using (var builder = renderGraph.AddRasterRenderPass<PassData>("Multi-Override Opaques (RG)", out var pass))
// Fill the data object that RG will pass to your render function
pass.lists = lists.ToArray(); // 'lists' is your List<RendererListHandle>
pass.clearColor = Color.black;
pass.cameraColor = res.activeColorTexture;
foreach (var rl in pass.lists) builder.UseRendererList(rl);
builder.UseTexture(pass.cameraColor, AccessFlags.Read); // <-- read camera color (has sky)
builder.SetRenderAttachment(colorTex, 0, AccessFlags.Write); // our off-screen color
builder.SetRenderAttachmentDepth(depthTex, AccessFlags.Write); // private depth
builder.SetRenderFunc((PassData data, RasterGraphContext ctx) =>
// 1) Prefill our off-screen RT with the current camera color (which already includes the sky)
Blitter.BlitTexture(ctx.cmd, data.cameraColor, new Vector4(1,1,0,0), 0, false);
// 2) Clear only DEPTH (keep color we just copied)
ctx.cmd.ClearRenderTarget(true, false, data.clearColor);
// 3) Draw all opaque objects with your override materials
foreach (var rl in data.lists)
ctx.cmd.DrawRendererList(rl);
using (var builder = renderGraph.AddRasterRenderPass<PassData>(
"Multi-Override → Camera (RG)", out var copy))
// pass fields not needed here; just read + write
builder.UseTexture(colorTex, AccessFlags.Read);
builder.SetRenderAttachment(res.activeColorTexture, 0, AccessFlags.Write);
builder.SetRenderFunc((PassData _, RasterGraphContext ctx) =>
Blitter.BlitTexture(ctx.cmd, colorTex, new Vector4(1,1,0,0), 0, false);