This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
Setting Up Properties
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
Extending Editor Functionality
嵌入式节点类型
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

定制材料

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.自定义资料是根据基础或用户资料文件格式使用XML实现的手动资料。基本资料和用户资料都可以是自定义资料。

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).在目标目录中创建一个*.basemat材质文件(所有Unigine基础资料都位于data/core/materials/default目录中)。
  2. Implement the base material according to the base material file format in the created *.basemat file.
    注意
    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 1: 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 1: 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 1: 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 1: 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 - either combine existing shaders or write your own ones.指定一组着色器-合并现有着色器或编写自己的着色器。
  4. Depending on the set of shaders, add required textures, parameters, and states to the base material.根据着色器集,将所需的纹理,参数和状态添加到基础材料。
  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. Declare the XML file and the base material.
    源代码 (XML)
    <?xml version="1.0" encoding="utf-8"?>
    <base_material name="mesh_base" editable="0" parameters_prefix="m" defines="VERTEX_ATTRIBUTE_GEOMETRY">
    ...
    </base_material>

    Check the base_material element for the details.Check the base_material element for the details.

    Check the base_material element for the details.
    声明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>

    Check the base_material element for the details.检查 base_material 元素以获取详细信息。

  2. Specify shaders.
    源代码 (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 shader element for the details.Check the shader element for the details.

    Check the shader element for the details.
    指定着色器。
    源代码 (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 shader element for the details.检查shader元素以获取详细信息。

  3. Specify material states.
    源代码 (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.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.
    源代码 (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.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.
    源代码 (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.Check the bind element for the details.

    Check the bind element for the details.
    设置绑定。
    源代码 (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>
最新更新: 2021-04-09
Build: ()