Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Voxel rendering for Godot 4 based on an efficient 2-level DDA algorithm implemented 100% on the GPU as a fragment shader.This approach allows for good performance and opens up the possibility of making runtime changes to voxels at a relatively low cost.Please see the detailed description on GitHub.
Voxel
Voxel rendering addon for Godot 4.0.
Based on an efficient 2-level DDA algorithm, implemented 100% on the GPU as a fragment shader.
This approach allows for good performance and opens up the possibility of making runtime changes to voxels at a relatively low cost.
Detailed documentation in mostly in the shader source files.
Scroll down on this page for screenshots on what's possible.
Example
Open the example scenes:
addons\voxel\Examples\Park
addons\voxel\Examples\TorusBox
There are separate shaders for the opaque, transparent and shadow passes. They are rendered by their own child nodes, the shaders are defined there. GDScript is required only to verify the configuration and set up the child nodes in a consistent way.
Algorithm
The shader is based on a 2-level DDA algorithm, this is also known as raymarching.
From the perspective of the volume the voxels are rendered into is just the simplest possible box mesh. It does not have anything else other than 8 vertices and 12 faces. It does not need UV, nor normals.
Front faces are culled, only the back faces are rendered. It allows for viewing the voxel volume from inside, while still provide full view from the outside.
For each view ray the shader
- map the ray to the voxel box (model space)
- calculate front face intersection from the back one
- walks over the voxel cubes (1st level)
- skip any voxel cubes behind the view plane
- for each voxel cube with any non-empty voxels
- skip any voxels behind the view plane
- call the sampler to determine whether the voxel exists, opaque or transparent
- accumulate transparent voxels along the ray
- stop at the first opaque voxel along the ray
- call the sampler to fetch PBR properties (separate for opaque and transparent)
The opaque, transparent and shadow passes differ, because they do only the processing required for the given pass. Transparent voxels are not rendered to the shadow map, for example.
The DDA algorithm in the shader code is designed to be reusable. It is easy to provide a custom sampler for your specific needs without touching the raymarching algorithm. This way you can change the PBR material of your voxels in any way you want and look up extra information based on the voxel type or position to match your game design goals. What is considered to be opaque voxel can also be customized.
Remarks
Vox import
There was a Vox resource loader, but it got broken by a late Godot beta.
Texture array imports
The texture array import configuration is critical for the shader to accept the textures. If you get rendering errors in the Output tab, then that's the most likely reason.
Transparency
Transparency is not tested with this current project, but worked well before. I will include a test project for transparency later.
The shader implements color filtering with proper transmittance calculation. It is taking the screen texture as the background, which poses some limitations. Color filtering works as expected inside the same voxel volume, but
Incorrect received shadows and lighting
Shadows received by the voxel and the lighting (normals) are incorrect with the current official Godot 4.0 release.
- Reason is detailed in Proposal 1942
- A solution has been proposed in PR 65307
At the time of writing the fix has not been made it into an official Godot release.
Please vote on the above PR and proposal. Thank you!
In order to get proper lighting you need to rebuild Godot with the changes from the above PR merged into the official code. At the time of writing the changes can merge with both the Godot 4.0 code and the current master (4.1).
- Fork the Godot repository (if you haven't yet)
- Create a new branch and switch to it
- Cherry-pick the changes from the above PR's branch
- Build a release version of Godot locally
set PYTHONUNBUFFERED=1
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
scons -j 12 platform=windows target=editor >build.log 2>&1
Customize the -j
parameter to match the number of threads your CPU can run in parallel.
If you have enough free RAM, then it is faster to build Godot on a ramdisk. You can create one using ImDisk.
(It also saves quite a few writes to your NVMe/SSD.)
Don't forget to copy your Godot binary from the ramdisk to your normal disk at the end, ramdisk contents are lost on the next OS reboot.
Plans
- Resurrect the Vox resource loader
- Clean up and add the automated placement of
- Lights to make use of SDFGI
- Occluders to reduce overdraw
- Colliders to enable physics
- Add more examples (PRs are very welcome, I'm not an artist)
Screenshots
Screenshots and videos what this plugin may be able to do later, once I can clean up and add all the GDExtension based C code back to the project which I had to remove.
Voxel asserts used in the tests: Tiny Voxel Dungeon by maxparata
Vox import
Godot (SDFGI, SSAO, Glow) vs. MagicaVoxel rendering: Full resolution
Light placement
Automated placement of light in the cluster centroids of emissive voxels:
Lighting test:
Staircase lights:
Occluders
I made no screenshots of occluder placement, but they work similarly to collider placement.
Colliders, physics
Collider placement
Videos are on OneDrive, because they are big.
Transparent voxels
It actually calculates color transmittance, so colorful glass behaves as expected. Unfortunately there are no colorful shadows. They could be faked with projectors, which should be supported (not tested it yet).
Rendering performance tests
60fps with 64 rooms (geForce RTX 3080Ti)
With automated light placement included (no fps recorded, unfortunately, it was around 30-40):
Fun bugs
A bug resulted in a fancy memory garbage visualizer during shader development:
Voxel rendering for Godot 4 based on an efficient 2-level DDA algorithm implemented 100% on the GPU as a fragment shader.
This approach allows for good performance and opens up the possibility of making runtime changes to voxels at a relatively low cost.
Please see the detailed description on GitHub.
Reviews
Quick Information
Voxel rendering for Godot 4 based on an efficient 2-level DDA algorithm implemented 100% on the GPU as a fragment shader.This approach allows for good performance and opens up the possibility of making runtime changes to voxels at a relatively low cost.Please see the detailed description on GitHub.