Sign in to follow this  
ayrton2388

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

Recommended Posts

I need some help rendering this model right. It`s 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]http://www.youtube.com/watch?v=phDOAQ27Ocs[/media]

Share this post


Link to post
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 this post


Link to post
Share on other sites
The wonderful Shawn Hargreaves has blogged about this exact issue:

[url="http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx"]http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx[/url]

and here:

[url="http://blogs.msdn.com/b/shawnhar/archive/2011/05/06/antialiasing-alpha-cutouts.aspx"]http://blogs.msdn.com/b/shawnhar/archive/2011/05/06/antialiasing-alpha-cutouts.aspx[/url]

He had another more related post, but I can't seem to find it at the moment.

Share this post


Link to post
Share on other sites
[quote name='andreilng' timestamp='1305811424' post='4812983']
As far as i know , you cant use alpha-testing in XNA 4.0. Am i wrong?
[/quote]

You certainly can, there's an [url="http://msdn.microsoft.com/en-us/library/ff433662.aspx"]AlphaTest[/url] 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 this post


Link to post
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?
It`s 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.

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