This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Программирование
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
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
CIGI Client Plugin
Rendering-Related Classes
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Hierarchy and Inheritance

In Unigine, materials can form hierarchy. However, there are several rules and constraints that described below and must be taken into account.

Materials Hierarchy

Materials hierarchy forms by inheriting one material from another. A parent material passes its properties to the inherited material so that they can be overridden.

Unigine provides a set of base materials with the built-in shaders which are always at the top of the materials hierarchy. The base materials cannot be organized in hierarchy: no base material can be inherited from another base material. Moreover, properties of the base materials cannot be changed. So, to modify one of the base materials, you should inherit a user material from it: the base material will pass its properties to the inherited material.

However, not only base materials can be used as parent ones. You can inherit a new material from any user material.

Notice
All inherited and non-overridden properties will be updated automatically, if they are updated in the parent material.

The parent of the material can be changed by dragging the material to a new parent.

In this way, there are the following reasons to create materials hierarchy:

  • Inheriting from the base material allows editing its properties via Materials Editor.
  • Inheriting from the user material allows for mass controlling values of multiple materials parameters.

Hierarchy of materials in the Materials Hierarchy Window
Base mesh_base material
Child material inherited from mesh_base

The material ball on the left picture is rendered using the mesh_base base material from the default set of materials. The material ball on the right picture is inherited from mesh_base and has 1 texture changed (the albedo texture). All the other properties are identical to the base material ones.

Materials Loading Order

Materials hierarchy doesn't affect the loading order of materials: on the engine start-up, all materials of the project are loaded, the base materials are loaded first. And since each user material refers to both the parent and the base materials, the base material is used as the parent one until the actual parent is loaded. So, when the application is loaded, all materials existing in the project are presented in the materials hierarchy.

Referring Materials by GUIDs

A GUID (Globally Unique Identifier) is an identifier for a material. The GUID is a 40-character hexadecimal string generated by using the SHA-1 hash algorithm.

Materials hierarchy is based on GUIDs: all materials are referred by GUIDs, even the base and manual ones (the GUIDs for such materials are generated in run-time by their names).

Only the user materials store their GUIDs explicitly: the GUID is generated automatically on user material creation and is written in the *.mat file.

Notice
Each user material created via Material Editor has the GUID.
For example:
Source code (XML)
<material version="2.5.0.2" name="mesh_base_0" guid="3e7f5c9535777e15966cb5f915d25b62620b2bef" parent="401e90ccd85f4f2bb97c19ab9e1351325c4012eb" base_material="mesh_base"/>
The user material GUID is stored in the guid attribute. If the user material is inherited from another user material, it will refer the parent by its GUID (the parent attribute in the example above).

Using GUIDs makes it difficul to edit the user materials manually. For example, to rename such material, it is required to generate a GUID for the new name and replace the current GUID.

For the base and manual materials, the GUIDs are generated in run-time by their names. If the name of such material is changed, the GUID will also be changed. That is why the base and manual materials cannot be renamed in run-time. For the same reason, the *.basemat and *.mat files store their names, not GUIDs. And references to such materials stored in these files are usually name-based too.

Types of Inheritance

As it was mentioned above, the user material can be inherited from the base, user or manual user material. Depending on the type of the parent, the *.mat file will store the reference to it as follows:

  • Parent: base material. The *.mat file stores a GUID of the user material and a name of the base material.
    Source code (XML)
    <material version="2.5.0.2" name="mesh_base_4" guid="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
  • Parent: user material. The *.mat file stores a GUID of the user material, a GUID of the parent material and a name of the base material.
    Source code (XML)
    <material version="2.5.0.2" name="mesh_base_6" guid="9542cd76ae16362527359168ea2e9ff1b42c8c2e" parent="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
  • Parent: manual user material.
    • If the inherited user material is also manual, the *.mat file stores a name of the user material, a name of the parent material and a name of the base material.
      Notice
      Only the manual material can refer to the parent manual material by the name.
      Source code (XML)
      <material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
    • If the inherited user material isn't manual, the *.mat file stores a GUID of the user material, a GUID of the parent material (generated in run-time by its name) and a name of the base material.
      Source code (XML)
      <material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>

Creating a User Material

Unigine provides the huge set of built-in base materials to meet practically all user's demands. So, the fastest and the safest way to create a new material is to create a user material by inheriting it from the base one and adjusting its properties.

Notice
The user material created via Materials Editor in run-time cannot be customized: a set of user material properties cannot differ from properties of the parent (base) material.

To inherit a material, perform the following in the Materials Editor:

  1. Select the base material.
  2. Inherit from this material: click the Inherit button or right-click the material and choose Inherit.

    The new *.mat file that stores a GUID of the new material and a reference to the mesh_base base material will be created. To rename the material, right-click the material and choose Rename: the file will be renamed as well.
  3. Enable properties you want to apply to your material in the States tab of the inherited material.

  4. Replace default textures with your prepared ones in the Textures tab of the inherited material.

  5. Tweak the available parameters in the Parameters tab of the inherited material.

Notice
States, textures and parameters of the base material cannot be changed.
Last update: 10.08.2018
Build: ()