- Home /
Forcing Multi-Pass shader to use Deferred passes instead of Forward passes?
I wrote a Multi-pass CG vertex/fragment shader that does some stencil masking before finally rendering the object.
My issue is that as soon as I use more than one pass in my Opaque shader, it is rendered with Forward Alpha (unity 5's profiler says RenderForwardAlpha.Render
).
Render tags for masking pass:
Tags { "RenderType"="Opaque" "Queue"="Geometry+1"}
ColorMask 0
ZWrite off
Cull Front
ZTest Less
Render tags for final pass:
Tags { "RenderType" = "Opaque" "Queue" = "Geometry+3" }
ZWrite Off
Blend Off
Lighting Off
ColorMask RGB
ZTest Always
As you can see, I am trying my best to tell Unity to render an Opaque object, using nothing except Deferred Rendering.
I debugged it to the point where if I have nothing in my CG vert/frag but I have two Opaque passes, those meshes go to the ForwardAlpha renderer...
What am I missing? How can you write a muliple pass Deferred CG shader?
PS: I can successfully use sampler2D _CameraDepthNormalsTexture;
, but whether I use it or not, it still renders in ForwardAlpha if it has more than 1 pass.
Did you set the rendering path of the camera to deferred rendering?
http://docs.unity3d.com/$$anonymous$$anual/class-Camera.html
_Gkxd Yes, I have. Both the camera and the player settings are on (non-legacy) Deferred just to make sure. But either way, the Profiler shows all other (and non transparent) geometry still being rendered in Deferred Rendering mode; it's just this thing with passes that turns that specific geometry to forward.
Answer by Llockham-Industries · Oct 27, 2017 at 02:01 AM
You could try adding Tags{ "LightMode" = "Deferred" }
. But I'm not certain deferred rendering supports multipass shaders. You could get around it by giving your objects renderer multiple materials, but if it has multiple submeshes this quickly falls apart. :/
Did a quick test, you can have multiple passes with the deferred tag render in the order listed in the shader. Though you'll need a fair understanding of ver/frag shaders and Unity's deferred rendering path to make any use of this.
Your answer
Follow this Question
Related Questions
Surface Shader World Normal 0 Answers
Parsing values in multipass cg shader 0 Answers
Multipass Shader Question - How to handle alpha blending between passes 0 Answers
Shader - Share values between different pass 0 Answers
Get color of pixel before pass: prefer cg, shaderlab is last resort 0 Answers