Billboarded trees

Started by
19 comments, last by alfith 18 years, 1 month ago
I'm making a map with billboarded trees, it workes great with one tree but with a few trees it looks like this: Image hosting by Photobucket I'm using tga files as the trees with an alpha channal and rendering the trees in blend mode. Why is there that weird color were the trees overlap? Is it a problem with the pictures, the order that I'm drawing, the blendFunc..? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
You either need to sort your tree billboards or using alpha testing.
Author Freeworld3Dhttp://www.freeworld3d.org
The best solution is to sort the tree polygons with relation to the camera, and draw from back-to-front. It's obviously more involved and requires more processing power, though...
cant you just disable depth testing before drawing the trees?
Quote:Original post by Glaiel_Gamer
cant you just disable depth testing before drawing the trees?

Disabling Z compares would actually make the problem worse.

A tree with a farther Z could be drawn on top of a tree with a closer Z. You could potentially see a base of a tree appear in front of tree leaves. :)
Quote:Original post by bpoint
The best solution is to sort the tree polygons with relation to the camera, and draw from back-to-front. It's obviously more involved and requires more processing power, though...


Why not sort front-to-back? Wouldn't that speed up the rendering and depth testing?
Quote:Original post by Dorvo
Why not sort front-to-back? Wouldn't that speed up the rendering and depth testing?

Front-to-back drawing wouldn't give the right results. The pixels on the outside of the tree edges would be blended with the terrain, and not other (potential) trees in the background.

Hence, back-to-front drawing is required.
Front-to-back won't work if you actually use blending.

The traditional way to do billboards is to sort back-to-front, turn off Z write, and keep Z-test on. Then draw them with blending enabled.
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
Front-to-back won't work if you actually use blending.

The traditional way to do billboards is to sort back-to-front, turn off Z write, and keep Z-test on. Then draw them with blending enabled.


Understood. See? You learn something new every day. [grin]
I sorted back to front like this:
struct STree{ VERTEX position; double rotation; double height,width; GLuint tID; STree(double x, double y, double z, double h, double w, GLuint t); void Render();  //overload '<' used for sorting	    friend bool operator<(const STree& lhs, const STree& rhs)	{		return ( (lhs.position.x - Camera.PositionX())*(lhs.position.x - Camera.PositionX())               + (lhs.position.z - Camera.PositionZ())*(lhs.position.z - Camera.PositionZ())               >  (rhs.position.x - Camera.PositionX())*(rhs.position.x - Camera.PositionX())               + (rhs.position.z - Camera.PositionZ())*(rhs.position.z - Camera.PositionZ()) );	}};...sort(Trees.begin(), Trees.end())

every time a drew the trees.
Or should I've sorted it in one of these ways?
friend bool operator<(const STree& lhs, const STree& rhs)	{		return ( (lhs.position.x * Camera.PositionX())               + (lhs.position.z * Camera.PositionZ())               >  (rhs.position.x * Camera.PositionX())               + (rhs.position.z * Camera.PositionZ()) );	}		friend bool operator<(const STree& lhs, const STree& rhs)	{		return ( lhs.position.z               <  rhs.position.z );	}


But it looked like this(no matter how I sorted them):
Image hosting by Photobucket

The same problem?
What did I do wrong?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky

This topic is closed to new replies.

Advertisement