Materials

Learn all about using materials on voxels!

Using landscape materials

The fastest way to get started with materials in the plugin is to reuse existing landscape materials.

Create a new Voxel Landscape Material Collection

Assign your landscape material to the Material property:

This popup should appear, click Fix Now. This will replace the layer blend nodes in your material by ones compatible with both Unreal Landscapes and voxels.

On your voxel world, switch to Multi Index and set the collection to the one we just created

You should now see your material on your voxel world!

You can now follow the Painting section of Multi Index Materials!

Use Cases

Colored Material

If you just want your material to be a flat color, you need to use the RGB material config, and set Voxel Material to either:

M_VoxelMaterial_Colors if you want flat shading:

M_VoxelMaterial_Colors_NormalShading if you want a normal shading:

Single Material

If you want your entire world to have a single material, use the RGB material config and set Voxel Material to your material.

Up to 5 smoothly blended materials

If you want to blend a maximum of 5 materials on your entire world, you can use a 5 way blend.

To do so, set your material config to RGB. Then, create a material instance like Examples/Materials/Quixel/MI_VoxelQuixel_FiveWayBlend_Inst'.

To paint, use the Five Way Blend mode:

Up to 256 materials with no blending

If you want to have up to 256 materials with no blending between them, use the Single Index material with a Voxel Basic Material Collection.

  • Set your voxel world material config to Single Index

  • Create a new Voxel Basic Material Collection and set your Voxel World Material Collection to it:

  • Fill it up with materials:

  • To paint a material, use the Single Index paint mode

  • This mode is most useful with the Cubic mode:

Behind the scenes, the voxel meshes are split into multiple sections to render each material.

Because of this, don't paint too many different indices too close to each others, or your draw call count will explode.

Up to 256 materials with max 4 materials blended per voxel

See Multi Index Materials.

UV

Main UV channel

There are three UV modes:

  • Global UVs: U = Global Position X and V = Global Position Y. Useful to quickly test materials without adding some triplanar projection to them, but has issues if your voxels aren't all more or less facing up.

  • Pack WorldUp in UVs: pack the world generator up vector in the UVs. You can recover it like that:

    • X = U

    • Y = V

    • Z = sqrt(1 - U*U - V*V)

Additional UV channels

The plugin also stores additional UV channels in voxel materials. By default, 2 channels are stored. This can be changed in C++ using VOXEL_MATERIAL_ENABLE_UVX in Voxel\Source\Voxel\Public\VoxelUserDefinitions.h.

UV channels can be set in voxel graphs using the following nodes:

In C++, use SetUV_AsFloat. You can then read the values in your material using:

Normal

There are three normal modes:

  • No Normal: no normal are computed except on the chunk borders where they are needed for the transvoxel transitions.

  • Gradient Normal: use the density field gradient to compute the normal. If it doesn’t look good, try to divide the output value your world generator by 5, or use the Set High Resolution Value node in voxel graphs: as the voxel values are clamped between -1 and 1, this allows you to gain some precision that would be lost by the clamping. Relatively expensive if you have a complex world generator.

  • Mesh Normal: compute the normal from the triangles, unless on the chunk borders where gradient normal are used because mesh normal aren’t the same for different chunks.

Tessellation

Tessellation is automatically computed if the material is tessellated.

Tricky details

Tangent Space Normals

Does not apply to Cubic!

Voxel meshes do not have tangents. As such, you can't use Tangent Space Normals. Since these are on by default, you need to disable them in all the materials you will be using on the voxel world:

Additional Data Channels

Single Index only uses the Alpha channel to store the index. You can store a RGB color in the remaining vertex colors.

Voxel Graph Usage

Use the Set Single Index/Add Multi Index/Set Color/Set UV nodes. These nodes are "smart": based on the material config used, they will only set the relevant fields.

Material Collection Helper

As it can be hard to know which material collection index corresponds to which material, you can use:

This will return the index of that material in the active voxel world Material Collection.

C++ Usage

In C++, you can use the FVoxelMaterialBuilder located in VoxelMaterialBuilder.h. First call SetMaterialConfig on it, and then the various edit function (AddMultiIndex etc), and finally Build.

FVoxelMaterialBuilder Builder; Builder.SetMaterialConfig(EVoxelMaterialConfig::MultiIndex); Builder.AddMultiIndex(0, 0.5f); Builder.AddMultiIndex(1, 0.2f); Builder.AddMultiIndex(2, 0.7f); Material = Builder.Build();

Dithering

If you want your chunks to dither properly when changing LOD, you need to set your material Blend Mode to Masked:

and plug the Voxel Opacity material function into the opacity mask output:

Using a different material on sides/top/bottom in Cubic Mode

You might want to use a different material depending on the face in cubic mode.

To do so, tick One Material Per Cube Side in the advanced section of your voxel world Materials category:

Then you'll need to do a bit of math:

  • Tops will have the material with index 3 x Index

  • Sides will have the material with index 3 x Index + 1

  • Bottoms will have the material with index 3 x Index + 2

So for instance, say you want to have:

  • On material index 0 : Grass on top, Dirt on sides and Rock on bottom

  • On material index 1 : Sand on top, Gravel on sides and Rock on bottom

Then you need to use the following indices in your material collection:

  • Index 0 : Grass

  • Index 1 : Dirt

  • Index 2 : Rock

  • Index 3 : Sand

  • Index 4 : Gravel

  • Index 5 : Rock

Last updated