This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
VR Development
双精度坐标
应用程序接口
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
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的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). 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.
    设置绑定。
    源代码 (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>
最新更新: 2023-12-19
Build: ()