Real-Time Rendering——Chapter 5 Shading Basics着色基础 5.1 Shading Models 着色模型

This chapter will discuss those aspects of shading that are equally applicable to photorealistic and stylized rendering. Chapter 15 is dedicated specifically to stylized rendering, and a significant part of the book, Chapters 9 through 14, focuses on physically based approaches commonly used for photorealistic rendering.

本章将讨论那些同样适用于照片级真实感和风格化渲染的着色方面。第15章专门讨论风格化渲染,这本书的重要部分,从第9章到第14章,集中讨论了通常用于照片级真实感渲染的基于物理的方法。

Figure 5.1. The top image is from a realistic landscape scene rendered using the Unreal Engine.The bottom image is from the game Firewatch by Campo Santo, which was designed with a illustrative art style. (Upper image courtesy of G¨okhan Karadayi, lower image courtesy of Campo Santo.) 

图5.1。顶部的图像来自使用虚幻引擎渲染的真实景观场景。底部的图像来自Campo Santo的游戏Firewatch,它的设计带有插图艺术风格。(上图由G okhan Karadayi提供,下图由Campo Santo提供。)

5.1 Shading Models 着色模型

The first step in determining the appearance of a rendered object is to choose a shading model to describe how the object’s color should vary based on factors such as surface orientation, view direction, and lighting.

确定渲染对象外观的第一步是选择一个着色模型来描述对象的颜色应如何根据表面方向、视图方向和照明等因素而变化。

The basic idea behind Gooch shading is to compare the surface normal to the light’s location. If the normal points toward the light, a warmer tone is used to color the surface; if it points away, a cooler tone is used. Angles in between interpolate between these tones, which are based on a user-supplied surface color. In this example, we add a stylized “highlight” effect to the model to give the surface a shiny appearance. Figure 5.2 shows the shading model in action.

Gooch明暗处理背后的基本思想是比较表面法线和灯光位置。如果法线指向光,则使用暖色调来给表面着色;如果它指向别处,则使用较冷的颜色。介于两者之间的角度在这些色调之间进行插值,这些色调基于用户提供的表面颜色。在这个例子中,我们为模型添加了一个风格化的“高光”效果,以赋予表面闪亮的外观。图5.2显示了阴影模型的作用。

Shading models often have properties used to control appearance variation. Setting the values of these properties is the next step in determining object appearance. Our example model has just one property, surface color, as shown in the bottom image of Figure 5.2.

着色模型通常具有用于控制外观变化的属性。设置这些属性的值是确定对象外观的下一步。我们的示例模型只有一个属性,表面颜色,如图5.2底部的图像所示。

Figure 5.2. A stylized shading model combining Gooch shading with a highlight effect. The top image shows a complex object with a neutral surface color. The bottom image shows spheres with various different surface colors. (Chinese Dragon mesh from Computer Graphics Archive,original model from Stanford 3D Scanning Repository.) 

图5.2。一种风格化的明暗处理模型,结合了古奇明暗处理和高光效果。上图显示了一个具有中性表面颜色的复杂对象。下图显示了具有各种不同表面颜色的球体。(中国龙网格来自计算机图形档案库,原始模型来自斯坦福3D扫描库。)

Like most shading models, this example is affected by the surface orientation relative to the view and lighting directions. For shading purposes, these directions are commonly expressed as normalized (unit-length) vectors, as illustrated in Figure 5.3.

与大多数着色模型一样,该示例受相对于视图和照明方向的曲面方向的影响。出于阴影的目的,这些方向通常表示为归一化(单位长度)向量,如图5.3所示。

Figure 5.3. Unit-length vector inputs to the example shading model (and most others): surface normal n, view vector v, and light direction l. 

图5.3。示例着色模型(和大多数其他模型)的单位长度向量输入:表面法线n、视图向量v和光照方向l。

Now that we have defined all the inputs to our shading model, we can look at the mathematical definition of the model itself:

现在我们已经定义了着色模型的所有输入,我们可以看看模型本身的数学定义:

Clamping operations, typically clamping to 0 or clamping between 0 and 1, are common in shading. Here we use the  notation, introduced in Section 1.2, for the clamp between 0 and 1 used in the computation of the highlight blend factor s. The dot product operator appears three times, in each case between two unit-length vectors; this is an extremely common pattern. The dot product of two vectors is the product of their lengths and the cosine of the angle between them.So, the dot product of two unit-length vectors is simply the cosine, which is a useful measure of the degree to which two vectors are aligned with each other. Simple functions composed of cosines are often the most pleasing and accurate mathematical expressions to account for the relationship between two directions, e.g., light direction and surface normal, in a shading model. 

Clamp: 如果 x 值小于 a,则返回 a;如果 x 值大于 b,返回 b;否则,返回 x

Clamp操作,通常Clamp到0或Clamp在0和1之间,在着色中很常见。这里,我们使用第1.2节中介绍的符号,用于计算高光混合因子s时使用的0和1之间的Clamp。点积运算符出现三次,每次都出现在两个单位长度向量之间;这是一种极其常见的模式。两个向量的点积是它们的长度和夹角余弦的乘积。因此,两个单位长度向量的点积就是余弦,它是两个向量相互对齐程度的有用度量。在着色模型中,由余弦组成的简单函数通常是说明两个方向(例如,光线方向和表面法线)之间关系的最令人满意和最准确的数学表达式。

 Another common shading operation is to interpolate linearly between two colors based on a scalar value between 0 and 1. This operation takes the form that interpolates between ca and cb as the value of t moves between 1 and 0, respectively.

另一种常见的着色操作是基于0和1之间的标量值在两种颜色之间进行线性插值。当t的值分别在1和0之间移动时,该运算采取在ca和cb之间插值的形式。

This pattern appears twice in this shading model, first to interpolate between cwarm and ccool and second to interpolate between the result of the previous interpolation and chighlight. Linear interpolation appears so often in shaders that it is a built-in function, called lerp or mix, in every shading language we have seen.

这个图案在这个着色模型中出现了两次,第一次是在cwarm和ccool之间进行插值,第二次是在前一次插值的结果和chighlight之间进行插值。线性插值在着色器中出现得如此频繁,以至于在我们见过的每种着色语言中,它都是一个内置函数,称为lerp或mix。

 The line “r = 2 (n · l)n − l” computes the reflected light vector, reflecting l about n. While not quite as common as the previous two operations, this is common enough for most shading languages to have a built-in reflect function as well.

行“r = 2 (n · l)n − l”计算反射光矢量,将l反射约n,虽然不像前两个操作那样常见,但对于大多数着色语言来说,这也足够常见,因为它们也有内置的反射函数。

By combining such operations in different ways with various mathematical expressions and shading parameters, shading models can be defined for a huge variety of stylized and realistic appearances.

通过以不同的方式将这些操作与各种数学表达式和着色参数相结合,可以为各种风格化和逼真的外观定义着色模型。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

椰子糖莫莫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值