5
\$\begingroup\$

In a 3D game i have large no. of trees with alpha value. What is the efficient way to draw all? What i tried is Taking every tree as a object and draw according to its z value and using billboarding. But large draw calls, hiting performance.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Where is the bottleneck: on the CPU or the GPU? \$\endgroup\$
    – Tamschi
    Commented Feb 4, 2012 at 13:43

2 Answers 2

4
\$\begingroup\$

You can use geometry instancing to draw a large number of trees in one draw call. (That article is written about Direct3D 9, but the same feature should be available in any 3D graphics API.) That should improve CPU performance, if that's indeed the bottleneck.

If the trees are alpha-blended you still have to sort them back-to-front yourself, though, which can itself be a significant performance cost. There's no good way around the necessity of sorting to get correct rendering with alpha blending (although see this answer for some alternative approaches).

\$\endgroup\$
0
\$\begingroup\$

You can set a maximum draw distance and use it as a limit instead drawing every tree. With Z buffer you can start by drawing the trees closer to your point of view and then move to the farthest trees. Also be sure of not drawing trees or objects if they are outside of your current view. (Culling)

Finally another way to deal with this is not drawing trees that are already hidden by other trees. For that you need to make a vector from the point of view to the target tree and see if there is a tree intersection in the middle. If its true then you don't draw the tree.

I hope I helped.

\$\endgroup\$
3
  • \$\begingroup\$ Occlusion checking between trees won't work, as the textures are at least partially transparent and the target tree is a billboard and not a point. Occlusion checking against other objects may work though. Z-buffer sorting doesn't work properly on semi-transparent pixels, wich is why they must be drawn back to front. Culling is a good idea if you do it before sorting the trees. \$\endgroup\$
    – Tamschi
    Commented Feb 4, 2012 at 16:23
  • \$\begingroup\$ You can try make a "geometric hitbox" using a smaller adjusted area instead using the real tree size for example half of the real size. It isn't the perfect solution but works better than having nothing. That way the partial alpha part of the texture wouldn't make much of difference. Or even instead a using a rectangle you could optimize and use 3 Vectors/Points (triangle) and just check the area "inside" them supposing your trees are triangular ;P this works well on small projects. \$\endgroup\$
    – Navy Seal
    Commented Feb 4, 2012 at 16:37
  • \$\begingroup\$ They will still flicker if it's not exact. Drawing the fully opaque pixels with z-buffer enabled without blending and the partially transparent ones with depth-sorting back to front in a second pass after all opaque geometry was drawn should be more efficient. \$\endgroup\$
    – Tamschi
    Commented Feb 4, 2012 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .