Author Topic: Voxel Engine  (Read 11509 times)

0 Members and 1 Guest are viewing this topic.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Voxel Engine
« on: June 21, 2011 »
I'm releasing the source code for my voxel engine. It currently uses quadtree subsampling to reduce the number of rays being cast, and the fast voxel traversal algorithm to accelerate those rays which are cast. I'm planning to take on the sparse voxel octree traversal approach if I can manage to pull it off. I'm fairly happy with this as it stands, there are a few things not yet implemented correctly, such as texture mapping in such a way so as to take advantage of the quadtree subsampling, and a proper link list that would allow shapes other than spheres. Still I would like to share the source with others who have some interest in voxels. Voxels are the future make no doubt about it. Polygons have had their day.

Edit - Texture mapping now works better, managed to increase the resolution with no loss in speed. Maximum number of shapes increased to 256. Limited support for discs, capsules and cylinders.
« Last Edit: June 23, 2011 by rain_storm »

Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 976
  • Karma: 258
    • View Profile
Re: Voxel Engine
« Reply #1 on: June 21, 2011 »
This looks interesting! Doesn't work properly for me though.  :-\  See attached screenshot.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Voxel Engine
« Reply #2 on: June 21, 2011 »
It works well here - the source is very nicely set out too.

K+ Thanks for sharing.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4379
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Voxel Engine
« Reply #3 on: June 21, 2011 »
That looks fantastic. K++, mate  :clap:
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Voxel Engine
« Reply #4 on: June 21, 2011 »
Awesome work!
Someday I need to start learning this kind of thing. :goodpost:
Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 976
  • Karma: 258
    • View Profile
Re: Voxel Engine
« Reply #5 on: June 21, 2011 »
I know my PC is shite, no need to rub it in you lot!  :P
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Voxel Engine
« Reply #6 on: June 21, 2011 »
Doesn't work on mine :(

2GHZ
3GB RAM
GEFORCE 9600M GT 512MB

WINDOW 7

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1150
  • Karma: 174
    • View Profile
    • Raizor's Dev Blog
Re: Voxel Engine
« Reply #7 on: June 21, 2011 »
This looks interesting! Doesn't work properly for me though.  :-\  See attached screenshot.

Same for me on Win7 x64 with a GeForce GTS 250

Looks cool though, even if it is a bit screwed up here.
raizor

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Voxel Engine
« Reply #8 on: June 21, 2011 »
I get the same results only when I set the screen resolution to 800x600. Perhaps this is an issue with StretchDIBits at certain resolutions? For some weird reason clearing the pixel buffer seems to help, why is beyond me as the engine writes a colour to every single pixel each frame. Anyways I have an OpenGL workaround using glDrawPixel that might fix the issue...

WARNING : DO NOT RUN FROM INSIDE THE ZIP, EXTRACT IT FIRST!
the program searches for a file named world.bin in the current directory, if it is not found the program generates a world and writes it to disk. This causes a hang if its being run from within the zip file.


Edit - Attachment removed it didn't fix the issue. First post updated with the proper fix
« Last Edit: June 22, 2011 by rain_storm »

Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 976
  • Karma: 258
    • View Profile
Re: Voxel Engine
« Reply #9 on: June 21, 2011 »
Sorry mate no luck with the OpenGL version here, just a black screen. The normal version looks slightly better though. My resolution is 1440x900. Maybe this is a Nvidia issue since I also got a GeForce?
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Voxel Engine
« Reply #10 on: June 21, 2011 »
Excellent.......

One things thought....the open gl wouldnt run on mine but when I click on NO for Opengl then it run Great!

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1190
  • Karma: 228
    • View Profile
    • Homepage
Re: Voxel Engine
« Reply #11 on: June 21, 2011 »
Awesome stuff, love voxels, started a thread about them on gamedev.net a few years back, to ask why I never see them used, even though I knew some impressive voxel demos. I believe the conclusion was that it takes too much memory...?

When I think about voxels I think about Commanche (helicopter DOS game), with exceptionally cool voxel terrains. I don't see why this game isn't bested yet (to my knowledge), all hardware components have improved over the years and commanche looks good to me even today (screeny). Also Ken Silvermans voxlap ran silky smooth on my hardware at least 3 years back.

Cool post rain_storm, new exe worked for me, awesome work!
What do you say is holding voxels back?
« Last Edit: June 21, 2011 by Kirl »
www.kirl.nl
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Voxel Engine
« Reply #12 on: June 22, 2011 »
Nice one, shame not working to well on mine XP Pro, Nvidia  :telloff: (Nvidia have a lot to answer for in my book)
Thanks for sharing  ;D

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Voxel Engine
« Reply #13 on: June 22, 2011 »
@Kirl
What's been holding voxels back? In my opinion it was a combination of memory footprint, processing power and lack of support from Graphic card vendors.

Nowadays theres more than enough processing power, the above engine is completely software rendered but there are raycasters implemented entirely on the GPU with an order of magnitude in increased power.

Memory footprint is no longer an issue. The sparse octree traversal algorithm is like the google search engine of voxel traversal. Only a tiny subset of the world needs to be physically defined. Any vast empty regions become compressed into a single integer. On the other hand any vast regions entirely made up of a single colour are also compressed into a single integer. This leaves a lot of room for fine detail where its needed. Traversal is also an order of magnitude faster than the meathod I used here. So you have massive terrains with a level of detail not possible with polygons, using an algorithm that runs at real time on todays hardware.

There's nothing holding it back anymore.

@Peeps who are having render issues
The problem is that the initial quadtree subdivision is performed according to the aspect ratio, which forces each block to be a perfect square...

Code: [Select]
    // quadtree subdivision...
    int S = Canvas.Width / max(Screen.AspectX, 1);
    for (int y = 0; y < Screen.AspectY; y++)
    for (int x = 0; x < Screen.AspectX; x++) QuadTree(x*S, y*S, S);

While further quadtree subdivisions are always into 4x4 squares. Which gives a loss in precision if the initial squares are not powers of two...

Code: [Select]
    s = s/2;
    QuadTree(x,   y,   s);
    QuadTree(x+s, y,   s);
    QuadTree(x,   y+s, s);
    QuadTree(x+s, y+s, s);

I think the solution is something like this...

Code: [Select]
    temp = s/2;
    if (temp*2 == s) {
        s = s/2;
        QuadTree(x,   y,   s);
        QuadTree(x+s, y,   s);
        QuadTree(x,   y+s, s);
        QuadTree(x+s, y+s, s);
    } else {
        // sub divide properly...
    }
but its not that easy. The method I use for subdividing requires getting the greatest common divisor of the width and the height. But these are perfect squares. The greatest common divisor is the same as the size. Besides this is an important recursive function I would rather perform the extra overhead outside of this. And ensure that the initial squares are always powers of two. Anybody know how to do that?

Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1190
  • Karma: 228
    • View Profile
    • Homepage
Re: Voxel Engine
« Reply #14 on: June 22, 2011 »
There's nothing holding it back anymore.
So where are the big studio games, like the endless fps's that all boast destructable terrain? I can see a lot of strategic potential in a dynamic environment that retains it's volume. So wherever you dig/carve/blast/whatever, the rubble remains. I know little to nothing about the technical difficulties, but it seems as easy as emptying one cluster of voxels and filling another.

Actually, I just want to see a 3d digdug game! :)

www.kirl.nl
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Voxel Engine
« Reply #15 on: June 22, 2011 »
This is some duct tape programming but hey it works, and I can't think of an elegant solution that doesn't require rewriting half the code. See first post for the fix

The voxel games will come, just as soon as the majority of the market all have genaral purpose graphic processors. At the moment you really need that level of processing power to outshine the ploygon based engines. Although Minecraft is a great example of what the current mid range PC is capable of.

« Last Edit: June 22, 2011 by rain_storm »

Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 976
  • Karma: 258
    • View Profile
Re: Voxel Engine
« Reply #16 on: June 22, 2011 »
Cool, works like a charm now! I'll have a deeper look. Thanks for the fix!  :clap:
Challenge Trophies Won:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1150
  • Karma: 174
    • View Profile
    • Raizor's Dev Blog
Re: Voxel Engine
« Reply #17 on: June 22, 2011 »
Cool, works like a charm now! I'll have a deeper look. Thanks for the fix!  :clap:

Works for me too now. Looks really good too.
raizor

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Voxel Engine
« Reply #18 on: June 23, 2011 »
Updated - Quadtree subsampling now works with texture mapping, Added extra shapes, now it supports discs, spheres, capsules and cylinders, and increased the maximum number of shapes to 256.

These extra shapes are only partially implemented. Collision detection is still performed as though all shapes were spheres. So there may be some overlap between shapes. Also the objects are not yet added to the link list based on their volume this can cause artifacts where parts of a shape are not displayed correctly.
« Last Edit: June 23, 2011 by rain_storm »

Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1190
  • Karma: 228
    • View Profile
    • Homepage
Re: Voxel Engine
« Reply #19 on: June 23, 2011 »
Very cool stuff, love flying around the cave like environments and losing all track of up/down. How about some destructible voxels?
www.kirl.nl
Challenge Trophies Won: