Shader Graph & Custom Shaders Setup

HTrace is compatible with Shader Graph and custom shaders as long as they adhere to the naming conventions used by Unity in its own shaders. If an object using a custom shader or a Shader Graph material is missing from voxelization or appears to have an incorrect diffuse color, it is likely that the issue stems from property naming. This guide outlines how to set up shaders to ensure compatibility with voxelization:

Base Color and Alpha

Each graph or shader must contain a Vector4 property with a Reference named _BaseColor, with the Exposed checkbox set to true. This property represents the color multiplier for the Base Map in the material inspector UI of Unity’s native Lit shader.

This property is essential for making a surface visible during voxelization, as it serves as the final fallback for surface color and alpha if all other properties are absent.

If this color multiplier is irrelevant for your shader, you can set all its four components to 1 and multiply any used (connected to the Master Node) node by it. This way, the shader output remains unaltered, but the property will still be registered.

You can keep this property (or any other property) disconnected from your graph when working in the editor. However, be aware that it may be stripped during the build process.

It is crucial that this property is non-zero in the material UI—specifically, the .wcomponent must not be zero, and at least one of the .xyzcomponents must be non-zero. In other words, a surface will not be voxelized if it is fully transparent or completely black.

Texture & Other Properties

When adding additional properties, ensure that they follow Unity’s naming conventions. For example, a simple Lit shader might include the following properties:

  • _BaseColor: Diffuse color multiplier

  • _BaseColorMap: Diffuse color texture

  • _BaseColorMap_ST: Diffuse color texture tiling (.xy) and offset (.zw)

  • _UVBase: Texture UV channel

Using these properties you can voxelize a textured surface. An example of such shader can be downloaded here:

Complex Shaders

HTrace can support complex shaders with layered texturing and additional custom properties. All natively supported properties and their names can be found in VoxelMaterialEvaluation.hlsl file. You are free to add your own properties and logic there and customize the exiting ones to fit your needs.

The evaluation of certain shader types can be disabled if they are not required. For example, if your project does not utilize Terrain or Terrain Trees, you can disable the evaluation of the TerrainLit and SpeedTree shaders. This can be achieved in the VoxelMaterialEvaluation.hlsl file by flipping the #define toggles of EVALUATE_SHADERNAME to 0. Disabling unnecessary shader evaluations can speed up the voxelization process in certain scenarios.

Last updated