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
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语义学

Redefined UUSL semantics allows you to create unified input\output shader structures for both graphics APIs.重新定义的UUSL语义使您可以为两个图形API创建统一的输入\输出着色器结构。

Vertex Shader Semantics顶点着色器语义#

Vertex shader semantics contain necessary input and output data for shader. You should initialize variables first and then use them.顶点着色器语义包含着色器必需的输入和输出数据。您应该先初始化变量,然后再使用它们。

UUSL OpenGL Direct3D 描述
INIT_ATTRIBUTE(TYPE,NUM,SEMANTICS) in TYPE s_attribute_ ## NUM; TYPE attribute_ ## NUM : SEMANTICS; Adds a semantic to a vertex shader variable.向顶点着色器变量添加语义。
INIT_OUT(TYPE,NUM) out TYPE s_texcoord_ ## NUM; TYPE data_ ## NUM : TEXCOORD ## NUM; Adds an output data semantic.添加输出数据语义。
INIT_POSITION - float4 position : SV_POSITION; Adds a position system-value semantic.添加位置系统值语义。
INIT_INSTANCE - uint instance : SV_INSTANCEID; Adds a per-instance identifier system-value semantic.添加每个实例标识符的系统值语义。

Here is an example of vertex shader input and output structures:以下是顶点着色器输入和输出结构的示例:

UUSL
// Input vertex data
STRUCT(VERTEX_IN)
	INIT_ATTRIBUTE(float4,0,POSITION)	// Vertex position
	INIT_ATTRIBUTE(float4,1,TEXCOORD0)	// Vertex texcoord (uv)
	INIT_ATTRIBUTE(float4,2,TEXCOORD1)	// Vertex basis tangent
	INIT_ATTRIBUTE(float4,3,TEXCOORD2)	// Vertex color
END

// Our output vertex data
STRUCT(VERTEX_OUT)
	INIT_POSITION		// Out projected position
	INIT_OUT(float4,0)	// Texcoord (uv)
	INIT_OUT(float3,1)	// Vertex direction
END

Use the following pre-defined variables to use the input\output vertex shader semantics:使用以下预定义变量来使用输入\输出顶点着色器语义:

UUSL OpenGL Direct3D 描述
IN_INSTANCE gl_InstanceID input.instance An input per-instance identifier system-value variable.输入的每个实例标识符系统值变量。
IN_ATTRIBUTE(NUM) s_attribute_ ## NUM input.attribute_ ## NUM An input shader variable.输入着色器变量。
OUT_DATA(NUM) s_texcoord_ ## NUM output.data_ ## NUM An output texture coordinates variable.输出纹理坐标变量。
OUT_POSITION gl_Position output.position An output position system-value variable.输出位置系统值变量。

Fragment Shader Semantics片段着色器语义#

Fragment shader semantics contain necessary input and output data for shader. You should initialize variables first and then use them.片段着色器语义包含着色器必需的输入和输出数据。您应该先初始化变量,然后再使用它们。

UUSL OpenGL Direct3D 描述
INIT_IN(TYPE,NUM) in TYPE s_texcoord_ ## NUM; TYPE data_ ## NUM : TEXCOORD ## NUM; Adds an input texture coordinates semantic.添加输入纹理坐标语义。
INIT_COLOR(TYPE) out TYPE s_frag_color; TYPE color : SV_TARGET; Add an output diffuse or specular color semantic (single RT).添加输出漫反射或镜面反射的颜色语义(单个RT)。
INIT_DEPTH - float depth : SV_DEPTH; Add an output depth system-value semantic.添加输出深度系统值语义。
INIT_MRT(TYPE,NUM) out TYPE s_frag_data_ ## NUM; TYPE color_ ## NUM : SV_TARGET ## NUM; Add an output color system-value semantic (some RTs).添加输出颜色系统值语义(某些RT)。
INIT_FRONTFACE --- bool frontface : SV_ISFRONTFACE; Adds an input semantic indicates primitive face (frontface or not).添加表示原始面孔(是否为正面)的输入语义。

To use the variables in the code, use the following variables:要在代码中使用变量,请使用以下变量:

UUSL OpenGL Direct3D 描述
IN_POSITION gl_FragCoord input.position An input position value.输入位置值。
IN_DATA(NUM) s_texcoord_ ## NUM input.data_ ## NUM An input texture coordinates variable.输入纹理坐标变量。
IN_FRONTFACE !gl_FrontFacing input.frontface Floating-point scalar that indicates a back-facing primitive. A negative value faces backwards, while a positive value faces the camera.浮点标量,指示向后的原语。负值朝向后,而正值朝向相机。
OUT_COLOR s_frag_color output.color An output color value (single RT).输出颜色值(单个RT)。
OUT_DEPTH gl_FragDepth output.depth An output depth value.输出深度值。
OUT_MRT(NUM) out TYPE s_frag_data_ ## NUM; output.color_ ## NUM An output color value for MRTs. MRT的输出颜色值。

Here is a simple example of using the variable in the main function of the shader:以下是在着色器的主要功能中使用变量的简单示例:

USUL
MAIN_FRAG_BEGIN(FRAGMENT_IN)
	
	float4 texcoord = IN_DATA(0);

	/* ... other code ... */
MAIN_FRAG_END

Geometry Shader Semantics几何着色器语义#

UUSL OpenGL Direct3D 描述
INIT_GEOM_IN(TYPE,NUM) in TYPE s_geom_texcoord_ ## NUM[]; TYPE data_ ## NUM : TEXCOORD ## NUM; Add an input texture coordinates semantic for the geometry-shader stage.为几何着色器阶段添加输入纹理坐标语义。
INIT_GEOM_OUT(TYPE,NUM) out TYPE s_geom_texcoord_ ## NUM; TYPE data_ ## NUM : TEXCOORD ## NUM; Add an output texture coordinates semantic for the geometry-shader stage.为几何着色器阶段添加输出纹理坐标语义。
UUSL OpenGL Direct3D 描述
IN_GEOM_DATA(NUM,INDEX) s_geom_texcoord_ ## NUM ## [INDEX] input[INDEX].data_ ## NUM An input texture coordinates value.输入的纹理坐标值。
IN_GEOM_POSITION(INDEX) gl_in[INDEX].gl_Position input[INDEX].position An input position value.输入位置值。
OUT_GEOM_DATA(NUM) s_geom_texcoord_ ## NUM output.data_ ## NUM An output texture coordinates value.输出纹理坐标值。
TRIANGLE_IN triangles triangle Input primitive type: triangle list or triangle strip.输入基本类型:三角形列表或三角形带。
TRIANGLE_OUT triangle_strip TriangleStream Output primitive type: a sequence of triangle primitives输出图元类型:三角形图元序列
LINE_IN lines line Input primitive type: line.输入基本类型:line。
LINE_OUT line_strip LineStream Output primitive type: a sequence of line primitives输出图元类型:线图元序列

Unified Shader Semantics统一着色器语义#

Unified shader semantics allows you to create single structure for both vertex and fragment shaders. It facilitates the work with vertex and fragment shaders input/output structure by using single structure for both shaders: this structure will be output for vertex shader and input for fragment shader respectively.统一着色器语义允许您为顶点和片段着色器创建单一结构。通过为两个着色器使用单一结构,可以简化使用顶点和片段着色器输入/输出结构的工作:该结构将分别为顶点着色器输出和为片段着色器输入。

You can write vertex and fragment shader in a single file with .shader extension. In this case, in the material you should specify this .shader file for both shader stages.您可以在一个扩展名为.shader的文件中写入顶点和片段着色器。在这种情况下,应在材质中为两个着色器阶段都指定此.shader文件。

源代码 (XML)
BaseMaterial <texture_prefix=tex var_prefix=var>
{
	// ...

	Pass auxiliary if [auxiliary]
	{
		Vertex = "core/materials/base/objects/mesh/shaders/auxiliary/auxiliary.shader"
		Fragment = "core/materials/base/objects/mesh/shaders/auxiliary/auxiliary.shader"
	}

	// ..
}
UUSL VERTEX FRAGMENT 描述
INIT_DATA(TYPE,NUM,NAME) INIT_OUT(TYPE,NUM) \ #define NAME GET_DATA(NUM) INIT_IN(TYPE,NUM) \ #define NAME GET_DATA(NUM) Data initialization.数据初始化。
GET_DATA(V) OUT_DATA(V) IN_DATA(V) Helper for getting/setting data by using data name.使用数据名称获取/设置数据的助手。

IF statement中频声明#

There is also the IF_DATA(NAME) statement to execute an operation if the data is not null.如果数据不为空,还可以使用 IF_DATA(NAME)语句执行操作。

UUSL VERTEX FRAGMENT 描述
IF_DATA(NAME) #ifdef NAME #ifdef NAME Opening IF conditional statement.打开IF条件语句。
ENDIF #endif #endif Closing IF conditional statement.关闭IF条件语句。

Here is a code snippet of shader, where the shader's IF statement is used.这是着色器的代码片段,其中使用了着色器的IF语句。

UUSL
//input struct
STRUCT(FRAGMENT_IN)
/* ... */
	#ifdef ALPHA_FADE && USE_ALPHA_FADE
		INIT_DATA(float,1,DATA_ALPHA_FADE)
	#endif
/* ... */
END

//main functions
MAIN_FRAG_BEGIN(FRAGMENT_IN)
/* ... */
	IF_DATA(DATA_ALPHA_FADE)
		//code to execute if the data is not null
		alphaFadeDiscard(DATA_ALPHA_FADE,IN_POSITION.xy);
	ENDIF
/* ... */
MAIN_FRAG_END
最新更新: 2023-11-30
Build: ()