Custom Materials
If for some reason you cannot find the material to inherit or you need a special post-process, there is a way of creating a brand new material. This way is not recommended, as even slight changes in the source code can influence your material and it would not work correctly.
The algorithm of a custom material creation is the following:
- Create a material library - a .mat file in the target directory (all of the Unigine libraries are located in the data/core/materials/default directory).
- Create a base material declaration in the created material library.
- Specify a set of shaders - either combine existing shaders or write your own ones.
- Depending on the set of shaders, add required textures, parameters, and states to the declaration.
- Check, if the new material is loaded and rendered correctly.
As an example, check the base mesh_base material (data/core/materials/default/unigine_mesh.mat). It has two workflows: specular and metalness, contains a huge set of features.
-
Declare the XML file and material library.
<?xml version="1.0" encoding="utf-8"?> <materials version="2.0" editable="0"> ... </materials>
Check the materials element for the details.
-
Declare the material.
<material name="mesh_base" editable="0" parameters_prefix="m" defines="VERTEX_ATTRIBUTE_GEOMETRY"> ... </material>
Check the material element for the details.
Specify shaders.
<shader pass="deferred" object="mesh_static" deferred="1" defines="BASE_DEFERRED" two_sided_defines=",TWO_SIDED" vertex="core/shaders/mesh/opacity/deferred.shader" fragment="core/shaders/mesh/opacity/deferred.shader"/> <shader pass="depth_pre_pass" object="mesh_static" deferred="1" two_sided_defines=",TWO_SIDED" defines="BASE_ALPHA_TEST,TRANSPARENT" transparent_defines=",ALPHA_TEST,TRANSPARENT_BLEND" vertex="core/shaders/mesh/depth_pre_pass.shader" fragment="core/shaders/mesh/depth_pre_pass.shader"/> ...
Check the shader element for the details.
-
Specify material states.
<state name="alpha_fade" defines="name" hidden="1"/> <state name="workflow" items="metalness,specular" defines="items"> <state name="multiple_environment_probes" transparent="2" defines="name">0</state> <state name="specular_map" workflow="0" defines="name" pass_defines="deferred,forward> ...
Check the state element for the details.
-
Set parameters.
<parameter prefix="m" name="material_mask" deferred="1" shared="0" type="expression">0xffffffff</parameter> <parameter name="albedo_color" workflow="0" shared="0" type="color">1.0 1.0 1.0 1.0</parameter> <parameter name="color" type="combiner" albedo_color="XYZW" diffuse_color="XYZW"/> ...
Check the parameter element for the details.
-
Specify textures.
<texture unit="0" name="diffuse" workflow="1" anisotropy="1">core/textures/common/white.dds</texture> <texture unit="0" name="albedo" workflow="1" anisotropy="1">core/textures/common/white.dds</texture> ...
Check the texture element for the details.
-
Set bindings.
<bind object="mesh_cluster" to="mesh_static"/> <bind object="mesh_clutter" to="mesh_static"/> <bind object="mesh_dynamic" to="mesh_static"/> <bind object="mesh_skinned" to="mesh_static"/> ...
Check the bind element for the details.