#### Archived

This topic is now archived and is closed to further replies.

# Voxels, Voxels, everywhere, and not a one to blit :(

This topic is 5346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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? "And is it right, butterfly, They like you best framed and dried?"

##### Share on other sites
i wonder if bilboarding is the technique you''re looking for.

Its a simple method of taking a flat object in 3d space and rotating it so its always facing the camera.

##### Share on other sites
a nice but limited thing are point sprites (or just points if you dont need textures). you specify the position and opengl will render a square facing the camera.

things you will need:
float quadratic[] = {1.0f, 0.0f, 0.01f};
(you can look up the point parameter extension for the formulas)

glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize);
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize);
(the problem.. the maximum size can make them useless if you need them bigger than possible)

glPointSize(20);
(limit for my radeon 9800 is 64)

##### Share on other sites
quote:
Original post by Karen_Rei
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?

(disclaimer: I dont know a huge amount about the subject at hand so what i say after this could be complete bunk)

The thing is, OpenGL does have a ''draw a 2d shape in 3d-space'' concept, techinicaly speaking drawing a quad, with all its vertices on the same Z-point, would give you that effect.

Assuming that would do the job, would it be possible to use a quad of fixed size and draw them into the scene at the correct z-buffered position, letting the perspectice transformation take care of resizing?
or if not a fixed size, scale the position of the vertices as needed, so your 20*20 block only uses 1 quad taking up the whole 20*20 space?

##### Share on other sites
quote:
Original post by _the_phantom_
The thing is, OpenGL does have a ''draw a 2d shape in 3d-space'' concept, techinicaly speaking drawing a quad, with all its vertices on the same Z-point, would give you that effect.

Unfortunately, that won''t work. If you create a quad with all points having the z coordinate, they won''t all have the same z coordinate after rotation. The key is to have it always have the same z coordinate after rotation.

In reference to the other two posts:

Billboarding is exactly what I''m looking for (albeit, billboards without textures); I should have been more explicit. And those point sprites should do it (although I''ve never even heard of those OpenGL functions before! They''re not in any of my books. Doing a search for them online, I see lots of interesting possibilities for use of them in other applications, such as glowing particle systems, easy visualization of light sources, etc)

Thanks... you showed that you know OpenGL a lot better than I do. I bet this will work. And I should still be able to do it with vertex arrays. Neat I''ll try to get it implemented today. The program is a tesselating LOD renderer which combines height maps and customizable fractal interpolation to allow infinite zoom on objects without loss of detail. I''ve already got it working fairly nicely by connecting the points with polygons, although they really need to be rendered as voxels to get rid of the holes where the polygons don''t meet smoothly and for better performance. Given enough CPU time, it tesselates everything down to about one pixel''s worth on the screen (making it ideal for a voxel-based engine as opposed to a polygon-based one), but it can''t do that instantly, and so when you zoom in rapidly to an object, it needs to be able to render voxels that are larger than one pixel temporarily.

##### Share on other sites
sounds like a situation for points. im not sure if the size limit applies to only point sprites or points in general (though im sure i already ended up with a point filling the whole screen). else you might be limited to "voxels" with a size of 64x64 pixels.
also: some of the functions might/will require using extensions (perfect time to have a look extgl, glee, glew and all the other libs to make life easier)

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009794
• ### Who's Online (See full list)

There are no registered users currently online

×