Bump Map

original link:http://freespace.virgin.net/hugo.elias/graphics/x_polybm.htm




Bump mapping is very much like Texture Mapping. However, where Texture Mapping added colour toa polygon, Bump Mapping adds, what appears to be surface roughness. This can have a dramaticeffect on the look of a polygonal object. Bump Mapping can add minute detail to an object whichwould otherwise require a large number of polygons. Note that the polygon is still physicallyflat, but appears to a be bumpy.
Take a look at the cube on the left. If you look closely, you can see lots of detail on it.It looks as if it must have been made from millions of tiny polygons, but is made from just 6.You might ask how this differs from Texture Mapping. The difference is that a Bump Map isa Texture Map that responds to the direction of the light.

The theory behind Bump Mapping

Take a close look at a rough surface. From a distance, the only way you know it is roughis by the fact that it's brightness changes up and down across it's surface. Your brain canpick out these bright and dark patterns and interpret them as bumps on the surface.

The little picture on the left illustrates this. You see what looks like an embossed surface. Some rectangles and letters have been pressed into it, but if you touch it, it just feels likethe glass of your monitor.Nothing more has been done than change the brightness if the image injust the right places, your brain does the rest. This technique can be used to add real feelingto a polygon.

So how did I know which bits to make bright, and which to make dark? It's easy. Most peoplespend their lives in an environment where the main light source is above them (except us spodsof course, whose main light source comes from the monitor). So surfaces angled upwards tend tobe brightly lit, and downward inclined surfaces tend to be darker. Therefore it follows that ifyour eyes see light and dark areas on an object, they will interpret them as bumps; lighter bitsit takes as up-facing, and darker bits it takes as down-facing. So, I just coloured the lineson the image accordingly.
As if you needed any more evidence, here is exactly the same image, but rotated 180 degrees.It appears to be the inverse of the previous one. Those areas that appeared to be pushed in, nowseem to have popped out, and vice-versa.

Now, your brain is not entirely stupid. If you had visual evidence that the inverted image waslit from underneath, your brain would again interpret it as the first image. Infact, if youstare, and think hard enough about a light source comming from the bottom right, you can makethat happen.


What is a Bump Map

A bump map is very much like a texture map. However, rather than containing colours, it containsbumps. The most common way to represent bumps is by the height field method. A greyscaled texturemap is used, where the brightness of each pixel represents how much it sticks out from thesurface (see image on right). This is a very convenient way to store a bump map, and it's simpleto make. How this information is used by the renderer will become apparent later.
Of course, you needn't limit yourself to such simple patterns. You can have wood, stone,peeling paint, anything you want.


So how's it done

Bump mapping is an extension of the Phong Shading technique. In Phong Shading, the surfacenormal was interpolated over the polygon, and that vector was used to calculate the brightnessof that pixel. When you add bump mapping, you are altering the normal vector slightly, based oninformation in the bump map. Adjusting the normal vector causes changes in the brightness of thepixels in the polygon. Simple.

Now, there are several ways of acheving this. I have never actually programmed real phongshading or bump mapping, only the fast versions (which work very nicely thankyou), so I amkind of making this next bit up as I go along. Bare with me.

OK, so we need a method for converting the height information on the bump map into vectoradjustment information for the phong shader. This is not so hard to do, but it might be trickyto explain.

OK, so first you'll need a way to convert the bumps on the bumpmap into little vectors,one vector for each pixel. Take a look at the zoomed-in view of a bumpmap on the left. The lighterpixels stick out more than the darker ones. Get the picture? Now, for each pixel, a vector must becomputed. These vectors represent the incline of the surface at that pixel. The picture on theright represents this. The little red vectors point in the 'downhill' direction.
There are many ways to calculate these vectors. Some are more accurate than others, but itdepends exactly what you mean by accurate. One of the most common methods is to calculate theX and Y gradient at that pixel:

	x_gradient = pixel(x-1, y) - pixel(x+1, y)
	y_gradient = pixel(x, y-1) - pixel(x, y+1)
With these two gradients, you will now need to adjust the normal vector of the polygon atthat point.

Here is the polygon, with it's origional normal vector, n. Also shown are the twovectors which are going to be used to adjust the normal vector for this pixel. The two vectorsmust be aligned with the bumpmap for the polygon to be rendered correctly. I.E. the vectors areparallel to the axes of the bumpmap.
On the right are the bump map, and the polygon. Both pictures show the U and V vectors.
Now you can see the new Normal vector after adjustment. The adjustment is simply:
	New_Normal = Normal + (U * x_gradient) + (V * y_gradient)
With this New_Normal vector, you can procede to calculate the brightness of the polygon atthat point, using the usual phong shading technique.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值