- Home /
How to set the render target(s) for projector shaders?
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) {
//...
}
}
After some more research I still haven't come up with a solution besides creating my own CommandBuffer for a custom projector implementation.
It turn's out the issue I was having with targeting to the normal buffer RT from the shader was just because I was using unity 5.3 with the newer deferred renderer, but my shader was trying to use the old deferred render path Light$$anonymous$$ode(s).
Switching the Pass "Light$$anonymous$$ode" = "Deferred" allowed me to write to the appropriate RT(s) without needing a CommandBuffer to switch RT(s) and draw a mesh.
However, Pass "Light$$anonymous$$ode" = "Deferred" for a Projector material doesn't work. I suspect this is because Projectors have their own render path? So, I think the question is still open.
Answer by EvilSam · Dec 30, 2015 at 04:40 AM
In this blog, you can find a few examples of very similar situations, especially the "Deferred Decals" example does almost exactly what you want to do, you just may want implement perspective projection instead of the box projection in the example.
The command buffer stuff I was referring to was more or less the same as the example you provided. I understand I can create my own projector/decal system with Command Buffers.
However, the question is about unity projectors. Assu$$anonymous$$g you could use Light$$anonymous$$ode pass tag with a unity projector material, command buffers would not be needed. So, I think the question still stands. How do we specify the Projector RT(s) if Light$$anonymous$$ode doesn't seem to work?
Thanks
Your answer
Follow this Question
Related Questions
Unity Blob shadow projector massive tris amount, why? 1 Answer
Complex Depth Shader 0 Answers
How to make transparent only colliding part of object? 0 Answers
How do I make a boat that doesn't let water enter?,How do I make a boat that water cant get in to 2 Answers
How to show a trail in the shape of a mesh to create the effect of it moving really fast? 1 Answer