Voxel Engine and Optimization

komorra picture komorra · Oct 12, 2011 · Viewed 10.6k times · Source

Recently I've started developing voxel engine. What I need is only colorful voxels without texture, but at very large amount (much smaller than minecraft) - and the question is how to draw the scene very fast? I'm using c#/xna but this is in my opinion not very important in this case, let's talk about general cases. Look at these two games:

  1. http://www.youtube.com/watch?v=EKdRri5jSMs
  2. http://www.youtube.com/watch?v=in0bavLJ8KQ

Especially I think video number 2 represents great optimization methods (my gfx card starts choking just at 192 x 192 x 64) How they achieve this?

What i would to have in the engine:

  • colorful voxels without texture, but shaded
    • many, many voxels, say minimum 512 x 512 x 128 to achieve something like video #2
    • shadows (smooth shadows will be great but this is not necessary)
    • optional: dynamic lighting (for example from fireballs flying, which light up near voxel structures)
    • framerate minimum 40 FPS
    • camera have 3 ways of freedom (move in x-axis, move in y-axis, move in z-axis), no camera rotation is needed
    • finally optional feature may be Depth of Field (it will be sweet ^^ )

What optimization I have already know:

  • remove unseen voxels that resides inside voxel structure (covered from six directions by other voxels)
    • remove unseen faces of voxels - because camera have no rotation and always look aslant forward like in TPP games, so if we divide screen by vertical cut, left voxels and right voxels will show only 3 faces
    • keep voxels in Dictionary instead of 3-dimensional array - jumping through array of size 512 x 512 x 128 takes miliseconds which is unacceptable - but dictionary int:color where int describes packed 3D position is much much faster
    • use instancing where applciable
    • occluding? (how to do this?)
    • space dividing / octtree (is it good idea?)

I'll be very thankful if someone give me a tip how to improve existing optimizations listed above or can share ideas of new improvements. Thanks

Answer

David Williams picture David Williams · Oct 12, 2011

1) Voxatron uses a software renderer rather than the GPU. You can read some details about it if you read the comments in this blog post:

http://www.lexaloffle.com/bbs/?tid=201

I haven't looked in detail myself so can't tell you much more than that.

2) I've never played 3D Dot Game Heroes but I don't have any reason to believe it uses voxels at all. I mean, I don't see any cubes being added or deleted. Most likely it is just a static polygon mesh with a nice texture applied.

As for implementing it yourself, do not try to draw the world by rendering cubes as this is very slow. Instead you should process the volume and generate meshes lying on the intersection of solid voxels and empty ones. Break the volume into suitable sized regions (e.g. 32x32x32) and generate a mesh for each.

I have written a book article about this which you might find useful. It's actually about smooth voxel terain but a lot of the priciples stll apply.

You can read it on Google books here: http://books.google.com/books?id=WNfD2u8nIlIC&lpg=PR1&dq=game%20engine%20gems&pg=PA39#v=onepage&q&f=false

And you can find the associated source code here: http://www.thermite3d.org