jPCT - a 3d engine for Java > Support

Transparent Object and ZBuffer

<< < (2/2)

Jakes:
You saíd that they dont write to zbuffer, is that it? is there any reason why? aside from not writing the alpha values of course, they should write their values as being a normal plane, no?

EgonOlsen:
They can't write into the depth buffer and that causes the effect that you see here. Imagine a tree with lots of foliage. Depending on the view angle, the drawing order of it's polygons might be back to front (fine for transparency) or front to back or something in between (most likely). If they would write into the depth buffer, all foliage that's rendered first would block everything that's behind it and that just doesn't look right. That includes completely transparent areas, because depth checks and writes happen before the actual rendering. That's just how it works, I'm afraid. Your planes are being sorted (if they are different objects) by using the simple, so called, painter's algorithm, but that's never perfect. If there is a set order that's the same in every case, you can apply a zsort-offset with some method in Object3D, but that's not applicable in most applications.
Another way to fight this problem, is to use a custom shader that doesn't do transparency but some kind of stippling instead. I did that for some trees in my game Naroth. Birch and oak trees are rendered as transparent objects, so that there might be unwanted polygon overlaps, but you hardly notice them if you don't watch closely. Pine trees on the other hand are rendered using stippling.

Jakes:
Yeah, I know that what I was expecting was the issue with the painters algorithm, and that was what I was expecting, because even if I wanted to used the discard method on a shader, the plane in the back would still overlap with the front plane, so thats why I was asking if there is a way to force those planes to write to the buffer, even if the clipping were to happen, and then I would sort them myself or even use a shader to discard the pixels I dont want to be written to the zbuffer. in that case the rendering would appear fine.

EgonOlsen:
You really don't want them to write into the buffer, because you would get the exact same problems with ordering, just worse. If you know the order, you can use the mentioned z-offset method to "sort" them beforehand. Or use a custom shader to discard the pixels yourself on non-transparent objects if that's an option.

Navigation

[0] Message Index

[*] Previous page

Go to full version