Sign in to follow this  
Timptation

Noob transparency question

Recommended Posts

It occurs to me that any objects with transparency should be rendered after opaque objects, but the alpha'd objects themselves can't be ordered in a way that the depth test won't block other alpha'd objects behind them. Turning off the test means they'll be drawn over the opaque objects. I could sort the objects myself by Z, but that still leaves objects that are in that classic "X" formation, intersecting through each other. Am I missing something here?

Share this post


Link to post
Share on other sites
The more I think of it I don't think this situation ever comes up in gaming, so perhaps we just do our best to avoid it in the first place. There may not be a simple solution. Lots of people have viewed this thread, and no one seems to have an answer, so I guess I'm not the only one who is at a loss here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Timptation
The more I think of it I don't think this situation ever comes up in gaming, so perhaps we just do our best to avoid it in the first place. There may not be a simple solution. Lots of people have viewed this thread, and no one seems to have an answer, so I guess I'm not the only one who is at a loss here.


You're right, there is no simple solution.

This is the general algorithm:
* Render opaque objects (ideally: front to back)
* Render transparent objects back to front
* Avoid intersecting transparent objects (i.e. X shapes) as much as possible.

If you use transparency to smooth edges (i.e. when rendering leaves and grass), the following algorithm will minimize the artefacts:
* Render opaque objects (ideally: front to back)
* Render the opaque pixels of the transparent objects (in any order, alpha blend off, alpha test to greater equal, alpha reference to 255)
* Render transparent pixels of the transparent objects back to front (alpha blend on, alpha test to less, alpha reference to 255)

Note that you have to render transparent objects twice!

I hope that helps!

Share this post


Link to post
Share on other sites
If you're looking for a way to correctly sort stuff back to front and avoid "X" formations, BSPs are your best friend. X formations aren't a problem as they should be splitted when building the BSP.

Every frame you should traverse the BSP and reorder all transparent triangles back to front. While doing it, avoid useless draw calls. Take also care when choosing the splitting plane, as the worst case scenario is a long list of triangles.

I could be wrong but in general there's no clean solution for transparency. You would need some kind of deep z buffer to correctly support transparency. Unluckly no hardware supports that.

If you have to render a transparent object made up of 20k tris, to create and traverse a BSP is an huge waste of resources. It would be better to draw the backfaces and then the front faces.

On the other hand if your scene is an apartment whose walls are made of glass, a BSP is your best friend.

Another solution is to look at depth peeling: http://developer.nvidia.com/object/Interactive_Order_Transparency.html

But this couldn't be the faster way to draw stuff, being a multipass algorithm... ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this