本帖最后由 DUO 于 2023-3-29 21:46 编辑
One of the biggest problems that video game developers have when they start studying shaders in Unity is that there is little information for beginners on the web. Whether you are an independent developer or focused on AAA projects, it can be a little daunting due to the technical nature of the knowledge necessary to develop these types of programs.
当视频游戏开发者开始学习Unity中的着色器时,最大的问题之一是网上对初学者的信息很少。无论你是独立开发者还是专注于AAA项目,由于开发这些类型的程序所需的技术知识的技术性质,这可能会让人感到有些令人望而生畏。
Despite this challenge, Unity offers a significant advantage since it is multiplatform. It allows us to write our videogames only once and then export them to different devices, including consoles and smartphones. So, once we start our adventure into the world of shaders, we only need to write our code one time, and the software will take care of compiling it for the different platforms (OpenGL, Metal, Vulkan, Direct3D, GLES 20, GLES 3x).
尽管存在这一挑战,Unity 有一个重要的优势,它是跨平台的。这使得我们只需要编写一次我们的游戏,然后将它们导出到不同的设备上,包括游戏机和智能手机。因此,一旦我们开始进入着色器的世界,我们只需要编写我们的代码一次,软件将负责为不同的平台(OpenGL、Metal、Vulkan、Direct3D、GLES 20、GLES 3x)进行编译。
The Unity Shaders Bible has been created to solve most of our problems when starting in this world. We will begin by reviewing the structure of a shader in the Cg and HLSL languages to get to know its properties, commands, functions, syntax.Did you know that there are three types of Rendering Pipeline in Unity, and each of them has its own qualities? Throughout the book, we will specify each of them, verifying how Unity processes the graphics to project our video games on the computer screen.
写《Unity着色器圣经》这本书是为了解决我们在这个领域开始时遇到的大部分问题。我们将开始通过回顾Cg和HLSL语言中的着色器结构,以了解其属性、命令、函数、语法。你知道在Unity中有三种类型的渲染管道,每种都有其独特的特性吗?在本书中,我们将详细介绍它们,并验证Unity如何处理图形以将我们的电子游戏投影到计算机屏幕上。
I. Topics we will see in this book.
The book is divided into three chapters to linearly address the topics to the extent that we need to; however, it is worth mentioning that this book will be subject to structural changes over time to improve the understanding of its content and achieve a good interaction with the reader. All the code we will see in this book has been tested using the Visual Studio Code editor and checked in Unity for the different types of Render Pipeline.
I. 我们将在本书中看到的主题
本书分为三章,以线性方式探讨主题,以满足我们的需求;然而值得一提的是,这本书将随着时间的推移而进行结构性变化,以改进对其内容的理解,并与读者进行良好的互动。本书中所有的代码都经过了使用 Visual Studio Code 编辑器进行测试,并在 Unity 中检查了不同类型的渲染管线。
Chapter I: Introduction to the shader programming language.
This chapter looks at the base knowledge that needed before starting, such as the structure of a shader in ShaderLab language, the analogy between the properties and connection variables, SubShader and commands (ColorMask, Stencil, Blending, etc.), Passes and structure of Cg and HLSL, the design of a function, Input vertex analysis, Output vertex analysis, the analogy between a semantic and a primitive, vertex shader stage structure, fragment shader stage structure, matrices and more. This chapter is the starting point to understand fundamental concepts about how a
shader works in Unity.
第一章:着色器编程语言介绍
本章介绍了开始之前需要的基础知识,例如ShaderLab语言中着色器的结构,属性和连接变量之间的类比,SubShader和命令(ColorMask、Stencil、Blending等),Passes和Cg和HLSL的结构,函数的设计,输入顶点分析,输出顶点分析,语义和原语之间的类比,顶点着色器阶段结构,片段着色器阶段结构,矩阵等。本章是了解Unity中着色器工作原理的基本概念的起点。
Chapter II: Lighting, shadows, and surfaces.
Addresses highly relevant issues, such as normal maps and their implementation, reflection maps, lighting and shadow analysis, basic lighting model, surface analysis, mathematical functions, specularity and ambient light. We also review Shader Graph, its structure, functions in HLSL, nodes, properties and more. In this chapter, we will make our video game look professional with simple lighting concepts.
第二章:照明,阴影和表面
涉及到一些高度相关的问题,例如法线贴图及其实现、反射贴图、照明和阴影分析、基本照明模型、表面分析、数学函数、高光和环境光。我们还将回顾Shader Graph,其结构、在HLSL中的功能、节点、属性等。在本章中,我们将使用简单的照明概念使我们的视频游戏看起来更专业。
Chapter III: Compute shader, ray tracing and Sphere tracing.
We will put into practice advanced concepts, such as the structure of a compute shader, buffer variables, kernels, sphere tracing implementation, implicit surfaces, constructive solid geometry, shapes and algorithms, introduction to ray tracing, configurations and high-quality rendering. Our studies will conclude in this chapter. We will investigate GPGPU programming (general-purpose GPU) using shaders of type .compute, reviewing the sphere tracing technique and using Direct Raytracing (DXT) in HDRP.
第三章:计算着色器,光线追踪和球体追踪
我们将实践高级概念,例如计算着色器的结构、缓冲变量、核心、球追踪实现、隐式曲面、构造实体几何、形状和算法、射线追踪入门、配置和高质量渲染。我们的研究将在本章中结束。我们将使用.compute类型的着色器调查GPGPU编程(通用GPU),回顾球追踪技术,并在HDRP中使用直接射线追踪(DXT)。
II. Recommendations.
Working with a code editor with IntelliSense in graphics language programming is essential, specifically in Cg or HLSL. Unity has Visual Studio Code which is a more compact version of Visual Studio Community. This editor contains some extensions that add IntelliSense to both C#, ShaderLab, and HLSL.
For those who will use Visual Studio Code editor, we recommend installing the following extensions: C# for visual studio code (Microsoft), Shader language support for VS Code (Slevesque), ShaderLab VS Code (Amlovey), Unity Code Snippets (Kleber Silva).
II. 建议
在图形语言编程中使用具有代码智能提示的代码编辑器非常重要,特别是在Cg或HLSL中。Unity具有Visual Studio Code,这是Visual Studio Community的更紧凑版本。该编辑器包含一些扩展,可为C#,ShaderLab和HLSL添加代码智能提示。
对于将使用Visual Studio Code编辑器的人,我们建议安装以下扩展程序: Visual Studio Code的C# (Microsoft), VS Code的着色器语言支持 (Slevesque), ShaderLab VS Code (Amlovey), Unity代码片段 (Kleber Silva)。
**【DUO佬:现在代码提示AI非常智能,安装Copilot插件也是非常重要的!我的学习方法里有讲哦!】**
III. Who this book is for.
This book has been written for Unity developers looking to improve their graphics knowledge or create professional-looking effects. It is assumed that the reader already knows, understands, and has access to the Unity interface, so we will not go into these details. Having previous knowledge of C# or C++ would be a great asset in understanding the content presented in this book; however, it is not an exclusive requirement.
It is essential to have basic knowledge in arithmetic, algebra and trigonometry to understand more advanced concepts. Anyway, we will still review mathematical operations and functions to explain what we’re developing fully.
III. 本书的受众。
本书适合Unity开发者想要提高他们的图形知识或者创建专业的效果。读者已经知道、理解并可以访问Unity界面,因此我们不会详细介绍这些细节。已经具备C#或C++的基础知识将有助于理解本书中提出的内容,但这不是必需的。
理解更高级概念需要掌握算术、代数和三角学的基础知识。无论如何,我们仍然会回顾数学运算和函数以充分解释正在开发的内容。
IV. Glossary.
Given their nature, in this book, we will find phrases and words distinguished from the rest, which we can quickly identify because we will highlight them to emphasise an explanation or concept. Likewise, there will be blocks of code in HLSL language to exemplify some functions.
The book will show in bold font (e.g. _Color) essential words or lines of code. Some relevant words or technical definitions will be shown in italic (e.g. normal), and constant values will be displayed in UPPER CASE (e.g. RGBA)
In the book, we can find blocks of code that include three points (...), which refer to variables and/or functions included by default within the code.
IV.词汇表
由于它们的性质,在本书中,我们将使用与其他普通文本有所区别的短语和单词,为了快速识别它们,因为我们将强调它们以强调解释或概念。 同样,将使用有HLSL语言的代码块来举例说明一些函数。
本书将以粗体字体(例如 _Color)显示关键字或代码行。 一些相关的单词或技术定义将以斜体显示(例如 normal ),常量值将以大写字母显示(例如RGBA)。
在本书中,我们可以找到包含三个点(...)的代码块,这些点指的是代码中默认包含的变量或函数。
V. 勘误
本书所有完整翻译内容和勘误只会在本《技你太美101》论坛进行更新。
VI. 源码和捐赠
本书是B站视频《着色器入门》的重要参考书籍来源,课程所用的实践源码也会在本《技你太美101》论坛同步更新。