Jump to content

Voxel Madness


Josh

4,503 views

 Share

After three days of intense work, I am proud to show you this amazing screenshot:

Image0.thumb.jpg.a74d9a424e2ce37f0839027bb436cf7f.jpg

What is so special about this image? I am now successfully uploading voxel data to the GPU and writing lighting into another texture, using a texture buffer object to store the voxel positions as unsigned char uvec3s. The gray color is the ambient light term coming from the Blinn-Phong shading used in the GI direct light calculation. The next step is to create a light grid for the clustered forward renderer so that each light can be added to the calculation. Since voxel grids are cubic, I think I can just use the orthographic projection method to split lights up into different cells. In fact, the GI direct light shader actually includes the same lighting shader file that all the model shaders use. Once I have that done, that will be the direct lighting step, and then I can move on to calculating a bounce with cone step tracing.

Clustered forward rendering, real-time global illumination, and physically-based rendering are all going to come together really nicely, but this is definitely one of the hardest features I have ever worked on!

Here are a few wacky screenshots from the last few days.

Why are half my voxels missing?!

Image1.thumb.jpg.4bae3119f7cb8104acc6d1f5355fe4f6.jpg

Why is only one texture layer being written to?!

Image12.thumb.jpg.9fc9bc41bf0dc78e21d19fd19f5146fe.jpg

Ah, finally rendering to six texture layers simultaneously...

Image2.thumb.jpg.162216755b1502426b9dd9008a1431b2.jpg

  • Like 3
 Share

16 Comments


Recommended Comments

Looking awesome, can wait to try it out!  Are the voxels calculated at load time?  How does this work for meshes that are created by code and are edited through out run time?

Link to comment
21 minutes ago, SpiderPig said:

Looking awesome, can wait to try it out!  Are the voxels calculated at load time?  How does this work for meshes that are created by code and are edited through out run time?

I think there’s going to be a cache of static objects, and only the dynamic objects will be recalculated. This is a theme in shadow maps, navmeshes, and GI, so I think there will probably be a command and editor setting to set an entity as static, after which it will be immovable (and more efficient).

  • Upvote 1
Link to comment
1 minute ago, SpiderPig said:

Sounds good.  Will there also be a quality setting?  Like a voxel density or something... I'm just thinking out loud :D

Yes of course. I think there are a lot of places where the quality and speed can be adjusted. If all my ideas work, I do think fast real-time-time reflections of offscreen objects will be possible.

  • Like 2
Link to comment

Well I have a plan to make every single part of the process super fast so I can’t imagine why it would slow down. Will probably require s good card for high resolutions but it should be fast enough for VR.

  • Upvote 1
Link to comment

That's pretty cool!

If I imported a heightmap, will Turbo all me to generate voxel based geo instead of standard geo if desired? Can the voxel geo be modified during runtime (ala Minecraft)?

Link to comment

I think the voxel data Josh  has made is only for lighting calculations and not part of the mesh class... you will probably have to make your own voxel generator for things like terrain, which wouldn't be too hard.

 

Another question for Josh - can the voxel data be instanced along with an Instanced entity?  Or will each instance need recalculating? ?

Link to comment

I’m thinking that each surface will stored a map of cached voxels at each scale that gets requested. Weak pointers will be used so that the caches will be deleted when no longer in use. That way as the GI updates no polygon voxelization will occur after the first time, for the most part.

i can’t think of any part of the routine that will be terribly slow.

  • Thanks 1
Link to comment

Even ray casting a line for speculation reflection can be made fast if the lowest res mipmap is checked first, and then higher res mipmaps are subsequently checked if necessary,  since they basically form an octree.

  • Like 1
Link to comment

Sounds like you've thought of everything ?  How has the shadow distance been affected?  Is there still a limit to how far away it can be shown from the camera?  I'm guessing the further away from the camera the more voxels that need to be checked...?

Link to comment
3 hours ago, SpiderPig said:

Sounds like you've thought of everything ?  How has the shadow distance been affected?  Is there still a limit to how far away it can be shown from the camera?  I'm guessing the further away from the camera the more voxels that need to be checked...?

This has nothing to do with direct lighting. For directional lights I am going to try using a bunch of box lights that fill the visible area. I don’t think this will extend as far as the eye can see but I think it will provide much more efficient texture usage, since cascaded shadow maps have so much wasted space.

The GI will definitely have a limited range, probably using 3-4 cascaded boxes grids around the camera.

  • Like 1
Link to comment

Actually in the case of low density outdoor scenes, I.e. a desert without trees in every area, I think shadows could probably extend forever. Dammit now you have got me thinking about whether it is possible....

  • Haha 1
Link to comment

Either way, Turbo is already a massive improvement on Leadwerks.  It's always fun to see what things might be possible :D

Link to comment
9 hours ago, SpiderPig said:

How has the shadow distance been affected?  Is there still a limit to how far away it can be shown from the camera?

Okay, I thought of something. I think I have a way where we can have directional lights with unlimited shadow distance. Possibly...

  • Upvote 2
Link to comment
Guest
Add a comment...

×   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.

×
×
  • Create New...