Author Topic: Voxel Graphics Library  (Read 3371 times)

Gothon

  • Newbie
  • *
  • Posts: 8
Voxel Graphics Library
« on: October 02, 2012, 12:11:12 am »
Hello,  I have made a QB64 wrapper for my FreeBASIC Voxel library.  http://vast3d.com/voxelgfx/
You can download the required files here: http://vast3d.com/voxelgfx/bin/VoxelGFX_QB64.zip.

To run this you will need to also have an OpenGL library package set up.  My example program ExLinesQB64.bas uses the UnseenGDK-GL package to setup OpenGL. http://www.qb64.net/forum/index.php?topic=6335.0

Note that this will only run on Windows as it is now.  For this to work on Linux would require acquiring/compiling the needed binaries and also changing the DECLARE LIBRARY references to those libraries in VoxelGFX_QB64.bi.

Also note that because QB64 functions cannot return TYPE structures nor pass them by value, my QB64 wrapper makes use of different syntax than the FreeBASIC version.

Instead of writing:
Code: [Select]
VoxLine Vec3I(1, 2, 3), Vec3I(4, 5, 6)

You must write:
Code: [Select]
V3I 1, 2, 3
V3I 4, 5, 6
VoxLine
or equivalently:
Code: [Select]
V3I 1, 2, 3: V3I 4, 5, 6: VoxLine

However, you still need to create Vec3I variables and pass them to functions that use them to return information like VoxGetVolumeSize, VoxCursorTest, VoxSubCursorTest:
Code: [Select]
Dim Size As Vec3I
VoxGetVolumeSize Size, VOXEL_SCREEN
'Size.X, Size.Y and Size.Z now contain the dimensions of the 'screen' volume.

Omega

  • Sr. Member
  • ****
  • Posts: 406
  • Path finding making a mockery of me..
    • Recall site..
Re: Voxel Graphics Library
« Reply #1 on: October 02, 2012, 02:12:39 am »
I feel it's a bit slower than it should be.
+-30fps... on something the size of a minecraft map.. is that right?
But.. something i'm thinking of using this for.
3D sprites.

Mind explaining more..
Could I make 3D sprites? lets say 64x64x64 drawing multiple sprites..
IDK.. Just a cool idea I had to save time making and animating sprites.
As I could easily import images and convert those to 3d and make a editor for fine tuning VOXEL sprites!! =D

I have no idea where to begin with this.
-https://sites.google.com/site/vrtronics/

 home of ceberon-

Gothon

  • Newbie
  • *
  • Posts: 8
Re: Voxel Graphics Library
« Reply #2 on: October 02, 2012, 10:14:38 am »
I feel it's a bit slower than it should be.
+-30fps... on something the size of a minecraft map.. is that right?
But.. something i'm thinking of using this for.
3D sprites.

Mind explaining more..
Could I make 3D sprites? lets say 64x64x64 drawing multiple sprites..
IDK.. Just a cool idea I had to save time making and animating sprites.
As I could easily import images and convert those to 3d and make a editor for fine tuning VOXEL sprites!! =D

I have no idea where to begin with this.

Yes, sprites are the idea.  The renderer uses only a minimal amount of geometry but because it renders the interior pixels, it can still be slow at high resolutions.   A 256x256x256 voxel screen will actually only have 4*(256+256+256) = 3072 triangular faces (2 on each side of each cross sectional plane), despite being made of 256^3 = 16 million voxels.  However, these faces are all overlapping and covering much of the screen.  The texel transfer rate of video card becomes the dominant factor here.

A better strategy is to make a number of smaller, say 32x32x32 sprites, and render multiple copies of them.  You can use VoxRenderVolume, or VoxRenderSubVolume in conjunction with glTranslate? to accomplish this for example.  Additionally the Volume_Static may be useful if you don't intend to change a model after loading it or generating it.  And of course you can mix conventional OpenGL graphics with voxel sprites.  You can even use the VOXEL_NO??? flags with VoxRender or omit even calling it if you want to control the OpenGL states and matrices yourself.

Still, it is possible to make simple programs based on only a single central volume.  But perhaps the 128x128x128 size I use in the Lines example is too much for some cards.
« Last Edit: October 02, 2012, 11:23:23 am by Gothon »

Gothon

  • Newbie
  • *
  • Posts: 8
Re: Voxel Graphics Library
« Reply #3 on: October 17, 2012, 03:40:51 pm »
Also besides large faces.  There is another bottleneck with higher resolutions to be aware of.  Voxel volumes are edited in system memory and uploaded to video memory for rendering.  Currently the entire volume is re-uploaded on the last VoxVolumeUnlock call.  Since high resolution volumes are large though, this can be a huge amount of data to upload.

I recently upgraded my video card, and the new one can actually handle the large overlapping faces very well even at 512x512x512, but uploading that 8MB of voxel data at 128x128x128 is still time consuming.  To help with this, I now have VSet and VoxLine?? functions using glTexSubImage3D to incrementally update the video memory texture voxel by voxel when the volume is unlocked.

All you have to do is download the new binary file and remove the VoxVolumeLock and VoxVolumeUnlock calls from the example to try this out.  I do warn however that while this will probably make the example faster, it can generate a huge number of glTexSubImage3D calls and will probably be slower in situations where large portions of the volume have changed since the previous frame.
« Last Edit: October 17, 2012, 03:53:03 pm by Gothon »

Omega

  • Sr. Member
  • ****
  • Posts: 406
  • Path finding making a mockery of me..
    • Recall site..
Re: Voxel Graphics Library
« Reply #4 on: October 26, 2012, 10:22:42 pm »
Thanks buddy
Gona screw around with this a bit today.
-https://sites.google.com/site/vrtronics/

 home of ceberon-