- Home /
Objects behind transparent objects (sometimes) not drawn.
Hi,
I have a couple of non-convex, intersecting transparent objects. I was having problems with the rendering order, which I understand is due to the fact that Unity only sorts transparent objects on a per-object basis.
So I decided to use the "Transparent/Diffuse ZWrite" shader described in ShaderLabs, which enables the ZBuffer / Depth Buffer on a first pass: http://docs.unity3d.com/Documentation/Components/SL-CullAndDepth.html
Shader "Transparent/Diffuse ZWrite" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
// extra pass that renders to depth buffer only
Pass {
ZWrite On
ColorMask 0
}
// paste in forward rendering passes from Transparent/Diffuse
UsePass "Transparent/Diffuse/FORWARD"
}
Fallback "Transparent/VertexLit"
}
Now that did solve my rendering order problem, but it introduced a new one:
Sometimes, depending on the positions of the objects, the parts of object A that are behind parts of object B are just not drawn. And vice-versa. I also have particles in there, behind the transparent objects, and they behave the exact same way: sometimes being drawn, sometimes not (they appear/disappear simultaneously with object B).
Note that the basic Transparent/Diffuse shader did not seem to have this problem. Definitely not with the particles.
I get the feeling that this is something simple, like Unity figuring "OK, this object is hidden, I don't need to draw it". But it's only partially hidden, and for some sets of positions, the engine actually gets it right. Some kind of culling, perhaps?
Any clues?
Actually I pretty sure you're screwed on that. All my self transparent shaders have vertex colours to put them in different passes.
And does that help? Sorry if that's a silly question, I'm very new to shaders (and Unity, for that matter).
In this instance I'm more worried about rendering something that's correct than about rendering it fast, so I'll take any solution, even a costly one.
Well if you want to have something be transparent over itself, you pretty much have to separate it into different passes and control the ordering. That can be done in a shader, but it pretty much only works for effects like windows, wind shields etc. It does also work for things which are effectively surrounding each other (so bone, muscle, skin etc in something where those become transparent to see inside).
There's a non-perfect approach using Cut Out shaders too, but without depth sorted triangles in the graphics hardware: self transparency is a problem.
Ah, I see, but in order to do that, I would have to know beforehand what parts of the object are behind other parts, which would be difficult in this case.
I was under the impression that "ZWrite On" forced triangle depth sorting, (and it does help) but since it's not working quite as I hoped, I guess not. Is there really no way to force it?
Thank you for your help.
Your answer
Follow this Question
Related Questions
Adding Materials to an object. 1 Answer
Occlusion, hiding an object within a transparent box. 0 Answers
What's the best way to animate a transparent image descending over a circular image? 0 Answers
Rendering an entire object as transparent 1 Answer
Text Mesh - Ignores Backface culling & Depth Test? 2 Answers