This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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

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 Textures
GBuffer纹理#

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 -斜角值。

Channels of these textures fill the corresponding fields of the GBuffer and GBufferSpecular structures.这些纹理的通道填充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具有不同的字段:

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;
};

要将Specular G-buffer转换为Metalness G-buffer,请使用specularToMetalness()函数。

GBuffer Functions
GBuffer功能#

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 ) #

将与视图相关的阴影添加到gbuffer。

参数

  • inout GBuffer gbuffer - GBuffer实例。
  • float3 view - 查看向量。

void shadingGBuffer ( inout GBuffer gbuffer ) #

添加依赖于材质参数的阴影。

参数

  • inout GBuffer gbuffer - 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 ) #

将光照贴图纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_LIGHTMAP - 光照贴图纹理。
  • float2 uv - UV坐标。

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

将速度纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer结构。值将写入其中。
  • TEXTURE_IN TEX_VELOCITY - 速度纹理。
  • float2 uv - UV坐标。

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

将材质蒙版纹理值加载到传递的GBuffer实例。

参数

  • inout GBuffer gbuffer - Gbuffer结构。值将写入其中。
  • TEXTURE_IN_UINT TEX_MATERIAL_MASK - 材质蒙版纹理。
  • float2 uv - 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);
/* ... */
最新更新: 2024-12-13
Build: ()