- Home /
Problem with transparent planes behind each other
Hi. I have planes with a transparent vertex shader to cutout some black shapes. In front of it, a little bit closer to the camera, is a rotating plane that should illustrate fog. It has also a transparent vertex shader, but the color is white gray. If i move with the player, sometimes the one whole black cutoutplane gets a brighter color than the others because of the 'fog' in front. Why is that? Is there a problem with rendering two tansparent planes behind one other?
Unity deffered rendering is known to do this sort of issues, but even other renderes do so. Try $$anonymous$$aking sure the planes are not static, so unity wont batch them(batching transparent objects are also a problem)
Answer by Owen-Reynolds · Oct 21, 2013 at 04:28 AM
"Is there a problem with rendering two t[r]ansparent planes behind one other?" Yes, if the system can't always tell which is in front of the other. For transparent objects, the draw order matters (if you draw the cutout after the fog, the solid parts aren't foggy.)
Suppose you have planes like this, where the O is the center (`transform.position`):
----large--- O ---plane-------
---small-O-plane--
C3 C2 C1
Unity (and probably everything) measures to object 000. The camera at C1 clearly thinks small is in front of large. At C2 it probably also does (since it uses Z-distance, not real distance,) but at C3 it thinks large is in front of small. So moving from C1 to C3 gives a "pop" as the draw order flips (nothing moves, but color changes.)
One fix is just to move them further apart. Or use more, smaller planes.
The "real" fix is to look at the RenderQueue in the shader. Copy the fog's particle shader and add the "+10" to the queue (the shader docs show how to do this.) Use that in the fog material, and now it will always go "over" regular stuff (even if it should be behind.)
I wrote in the shader Tags "Queue"="Transparent +10". I still can't belive it, it actually really works now! Thank you so much, you just made my day! :)
Seems, as you helped others as well :-) It's working with changing the RenderQueue! Thank you lots and lots and lots!!