Jump to content
  • Advertisement
Sign in to follow this  
daniel_i_l

Billboarded trees

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!