Jump to content

Voxel terrain


Recommended Posts

Just a little preview of something I am working on... an infinite deformable voxel terrain.

Still lots to fix for now though... I need to move the noise processing into a web worker which I'm finding tricky and for some reason the part of the terrain that starts behind the camera seems to be in eternal darkness :P 

It does run at 60fps and 4k resolution on my machine, but it has some nasty slowdowns when loading new chunks and my guess is it won't run too well on slow machines yet.

I am also struggling to get nice shadows on the terrain... I guess we need CSM to do this properly because the terrain is so large. 


Link to comment
Share on other sites

34 minutes ago, Deltakosh said:

Wooot! Would love to try it

Soon! Right now I have implemented workers, but the terrain is loading multiple times because the rest of my code isn't thread safe :P

@Deltakosh Any idea how long before we can have CSM shadows? Maybe it could be something worked on for 2.4? 

Link to comment
Share on other sites

  • 2 weeks later...

A little update...

I've completely replaced the meshing algorithm, so instead of dual marching cubes its now using naive surface nets. That has dramatically improved the performance so I can now render right into the far distance and still run at 60fps.

I'm thinking of replacing the material shader - at the moment I'm using the triplanar material from the materials library but it seems to have some problems  (at least in my usage case).

After that, the next step is to make the terrain deformable.


Link to comment
Share on other sites

Ok, so, teach us stuff, Dal! 

Hmm.  :)  (thanks for blazing trails with BabylonJS, by the way).  Umm... so a "voxel"... is like a cubical tower... with a potentially-angled top face? 

Is a voxel top face always 2 triangles?  Or can a voxel top be 8 triangles (4 squares)?  12 triangles?  16?  Or are 8, 12, 16 considered a "herd" of voxels?  A covey?  A flock?   Floxels?  :D

And, umm, what the heck is smoothing your landscape (first picture) so nicely?  A shader?  It's not blocky at all, but it looks a little "smeary".  Still cool.

Anyway, it's not your job to teach us about voxels.  I read a bit about the pros and cons... and it sure sounds like a method that has plenty of applications.  Procedural, eh?  (abils to be infinite).  Nice.  That could be done with standard tri-mesh, too, though, I suspect. 

You sound like you know what you're doing, Dal.  I bet you will do procedural grounds of BOTH kind, eh?  (beg beg)  heh.

Cool project, Dal.  As far as Cascaded Shadow Maps (I looked it up for the youngsters)... be patient.  The delay is usually good news.  It might mean that "the big dogs" are looking at CSM and making evil plans to implement it.  But maybe not.  :)  Good luck on your project.. keep us posted.

Link to comment
Share on other sites

It works in much the same way as the minecraft-style cube voxels, but instead of just drawing triangles to represent the faces of each cube (each square face being made up of 2 right-angled triangles) it instead uses a clever formula to work out how much of the surface passes through the cube and draws only the polygons for the point where we cross from air to solid.  This blog explains it better than I ever could: http://0fps.net/2012/07/12/smooth-voxel-terrain-part-2/

I'm no mathematician - I didn't invent the system, I just did some research into the different methods and read some papers, and I found Mikola Lysenko's nice blog. He presents his own method (so its not patented) and some  MIT licensed sample code there in javascript which I've modified and integrated with BABYLON.

The terrain painting is done using the triplanar shader from the Babylon materials library, although I am having issues with it painting the area that starts behind the camera in complete blackness... I haven't yet figured out what causes that.

This currently uses perlin noise to generate the terrain and it is chunked, so it's fully infinite,


Things on my todo list for this ( they might not all happen)

- Better noise (more natural terrain)

- Collision and picking - In theory this might already work, as I've extended GroundMesh but I need to check it.

- Editing (digging holes, raise, lower, flattening, maybe some erosion tools)

- Heightmap loading - I'd like to be able to use a heightmap as well as noise to get a more natural look.

- Moving the loading of new chunks to a worker thread (already partly done)

- Better material... I might need a more advanced triplanar shader. 

- Biomes - I'd like to be able to have grassland, snow, desert etc. regions that blend together.

- Saving - I want to be able to save the edits to the terrain so that the world is persistent. 


Things I am hoping others will work on to make this look good in the end:

- CSM shadows

- Better outdoor lighting..  maybe some sort of global illumination

- Better SSAO - the current one causes a textile effect and is VERY slow. I think @Luaacro is planning something for that.

- Better other post effects. Most of the ones we have seem to be unacceptably slow in large open world scenes. I'm hoping we'll see speed improvements as the engine matures and people can implement more advanced post shaders in the longer term now that we can use WebGL 2.0 features.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...