Overriding default voxel materials

Modified on Thu, 25 Aug 2022 at 11:48 AM

Voxel Play uses a series of custom shaders to render the different voxel types like opaque, cutout (for tree leaves), water, etc. All voxels of the same render type use the same material regardless of the number in the scene. The opaque render type is the most common, used for terrain. It has several attributes like integrated fog and AO.



At some point you will need to render something that requires a custom material. Voxel Play provides two ways to use custom materials:


- Custom voxel types. Choose "Custom (prefab)" from the list above and assign your own prefab. This prefab can use any kind of material/shader and will be instantiated according to the settings (instantiate, GPU instanced drawing direct or indirect, etc.). See Custom Voxel Types section for more details.


- Override Material. Enable this option to assign a custom material to be used with this voxel definition:



The override material option allows you to use a custom material/shader for rendering this voxel. Note that this option only applies to the default render types above except Custom (custom voxels always use the material associated to the custom gameobject or will use a default VP Model material by default). This is an advanced option which requires shader knowledge as you have to provide a compatible material and shader.


Pros/Cons of Custom Voxel types vs Override Material:


Feature
Custom voxel type
Override material
ShapeUses a prefab which can be of any shape/size and can contain anything, including custom scripts, children gameobjects, etc.Cube
Supports integrated FogNoYes
Supports integrated AONoYes
Rendering optionsInstantiate (normal gameobject),
GPU instancing option
Renders as part of the chunk mesh
Supports smooth lightingGameobject requires the script VoxelPlayBehaviour with "Use Voxel Light" enabled.
Yes
Collider supportGameobject can have a custom collider. When GPU instancing option is enabled, Voxel Play can also generate collider data and merge that with the chunk collider avoiding the creation of a gameobject just to hold the collider.
Yes, uses the same chunk collider
Typical usageIdeal for independent objects (vegetation, trees, stairs, windows, doors, custom shapes, rocks, objects, etc.) Ideal for customizing the default shaders
Can be used for large amount of voxels, like terrain
Max number of materials
Unlimited number of custom voxel definitions (each one can use a different material)
A maximum of 16 rendering materials can be used, including the default VP shaders. This means you can create 9 or 10 overriding materials. Use this option only to render massive amount of voxels with a custom material.



Voxel Play provides a few shaders that can be used to override the opaque render type (you can create a material and assign this shader, then use it instead of the default shader):



The example override shaders can be found in Voxel Play/Resources/VoxelPlay/Shaders folder with names VPVoxelTriangleOpaqueWorldSpace***. Technical details about compatible shaders can be found here.


Important: using this Override Material option, you can use your own shaders instead of the default Voxel Play shaders for each one of the render types. However please note that a maximum of 16 different render materials can be used this way (including the default shaders of Voxel Play). You can however use the same rendering material for any number of voxel definitions. If you need to use more custom materials in your world, use Custom Voxel Definitions instead which allows you to use a separate prefab which can use any material.



Check these videos for more details:


Single texture overriding material:


Multi-texture overriding material:




Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article