- Home /
Draw order when using RenderTargets ?
I'm curious what the draw order is when using render targets because I'm seeing some weird behavior in Unity 4.3 . Respectively, when you have transparent objects that get rendered by a camera, and then the camera has a post processing effect, the draw order is fucked up.
What my setup is : I render opaque and transparent objects from Camera 1, I then have an image filter that combines Camera1 with Camera 2 (which renders it's own objects). Whenever I disable the filter on Camera 1, everything looks ok, when I add the extra filter, transparent objects are not rendered.
However, I found a small fix : have all transparent objects render in the Geometry+1 que. If I add this to all transparent shaders, everything renders correctly ! However, this means modifying all transparent shaders + built in ones to make everything work correctly which doesn't sound feasible. It seems as though the render target filter draw call is getting called BEFORE drawing transparent objects which sounds stupid. Is this a bug ? Is it Intended ?
I've seen this issue before and honestly I couldn't fix it. $$anonymous$$ine was more related to the alpha getting rendered incorrectly when using RenderTextures, so alpha blending was messed when I went to combine in the post effect.
A quick fix though would be to set the queue using the material. This avoids having to modify the Shaders themselves, and gives flexibility in doing it on a material basis.
Hope this helps!
Answer by relativegames · Dec 12, 2013 at 11:39 AM
Ok, so after about 3 hours of trying to tweak the image shader I noticed something, the SSAO shader when turned on/off did not exhibit this issue, so turning it on or off did not have any impact on transparent objects, they were still getting rendered. So then I realized that my shader was copied from a "standard unity shader" which had a lot of tags. So basically after removing these :
Tags {"Queue"="Geometry+3" "RenderType"="Opaque" }
LOD 200
Pass
{
Lighting On
Tags {"LightMode" = "ForwardBase"}
It started working as expected. You still need the "Pass {" but everything else needs to be removed. I also added
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
from the SSAO shader.