Jump to content
  • Advertisement
Sign in to follow this  
Alaric

[.net] [XNA] Alpha Blending Issue

This topic is 4275 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'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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!