材质基础
The virtual world, similar to the real world, contains many different objects, and we can see and distinguish them due to the interaction of the their materials with light. It is materials that make objects green, transparent or, for example, mirror-like. PBR (Physically-Based Rendering) system was developed to ensure uniformity of materials and make them look as realistic as possible. This system considers the properties of each material and uses mathematical formulas to accurately simulate how light behaves when it interacts with the object's surface. In other words, it creates a realistic environment where light behaves as it would in the real world. This model is widely used in various engines, including UNIGINE.虚拟世界与现实世界相似,包含许多不同的物体,我们能看见并区分它们是因为其材质与光线的相互作用。正是材质使物体呈现绿色、透明或如镜面般反光。PBR(基于物理的渲染)系统的开发旨在确保材质的一致性并使其尽可能逼真。这个系统考虑每种材质的特性,使用数学公式精确模拟光线与物体表面交互时的行为。换句话说,它创造了一个光线行为与现实世界相同的逼真环境。该模型被广泛应用于各种引擎,包括UNIGINE。
In terms of UNIGINE, a material is a rule defining how the surface (or in some cases a volume) will look like: its color, interaction with lights, reflection and refraction parameters, etc. The material can imitate red plastic, yellow sand, transparent glass, shiny metal, muddy water and much more. The set of basic material properties includes:在UNIGINE中,材质是定义表面(或某些情况下的体积)外观的规则:其颜色、与光线的交互、反射和折射参数等。材质可以模仿红色塑料、黄色沙子、透明玻璃、闪亮金属、浑浊的水等等。基础材质属性集合包括:
- States that specify conditions, based on which the Engine applies corresponding shaders, textures, and parameters. For example, you can set the Water state to enable/disable sea foam. Depending on the selected state (foam / no foam), the engine will choose the required shaders.状态(States):指定引擎根据条件应用相应着色器、纹理和参数的规则。例如可以设置Water状态来启用/禁用海浪泡沫。根据选择的状态(有泡沫/无泡沫),引擎会选择所需的着色器。
-
A set of Textures. As a rule, a base material has several textures. This is caused by the following reasons:纹理 (Textures):通常基础材质具有多个纹理,原因如下:
- Shader may require more than one texture.着色器可能需要多个纹理
- Different rendering stages user different textures.不同渲染阶段使用不同纹理
- A state may require a specific texture.特定状态可能需要特定纹理
- Parameters — arguments passed to the shader that define how the shader will be used.参数(Parameters):传递给着色器的参数,定义着色器的使用方式。
- Shaders — basis of materials, special programs that actually draw the material, taking into account the defined parameters, modes, textures, and so on. Each material has several shaders, and one of them is used depending on the selected mode and stage of drawing. In addition to the basic shader types — vertex, fragment and geometry shaders, there are other types.着色器(Shaders):材质的基础,是实际绘制材质的特殊程序,会考虑定义的参数、模式和纹理等。每个材质都有多个着色器,根据选择的模式和绘制阶段使用其中之一。除了基础着色器类型(顶点、片段和几何着色器)外,还有其他类型。
Materials have limitations in terms of their application to different types of objects: some are used for surfaces of objects that have a defined geometric shape (like a car, a tree or a kitten), some define volumes (clouds), some — volume and surface (water), and some are just projected on any surface, like a spot from a spotlight with a multicolored light filter. Therefore, keep in mind that different types of objects have their own (applicable) materials.材质在应用于不同类型物体时存在限制:有些用于具有明确几何形状的物体表面(如汽车、树木或小猫),有些定义体积(如云朵),有些同时定义体积和表面(如水),还有些只是投射在任何表面上的效果(如带彩色滤光片的聚光灯光斑)。因此请注意,不同类型的物体有其适用的特定材质。
Material Hierarchy材质层级结构#
UNIGINE has its own hierarchical material system. The hierarchy is formed by inheriting one material from another. All properties are passed from the parent to the child and can be overridden (as in object-oriented programming). If any parameter value changes for the parent, it is automatically changed for all its children, except for those in which it was previously overridden (adjusted) manually.UNIGINE拥有其专属的层级化材质系统。该层级结构通过材质间的继承关系形成,所有属性都从父材质传递到子材质,并可被覆写(类似于面向对象编程)。当父材质的参数值发生变更时,该变更会自动应用于所有子材质,除非子材质已手动覆写(调整)过该参数。
For example, Material A has two parameters (Color = Blue and Reflection Coefficient = 1.4), and Material B is inherited from Material A, and its color is changed manually (to Red). When you change the reflection coefficient of Material A to 2.0, Material B will have the following parameters: Color = Red (overridden) and Reflection Coefficient = 2.0 (inherited).例如:材质A拥有两个参数(颜色=蓝色,反射系数=1.4),材质B继承自材质A,且其颜色被手动修改为红色。当你将材质A的反射系数改为2.0时,材质B的参数将变为:颜色=红色(已覆写)和反射系数=2.0(继承自父材质)。
This is very convenient, because by changing one parameter, you can customize several materials at once. For example, a whole group of materials imitating car paint and overriding only the parent's base color can be turned into metallic or matte by changing just a couple of parameters in the parent.这种机制非常便利,因为通过修改单个参数即可同时调整多个材质。例如,通过修改父材质的几个参数,就能将一整组仅覆写父材质基础颜色的汽车漆材质统一改为金属或哑光效果。
Base and User Materials基础材质与用户材质#
In general, materials can be divided into two categories:大体上,材质可以分为两大类:
- Base materials are the basis for all customizable materials in the project. The base material can be implemented by programmers (it can be changed only by editing the text file itself manually, as code), or without code using a special visual editor. The second approach is convenient for 3D artists, because it allows independently implementing almost any functionality. A base material is always at the top of the hierarchy and cannot be inherited from another base material. Base materials have the *.basemat extension. 基础 (base) 材质是项目中所有可定制材质的根基。基础材质可由程序员实现(只能通过手动编辑文本文件来修改,如同代码),也可通过专用可视化编辑器无代码创建。后者对3D美术师更为友好,因其允许自主实现近乎所有功能。基础材质始终位于层级结构顶端,且不能继承自其他基础材质。基础材质使用*.basemat扩展名。
- User materials are the materials inherited from base materials. Their parameters can be customized in the editor, changing the appearance of objects that use them. The set of parameters of a user material cannot differ from its parent, only the values (textures, values, etc.) can be changed. User materials have the *.mat extension.用户 (user) 材质是从基础材质继承而来的材质。其参数可在编辑器中调整,从而改变使用这些材质的物体外观。用户材质的参数集合必须与父材质保持一致,仅能修改具体数值(如纹理、参数值等)。用户材质使用*.mat 扩展名。
Post Effects后期特效#
In addition to the materials that are assigned to the objects directly, there are materials that can be applied to the whole image in order to modify it, like a colored light filter that is placed on the camera lens. They are called post effects because they are applied (overlaid) after the overall picture is already rendered. Post effects allow implementing such visual effects as thermal imaging or night vision.除了直接分配给物体的材质外,还存在可应用于整个画面以进行修改的材质,就像放置在相机镜头上的彩色滤光片。它们被称为后期特效,因为这些效果是在整体画面渲染完成后再叠加应用的。后期特效可实现诸如热成像或夜视仪等视觉效果。
Extending the Set of Materials扩展材质集合#
UNIGINE provides a rich set of built-in base materials out of the box. But no matter how rich the library is, you'll always want to add something and UNIGINE allows that, because the principle of extensibility is the basis of the material system. You can create your own materials that implement almost any functionality in either of the following ways:UNIGINE提供了一套丰富的内置基础材质。但无论材质库多么丰富,你总会想要添加一些内容,而UNIGINE允许这样做,因为可扩展性原则是材质系统的基础。你可以通过以下任一方式创建实现几乎任何功能的自定义材质:
- In the visual editor without code, we will talk about this later.在可视化编辑器中无代码创建(我们稍后将讨论这一点)
- Create your own abstract material and inherit the base material from it. Abstract materials allow you to simplify the programming of shaders and hide the complexity of the functionality implementation. Like abstract classes in object-oriented programming, they serve as a template for defining certain parameters and functions that can be extended later. The abstract material itself cannot be assigned to an object.创建自己的抽象材质,并从中继承基础材质。抽象材质可简化着色器编程并隐藏功能实现的复杂性。就像面向对象编程中的抽象类一样,它们作为模板用于定义可后续扩展的特定参数和函数。抽象材质本身不能直接分配给物体
- Create a custom shader using UUSL.使用UUSL创建自定义着色器
本页面上的信息适用于 UNIGINE 2.20 SDK.