目录索引
译文
我们已经学习了大部分渲染管线的结构,并了解了 Unity 中着色器的工作原理。在本章节中,我们将介绍一种新的构建着色器的方式:Shader Graph,其结构基于我们之前所学习的知识。
Shader Graph 是一个基于 HLSL、支持通过节点可视化编程的包(package),美术人员和程序员可以通过节点(nodes)创建自定义着色器,而无需编写代码。同时,Shader Graph 的自定义函数(Custom Function)节点与 HLSL 的兼容性也很高,这允许我们在程序中生成特定函数。
目前只有 URP 和 HDRP 支持 Shader Graph。
![图片[1]-《Unity着色器圣经》9.0.1 | 什么是Shader Graph-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-105-1024x439.jpeg)
在使用 Shader Graph 时我们需要注意所使用的 Unity 编辑器的版本,因为为 Unity 2018 开发的 Shader Graph 是不会获得支持的 BETA 版本,而为 Unity 2019.1(以及更新的版本)开发的是可以主动兼容的 Shader Graph。
另一个需要考虑的问题是,因为 Unity 每次版本更新都会添加新功能,因此我们通过 Shader Graph 创建的着色器很可能在不同的 Unity 版本中无法正确编译,如果我们使用自定义函数,情况更是如此。
即使这样,Shader Graph 还是开发着色器的好工具吗?答案是:没错,对于艺术家来说更是如此。
对于使用过 3D 建模软件(如 Maya 或 Blender)的用户来说,Shader Graph 非常有用,因为它使用的节点系统与 Hypershader 和 Shader Editor 非常相似,可以更直观地创建着色器。
![图片[2]-《Unity着色器圣经》9.0.1 | 什么是Shader Graph-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-104-1024x360.jpeg)
在具体介绍 Shader Graph 的界面与功能之前,请注意界面上的功能会根据版本的不同而有所变化。在编写本书时,Shader Graph 的最新版本为 12.0.0。
如果我们在 12.0.0 版本中新建一个 Shader Graph,就会发现顶点着色器和片元着色器阶段是分开的、各自独立工作的。但如果我们使用 8.3.1 版本,这两个着色器就会合并到一个名为 Master 的节点中,该节点代表·着色器的最终输出颜色。
事实上,如果我们在 8.3.1 版本中创建了一个着色器,然后再更新到 12.0.0 版本,很可能会因为一些功能上的变化导致着色器无法编译。
原文对照
Up to this point, we’ve reviewed much of the rendering pipeline structure, as well as understood how a Unity shader works. Now we will introduce Shader Graph, since its structure and analogy are based on all the previous knowledge we have acquired.
Shader Graph is a package that adds support for a visual node editing tool. Based on HLSL, its interface can be used by artists and developers to create custom shaders through nodes instead of having to write code. Even so, its Custom Function node has a high compatibility with HLSL, which allows us to generate specific functions within the program.
Currently, Shader Graph is available for two rendering modalities, these are High Definition RP and Universal RP.
![图片[1]-《Unity着色器圣经》9.0.1 | 什么是Shader Graph-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-105-1024x439.jpeg)
We must consider that when working with Shader Graph, the versions developed for Unity 2018 are BETA versions and do not receive support, whereas the versions developed for Unity 2019.1 and onwards are actively compatible and do receive support.
Another consideration is that it is very likely that our shaders created with this interface are not compiled correctly in their different versions. This is because new features are added in each update, which makes our node set stop compiling in most cases, even more so if we are using custom functions.
So, is Shader Graph a good tool for developing shaders? The answer is yes, even more so for artists.
For those who have worked with 3D software such as Maya or Blender; Shader Graph will be very useful since it uses a system of nodes very similar to Hypershader and Shader Editor, which allows the shader creation to be more intuitive.
![图片[2]-《Unity着色器圣经》9.0.1 | 什么是Shader Graph-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-104-1024x360.jpeg)
Before introducing this matter, be aware that the Shader Graph interface has functional variations according to its version, e.g. At the time of writing this book, its most up-to-date version corresponds to 12.0.0.
If we create a node within this version we can see that the vertex and fragment shader stage appear separate and work independently, however, if we go to version 8.3.1, both stages are merged within a node called “Master”, which refers to the final shader output color.
As we mentioned before, it is very possible that the shaders created in this interface do not compile in all its versions, in fact, if we create a shader in version 8.3.1 and update to version 12.0.0, there are probably functional changes that prevent its compilation process.
暂无评论内容