Sign in to follow this  
dbh

Alpha-Blending Issues [SOLVED]

Recommended Posts

I'm having a few alpha blending issues, and my knees are shaking at the fear of having to sort my render list :D Anyway, let me describe the problem and see if any Dr's can give me a diagnosis. When alphablending a quad (using just xyz and tex coordinates for the FVF, no color tags, or anything special), that quad blends FINE with certain objects, and not so fine with others. In the glitch cases, it appears as if the quad I am blending is completely blocking the objects behind it; I can see the "map/environment" through the quad, so I know the blending is working-- it's just that I can't see objects between that environment layer and the object I am blending. Sounds dangerously like a sort issue, yes? Okay, so if that's the case... where do I go from here? This isn't a shooter, so I'd rather not rewrite my entire rendering engine to work with a tree or any serious culling-- I know how to do that, and perhaps I should have-- but it's late in the game, I'd rather not redesign the whole technical side. If I do need to work on my sorting-- where do I start? Is the general idea: 1. Get distance from camera to every object 2. Sort by distance (far->near). 3. Render from far->near. ? -dbh [Edited by - dbh on September 7, 2005 1:13:07 AM]

Share this post


Link to post
Share on other sites

Sounds like your alpha blended quad has zwrite on (this may or may not be what you want). So if you draw the blended quad before the other objects, it blended with the background, and filled in the zbuffer.

But either way, when you alpha blend, you almost always need some kind of sorting.

There are many ways to do things depeding on what you need. You don't necessarily need to sort every object and especially not if you only rendering a few alpha blended quads that don't overlap.

A simple way to start out is by seperating opaque (non-translucent/transparent) objects from non-opaque. Draw all opaque objects first in any order (since they are opaque you don't have to sort, although modern cards prefer rough front to back sorting if you want to squeeze out all the juice. I wouldn't worry about it till later though).

Then test to see if you can just draw your non-opaque items in any order after opaque. for particles, this may be just fine, or if your quads don't overlap much.

If that fails, see if you always have a set order regardless of camera orient, if so, use that. This can also be generalized by giving groups of transparent objects (or just the objects themselves) a fixed sort number and sorting the groups based on that id.

If that fails, you can try and sort objects via distance to the viewer. You can use bounding box centers, closest face/point, or whatever metric fits for you. Use the easiest that works for you. Note, sometimes people don't do exact sorting by distance for every object, but they place them in buckets (with everything in the same bucket being roughly the same general distance from the camera). This can save some sorting time if you have a large number of objects.

If you haven't noticed the basic point is to try and do as little "work" as possible. This isn't just being lazy, it also tends to be the fastest; and it also means you don't waste time doing work you don't need to. You can also combine all the steps to come up with a system that does as little work as it can unless it absolutely has to do more.

Hope that helps some.


Share this post


Link to post
Share on other sites
I think the z-buffer is what is causing those other objects not to appear, you can turn z-write off but you might get strange results if you don't render your blended objects last.

Somebody [edit: like the post above, doh] that knows more about this than me can give you the details on the best way to sort, but I think the idea is to render your blended objects last, sorted back to front...

Share this post


Link to post
Share on other sites
Extra thanks to both of you... your posts have already put me on the right track. I didn't even consider using cheap methods like that to get the job done.. thanks for the tip, Multisample!

Thanks to you too, MasterWorks... I think I was drawing those blended objects too early, so I'm going to try pushing them to later in the render.

I think, since the camera in my game is always looking down the +y axis (zoomable, and can be moved up and down the z-- just not rotatable)-- I may try sorting by y position first, see what that does. More often than not, that may just do the trick.

Thanks again you too for taking the time to provide me with insight and help instead of just a simple "sort your render"-type posts ;) It does make a difference.

-dbh

Share this post


Link to post
Share on other sites
Just wanted to let you guys know it worked! I sorted my quads by lifetime (they go up, towards the camera the longer they exist) and sorted my enemies by their y-axis values-- and voila! Problem fixed.

Thanks for the help!

-dbh

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