- Home /
object with alpha texture disappears at horizon line
i modelled two palms; the leaves are just planes with an alpha mask. i also have water pro in my scene; now when i play the leaves disappear at the horizon (e.g. where the water meets the sky)
another interesting fact is that if something is behind those leaves they do get rendered, so i suppose it has something to do with the water cutting off something or being prioritized before the alpha mask, but i can't quite put my finger on it.
if i select diffuse instead of transparent/diffuse everything is like it should be:
maybe there's just some small option i'm missing; this is the first time i worked with alpha masks inside of unity.
the texture is a .psd with the alpha in the first channel by the way...
i would be grateful for any hints, thanks.
@LeeGibson What shader are you using for the leafs? Transparent/Cutout/Diffuse? This has to do with Z-writing and reading. And what shader are you using for the water? Does it have any options inside with Ztest and Zwrite?
Transparent>Diffuse... The water shader is FX/Water from water pro, unfortunately it doesn't have options called Ztest/Zwrite.
@LeeGibson Did you try to look from the other side of the trees? Or from above? There will probably be no problem there. The shader doesn't have options, I meant that you need to look into the shader and see if those properties are on or off. But if you are stuck to the shader, you will need to do some trickery to make the trees and the water sort properly in the depth queue.
Answer by Marnix · Jun 29, 2011 at 02:03 PM
It is very likely that your water object is also set as a transparent object. Unity does a depth sort by position. It is very likely that your trees are further away than the pivot point of your water plane. (Have you looked at the other side of the trees?)
To solve this, you can put your water plane to be non-transparent, so it will be rendered earlier than your transparent trees and will not give you problems with any transparent object anymore.
If you really want the water plane to be transparent, you should go for the render ordering, but it will always result in false images, because it is fully dependent on your view angle towards the transparent objects.
now that you mention it - no, i didn't. and you're right, the back of my trees is okay. i'll test now how the water looks when non-transparent, maybe it will still look okay. would repositioning the water be another workaround?
@LeeGibson Or creating multiple water planes so that the trees will always be closer than the water's pivot point to your camera. It's a bit tricky, but there is no way to come around this one. Transparent water planes are just not good, because they are way too big. $$anonymous$$aybe the cutout shader does a good job for you as well, but I'm not sure about that.
Answer by aldonaletto · Jun 29, 2011 at 01:47 PM
This problem may be caused by shaders that do not write to the Z (or depth) buffer. You can work around this by changing the rendering order. Test which queue value solve your problem with the script below, which must be assigned to the palm tree:
var order = 2800;
function Update(){
renderer.material.renderQueue=order;
}
Once the value is found, you can set it in your shader or in the Start function.
@aldonaletto I don't like this workaround, because it is better to adjust the shader for this purpose. Unity does resolve depth sorting, so setting a fixed render order doesn't seem as a good solution to me.
it worked! i'm able to see the leaves at value 3200. i can't find the transparent/diffuse shader to set the order there - is it okay to just place the code in a start function for every treetop?
The problem is what @$$anonymous$$arnix said: you set the rendering order and everything is ok until you have to look the scene from the other side. If you never have to do this, ok; if you may need to do this, then the solution is to set the rendering order in Update, and change it when you need.
Another possible alternative: you can try the Transparent/Cutout/Diffuse shader in the tree material. I'm not totally sure, but it seems transparent cutout shaders update the Z buffer, so they do not depend on the render queue. A cutout shader doesn't have semi transparencies: pixels are 100% transparent or 100% opaque, depending of the alpha value (adjustable in the Inspector).
NOTE: By the way, @$$anonymous$$arnix suggested exactly the same shader 25 $$anonymous$$utes before (I saw it only now).
Indeed, that's what I meant. Updating the render order is magic and something you don't really want to do yourself, because there are no good or bad values and you take a part of the engine's responsibility back to yourself, but it is possible to do everything manually. But not wanted =)
I agree, but unfortunately sometimes you have no choice: semitransparent shaders (and some opaque shaders too) do not update the Z buffer, and when two objects with such shaders are superposed the only solution is to alter the rendering order. It may become a nightmare, specially if more than two objects are intersecting, or when you walk around them...
Your answer
Follow this Question
Related Questions
Boat wake/foam 0 Answers
Using noise as texture 2 Answers
"Pro" Water turns an ugly gray in distance 0 Answers
How to add transparency to a waving shader? 1 Answer
Unity Water Brown for Imported Mesh 0 Answers