This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Rebuilding the Engine 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
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
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 appropriate base material 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 engine source code can influence your material and it would not work correctly.

A custom material is a manual material implemented using XML according to the base or user material file format. Both the base and the user material can be the custom one.

Custom Base Material#

The custom base material is the same as the default one: it is read-only, non-hierarchical, referred by the name and so on.

So, the algorithm of custom base material creation is the following:

  1. Create a *.basemat material file in the target directory (all of the Unigine base materials are located in the data/core/materials/default directory). Check the ULON Base Material File Format article for the details.
  2. Implement the base material according to the base material file format in the created *.basemat file.
    Source code (ULON)
    BaseMaterial mesh_base <node=ObjectMeshStatic editable=true var_prefix=var texture_prefix=tex>
    {
    	/* ... */
    }
    Notice
    As any manual material, the base material doesn't need the GUID. It will be generated in run-time by its name.

    When implementing the custom base material, you can set the editable flag to true: it will allow you to adjust the material via the Materials Editor to get the desired visual effect.

    Notice
    Despite the fact that the base material can become editable, you cannot save changes made to it via the Materials Editor, so you should manually transfer the obtained values to the *.basemat file.
  3. Specify a set of shaders for passes - either combine existing shaders or write your own ones.
    Source code (ULON)
    Pass deferred <defines="BASE_DEFERRED,TWO_SIDED,ALPHA_TEST,TRANSPARENT_BLEND" node=ObjectMeshStatic>
    {
    	Vertex = "core/shaders/mesh/opacity/deferred.shader"
    	Fragment = "core/shaders/mesh/opacity/deferred.shader"
    }
    
    Pass depth_pre_pass <defines="BASE_ALPHA_TEST,TWO_SIDED,ALPHA_TEST,TRANSPARENT_BLEND" node=ObjectMeshStatic>
    {
    	Vertex = "core/shaders/mesh/depth_pre_pass.shader"
    	Fragment = "core/shaders/mesh/depth_pre_pass.shader"
    }

    Check the pass ULON node for the details.

  4. Depending on the set of shaders, add required textures, parameters, and states to the base material:
    • Specify material states.
      Source code (ULON)
      State ambient_light = 1 <hidden = true>
      State alpha_fade <hidden = true>
      State skinned <hidden = true>
      State spline <hidden = true>
      
      Group Default  
      {
      	State workflow <items = ["metalness","specular"]>
      	State deferred = 1 <title = "Deferred Buffers" tooltip = "Deferred buffers rendering">
      	State multiple_environment_probes = 0 if [transparent == 2]
      }

      Check the state element for the details.

    • Set parameters.
      Source code (ULON)
      Group Default  
      {
      	Mask24 material_mask = 0xffffffff <pass = "deferred" shared = false expression = true>
      }	
      
      Group Base
      {
      	Color albedo_color = [1.0 1.0 1.0 1.0] <shared = false title = "Albedo">
      	Slider metalness = 0.0 <shared = false tooltip = "Metalness multiplier">
      	Slider roughness = 1.0 <shared = false tooltip = "Roughness multiplier">
      	Slider specular = 0.5 <shared = false title="Specular" tooltip = "Specular multiplier">
      	Slider triplanar_blendr = 0.5 <shared = false  title = "Triplanar blend" tooltip = "Triplanar">
      }

      Check the parameter element for the details.

    • Add textures.
      Source code (ULON)
      Group Base
      {
      	Texture diffuse = "core/textures/common/white.dds" <unit = 0 anisotropy = true tooltip = "Diffuse texture, alpha channel is detail texturing modulation">
      	Texture albedo = "core/textures/common/white.dds" <unit = 0 anisotropy = true tooltip = "Albedo texture"> 
      }

      Check the texture element for the details.

    • Set bindings.
      Source code (ULON)
      Bind ObjectMeshStatic = ObjectMeshCluster <defines = "USE_CLUTTER_CLUSTER_PARAMETERS">
      Bind ObjectMeshStatic = ObjectMeshClutter <defines = "USE_CLUTTER_CLUSTER_PARAMETERS">
      Bind ObjectMeshStatic = ObjectMeshDynamic 
      Bind ObjectMeshStatic = ObjectMeshSkinned

      Check the bind element for the details.

  5. Check, if the new material is loaded and rendered correctly.

As an example, check the base mesh_base material (data/core/materials/default/mesh/mesh_base.basemat). It has two workflows: specular and metalness, contains a huge set of features.

When the base material is ready, you can use it as any default base material.

Custom User Material#

A custom user material is similar to the custom base material except that such material is hierarchical: it has a parent material and refers to the base material. As any manual material, the custom user material cannot be renamed and its parent cannot be changed. Also changes made to parameters of such material via Materials Editor won't be saved (even if the editable flag is set).

The custom user material is implemented by programmers when it is necessary to create a material without using Materials Editor.

In *.mat file, a name of the custom user material is stored. However, its child materials can store name-based or GUID-based reference to it. A GUID for such material will be generated in run time by using its name.

The algorithm of custom user material creation is the following:

  1. Create a *.mat material file in the target directory.
  2. Implement the user material according to the material file format in the created *.mat file. As any manual material, the custom material doesn't need a GUID.
    Notice
    Specify the manual attribute for the custom material. Otherwise, the material won't be loaded as it will be treated as the run-time user material without the GUID.

In the example below, the user material is inherited from the mesh_base material and overrides its parameters:

Source code (XML)
<?xml version="1.0" encoding="utf-8"?>
<material version="2.5.0.2" name="mesh_base_1" base_material="mesh_base" manual="1">
	<parameter name="albedo_color">0 0 0 0</parameter>
	<parameter name="metalness">1</parameter>
	<parameter name="roughness">0</parameter>
</material>
Last update: 2021-12-13
Build: ()