I would like to set SV_Target0 and SV_Target2 to the diffuse and normal gbuffers (deferred) for a projector shader. Am I on the right track? I guess it would also be nice if I could change the RT per projector params (so I don’t change all projectors to the same RT’s.
Todo this same concept for meshs I could just use a CommandBuffer and DrawMesh, but I wasn’t sure about Projectors.
CommandBuffer
CommandBuffer buf = new CommandBuffer();
Camera.current.AddCommandBuffer (CameraEvent.BeforeLighting, buf);
// OnRenderObject
buf.SetRenderTarget(new RenderTargetIdentifier[] {
BuiltinRenderTextureType.GBuffer0, //color
BuiltinRenderTextureType.GBuffer2 //normal
}, BuiltinRenderTextureType.CameraTarget);
// foreach Mesh
buf.DrawMesh (_decalMesh, decal.transform.localToWorldMatrix, decal.Material);
Shader
// ...
Pass {
Tags {"LightMode" = "Deferred"}
//...
struct rastInput {
fixed4 albedo : SV_Target0;
fixed4 normal : SV_Target2;
};
//...
rastInput frag (fragInput i) {
//...
}
}