UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
Setting Up Properties
照明
Landscape Tool
Sandworm (Experimental)
使用编辑器工具执行特定任务
Extending Editor Functionality
嵌入式节点类型
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
Usage Examples
UnigineScript
C++
C#
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

UUSL GBuffer结构

G-buffer is a series of textures where all the visible information is written: albedo color, normals, lightmap, etc. G-buffer is used for deferred rendering pipeline. G缓冲区是一系列纹理,其中写入了所有可见信息:反照率颜色,法线,光照贴图等。G缓冲区用于延期渲染管道

UUSL has a handy GBuffer structure to fill it in the shader's code. UUSL具有方便的GBuffer结构以将其填充到着色器的代码中。

注意
Since main workflow in UNIGINE is metalness, it has different structure of G-buffer than specular workflow has.由于UNIGINE中的主要工作流程是金属性,因此它的G缓冲区结构与镜面工作流程不同。

GBuffer TexturesGBuffer纹理#

GBuffer has the following set of textures: GBuffer具有以下纹理集:

纹理名称 描述
Albedo RGBA8 RGB - albedo value.
A - occlusion value.
RGB -反照率值。
A -遮挡值。
Shading RGBA8 R - metalness value.
G - F0 (specular) value.
B - translucent value.
A - microfiber value.
R -金属度值。
G -F0(镜面)值。
B -半透明值。
A -超细纤维值。
Normal RGBA8 RGB - normal value.
A - roughness value.
RGB -正常值。
A -粗糙度值。
Velocity RG16F RG - pixel displacement value (XY coordinates). RG -像素位移值(XY坐标)。
Material Mask R32U R - material mask value. R -材质蒙版值。
Lightmap RG11B10F RGB - lightmap value. RGB -光照贴图值。
Features RGBA8 R - bevel value. R -斜角值。

Channels of these textures fill corresponding fields of the GBuffer structure.这些纹理的通道填充GBuffer结构的相应字段。

UUSL
struct GBuffer {
	float3	albedo;
	float	transparent;
	
	float	metalness;
	float	roughness;
	float	f0;
	float	microfiber;
	
	float3	normal;
	float	translucent;
	
	float2	velocity;
	
	float3	lightmap;
	float	occlusion;
	
	float	bevel;
	
	int		material_mask;
};

Specular G-buffer struct has different fields: Specular G-buffer struct具有不同的字段:

UUSL
struct GBufferSpecular {
	float3	diffuse;
	float	transparent;
		
	float3	specular;
	float	gloss;
	float	microfiber;
		
	float3	normal;
	float	translucent;
		
	float2	velocity;
		
	float3	lightmap;
	float	occlusion;
		
	float	bevel;
		
	int		material_mask;
};

To convert Specular G-buffer to Metalness G-buffer, use specularToMetalness() function.要将Specular G-buffer转换为Metalness G-buffer,请使用specularToMetalness()函数。

GBuffer FunctionsGBuffer功能#

GBuffer GBufferDefault ( ) #

Default constructor for GBuffer structure for metalness workflow. It creates an instance with default (not null) values.金属性工作流程的GBuffer结构的默认构造函数。它使用默认值(非null)创建一个实例。

返回值

GBuffer structure with default (not null) values.具有默认值(非null)的GBuffer结构。

GBufferSpecular GBufferSpecularDefault ( ) #

Constructor for GBuffferSpecular structure for specular workflow. It creates an instance with default (not null) values. GBufffer的构造函数,用于镜面反射工作流程。它使用默认值(非null)创建一个实例。

返回值

GBufferSpecular structure with default (not null) values. GBufferSpecular结构,具有默认值(非null)。

void shadingGBuffer ( inout GBuffer gbuffer, float3 view ) #

Adds a view-dependent shading to the gbuffer.将与视图相关的阴影添加到gbuffer。

参数

  • inout GBuffer gbuffer - GBuffer instance. GBuffer实例。
  • float3 view - View vector.查看向量。

void shadingGBuffer ( inout GBuffer gbuffer ) #

Adds a shading which is dependent on material parameters.添加依赖于材质参数的阴影。

参数

  • inout GBuffer gbuffer - GBuffer instance. GBuffer实例。

GBuffer specularToMetalness ( GBufferSpecular gbuffer ) #

Converts given specular GBufferSpecular to metalness Gbuffer.将给定的镜面反射GBufferSpecular转换为金属度Gbuffer。

参数

  • GBufferSpecular gbuffer - Specular GBufferSpecular instance to be converted.高光GBuffer要转换的高光实例。

返回值

Metalness Gbuffer instance. Metalness Gbuffer实例。

void setGBuffer ( GBuffer gbuffer ) #

Sets GBuffer values by using corresponding values of given GBuffer instance.通过使用给定GBuffer实例的相应值来设置GBuffer值。

参数

  • GBuffer gbuffer - GBuffer instance with necessary values to be set. GBuffer实例,需要设置必要的值。

void setGBuffer ( GBufferSpecular gbuffer ) #

Sets GBuffer values by using corresponding values of given GBufferSpecular instance.
Inside this method specularToMetalness() is called.
通过使用给定GBufferSpecular实例的相应值来设置GBuffer值。
在此方法中 specularToMetalness() 被调用。

参数

  • GBufferSpecular gbuffer - GBufferSpecular instance with necessary values to be set. GBufferSpecular实例,需要设置必要的值。

void loadGBufferAlbedo ( inout GBuffer gbuffer, TEXTURE_IN TEX_ALBEDO, float2 uv ) #

Loads albedo texture values (albedo color and occlusion) to GBuffer.将反照率纹理值(反照率颜色和遮挡)加载到GBuffer。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_ALBEDO - Albedo texture.反照率纹理。
  • float2 uv - UV coordinates. UV坐标。

void loadGBufferShading ( inout GBuffer gbuffer, TEXTURE_IN TEX_SHADING, float2 uv ) #

Loads shading texture values (metalness, f0, translucence, microfiber) to GBuffer.将阴影纹理值(金属度,f0,半透明,超细纤维)加载到GBuffer。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_SHADING - Shading texture.阴影纹理。
  • float2 uv - UV coordinates. UV坐标。

void loadGBufferNormal ( inout GBuffer gbuffer, TEXTURE_IN TEX_NORMAL, float2 uv ) #

Loads normal texture values (normal and roughness) to GBuffer.将正常的纹理值(normal和粗糙度)加载到GBuffer。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_NORMAL - Normal texture.普通纹理。
  • float2 uv - UV coordinates. UV坐标。

void loadGBufferLightMap ( inout GBuffer gbuffer, TEXTURE_IN TEX_LIGHTMAP, float2 uv ) #

Loads lightmap texture values to passed GBuffer instance.将光照贴图纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_LIGHTMAP - Lightmap texture.光照贴图纹理。
  • float2 uv - UV coordinates. UV坐标。

void loadGBufferVelocity ( inout GBuffer gbuffer, TEXTURE_IN TEX_VELOCITY, float2 uv ) #

Loads velocity texture values to passed GBuffer instance.将速度纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_VELOCITY - Velocity texture.速度纹理。
  • float2 uv - UV coordinates. UV坐标。

void loadGBufferMaterialMask ( inout GBuffer gbuffer, TEXTURE_IN_UINT TEX_MATERIAL_MASK, float2 uv ) #

Loads material mask texture values to passed GBuffer instance.将材质蒙版纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer structure. Values will be written in it. Gbuffer结构。值将写入其中。
  • TEXTURE_IN_UINT TEX_MATERIAL_MASK - Material mask texture.材质蒙版纹理。
  • float2 uv - UV coordinates. UV坐标。

Usage Example使用范例#

Defining the GBuffer Structure定义GBuffer结构#

To use GBuffer structure in your shader's code, you should define and initialize the GBuffer structure by using its constructors. For metalness worlkflow use GBufferDefault() constructor (for specular workflow you should use GBufferSpecular structure and GBufferSpecularDefault() constructor respectively).要在着色器的代码中使用GBuffer结构,应使用其构造函数定义和初始化GBuffer结构。对于金属化的worlkflow,请使用GBufferDefault()构造函数(对于镜面工作流,应分别使用 GBufferSpecular 结构和 GBufferSpecularDefault()构造函数)。

The following example shows the way of creating GBuffer structure for both workflows by using #ifdef #else #endif preprocessor statements.下面的示例演示了使用#ifdef #else #endif预处理程序语句为两个工作流创建GBuffer结构的方法。

UUSL
/* ... */
	#ifdef METALNESS
		GBuffer gbuffer = GBufferDefault();
		#define GBUFFER gbuffer
	#else
		GBufferSpecular gbuffer_s = GBufferSpecularDefault();
		#define GBUFFER gbuffer_s
	#endif
/* ... */
注意
Defining the GBUFFER with #define directive is handy to get access to GBuffer structure, no matter what type of the workflow is used.无论使用哪种类型的工作流程,使用#define指令定义GBUFFER都可以轻松访问GBuffer结构。

Filling the GBuffer Structure填充GBuffer结构#

After defining and initializing the GBuffer structure (like in an example above), you can easily fill the GBuffer's fields. You can fill the specific channel of the GBuffer texture.定义并初始化GBuffer结构后(如上述示例),您可以轻松地填充GBuffer的字段。您可以填充GBuffer纹理的特定通道。

UUSL
/* ... */
	#ifdef METALNESS
		GBUFFER.albedo		= color.rgb;
		GBUFFER.metalness	= shading.r;
		GBUFFER.roughness	= shading.g;
		
	#else
		GBUFFER.diffuse		= color.rgb;
		GBUFFER.specular	= shading.rgb;
		GBUFFER.gloss		= shading.a;
		GBUFFER.microfiber	= m_microfiber;
		
	#endif
/* ... */

Loading Textures to GBuffer Structure将纹理加载到GBuffer结构#

Another way of filling the GBuffer structure is using GBuffer functions for textures loading.填充GBuffer结构的另一种方法是使用GBuffer函数加载纹理。

In case of changing GBuffer structure fields, these loading functions will perform the same function, preventing possible errors during migration to another UNIGINE Engine version.在更改GBuffer结构字段的情况下,这些加载函数将执行相同的功能,从而防止在迁移到另一个UNIGINE Engine版本时可能出现的错误。

UUSL
// initialize textures
/* ... */
INIT_TEXTURE(1,TEX_NORMAL)
INIT_TEXTURE(2,TEX_ALBEDO)
INIT_TEXTURE(3,TEX_SHADING)
/* ... */

/* ... */
GBuffer gbuffer = GBufferDefault();
loadGBufferAlbedo(gbuffer, TEXTURE_OUT(TEX_ALBEDO),uv);
loadGBufferShading(gbuffer, TEXTURE_OUT(TEX_SHADING),uv);
loadGBufferNormal(gbuffer, TEXTURE_OUT(TEX_NORMAL),uv);
/* ... */
最新更新: 11pm30Asia/Novosibirsk-f2020Wed, 11 Nov 2020 13:30:55 +070011pm30