Real-Time Rendering——6.7.1 Blinn’s Methods 6.7.2 Normal Mapping法线映射

本文介绍了Blinn的原始凹凸贴图方法,包括使用bu和bv值改变表面法线,以及通过高度场来表示凹凸。接着详细阐述了法线映射,其中法线贴图直接存储法线坐标,允许曲面变形和最大化的纹理重用。讨论了切空间法线贴图、滤波问题以及从高度图导出法线图的方法。最后提到了地平线映射以增强法线贴图的效果。
摘要由CSDN通过智能技术生成

6.7.1 Blinn’s Methods

 

Blinn’s original bump mapping method stores two signed values, bu and bv, at each texel in a texture. These two values correspond to the amount to vary the normal along the u and v image axes. That is, these texture values, which typically are bilinearly interpolated, are used to scale two vectors that are perpendicular to the normal. These two vectors are added to the normal to change its direction. The two values bu and bv describe which way the surface faces at the point. See Figure 6.33.This type of bump map texture is called an offset vector bump map or offset map.

Blinn的原始凹凸贴图方法在纹理的每个纹理元素上存储两个有符号的值bu和bv。这两个值对应于沿u和v图像轴改变法线的量。也就是说,这些纹理值通常是双线性插值的,用于缩放垂直于法线的两个向量。这两个向量被添加到法线以改变它的方向。bu和bv这两个值描述了曲面在该点的朝向。参见图6.33。这种凹凸贴图纹理被称为偏移矢量凹凸贴图或偏移贴图。

Figure 6.33. On the left, a normal vector n is modified in the u- and v-directions by the (bu, bv) values taken from the bump texture, giving n′ (which is unnormalized). On the right, a heightfield and its effect on shading normals is shown. These normals could instead be interpolated between heights for a smoother look.

图6.33。在左侧,法线向量n在u和v方向上被从凹凸纹理中获取的(bu,bv)值修改,给出n’(未规格化)。在右侧,显示了高度场及其对着色法线的影响。这些法线可以在高度之间进行插值,以获得更平滑的外观。

Another way to represent bumps is to use a heightfield to modify the surface normal’s direction. Each monochrome texture value represents a height, so in the texture, white is a high area and black a low one (or vice versa). See Figure 6.34 for an example. This is a common format used when first creating or scanning a bump map, and it was also introduced by Blinn in 1978. The heightfield is used to derive u and v signed values similar to those used in the first method. This is done by taking the differences between neighboring columns to get the slopes for u, and between neighboring rows for v [1567]. A variant is to use a Sobel filter, which gives a greater weight to the directly adjacent neighbors [535].

另一种表示凸起的方法是使用高度场来修改表面法线的方向。每个单色纹理值代表一个高度,所以在纹理中,白色是高区域,黑色是低区域(反之亦然)。例子见图6.34。这是第一次创建或扫描凹凸贴图时使用的常用格式,也是由Blinn在1978年引入的。heightfield用于导出u和v符号值,类似于第一种方法中使用的值。这是通过获取相邻列之间的差异来获得u的斜率,以及相邻行之间v的斜率[1567]来实现的。一种变型是使用Sobel滤波器,其给予直接相邻的邻居更大的权重[535]。

Figure 6.34. A wavy heightfield bump image and its use on a sphere.
 图6.34。波浪高度场凹凸图像及其在球体上的应用。

6.7.2 Normal Mapping法线映射

 A common method for bump mapping is to directly store a normal map. The algorithms and results are mathematically identical to Blinn’s methods; only the storage format and pixel shader computations change.

凹凸贴图的常用方法是直接存储法线贴图。算法和结果在数学上与Blinn的方法相同;只有存储格式和像素着色器计算会发生变化。

The normal map encodes (x, y, z) mapped to [−1, 1], e.g., for an 8-bit texture the x-axis value 0 represents −1.0 and 255 represents 1.0. An example is shown in Figure 6.35. The color [128, 128, 255], a light blue, would represent a flat surface for the color mapping shown, i.e., a normal of [0, 0, 1].

法线映射编码映射到[1,1]的(x,y,z),例如,对于8位纹理,x轴值0表示-1.0,255表示1.0。图6.35给出了一个例子。浅蓝色的颜色[128,128,255]将表示所示颜色映射的平面,即[0,0,1]的法线。

 Figure 6.35. Bump mapping with a normal map. Each color channel is actually a surface normal coordinate. The red channel is the x deviation; the more red, the more the normal points to the right. Green is the y deviation, and blue is z. At the right is an image produced using the normal map. Note the flattened look on the top of the cube. (Images courtesy of Manuel M. Oliveira and Fabio Policarpo.)

图6.35。使用法线贴图的凹凸贴图。每个颜色通道实际上是一个表面法线坐标。红色通道是x偏差;红色越多,法线越向右。绿色表示y偏差,蓝色表示z偏差。右侧是使用法线贴图生成的图像。请注意立方体顶部的扁平外观。(图片由Manuel M. Oliveira和Fabio Policarpo提供。)

The normal map representation was originally introduced as a world-space normal map [274, 891], which is rarely used in practice. For that type of mapping, the perturbation is straightforward: At each pixel, retrieve the normal from the map and use it directly,along with a light’s direction, to compute the shade at that location on the surface. Normal maps can also be defined in object space, so that the model could be rotated and the normals would then still be valid. However, both worldand object-space representations bind the texture to specific geometry in a particular orientation, which limits texture reuse.

法线贴图表示最初是作为世界空间法线贴图引入的[274,891],在实践中很少使用。对于这种类型的贴图,扰动很简单:在每个像素上,从贴图中检索法线,并直接使用它和灯光的方向来计算表面上该位置的明暗度。法线贴图也可以在物体空间中定义,这样模型可以旋转,法线仍然有效。然而,世界和对象空间表示都将纹理绑定到特定方向的特定几何体,这限制了纹理的重用。

Instead, the perturbed normal is usually retrieved in tangent space, i.e., relative to the surface itself. This allows for deformation of the surface, as well as maximal reuse of the normal texture. Tangent-space normal maps also can compress nicely, since the sign of the z-component (the one aligned with the unperturbed surface normal) can usually be assumed to be positive.

相反,扰动的法线通常在切空间中检索,即,相对于表面本身。这允许曲面的变形,以及法线纹理的最大重用。切线空间法线贴图也可以很好地压缩,因为z分量(与未受干扰的表面法线对齐的那个)的符号通常可以假设为正。

Normal mapping can be used to good effect to increase realism—see Figure 6.36.

法线贴图可以很好的增加真实感——见图6.36。

Figure 6.36. An example of normal map bump mapping used in a game-like scene. Top left: the two normals maps to the right are not applied. Bottom left: normal maps applied. Right: the normal maps. (3D model and normal maps courtesy of Dulce Isis Segarra L´opez.) 

图6.36。一个在游戏场景中使用的法线贴图凹凸贴图的例子。左上:右边的两个法线贴图没有被应用。左下角:应用法线贴图。右图:法线贴图。(3D模型和普通地图由Dulce Isis Segarra L opez提供。)

Filtering normal maps is a difficult problem, compared to filtering color textures.In general, the relationship between the normal and the shaded color is not linear,so standard filtering methods may result in objectionable aliasing. Imagine looking at stairs made of blocks of shiny white marble. At some angles, the tops or sides of the stairs catch the light and reflect a bright specular highlight. However, the average normal for the stairs is at, say, a 45 degree angle; it will capture highlights from entirely different directions than the original stairs. When bump maps with sharp specular highlights are rendered without correct filtering, a distracting sparkle effect can occur as highlights wink in and out by the luck of where samples fall.

与过滤颜色纹理相比,过滤法线贴图是一个困难的问题。一般来说,正常颜色和阴影颜色之间的关系不是线性的,因此标准的滤波方法可能会导致令人讨厌的锯齿。想象一下看着闪亮的白色大理石砌成的楼梯。在某些角度,楼梯的顶部或侧面会捕捉到光线,并反射出明亮的镜面高光。然而,楼梯的平均法线是45度角;它将从与原始楼梯完全不同的方向捕捉高光。当具有尖锐镜面高光的凹凸贴图在没有正确过滤的情况下渲染时,会出现分散注意力的闪光效果,因为高光会由于样本掉落的位置而忽明忽暗。

Lambertian surfaces are a special case where the normal map has an almost linear effect on shading. Lambertian shading is almost entirely a dot product, which is a linear operation. Averaging a group of normals and performing a dot product with the result is equivalent to averaging individual dot products with the normals:

朗伯曲面是一种特殊情况,其中法线贴图对着色几乎具有线性效果。朗伯阴影几乎完全是点积,是线性运算。对一组法线求平均并对结果执行点积等效于对单个法线的点积求平均:

Note that the average vector is not normalized before use. Equation 6.14 shows that standard filtering and mipmaps almost produce the right result for Lambertian surfaces. The result is not quite correct because the Lambertian shading equation is not a dot product; it is a clamped dot product—max(l · n, 0). The clamping operation makes it nonlinear. This will overly darken the surface for glancing light directions,but in practice this is usually not objectionable [891]. One caveat is that some texture compression methods typically used for normal maps (such as reconstructing the zcomponent from the other two) do not support non-unit-length normals, so using non-normalized normal maps may pose compression difficulties. 

请注意,平均向量在使用前没有归一化。等式6.14表明标准滤波和小中见大贴图几乎为朗伯曲面产生正确的结果。这个结果不太正确,因为朗伯明暗处理方程不是点积;它是一个箝位点积—max(l · n, 0).。箝位操作使其成为非线性的。这将使掠射光方向的表面过度变暗,但在实践中,这通常是没有问题的[891]。一个警告是,一些通常用于法线贴图的纹理压缩方法(例如从其他两个重建z分量)不支持非单位长度法线,因此使用非规格化法线贴图可能会造成压缩困难。

In the case of non-Lambertian surfaces, it is possible to produce better results by filtering the inputs to the shading equation as a group, rather than filtering the normal map in isolation. Techniques for doing so are discussed in Section 9.13.

在非兰伯特曲面的情况下,通过将着色方程的输入作为一个组进行过滤,而不是单独过滤法线贴图,可以产生更好的结果。9.13节讨论了这样做的技术。

Finally, it may be useful to derive a normal map from a height map, h(x, y).This is done as follows [405]. First, approximations to derivatives in the x- and the y-directions are computed using centered differences as

最后,从高度图h(x,y)导出法线图可能是有用的。这是如下完成的[405]。首先,x和y方向导数的近似值使用中心差分计算,如下所示

The unnormalized normal at texel (x, y) is then 

纹理元素(x,y)处的非标准化法线为

Care has to be taken at the boundaries of the texture.

必须注意纹理的边界。

Horizon mapping [1027] can be used to further enhance normal maps by having the bumps be able to cast shadows onto their own surfaces. This is done by precomputing additional textures, with each texture associated with a direction along the surface’s plane, and storing the angle of the horizon in that direction, for each texel. See Section 11.4 for more information. 

地平线贴图[1027]可用于进一步增强法线贴图,使凸起能够将阴影投射到它们自己的表面上。这是通过预先计算附加纹理来完成的,每个纹理与沿表面平面的一个方向相关联,并为每个纹理元素存储该方向上的地平线角度。更多信息见第11.4节。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

椰子糖莫莫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值