[XNA ]Drawing the alpha-blended leafs of a 3d tree. Video inside

This topic is 2563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I need some help rendering this model right. Its a palm tree, made of a single mesh.
I am using BlendState.AlphaBlend before drawing it, but it looks wrong. I know that transparent models should be ordered and all, but since all the leaves are on a single mesh, how can i render it correctly? Here is a short video, so you can see for yourself.

[media]
[/media]

Share on other sites
The easiest solution is to use alpha-testing instead of alpha blending.

Share on other sites
As far as i know , you cant use alpha-testing in XNA 4.0. Am i wrong?

Share on other sites
Hi there. You will run into performance problem if you make your trees this way. You should split the tree into a trunk mesh and use quads for leaves. Then you will want to also use instancing. Look up the dx sdks island instance sample.

Share on other sites

As far as i know , you cant use alpha-testing in XNA 4.0. Am i wrong?

You certainly can, there's an AlphaTest effect built in for it. Or do the alpha testing in your own shader (it's shader-based in 4.0, like clipping planes).

As for using it, I think the biggest thing you have to worry about is the aliasing. You get a freebie in terms of not having to order it (since the pixels that are rejected are simply rejected, rather than the pixel being kept and blended with whats underneath it), but you may have ugly cut outs. But if you use pre-multiplied alpha you can reduce those artifacts (as described by the links Moe posted).

It seems Shawn is posting a lot about anti-aliasing these days, heh.

Share on other sites
Thank you for your replies. I really appreciate it.

I was thinking about using a two pass rendering technique for now.

* Pass 1: draw the solid part: alpha blending disabled, alpha test set to only accept the 100% opaque areas, and depth buffer enabled
* Pass 2: draw the fringes: alpha blending enabled, alpha test set to only accept pixels with alpha < 1, depth buffer enabled, depth writes disabled

Would this work in my case?
Its not hard to write that shader, i can do it, but i cant texture these tree models right in my custom shader yet, since they have 2-3 textures, and there`s just 1 mesh. I will sort that out somehow, but i wanna know if im going in a right direction.

• 10
• 16
• 9
• 13
• 41