Jump to content
  • Advertisement
Sign in to follow this  

Transparency and sorting

This topic is 4829 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! I've been looking into this topic for a while now, but I haven't found any good answers - just the same answers which don't help all that much. When rendering a partially transparent object, you would first render the opaque polys with Z read and write enabled, and then render the transparent polys *sorted* back to front with Z read enabled and Z write disabled. right so far? Then here comes the problems. 1: When sorting the polygons you need to pretransform the vertices. This must(?) be done in software which will waste CPU power (since it could be done by the GPU). Can this be done on the GPU in some way? 2: Sorting by averaging the Z-values of the polygon's vertices will not give perfect results. There are many times when there will be visible errors. 3: Sorting polygons and rendering back to front will result in massive changing of textures and shaders. 4: (Not that important to me - but interesting) Sorting the polygons in software will not give correct results when using vertex shaders.. So I guess my question is: How can I best render transparent polygons? I guess I can use BSP trees for static scenery, but what about dynamic models? what if your scene consists of 50 transparent metaballs, 1000 opaque boxes and alot of different particle systems. How do you render this in the correct order? The warcraft 3 models contain transparent textures. Any idea about how blizzard did it? Thaks in advance ;)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by pim
Hi!
I've been looking into this topic for a while now, but I haven't found any good answers - just the same answers which don't help all that much.

When rendering a partially transparent object, you would first render the opaque polys with Z read and write enabled, and then render the transparent polys *sorted* back to front with Z read enabled and Z write disabled.

right so far? Then here comes the problems.

1:
When sorting the polygons you need to pretransform the vertices. This must(?) be done in software which will waste CPU power (since it could be done by the GPU). Can this be done on the GPU in some way?

2:
Sorting by averaging the Z-values of the polygon's vertices will not give perfect results. There are many times when there will be visible errors.

3:
Sorting polygons and rendering back to front will result in massive changing of textures and shaders.

4: (Not that important to me - but interesting)
Sorting the polygons in software will not give correct results when using vertex shaders..

So I guess my question is: How can I best render transparent polygons?
I guess I can use BSP trees for static scenery, but what about dynamic models? what if your scene consists of 50 transparent metaballs, 1000 opaque boxes and alot of different particle systems. How do you render this in the correct order?

The warcraft 3 models contain transparent textures. Any idea about how blizzard did it?

Thaks in advance ;)


For 1 and 2, I think the usual way to sort is by distance from the camera. So there's no need to transform any vertices, just make sure the objects and camera are all specified in the same coordinate space, which is simple because everything is usually stored in world space to begin with.

For 3, yeah the state switches could be rough. I don't know any way around them, but I don't have much experience with it either so maybe someone knows a way. With that said, it shouldn't be too big a hit anyway because there usually aren't too many transparent/translucent objects in view at any given time.

I'm not quite sure what you mean by 4, care to elaborate?

As for particle systems, you don't need to sort any that are additively blended, which many are.

EDIT: That is, you don't need to sort each individual particle in an additively blended system. You still need to sort the entire system along with other non-opaque stuff.

Share this post


Link to post
Share on other sites
With number 4 I mean that vertex shaders might change the position of the vertex. But I guess this can be sorted with order independent transparency.

Never thought of sorting by distance from camera :P ..guess I'm too locked up in how I did it in my software rasterizer om my 486 :P

But there's still the problem with mid Z sorting... any comment on how to handle that?

Share this post


Link to post
Share on other sites
Quote:
With number 4 I mean that vertex shaders might change the position of the vertex. But I guess this can be sorted with order independent transparency.

Ah okay, gotcha.

I think for most programs sorting by just the object's position (as in, not sorting each vertex of each object) is what is done. There will be artifacts with intersecting objects, but for games it's not that big a deal since they are generally pretty fast-paced. Also, since most objects in a game will have collision detection, they won't be intersecting too much to begin with.
Quote:
But there's still the problem with mid Z sorting... any comment on how to handle that?

Unfortunately I'm not too sure about that, sorry. But again, unless you need a lot of graphical accuracy you usually won't need to sort per-vertex.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!