目录索引
译文
前向渲染是默认的渲染路径,支持诸如法线贴图、逐像素光照、阴影等多种材质功能。前向渲染包含了两种可以在着色器内编程的pass,分别是 base pass 和 additional pass。(译者注:pass一般不翻译成中文。base指基础,additional指附加)
在base pass中,我们可以定义 ForwardBase 光照模型;而在additional pass中,我们可以定义 ForwardAdd 光照模型。这两种模型都具有在着色器中计算光照的功能。Bass pass 可以逐像素地处理平行光,当场景中有多个平行光源时,则会处理最亮的光源。除此之外,bass pass 还可以处理光照探针、全局照明和环境光(天空盒光照)。
顾名思义, Additional pass 可以逐像素地处理额外的光源,也可以处理影响模型的阴影。如果场景中有两束光,我们的模型将只受其中一束光的影响。但如果我们为它配置了additional pass,那么该模型将同时受两束光的影响。
我们必须考虑的一点是每一个计算照明的pass都会单独生成一个绘制调用(draw call)。绘制调用指的是每次我们想要在电脑屏幕上绘制一个元素时,在 GPU 中进行的图形调用。这些调用需要大量的计算,因此需要尽可能地减少调用次数,特别是运行在移动设备上的项目。
为了更好的理解这个概念,现在假设我们的场景中有四个球体和一束平行方向光。对每个球体来说,它将生成一次发送到GPU的绘制调用。这意味着默认情况下每一个球体都会生成一次独立的绘制调用。
同样,平行光会影响场景中的所有球体,每个球体都会产生一次额外的绘制调用,这主要是因为着色器中的第二个pass计算了阴影投影。因此,四个球体加上一个平行光总共会产生八次绘制调用。
![图片[1]-《Unity着色器圣经》1.1.3 | 前向渲染-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-14-1024x477.jpeg)
在了解完base pass后,如果我们往shader中加入别的pass,那么我们将为每个模型增加一次新的绘制调用,图形负载将大幅增加。
有一些方法可以优化这一过程,我们将在本书的后半部分讨论。现在,我们将继续学习渲染路径的概念。
原文对照
Forward is the default rendering path and supports all typical features of a material (e.g. normal maps, pixel lighting, shadows, etc.). This rendering path has two different code written passes that we can use in our shader, the first, base pass and the second additional pass.
In the base pass, we can define the ForwardBase light mode and in the additional pass, we can define the ForwardAdd light mode. Both are characteristic functions of a shader with lighting calculation. The base pass can process directional light per-pixel and will use the brightest light if there are multiple directional lights in the scene. In addition, the base pass can process light probes, global illumination, and ambient illumination (skylight).
As its name says, the additional pass can process “additional lights” per-pixel or also shadows that affect the object, what does this mean? If we have two lights in the scene, our object will be influenced only by one of them, however, if we have defined an additional pass for this configuration, then it will be influenced by both.
One point that we must take into consideration is that each illuminated pass will generate a separate draw call. A draw call is a call graphic that is made in the GPU every time we want to draw an element on the screen of our computer. These calls are processes that require a large amount of computation, so they need to be kept to a minimum possible, even more so if we are working on projects for mobile devices.
To understand this concept, we are going to suppose that we have four Spheres and one directional light in our scene. Each Sphere, by its nature, generates a call to the GPU, this means that each of them will generate an independent draw call by default.
Likewise, the directional light influences all the Spheres that are found in the scene, therefore, it will generate an additional draw call for each Sphere, this is mainly because a second pass has been included in the shader to calculate the shadow projection, therefore, four Spheres, plus one-directional light will generate eight draw calls in total.
![图片[1]-《Unity着色器圣经》1.1.3 | 前向渲染-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/image-14-1024x477.jpeg)
Having determined the base pass, if we add another pass in our shader, then we are going to add a new draw call for each object, and consequently, the graphic load will increase significantly.
There are some ways to optimize this process, which we will talk about later in the book. For now, we will continue the rendering path concept.
暂无评论内容