PDA

View Full Version : Voxels in OpenGL :(



Rei
03-04-2004, 07:54 AM
I'm working on a voxel-based 3d engine in OpenGL. I've done voxel engines before in which the graphics library's only job was to blit pixels to the screen - my code did all the 3d math and primitive rendering. However, in the interests of efficiency, I'd like to use OpenGL this time to take advantage of fast routines and hardware acceleration. The problem is, OpenGL doesn't seem to be very aware of concepts related to voxel engines.

For example, regardless of the type of voxel engine (surface rendering, depth rendering, etc), you generally need a method to blit a 2d shape in 3d space. Technologically, this is very simple. Once the points are rotated into the display space, for each point you get the z value, and draw your 2d primitive (generally a square, rectangle, or circle) into the z buffer with all points having the same z depth. Easy - easier than your average 3d polygon draw routine, in fact, and only minimally more complex than even a simple 2d primitive drawing routine. However, for the life of me, I can't think of an efficient way to do that in OpenGL. The only ways I can think of are:

A) Replace each voxel with four 3d coordinates that act as corners to a polygon. Not only do I beforehand have to calculate the proper location of these points so that this new polygon will be centered around this voxel after rotation, but OpenGL has to do 4 times the work of rotating and then has to then do a polygon draw routine in 3d. That'll probably run *slower* than just writing my own routines and going without hardware acceleration.

B) For however much space the voxel would take up on the screen, you blit 3d points using OpenGL. Of course, if your voxel is up close and is taking up 20 by 20 pixels, you're going to need 400 3d points drawn with OpenGL, and the rotating of those points is going to be unbearable. Additionally, you still need to calculate where all those points are.

Both of these options are, quite clearly, unfeasable. Does anyone have any better ideas, or is a voxel-engine writer stuck with writing their own entire unaccelerated rotation and primitive functions for no good reason other than OpenGL doesn't contain a very simple "draw a 2d shape in 3-space" function?

Ideas?

Adrian
03-04-2004, 08:04 AM
Crossposted http://www.gamedev.net/community/forums/topic.asp?topic_id=211221

jwatte
03-04-2004, 08:53 AM
Point sprites might help.

Rei
03-04-2004, 10:06 AM
Thanks, somebody over on gamedev got an answer that should work.