Jump to content
  • Advertisement
Sign in to follow this  
LemonBiscuit

[XNA] Rendering alpha blended texture on a 3D model

This topic is 2049 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

Hello,

 

I'm trying to render a tree model in my XNA game.

To do so, I have in my model: 1 mesh for the bark, and several meshes for the leaves.

The leaves are actually transparent textures.

 

Here's what I got when I render it:

 

http://puu.sh/7oN93.jpg

 

As you can see it's all messed up, meshes are not rendered in the good order.

Is there a way to make it work without having to change the render order?

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

When you need is for the "transparent" pixels to not be written to the depth buffer. For that, you'll want to use alpha testing, not alpha blending (unfortunately that means that the transparency is an on/off thing, so you'll get hard edges). The AlphaTestEffect is what you want - or if you're writing your own shader, then use the clip instrinsic to discard pixels below your chosen transparency threshold.

Share this post


Link to post
Share on other sites

alpha blending must be done from back to front (painter's algorithm) to work correctly. 

 

cases where triangle A overlaps B, which overlaps C, which overlaps A, will need to be split up to render correctly.

Share this post


Link to post
Share on other sites

Hello,

 

Thank you for your answers.

 

I'm not using my own shader. I tried to find documentation for AlphaTestEffect, but I really don't understand how to use it...

Share this post


Link to post
Share on other sites

Wherever you're currently using BasicEffect (I'm assuming), switch it to AlphaTestEffect. (For instance, you can set the default effect for a model in your content project, under Content Processor, Default Effect).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!