Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Custom Pass injected by script
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class CustomPass : MonoBehaviour
public Mesh mesh;
public Material material;
DrawMeshPass m_DrawMeshPass;
void OnEnable()
m_DrawMeshPass = new DrawMeshPass();
m_DrawMeshPass.renderPassEvent = RenderPassEvent.AfterRendering;
RenderPipelineManager.beginCameraRendering += DrawMesh;
void OnDisable()
RenderPipelineManager.beginCameraRendering -= DrawMesh;
void DrawMesh(ScriptableRenderContext context, Camera cam)
if (mesh == null || material == null) return;
var renderer = cam.GetRenderer();
m_DrawMeshPass.mesh = mesh;
m_DrawMeshPass.material = material;
m_DrawMeshPass.matrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale);
class DrawMeshPass : ScriptableRenderPass
public Matrix4x4 matrix { get; set; }
public Mesh mesh { get; set; }
public Material material { get; set; }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cb = CommandBufferPool.Get("DrawMesh");
cb.DrawMesh(mesh, matrix, material);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment