Jump to content


Coding Performance Question


6 replies to this topic

#1 HackMaul

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2009 - 01:52 PM

I have a 3D terrain with sprites for foliage. On my terrain I have close to 20K sprites. It looks great, but it kills performance. I have broken up the list into quads, so I don't have to go through them all every time. But there is no getting around the fact that every frame I have to go through this huge list and check each location to see if it's drawn and then draw it. It's a pretty free form camera, so you can look off into the distance, move around, up, down, etc.

Right now I have a quad map which says whether that section was drawn or not. So for each drawn quad I go through the vector of trees and have to render/check every one.

I am wondering if someone knows of a better way to handle this situation, I hope that I have explained enough.

Thanks,

#2 Sol_HSA

    Senior Member

  • Members
  • PipPipPipPip
  • 517 posts
  • LocationNowhere whenever

Posted 04 February 2009 - 02:51 PM

A little background, like which API and platform you're using, and which principal extensions in case of OpenGL..
http://iki.fi/sol - my schtuphh

#3 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 04 February 2009 - 03:03 PM

Sol_HSA is correct that we need a little more info.

Look into octrees and associated algos (like c-buffers) for controlling your visibility determinations. Also, take a read through: http://www.devmaster...s/graphics_alg/

Also, look here for a collection of papers:
http://www.cgg.cvut....embers/bittner/

#4 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 04 February 2009 - 03:46 PM

It sounds like you're determining the visibility of each terrain quad invidually and then draw them?

The issue with that is that every draw call has some overhead. So often it's faster to draw 1000 polygons at once than to draw 5 times 100 polyons. There's a famous article by NVIDIA called Batch, Batch, Batch that explains the details.

#5 HackMaul

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2009 - 05:26 PM

Thank you for the responses. I'll make sure to follow up those links.

It's C++ and std::vector, one for the quad tree mapping and one list of trees in each smallest quad section. The quads are determined to be visible or not when the terrain is drawn. So I only go through the list of trees for the valid quads. Since my camera is so free form, there are a lot of quads visible. One of the issues is just going through so many trees for each frame. Like I stated, it's a 20k list that I have to traverse each frame.

I was actually looking for some data structure ideas if there are any. This is all in DirectX.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 04 February 2009 - 06:29 PM

Are you rendering every tree with its own draw call? If so, you should batch them together as Nick mentioned. Also try using instancing if you're in DirectX 9 or 10.

You are doing visibility determination recursively, correct? I.e. checking visibility at the root node, then proceeding to its children only if it can't be trivially accepted or rejected, etc. I assume you are, though it's not 100% clear from what you've said. Anyway, when you accept a node at a high level you should be able to render all the trees in the node at once, without needing to traverse the whole list.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 HackMaul

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2009 - 08:16 PM

It's directx 9 and I will definately do some research into that batch thing. That sounds like just the type of thing I was looking for, so it's great that this forum stepped up. I really appreciate it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users