“All it takes is for the rendered image to look right.”
—Jim Blinn
本章写得有些偷懒,是希望尽快跳到后面没有接触过的内容章节。
1 纹理映射管线
1.1 投影方程(The Projector Function)
常用的就是美术编辑(u,v)值,除此之外还有多种投影方式:
1.2 对应方程(The Corresponder Function)
对应方程转换纹理坐标到纹理坐标系的位置。它们在应用纹理到表面提供了灵活性。其中一个例子是利用API选择纹理的一部分来显示;
另一种类型是矩阵变换,可以应用到顶点和像素shader中。它可以移动,旋转,缩放,裁剪或者投影纹理到表面。
另一个类型的对应方程控制了纹理在超出[0,1]范围的应用方式,在DX中叫做“texture addressing mode.”,常用的类型如下:
- wrap (DirectX), repeat (OpenGL), or tile;
- mirror;
- clamp (DirectX) or clamp to edge (OpenGL);
- border (DirectX) or clamp to border (OpenGL)
1.3 纹理值
返回纹理对应坐标下的像素RGB值(可包括alpha)。
2 图像纹理(Image Texturing)
2.1 放大
最常见的放大滤波技术是nearest neighbor和线性插值。还有一种叫做 cubic convolution的方法,它使用4x4或者5x5的像素根据权重求和,它可以得到更好的放大效果。但是硬件一般不直接支持这种算法,它可以在shader中实现。
2.2 缩小
依然有3种方法:nearest neighbor,线性插值以及mipmapping:
- Mipmapping
最流行的在纹理映射中反走样的方法是mipmapping。其中的一组图像叫做mipmap chain,如下图:
组成高质量mipmap的两个重要因素是滤波和gamma矫正。
- Summed-Area Table
另一个防止过渡模糊的方法是Summed-Area Table(SAT)
- Unconstrained Anisotropic Filtering
这个是目前图像硬件最长用的提升纹理滤波质量的方法。
2.3 体积纹理
使用 (u,v,w)的三维纹理数据。
2.4 Cube Maps
由6个面组成的纹理,后续第十章详解。
2.5 Texture Representation
对于在同一个应用中控制很多张纹理,有很多中方法来提升性能。2.6节介绍纹理压缩。19掌中介绍纹理流和转码。
为了应用批处理,使用更大的纹理 texture atlas。
2.6 纹理压缩
3 Procedural Texturing
还有很多其它procedural texture算法,可以参考书中原文。
4 纹理动画
可通过修改[u,v]值达到简单的动画,也可以通过变换矩阵达到复杂一些的效果。
5 Material Mapping
纹理的常用方法是改变材质的属性,来影响着色方程。
材质还可以有进一步的应用。可以同来控制flow以及pixel shader本身。两个或者更多有不同着色方程的材质,可以通过一个纹理应用到同一个表面(纹理中像素值指定使用哪个材质计算)。
6 Alpha Mapping
alpha值可以通过alpha混合或者测试来实现多种效果,比如植物,爆炸和远距离物体。
一种效果较decaling,比如你希望在茶壶上渲染一个花朵,你不希望贴上整张图,所以就可以通过alpha测试只贴花朵。
其他效果查看原书。
7 Bump Mapping
这一节描述一大家族的小细节表现技术,我们叫做凹凸贴图(Bump Mapping)。它们都是逐像素来调整,但是不添加几何细节。
物体的细节可以划分为3类: macro-features – 涵盖许多像素;meso-features – 几个像素;micro-features – 小于一个像素。
7.1 Blinn’s Methods
一种是在纹理的每个texel中保存两个值:Bu,Bv,它们对于法向量的变化情况;
另一种四使用heightfield膝盖表面法向量的方向。
7.2 Normal Mapping
bump mapping常用的方法是直接保存法向量贴图。
8 Parallax Mapping
法线贴图的纹理在于,它不偏移位置,并且不会相互阻挡。
视差贴图的关键思想是通过检查被发现的可视像素的高度,对像素中应该看到的内容进行有根据的猜测。
8.1 Parallax Occlusion Mapping
9 Textured Lights
纹理也可以用来改变光源的光照强度。
进一步阅读材料
Heckbert has written a good survey of the theory of texture mapping [690] and a more in-depth report on the topic [691]. Szirmay-Kalos and Umenhoffer [1731] have an excellent, thorough survey of parallax occlusion mapping and displacement methods. More information about normal representation can be found in the work by Cigolle etal. [269] and by Meyer et al. [1205].
The book Advanced Graphics Programming Using OpenGL [1192] has extensive coverage of various visualization techniques using texturing algorithms. For extensive coverage of three-dimensional procedural textures, see Texturing and Modeling: A Pro-cedural Approach [407]. The book Advanced Game Development with Programmable Graphics Hardware [1850] has many details about implementing parallax occlusion mapping techniques, as do Tatarchuk’s presentations [1742, 1743] and Szirmay-Kalos and Umenhoffer’s survey [1731].
For procedural texturing (and modeling), our favorite site on the Internet is Shader-toy. There are many worthwhile and fascinating procedural texturing functions on display, and you can easily modify any example and see the results.
Visit this book’s website, realtimerendering.com, for many other resources.