I have a surface shader that has a feature that will only work in forward rendering mode. So I need to change my shader so that in the deferred variant of my compiled shader, a certain line sets a float to 0, effectively disabling the feature.
I tried this in my surf function but it doesn’t work:
#ifdef UNITY_PASS_DEFERRED
depthBlend = 0;
#endif
Is this keyword not what I’m supposed to use? Thanks!
Note, that won’t make something not render when the camera or project is rendering using deferred, only if that particular shader is using an opaque queue (background, geometry, or alphatest). If you’re using a transparent queue those will always use forward rendering, so that will never be true.
@bgolus This is surprising news to me since my shader IS actually in the “Overlay” render queue but I’m having trouble with depth as you can see in my other thread:
If my shader is being rendered in forward mode then why am I having this depth sample issue when the main camera is rendering in deferred mode? Shouldn’t it not make any difference?
Shader error in 'MyShader/MyShader': invalid or unsupported integer constant expression at line 125 (on d3d9)
Compiling Vertex program
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
Because surface shaders are funny things, and just because you set a queue doesn’t mean it’ll respect that, especially with deferred. This should probably be in the other thread, but you should try including exclude_path:deferred on the #pragma surface line. If there’s a deferred pass at all I believe Unity tries to use it when running deferred, and just changing the queue doesn’t disable its generation. You either need that option, or have alpha in that line.
@bgolus Unfortunately it looks like adding alpha has disabled ZWrite on my shader - which I really need. Is there another way to disable the deferred pass and keep ZWrite On?