0
101 May 19, 2011 at 12:48

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.

Any ideas?

#### 5 Replies

0
101 May 19, 2011 at 14:27

For alphablending to work you would have to sort the triangles, so that is not an option.

Use AlphaTest with a reasonable AlphaRef limit (aka only draw pixels above X alpha)

0
139 May 19, 2011 at 17:06

You could use a modeling tool to split up the leaves into separate pieces that you can then sort (this may not fix the problem 100%). You could use alpha-test as Brac suggested (indeed this is how many, many games draw vegetation). If you’re comfortable with shaders, rendertargets and so forth, you could also explore more advanced techniques such as depth peeling or the newer stochastic transparency.

0
101 May 19, 2011 at 18:37

Thank you for the replies.

Isnt order independent transparency a bit expensive? Anyway, might be a bit out of my league. I did write some basic shaders, but still pretty new to them.

Someone suggested that i should use a two pass rendering technique:

* 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?
EDIT: just tried the default AlphaTestEffect. Its way better, of course, but i still get some pixels wrong. Heres a screen:

http://imageshack.us/f/695/alphacv.jpg/

Again, would that two pass render help here?

0
139 May 19, 2011 at 19:01

That will help somewhat. The sorting will definitely be correct in the opaque areas, but it will still be wrong in the translucent areas. But if the translucent areas are only a thin fringe around the edges of the leaves, it might not be very noticable.

It will also help performance (probably). The two-pass method is likely to be faster than rendering everything transparently because on the second pass, you’ll be getting early-Z-culling from the depth laid down in the first pass. YMMV though.

As for the order-independent techniques, yes they will be more expensive on the GPU. They can still be useful for cases where correctness is a must and per-object or per-poly sorting isn’t going to cut it, or is prohibitively expensive. But it’s just one more tool in the toolbox.

0
101 May 19, 2011 at 19:12

Thank you. I really appreciate your help, guys.
Thanks a lot!

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 theres just 1 mesh. But at least i know im going in a right direction.