Voxel Grid
At the core, this shader turns triangles into cubes. We have various options for you to choose from on how this cubeification happens.
We call these cubes voxels or voxelification as that's the main style of this shader. While it isn't technically a voxel, we try our best to make it look like it.
General Options
Snap to Grid
This feature will make the cubes snap to an invisible grid of a set size. This is what creates that 'voxel' look.
When this is turned on, more grid options become available such as avatar scale awareness and a grid size map.
Grid Size
Determines the size of the grid we'll be snapping the cubes to.
Large values will result in a larger grid, creating less 'snapping' and 'choppiness' but at a cost of feeling less voxelized. The larger the grid the more it looks like there's actually just no grid that we're snapping to.
Smaller values will result in a smaller grid, creating bigger voxels. Decreasing the voxel grid also starts to introduce various optimizations.
You can read up on various optimizations here
Grid Size Map
When the grid size map is turned on, the grid size constant is replaced with a grid size texture map and a min/max grid size.
The grid size texture map is a grayscale map that tells the shader what grid size to use.
- Black values correspond to the minimum grid size.
- White values correspond to the maximum grid sizec.
- Everything in between black and white is a mix of the min/max values. E.g: a half-gray will produce a grid size between min and max.
- Uses UV0.
- Only the 'red' component is used.
This is great for a material that needs to have different grid sizes.
For example we might have a single material that takes up the whole avatar and we want everything to have a grid scale of 128 but we want the eyes to have a grid scale of 256. Instead of separating the eyes into their own material, we can:
- Create a grid size texture with everything black and the eyes set to white.
- Set the min grid size to 128, max grid size to 256
- Slot in our grid size texture. This will result in the body having a grid scale of 128 and the eyes will be 256 on only one material.
ZFighting Fix
During the cubification process, some cubes will end up overlapping. This overlap creates a flickering effect called 'Z-Fighting' which is when two or more faces occupy the same exact space.
When this is set to a non-zero value (ideally one), the shader will try to remove the z-fighting. Currently it does this by offseting each voxel forward/backward by a random small amount. The forward/backward offset is done in such a way that you can barely perceive that there's a slight offset.
Scale Grid with Avatar Size
More information can be found here
Grid Optimization
As an extra optional optimization step, you may bake a grid optimization texture for your avatar. This will give you a performance increase in most scenarios.
Doing The Bake
Simply right-click on an object/avatar that has the voxel materials on it (or has children with voxel materials) and click ValueFactory/Fast Voxel Shader/Bake Optimization Textures
. This will find all voxel materials (as long as they are on the renderers of the objects!), calculate the optimization textures for them and assing them to their materials.
That's it!
Side Effects
- Blendshapes that were hidden when the bake happened will likely not properly work anymore.