Game Development Community

Tree leaf translucency problems

by Alex Huck · in Torque Game Engine Advanced · 12/08/2006 (7:15 pm) · 2 replies

I'm having trouble setting up trees translucencyHere is my material for Figure 1:
new Material( Tree )
{
   baseTex[0] = "~/data/shapes/treesComm/tree";
   translucent = true;
   translucentBlendOp = LerpAlpha;
   translucentZWrite = true;
   alphaRef = 255;  // anything below this number is not visible and is not written to zbuffer
};


i11.photobucket.com/albums/a194/Alex_Huck/BadLeaves.png
Here is the code for Figure 2:
new Material( Tree )
{
   baseTex[0] = "~/data/shapes/treesComm/tree";
   translucent = true;
   translucentBlendOp = LerpAlpha;
   translucentZWrite = false;
   alphaRef = 255;  // anything below this number is not visible and is not written to zbuffer
};

(Note the difference in translucentZWrite = false/true;)

i11.photobucket.com/albums/a194/Alex_Huck/BadStump.png
It is not clearly shown here, and is very difficult to take a screen shot of, but it's kind of like a Klein Bottle
It appears that the foremost surface is 100% invisable, instead showing me what's behind it So instead of seeing the trunks foremost trunk texture I see what I'd see if I were looking at it from the opposite side, erh, kind of hard to explain, like the fourth dimension...
The leaves also show in front, however terrain and other objects do not, only other parts of the same model.

So in summary, Zwrite turned on makes the trunk ugly, Zwrite off makes leaves ugly


On a side note I'd like to thank Matthew Jones for his amazingly complete tree pack superb work. It's strange saying this, but there is a major con: It's too cheap (Price-, not quality-wise) :P

-edit- changed IMG tags to image

#1
12/14/2006 (6:29 pm)
Alex - a) please post this kind of thing on the correct forums (private). b) send me the tree, I want to take a look at it.
#2
01/16/2007 (3:34 pm)
Hey Alex, after looking at the tree that you sent me (thanks), I can see what the problem is. The trunk and leaves need to be separate Materials. Since they are the same, it tries to sort overlapping branches and leaves which is just not going to work very well. The trunk and branches need to be a solid Material - this will also improve performance since the GPU won't be blending pixels that don't need blending.

The leaves need translucentZWrite turned on, and a low alphaRef value. The artwork also needs to be set up properly for this effect. The leaves need to be well defined with the alpha channel matching the color channels perfectly. Remember that any alpha value less than what is specified in alphaRef will not be rendered and anything else will be rendered and blended. So if you have "fuzzy" low contrast leaves, then you will get results similar to your first image. Your alpha channel should be high contrast, with the leaf areas pretty much pure white and the non-leaf areas pure black.