This page has been translated automatically.
Programming
Fundamentals
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

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:

  1. 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).
  2. Create a base material declaration in the created material library.
  3. Specify a set of shaders - either combine existing shaders or write your own ones.
  4. Depending on the set of shaders, add required textures, parameters, and states to the declaration.
  5. 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.

  1. Declare the XML file and material library.

    Source code (XML)
    <?xml version="1.0" encoding="utf-8"?>
    <materials version="2.0" editable="0">
     ...
    </materials>

    Check the materials element for the details.

  2. Declare the material.

    Source code (XML)
    <material name="mesh_base" editable="0" parameters_prefix="m" defines="VERTEX_ATTRIBUTE_GEOMETRY">
     ...
    </material>

    Check the material element for the details.

  3. Specify shaders.

    Source code (XML)
    <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.

  4. Specify material states.

    Source code (XML)
    <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.

  5. Set parameters.

    Source code (XML)
    <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.

  6. Specify textures.

    Source code (XML)
    <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.

  7. Set bindings.

    Source code (XML)
    <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.

Last update: 2017-07-03
Build: ()