This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
Materials and Shaders
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
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

着色器

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, FragmentCompute 着色器。

The syntax is the following:语法如下:

ULON
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 着色器,请包含公共标头:

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 节点的着色器值。

ULON
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

  1. Write different shaders in separate files and then specify their paths as shader values in the pass:
    shaders/a.vert (UUSL)
    // some UUSL code
    shaders/b.frag (UUSL)
    // some UUSL code
    Source code (ULON)
    Pass deferred 
    {
    	Vertex = "shaders/a.vert"
    	Fragment = "shaders/b.frag"
    }
    在单独的文件中编写不同的着色器,然后在 pass 中将它们的路径指定为着色器值:
    shaders/a.vert (UUSL)
    // some UUSL code
    shaders/b.frag (UUSL)
    // some UUSL code
    Source code (ULON)
    Pass deferred 
    {
    	Vertex = "shaders/a.vert"
    	Fragment = "shaders/b.frag"
    }
  2. Include the code of a different shader by using the marker: #shader shader_name.
    Source code (ULON)
    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 shader_name
    Source code (ULON)
    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
    #}
最新更新: 2022-04-07
Build: ()