есть система https://blogs.unity3d.com/ru/2015/02/06/extending-unity-5-rendering-pipeline-command-buffers/
Код
using UnityEngine; using UnityEngine.Rendering; using System.Collections; using System.Collections.Generic;
// See _ReadMe.txt
public class DeferredDecalSystem { static DeferredDecalSystem m_Instance; static public DeferredDecalSystem instance { get { if (m_Instance == null) m_Instance = new DeferredDecalSystem(); return m_Instance; } }
// set this command buffer to be executed just before deferred lighting pass // in the camera cam.AddCommandBuffer (CameraEvent.BeforeLighting, buf); }
//@TODO: in a real system should cull decals, and possibly only // recreate the command buffer when something has changed.
var system = DeferredDecalSystem.instance;
// copy g-buffer normals into a temporary RT var normalsID = Shader.PropertyToID("_NormalsCopy"); buf.GetTemporaryRT (normalsID, -1, -1); buf.Blit (BuiltinRenderTextureType.GBuffer2, normalsID); // render diffuse-only decals into diffuse channel buf.SetRenderTarget (BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.CameraTarget); foreach (var decal in system.m_DecalsDiffuse) { buf.DrawMesh (m_CubeMesh, decal.transform.localToWorldMatrix, decal.m_Material); } // render normals-only decals into normals channel buf.SetRenderTarget (BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.CameraTarget); foreach (var decal in system.m_DecalsNormals) { buf.DrawMesh (m_CubeMesh, decal.transform.localToWorldMatrix, decal.m_Material); } // render diffuse+normals decals into two MRTs RenderTargetIdentifier[] mrt = {BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer2}; buf.SetRenderTarget (mrt, BuiltinRenderTextureType.CameraTarget); foreach (var decal in system.m_DecalsBoth) { buf.DrawMesh (m_CubeMesh, decal.transform.localToWorldMatrix, decal.m_Material); } // release temporary normals RT buf.ReleaseTemporaryRT (normalsID); } }
и Decal срабатывает на все что попадает в коллайдер, как можно рендерить на определенных слоях?