- Home /
Shader producing a different result in-game and in-editor
I'm working on a surface shader that is making objects partially transparent based on the position of another Gameobject. The shader works as part of Transparent queue however that makes it not be able to receive shadows. So now I made it have AlphaTest queue and this works great however in-game it seems to act strange and rendering multiple times while in-editor paused it works exactly how I want it. In-game I also notice some dragging effect when moving the view, like it's drawing multiple times. And it also seems that just at it starts the effect is correct but it quickly gets incorrect like shown below. What could be causing this?
In-game:
In-editor paused:
These are the Tags and Blend being used:
SubShader {
/*
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
*/
/*
TODO
This allows to cast shadows but for some reason it doens't clear the pixels between draws or something
Could also be draw order
Pausing in editor shows that it is working
*/
//
Tags { "Queue"="AlphaTest"
"IgnoreProjector"="True"
"RenderType"="TransparentCutout" }
Blend SrcAlpha OneMinusSrcAlpha
//
CGPROGRAM
As it is in Unity, transparent objects cannot receive shadows. That isn't really a feature of the engine, more a side effect on how it draws shadows. Simply changing the render queue of a transparent shader will do a lot more harm than good; in very few cases will this work (mainly if you are drawing a transparent object with fixed alpha and using grab textures). Your comment in the shader is correct - the pixels aren't being cleared. This is because Unity doesn't know that you aren't drawing anything at that point - lowering the render queue but keeping the object transparent means you will render nothing as the objects output, but Unity won't bother rendering behind it because it thinks there is a solid object there.