Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
4  
Where is the bottleneck: on the CPU or the GPU? –  Tamschi Feb 4 '12 at 13:43

2 Answers 2

up vote 4 down vote accepted

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).

share|improve this answer

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.

share|improve this answer
    
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. –  Tamschi Feb 4 '12 at 16:23
    
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. –  Navy Seal Feb 4 '12 at 16:37
    
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. –  Tamschi Feb 4 '12 at 16:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.