Billboarded trees
I'm making a map with billboarded trees, it workes great with one tree but with a few trees it looks like this:
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.
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...
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.
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.
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:
every time a drew the trees.
Or should I've sorted it in one of these ways?
But it looked like this(no matter how I sorted them):
The same problem?
What did I do wrong?
Thanks.
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):
The same problem?
What did I do wrong?
Thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement