以前自己看过shader,最近因为被客户逼着搞效果,只能自个儿捣鼓shader。好友把我深深鄙视一番。只好自己单独写篇环境贴图的文章,来小总结一下。

   环境贴图(Environment Mapping)又叫反射贴图(Reflection Mapping),在曲面上对反射效果进行很好的的近似。示意图如图所示:

未命名

   所有的EM方法都从一束来自视点的射线出发,到反射体的一个点终止,然后这束光线以这个点处的法线为基准进行反射。环境贴图近似假设进行反射的光源与物体都位于很远的位置,同时反射体不会反射自身。如果这些假设成立,就可以将反射体周围的环境看成围绕他的一个二维投影。

   EM的算法步骤如下:(摘自Real time rendering)

  Generate or load a two-dimensional image representing the environment.

  For each pixel that contains a reflective object, compute the normal at the location on the surface of the object.

  Compute the reflected view vector from the view vector and the normal.

  Use the reflected view vector to compute an index into the environment map that represent the incoming radiance in the reflected view direction.

  Use the texel data from the environment map as incoming radiance .

目前环境贴图应用的方法有Blinn和Newell方法、立方体贴图和球面贴图。具体的方法可以参考实时计算机图形学。

使用立方体贴图实现的效果如下:

IT@B90K{XAYJBI6L}L2_39X

posted on 2012-01-05 17:29  cg_ghost  阅读(2697)  评论(0编辑  收藏  举报