Transparent Objects

Started by
22 comments, last by GameDev.net 18 years, 6 months ago
Hi, My objective is to display many objects in the scene, some transparent, some not. I read the NeHe tutorial and searched this forum (and google of course) but wasn't lucky enough. Basically I already know that I would need to display the opaque objects first, then transparent objects with depth test enabled but depth buffer writing disabled. I also need to sort all vertices of transparent objects and display them back-to-front (or front to back) with GL_BLEND enabled and the corresponding BlendFunction. Is my understanding correct? Are there any detailed tutorials on this? I would appreciate any hints.
Advertisement
Quote:Original post by xinvar
My objective is to display many objects in the scene, some transparent, some not. I read the NeHe tutorial and searched this forum (and google of course) but wasn't lucky enough. Basically I already know that I would need to display the opaque objects first, then transparent objects with depth test enabled but depth buffer writing disabled.

It doesn't really matter whether depth buffer writing is enabled, since you're drawing back-to-front. Also, you don't HAVE to draw all the opaque objects first; it just helps increase efficiency by reducing either overdraw or sorting time.
Quote:I also need to sort all vertices of transparent objects and display them back-to-front (or front to back) with GL_BLEND enabled and the corresponding BlendFunction.

You need to sort the faces, not the vertices. Sorting the vertices will have a rather bizarre effect if you're using them in triangle strips or something. Otherwise, yeah, you've got it pretty much the same.
Thanks a lot for the quick answer, Sneftel!

Quote:It doesn't really matter whether depth buffer writing is enabled, since you're drawing back-to-front.

That's the point! Actually I was wondering why none of the information I read talked about disabling depth buffer writing.

Quote:Also, you don't HAVE to draw all the opaque objects first; it just helps increase efficiency by reducing either overdraw or sorting time.


Can I draw all transparent objects then some opaque objects? Say when I draw an opaque object that happens to be in between of two transparent objects, since depth writing wasn't disable when I drew the transparent objects, this opaque object would be totally occluded by the front transparent object. But the desired fact is to see-through the transparent to the opaque object.

Quote:You need to sort the faces, not the vertices. Sorting the vertices will have a rather bizarre effect if you're using them in triangle strips or something. Otherwise, yeah, you've got it pretty much the same.


How can I sort faces? What if two faces intersect?
Quote:Original post by xinvar
Can I draw all transparent objects then some opaque objects? Say when I draw an opaque object that happens to be in between of two transparent objects, since depth writing wasn't disable when I drew the transparent objects, this opaque object would be totally occluded by the front transparent object. But the desired fact is to see-through the transparent to the opaque object.

If you aren't drawing back-to-front, you need to use Z-writing. If you are drawing back-to-front, you don't need to use Z-writing. I'm not sure what your line of thought here is.

Quote:How can I sort faces? What if two faces intersect?
There's no good way to deal with intersecting faces in a one-pass situation. Luckily, situations where partially transparent faces intersect and actually matter are rare. If you absolutely need this, check out "depth peeling".
Quote:If you aren't drawing back-to-front, you need to use Z-writing. If you are drawing back-to-front, you don't need to use Z-writing. I'm not sure what your line of thought here is.


Okay I see your point here.

Quote:There's no good way to deal with intersecting faces in a one-pass situation. Luckily, situations where partially transparent faces intersect and actually matter are rare. If you absolutely need this, check out "depth peeling".


Here's a simple question: I have two (big) quads with texture, both of them are transparent. They intersect in the middle. I could display each quad as two seperate quads (so in total I would have 4 quads) then sort them. Is there a better way to do this?
Yes, you can tesselate them so that they no longer intersect. The "better" method (doesn't involve tesselation, which is slow, but does involve multiple passes, which is also slow) is, as I mentioned, depth peeling. Depth peeling basically allows you to draw transparent objects without sorting.
Quote:Original post by Sneftel
Also, you don't HAVE to draw all the opaque objects first; it just helps increase efficiency by reducing either overdraw or sorting time.


I am pretty sure that in order for transperancy to be rendered correctly, you have to draw the transparent objects last in back-to-front order.
Yep, you're right. you do.

...what was your point? I think we're saying the same thing. If you want, you can sort the opaque objects along with the transparent ones; if not, you have to render them all before the transparent ones.
Quote:Original post by Sneftel
If you want, you can sort the opaque objects along with the transparent ones;


I sorta didn't catch that point.
Ahh, got it. Yeah, I should have been clearer about that.

This topic is closed to new replies.

Advertisement