着色器
This type of node is used to describe a UUSL shader in an ULON-based material file. Currently, the engine supports Vertex, Control, Evaluate, Geometry, Fragment, and Compute shaders.这种类型的节点用于描述基于 ULON 的材质文件中的 UUSL 着色器。目前,引擎支持 Vertex, Control, Evaluate, Geometry, Fragment 和 Compute 着色器。
The syntax is the following:语法如下:
Shader name =
#{
// UUSL code
#}
As a node's value you must specify a UUSL-based code enclosed in "#{" and "#}".作为节点的值,您必须指定UUSL基于 "#{" 和 "#}" 的代码。
See the SDK/data/core/shaders/common/ directory for the list of headers implementing common shaders' functions which can be included and used in custom shaders. To start writing UUSL shaders, include the common header:请参阅 SDK/data/core/shaders/common/ 目录以获取实现通用着色器功能的标头列表,这些功能可以包含在自定义着色器中并使用。要开始编写 UUSL 着色器,请包含公共标头:
#include <core/shaders/common/common.h>
Types of Shaders着色器的类型#
The following types of shaders corresponding to their counterparts in different graphic APIs are available:以下类型的着色器对应于不同图形 API 中的对应物:
Unigine | DirectX | OpenGL |
---|---|---|
Vertex | Vertex | Vertex |
Control | Hull | Control |
Evaluate | Domain | Evaluate |
Geometry | Geometry | Geometry |
Fragment | Pixel | Fragment |
Compute | Compute | Compute |
Usage Examples使用示例#
The shader node is usually used as a shader value for the Pass node.着色器节点通常用作 Pass 节点的着色器值。
Shader shader_a =
#{
// some UUSL code
#}
Pass ambient
{
Vertex = shader_a
Fragment = shader_a
}
The advantages of this shader setup method are:这种着色器设置方法的优点是:
- It reduces the amount of identical code.它减少了相同代码的数量。
- One shader code can be used in different render passes.一个着色器代码可用于不同的渲染通道。
On the other hand, it is not the best approach for large shaders. Use includes for these cases:另一方面,它不是大型着色器的最佳方法。在这些情况下使用 includes:
- Write different shaders in separate files and then specify their paths as shader values in the pass:
// some UUSL code
// some UUSL code
在单独的文件中编写不同的着色器,然后在 pass 中将它们的路径指定为着色器值:Pass deferred { Vertex = "shaders/a.vert" Fragment = "shaders/b.frag" }
// some UUSL code
// some UUSL code
Pass deferred { Vertex = "shaders/a.vert" Fragment = "shaders/b.frag" }
- Include the code of a different shader by using the marker: #shader shader_name.
使用标记包含不同着色器的代码:#shader shader_name。
Shader a = #{ // shader code A }# Shader b = #{ // shader code B #shader a }# // the result shader b will look like this: Shader b = #{ // shader code B // shader code A #}
Shader a = #{ // shader code A }# Shader b = #{ // shader code B #shader a }# // the result shader b will look like this: Shader b = #{ // shader code B // shader code A #}