This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Плагины
Форматы файлов
Материалы и шейдеры
Rebuilding the Engine Tools
Интерфейс пользователя (GUI)
Двойная точность координат
API
Animations-Related Classes
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
VR-Related Classes
Работа с контентом
Оптимизация контента
Материалы
Визуальный редактор материалов
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Учебные материалы

Кастомизированные материалы

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) материал - это manual материал , реализованный с использованием XML в соответствии с форматом базового (base) или пользовательского (user) файла материалов. И базовый, и пользовательский материалы могут быть кастомизируемыми.

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. Создайте файл материала *.basemat в целевом каталоге (все базовые материалы Unigine находятся в каталоге data/core/materials/default).
  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>
    {
    	/* ... */
    }
    Примечание
    As any manual material, the base material doesn't need the GUID. It will be generated in run-time by its name.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.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.

    Примечание
    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.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.
    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.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.
    Реализуйте базовый материал в соответствии с форматом файла базового материала в созданном файле *.basemat.
    Примечание
    As any manual material, the base material doesn't need the GUID. It will be generated in run-time by its name.Как и любой другой материал руководства, базовый материал не требует GUID . Он будет сгенерирован во время выполнения по своему имени.

    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.При реализации пользовательского базового материала вы можете установить флаг editable на 1 : это позволит вам настроить материал через Редактор материалов , чтобы получить желаемый визуальный эффект.

    Примечание
    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.Несмотря на то, что базовый материал может стать редактируемым, вы не можете сохранить изменения, внесенные в него через Редактор материалов, поэтому вам следует вручную перенести полученные значения в файл *.basemat.
  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.Check the pass ULON node for the details.

    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.Check the state element for the details.

      Check the state element for the details.
      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.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.Check the parameter element for the details.

      Check the parameter 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.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.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.Check the bind element for the details.

      Check the bind 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.Check the bind element for the details.

    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.Check the state element for the details.

    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.Check the parameter element for the details.

    Check the parameter element for the details.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.Check the bind element for the details.

    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.В качестве примера проверьте базовый материал mesh_base (data/core/materials/default/mesh/mesh_base.basemat). Имеет два рабочих процесса: зеркальность и металличность, содержит огромный набор функций.

  1. Объявите XML-файл и базовый материал.
    Исходный код (XML)
    <?xml version="1.0" encoding="utf-8"?>
    <base_material version="2.0" name="mesh_base" editable="0" parameters_prefix="m" defines="VERTEX_ATTRIBUTE_GEOMETRY">
    ...
    </base_material>

    Подробности смотрите в элементе base_material .

  2. Укажите шейдеры.
    Исходный код (XML)
    <shader pass="deferred" node="object_mesh_static"
    	deferred="1"
    	defines="BASE_DEFERRED"
    	two_sided_defines=",TWO_SIDED"
    	transparent_defines=",ALPHA_TEST,TRANSPARENT_BLEND"
    	vertex="core/shaders/mesh/opacity/deferred.shader"
    	fragment="core/shaders/mesh/opacity/deferred.shader"/>
    		
    <shader pass="depth_pre_pass" node="object_mesh_static"
    	deferred="1"
    	two_sided_defines=",TWO_SIDED"
    	defines="BASE_ALPHA_TEST"
    	transparent_defines=",ALPHA_TEST,TRANSPARENT_BLEND"
    	vertex="core/shaders/mesh/depth_pre_pass.shader"
    	fragment="core/shaders/mesh/depth_pre_pass.shader"/>s
     ...

    Check the pass ULON node for the details.Подробности смотрите в элементе shader.

  3. 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.Check the state element for the details.

    Check the state element for the details.
    Укажите состояния материала.
    Исходный код (XML)
    <state name="ambient_light" hidden="1">1</state>
    <state name="alpha_fade"	defines="name"	hidden="1"/>
    <state name="skinned" defines="name"	hidden="1"/>
    <state name="spline" defines="name"	hidden="1"/>
    <group name="Default">
    	<state name="workflow" items="metalness,specular" defines="items"/>
    	<state name="deferred" title="Deferred Buffers" tooltip="Deferred buffers rendering">1</state>
    	<state name="multiple_environment_probes" transparent="2" defines="name">0</state>
    </group>
     ...

    Check the state element for the details.Подробности смотрите в элементе state .

  4. 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.Check the parameter element for the details.

    Check the parameter element for the details.
    Задайте параметры.
    Исходный код (XML)
    <group name="Default">
    	<parameter name="material_mask" deferred="1"	shared="0" type="expression" widget="mask24">0xffffffff</parameter>
    </group>
    
    <group name="Base">
    	<parameter name="albedo_color" workflow="0" shared="0" type="color" title="Albedo"			tooltip="Albedo multiplier">1.0 1.0 1.0 1.0</parameter>
    	<parameter name="metalness" workflow="0"	shared="0" type="slider" tooltip="Metalness multiplier">0.0</parameter>
    	<parameter name="roughness" workflow="0" shared="0" type="slider" tooltip="Roughness multiplier">1.0</parameter>
    	<parameter name="specular" workflow="0" shared="0" type="slider"	title="Specular" tooltip="Specular multiplier">0.5</parameter>
    	...
    	<parameter name="triplanar_blend" base_mapping="2" type="slider" title="Triplanar blend" tooltip="Triplanar">0.5</parameter>
    </group>
     ...

    Check the parameter element for the details.Подробности смотрите в элементе parameter .

  5. Исходный код (XML)
    <texture unit="0" name="diffuse"	workflow="1" anisotropy="1" group="Base" tooltip="Diffuse texture, alpha channel is detail texturing modulation">core/textures/common/white.dds</texture>
    <texture unit="0" name="albedo" workflow="0" anisotropy="1" group="Base"	tooltip="Albedo texture">core/textures/common/white.dds</texture>
     ...

    Check the texture element for the details.Подробности смотрите в элементе texture .

  6. 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.Check the bind element for the details.

    Check the bind element for the details.
    Установитe привязки.
    Исходный код (XML)
    <bind node="object_mesh_cluster" to="object_mesh_static" defines="USE_CLUTTER_CLUSTER_PARAMETERS"/>
    <bind node="object_mesh_clutter" to="object_mesh_static" defines="USE_CLUTTER_CLUSTER_PARAMETERS"/>
    <bind node="object_mesh_dynamic" to="object_mesh_static"/>
    <bind node="object_mesh_skinned" to="object_mesh_static"/>
    ...

    Check the bind element for the details.Подробности смотрите в элементе bind.

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).Настраиваемый пользовательский материал похож на настраиваемый базовый материал за исключением того, что такой материал является иерархическим: он имеет родительский материал и относится к базовому материалу. Как и любой другой материал руководства, пользовательский материал пользователя не может быть переименован, а его родительский элемент не может быть изменен. Также не будут сохранены изменения параметров такого материала через Редактор материалов (даже если установлен флаг editable).

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.В файле *.mat хранится имя пользовательского материала. Однако его дочерние материалы могут хранить ссылку на него на основе имени или GUID . GUID для такого материала будет создан во время выполнения с использованием его имени.

The algorithm of custom user material creation is the following:Алгоритм создания нестандартных пользовательских материалов следующий:

  1. Create a *.mat material file in the target directory.Создайте файл материала *.mat в целевом каталоге.
  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.
    Примечание
    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.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.
    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.
    Реализуйте пользовательский материал в соответствии с форматом файла материала в созданном файле *.mat. Как и любой другой материал руководства, пользовательский материал не требует GUID .
    Примечание
    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.Укажите атрибут manual для настраиваемого материала. В противном случае материал не будет загружен, так как он будет рассматриваться как пользовательский материал времени выполнения без GUID.

In the example below, the user material is inherited from the mesh_base material and overrides its parameters:В приведенном ниже примере пользовательский материал наследуется от материала mesh_base и имеет приоритет над его параметрами:

Исходный код (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>
Последнее обновление: 09.11.2022
Build: ()