法线贴图详解之----凹凸,法线以及高度图的区别及法线贴图蓝紫色的原因

2016-2-22 雨辰 遇到的一些问题

What’s the difference between Bump Maps, Normal Maps and Height Maps?

凹凸贴图,法线贴图以及高度图之间的区别


Normal Maps and Height Maps are both typesof Bump Map. They both contain data for representing apparent detail on thesurface of simpler polygonal meshes, but they each store that data in adifferent way.

法线贴图高度图都属于凹凸贴图的一种。他们所存储的数据都涉及到网格多边形表面细节,区别在于它们存储数据的方式不相同。

                              

On the left, a height map for bumpmapping a stone wall. On the right, a normal map for bump mapping a stone wall.

左边为石墙纹理的高度凹凸贴图,右边为石墙的法线凹凸贴图。


Above, on the left,you can see a height map used for bump mapping a stone wall. A height map is asimple black and white texture, where each pixel represents the amount thatpoint on the surface should appear to be raised. The whiter the pixel colour,the higher the area appears to be raised.

上述左边的图例为石墙纹理的高度凹凸贴图。高度图是一种简单仅含有黑白两色的纹理贴图,其像素的明暗代表游戏物体的凹凸。如某区域的白色的像素象征着此处有凸起的光影效果(即此处的高度值)。


A normal map is anRGB texture, where each pixel represents the difference in direction thesurface should appear to be facing, relative to its un-modified surface normal.These textures tend to have a bluey-purple tinge, because of the way the vectoris stored in the RGB values.

而法线纹理是一种RGB纹理,其像素存储的是游戏物体表面的法线信息。法线纹理往往都是蓝紫色的色调,因为其法线信息都存储在RGBB通道内(蓝色),所以呈现蓝色。

Modern realtime 3Dgraphics hardware rely on Normal Maps, because they contain the vectorsrequired to modify how light should appear to bounce of the surface. Unity canalso accept Height Maps for bump mapping, but they must be converted to NormalMaps on import in order to use them.

因为如今的实时3D图形硬件承担着巨大的渲染压力,需要无时无刻都需要对光影效果进行修改,所以最好的办法就是使用法线纹理,但是Unity还支持高度凹凸图,唯一麻烦的是在使用高度图之前要进行转换。



Why the bluey-purple colours?

为什么法线贴图都是蓝紫色的?
Understanding thisis not vital for using normal maps! It’s ok to skip this paragraph. However ifyou really want to know: The RGB colour values are used to store the X,Y,Zdirection of the vector, with Z being “up” (contrary to Unity’s usualconvention of using Y as “up”). In addition, the values in the texture aretreated as having been halved, with 0.5 added. This allows vectors of alldirections to be stored. Therefore to convert an RGB colour to a vectordirection, you must multiply by two, then subtract 1. For example, an RGB valueof (0.5, 0.5, 1) or #8080FF in hex results in a vector of (0,0,1) which is “up”for the purposes of normal-mapping - and represents no change to the surface ofthe model. This is the colour you see in the flat areas of the “example” normalmap earlier on this page.

这个小节的内容与法线纹理的使用无关,所以您可以选择跳过这个小节。通常情况下,美工会做出一张使用的RGB三个通道用来存放法线的XYZ三个轴向的坐标的法线贴图。但是Unity在导入法线贴图的时候会自动将法线贴图压缩成DXT5nm格式,这个格式的好处是它只使用AG(透明和绿色)两个通道来存放两个轴向的坐标值。而Z轴向的坐标值由于是单位坐标可以通过1减去另外前两个轴向坐标的平方和来得到(已知2个分量,可求第三个),从而可以以同样的容量存放更大尺寸的法线贴图,我们都知道图片的颜色通道存的都是非负数(法线贴图生成的时候已经把[-1,1]压缩为[0-1]),而我们的三维空间是[-1,1],所以我们要把它解析放大一下,方法就是对对应的颜色通道值乘以2再减1。这就能存储游戏物体所有的法线信息了。例如,一个RGB值为(0.5,0.5,1)或#8080ff(16进制)的颜色向量,它所存储法线向量值为(0,0,1),代表该图向上的法向量,即模型没有凹凸现象。对比本页面之前的模型平面区域,您就会发现这种颜色基调。

                              
A normal map using only #8080FF,which translates to a normal vector of 0,0,1 or “straight up”. This applies nomodification to the surface normal of the polygon, and therefore produces nochange to the lighting. Any pixels which are different to this colour resultsin a vectors that point in a different direction - which therefore modify theangle that is used to calculate light bounce at that point.

法线贴图其颜色值一般为# 8080ff,即相当于(0,0,1)的向上向量(Z轴)。由于该多边形表面法线没有改变,所以不改变它原本的光影效果。如果模型的法线有偏移(即有凹凸)时,都不会是蓝紫色,因为只要一修改某点的法线信息,就需要重新计算该点的光影。


A value of (0.43,0.91, 0.80) gives a vector of (–0.14, 0.82, 0.6), which is quite a steepmodification to the surface. Colours like this can be seen in the bright cyanareas of the stone wall normal map at the top of some of the stone edges. Theresult is that these edges catch the light at a very different angle to theflatter faces of the stones.

RGB值为(0.43,0.91,0.80)的像素点,其法线向量值为(–0.14,0.82,0.6),这意味着应用该贴图的模型表面非常不平整。参照下图,我们可以看到石头缝之间的明亮蓝紫色。这些区域在不同角度上反射和捕捉光线,用于美化或突显模型的真实感。

The bright cyan areas in thenormalmap for these stones show a steep modification to the polygon’s surfacenormals at the top edge of each stone, causing them to catch the light at thecorrect angle.

石墙的法线贴图的明亮蓝紫色区域用于突显模型的凹凸,使它们能在合适的角度捕捉光线。


A stone wall with no bumpmap effect. The edges andfacets of the rock do not catch the directional sun light in the scene.

一个没有凹凸效果的石墙。边缘和岩面没有捕捉太阳的方向光。
  The same stonewall with bumpmapping applied. The edges of the stones facing the sun reflectthe directional sun light very differently to the faces of the stones, and theedges facing away.

应用了凹凸贴图的石头墙。同时受到太阳光照射的石墙边缘与石墙以及阴暗处石墙边缘(黑色处)之间的反射区别。

  The samebumpmapped stone wall, in a different lighting scenario. A point light torchilluminates the stones. Each pixel of the stone wall is lit according to howthe light hits the angle of the base model (the polygon), adjusted by thevectors in the normal maps. Therefore pixels facing the light are bright, andpixels facing away from the light are darker, or in shadow.

应用了相同的凹凸贴图的石头墙,在不同的光照下会呈现不同的光影效果。上图为火炬所呈现的光影效果。石墙的每个像素点会与基础光照模型进行交互,然后修改法线贴图的信息。因此像素面正对光源处呈明亮区域,而背对光源较暗的像素则为黑。

标签: Unity3D-Shader Unity3D

发表评论:

雨辰 joyimp|@2011-2018 京ICP备16030765号