2
\$\begingroup\$

Title says it all.

What's efficient way to draw a lot of textured cubes in XNA4?

\$\endgroup\$
5
  • 6
    \$\begingroup\$ This seems very broad. Have you tried anything yet? Did you try to do it yourself and it's working too slowly? \$\endgroup\$ Aug 5 '11 at 2:23
  • 1
    \$\begingroup\$ How many is "a lot"? A thousand and a million are both "a lot" to draw. Expanding on what Drackir said, what is your current approach and what is wrong with it? \$\endgroup\$ Aug 5 '11 at 3:12
  • \$\begingroup\$ This question is probably a good place to start. \$\endgroup\$ Aug 5 '11 at 6:09
  • \$\begingroup\$ The answer will always boil down to the same thing : Instancing. Whether that's hardware instancing, or shader instancing, or transforming everything on the cpu and cramming it into a big vertex buffer, it'll still be : Instancing. \$\endgroup\$
    – Blecki
    Aug 5 '11 at 12:38
  • \$\begingroup\$ See also \$\endgroup\$ Aug 7 '11 at 5:26
7
\$\begingroup\$

I guess it is for another minecraft-inspired game, so "a lot" means several million cubes :) Well, be it minecraft, warcraft, XNA, OGL or whatever else, the task of drawing "a lot of anything" consists of two parts:

  • Reducing the size of the task.
  • Making the actual drawing efficient.

It's possible to write an entire book about these problem facets, so let's keep it simple.

How to reduce the amount of the cubes you need to worry about? Use octrees and perform frustum culling for visibility determination.

How to optimize the draw method for lots of cubes? Large number of cubes (maybe even all of them depending on your approach) will share the same material, so it will be easy to utilize instancing.

Then again, depending on how much "a lot" actually is, you may want to stop caring about rendering optimizations at all. With the modern hardware you can draw like ten million of textured cubes easily with almost no hassle: just divide them into large chunks and draw with basic batching and a simple index buffer.

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

Have a look at this SunBurn instancing example: http://indiefreaks.com/2011/01/27/hardware-instancing-with-igf-sunburn-rd-part-1/ and then part 2 http://indiefreaks.com/2011/01/28/hardware-instancing-with-igf-sunburn-rd-part-2/ It handles massive amounts of instanced objects.

\$\endgroup\$

You must log in to answer this question.

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