• Advertisement
Sign in to follow this  

Transparent Objects

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ahh, got it. Yeah, I should have been clearer about that.

Share this post


Link to post
Share on other sites
Quote:
you can sort the opaque objects along with the transparent ones; if not, you have to render them all before the transparent ones.


Sneftel means: Option 1: Sort all objects (opaque + transparent) and render them back-to-front (Technically correct, but sorting opaque objects is not necessary, see Option 2). Option 2: First, Render all opaque objects, Second, sort all transparent objects, Third, render all (sorted) transparent object back-to-front. Option 3: Use depth peeling (doesn't require sorting, but requires multiple-pass).

Thanks Sneftel. One more question about sorting faces: Assuming no two faces intersect, sort all the faces based on the average positions of each face's vertices. Is this algorithm correct?

Share this post


Link to post
Share on other sites
Great, thank you Sneftel. Time to start working now! I also took the time to search the literature (again) and was astonished to find that I didn't know about this wonderful Radix Sort (http://codercorner.com/RadixSortRevisited.htm). I probably won't try depth peeling (don't know vertex/fragment program yet) for now.

Share this post


Link to post
Share on other sites
Quote:
Original post by mossmoss
Save some fill rate by rendering opaque stuff front-to-back with z-test enabled.


Thanks mossmoss. I know I would need to render opaque stuff with z-test enabled, but would front-to-back be better than simply putting everything into the pipeline? I would need to sort them then.

Share this post


Link to post
Share on other sites
Quote:
Original post by xinvar
Quote:
Original post by mossmoss
Save some fill rate by rendering opaque stuff front-to-back with z-test enabled.


Thanks mossmoss. I know I would need to render opaque stuff with z-test enabled, but would front-to-back be better than simply putting everything into the pipeline? I would need to sort them then.


No, you don't need to sort them, z-buffer would take care of it.
The idea -- in my slightly obtuse way of explaining -- was that if you're going to sort translucents back-to-front for rendering purposes, make sure to sort ONLY translucent objects. Back-to-front is worst case for overdraw if using the z-buffer, so don't sort opaque back-to-front. Either sort them front-to-back or not at all (so they're in a "random" order).

Share this post


Link to post
Share on other sites
Quote:
No, you don't need to sort them, z-buffer would take care of it.
u contradict what u said earlier, what u mentioned first is correct
sort the opaque meshes in front to back order (from my testing in my game this gives about 1% increase in FPS (millage will vary of course) so its up to u if its worth it)

Share this post


Link to post
Share on other sites
Quote:

sort the opaque meshes in front to back order (from my testing in my game this gives about 1% increase in FPS (millage will vary of course) so its up to u if its worth it)


xinvar, just to elaborate with regards to performance with sorting opaque meshes front-to-back.

There are several situations here:
1.) you are CPU bound. Sorting anything will aggravate the situation.
2.) you are vertex/memory bandwidth-bound: sorting will have no effect.
3.) you are fill-rate bound (in the case of complex shaders). Sorting front-to-back of your opaque objects will allow early-out in the z test per-pixel which improves performance. If you have a complex scene it may be worth doing a quick z only pass of your opaque objects before rendering your opaque objects.

So, the sorting front-to-back is only good advice if you're fill rate bound on the GPUs that you're targetting.

Share this post


Link to post
Share on other sites
you could use a natural merge sort to take advantage of temporal coherence across frames. A modified byte-based radix sort would also work quite well and if you're using a Client/Server model for your rendering a radix sort would be almost free (do it during submission to the rendering backend).

You also might want to look into deffered shading if your hardware has floating point frame buffer support (GeForce FX/Radeon 9x00/Radeon X600+, but only GeForce 6 series has native 64bit frame blending etc)

Just my 2 cents

Share this post


Link to post
Share on other sites
Thank you FReY for the analysis. My program is actually GPU bounded (without transparent objects), but it's still real-time. I would consider sorting once it passes my okay threshold for fps :-)

Thank you silvermace for the nice suggestions, I would learn a lot from them! My card is Quadro 4400 so I'm free to explore all the possiblities you talked about.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It's true that if you render back to front you don't need to turn off depth writing, BUT if your ordering is not perfect it can help mask the errors.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement