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
双精度坐标
应用程序接口
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
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

统一的Unigine着色器语言

The Unified UNIGINE shader language (UUSL) allows you to create a single shader file for both 3D graphics APIs: OpenGL and Direct3D11. The language brings pre-defined data types and implemented functions that simplifies and unifies shaders writing process.统一UNIGINE着色器语言(UUSL)允许您为两个3D图形API(OpenGL和Direct3D11)创建单个着色器文件。该语言带来了预定义的数据类型和实现的功能,这些功能简化并统一了着色器的编写过程。

This section of the Unigine documentation contains information about the UUSL syntax (unified data types, intrinsic functions, parameters, textures, semantics, etc.) and tutorials on creating shaders. Unigine文档的本部分包含有关UUSL语法(统一的数据类型,内部函数,参数,纹理,语义等)的信息,以及有关创建着色器的教程。

Frequently Asked Questions经常问的问题#

What is UUSL?什么是UUSL?#

The Unified UNIGINE shader language (UUSL) is a wrapper, which unifies the most part of GLSL and HLSL syntax. You can use the UUSL instructions to write shader code without graphic API defining: it will work on both APIs.统一UNIGINE着色器语言(UUSL)是包装器,它统一了GLSL和HLSL语法的大部分内容。您可以使用UUSL指令来编写着色器代码,而无需定义图形API:它将在两个API上都可以使用。

Should I write shaders by using UUSL only?我是否应该仅使用UUSL编写着色器?#

Definitely not. UUSL is just a wrapper which facilitates the shader-writing process. You can also use an old-school approach by writing separately part of the shader for corresponding graphic API with GLSL and HLSL shading languages.绝对不是。 UUSL只是一个有助于着色器编写过程的包装器。您也可以使用老式的方法,分别使用 GLSL HLSL 着色语言为相应的图形API编写着色器的一部分。

Which shader stages does the Unigine engine have?Unigine引擎具有哪些着色器阶段?#

Unigine engine has the standard shaders pipeline: Vertex-Shader stageGeometry-Shader stageFragment-Shader stage. If you want to use tessellation, the pipeline will have 3 additional stages between vertex-shader and geometry-shader stages: Control-Shader stage, tessellation stage, Evaluation-Shader stage. Unigine引擎具有标准的着色器管道: Vertex-Shader阶段 Geometry-Shader阶段 Fragment-Shader阶段。如果要使用细分,则管线在顶点着色器阶段和几何着色器阶段之间还有3个附加阶段: Control-Shader阶段镶嵌细分阶段评估-着色器阶段

How are materials and shaders interrelated?材质和着色器如何相互关联?#

Material specifies which shaders for defined rendering pass it will use to render. You can define vertex, geometry and fragment shaders for a material. When you assign the material, the engine starts using its shaders to render the image. A piece of cake! 材质指定将用于渲染定义的 rendering pass 的着色器。您可以为材质定义顶点几何片段着色器。分配材质时,引擎将开始使用其着色器来渲染图像。一块蛋糕!

注意
Vertex and fragment shaders are mandatory for a material.材质必须使用顶点着色器和片段着色器。

We have a neat article about the materials files formats, check it out.我们有一篇关于 materials文件格式的简洁文章,请查看。

How to start using UUSL?如何开始使用UUSL?#

When you start writing shaders, include the UUSL headers and start coding!开始编写着色器时,请包含UUSL标头并开始编码!

Use the following commands to include the necessary headers:使用以下命令包括必要的标题:

USSL
// Include Unified Unigine Shader Language (UUSL) common header
#include <core/materials/shaders/api/common.h>

Do shaders need compilation?着色器需要编译吗?#

Yes, they do. But the engine does the job: just use the materials_reload console command if you made some changes in shader files. It is really handy: you don't need to compile the shader every time you made any changes, you see the result of the changes in runtime without engine restart!是的,他们这样做。但是引擎可以完成工作:如果对着色器文件进行了一些更改,只需使用 materials_reload 控制台命令。这真的很方便:您不需要每次进行任何更改都编译着色器,无需运行引擎即可看到运行时的更改结果!

注意
If you made changes in the material .mat file, you should reload the engine.如果您在材质.mat文件中进行了更改,则应重新加载引擎。

Can I debug the UUSL shader code?我可以调试UUSL着色器代码吗?#

Sure. If there is a shader error, the engine shows it in the console: 当然。如果存在着色器错误,引擎会在控制台中显示该错误:

The message contains information about which file has errors and their description (including the number of line).该消息包含有关哪个文件有错误及其描述(包括行数)的信息。

Export the shader file to the file and find this code line to figure out what's happen. Shader will be exported in a file with the graphic API shader format (.hlsl or .glsl) located relatively to the data folder. 将着色器文件导出到该文件,并找到此代码行以了解发生了什么。着色器将导出为相对于data文件夹具有图形API着色器格式(.hlsl.glsl)的文件。

How to create custom shader?如何创建自定义着色器?#

最新更新: 2023-06-23
Build: ()