Sign in to follow this  
Alaric

[.net] [XNA] Alpha Blending Issue

Recommended Posts

hi, I'm trying to build a "forest walkthrough" in XNA.(Just a little bit of background on my project) I'm starting out using the tree that was included with the ".OBJ Model Viewer" submission by "agamerguy" on the MSDN forums. The original app only supports the loading of a model at the world origin and allows rotation about the object in the y axis. This obviously is no good for a walkthrough simulation, so I altered the classes to support independent movement of the "avatar." After I got this working, I started loading other trees on the screen, to see how they would act. After I loaded them, I noticed that something didn't quite look right, and I'm pretty sure it has to do with my Alpha Blending. The leaves of each tree are a single alpha texture (png) that is applied to the front side as well as the back side of the "leaves.obj" for each tree. The problem that I am noticing is that a single texture can only accept the alpha of the next texture "behind" it. It completely excludes everything behind the next nearest texture. For example, if I have a tree located in a position such that a tree is directly in line with it (so that if you looked in a straight line, you would see the leaves at the front of the nearest tree, and in the transparent portion of the texture: the leaves at the back of the nearest tree; the leaves at the front of the far tree; the leaves at the backside of the far tree) I see the leaves directly in front of me, and the leaves at the back of the tree, but no further blending occurs. Is there anyone who knows of a way to achieve the blending that I desire? How do I "start at the back" of the screen and blend my way forward to the "front" of the screen?

Share this post


Link to post
Share on other sites
If you're using an order-dependant blending function (like you are already) then to get correct results you must sort your polys and draw them back to front, otherwise you'll get artifacts caused by semi-transparent pixels writing to the depth buffer.

Of course, doing a full sort every frame is a pain, IMHO you'd be better off not blending but instead using alpha-testing. That gives you a binary on/off for the tree leaves, and while you might get jaggier edges you won't have to sort and can draw them in any order (which means you can have tons of trees).

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