Tekkaman

导航

 

Phong Shading

  The most serious problem with Gouraud shading occurs when specular highlights are found in the middle of a large polygon. Since these specular highlights are absent from the polygon's vertices and Gouraud shading interpolates based on the vertex colors, the specular highlight will be missing from the polygon's interior. This problem is fixed by Phong shading.

  相比Gouraud,Phong Shading能更好地解决镜面照问题。

  Unlike Gouraud shading, which interpolates colors across polygons, in Phong shading a normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. The surface normal is interpolated and normalized at each pixel and then used in a reflection model, e.g. the Phong reflection model, to obtain the final pixel color. Phong shading is more computationally expensive than Gouraud shading since the reflection model must be computed at each pixel instead of at each vertex.

  顶点色=GlobalAmbient*kAmbientColor + LiVec*Normal*kDiffuseColor + RefVec*ViewVec*kSpecularColor

  Color = Dot(v,r)^m1*Spec*m2

  m1:光泽度,小的m1带来大而平滑的光斑。大的值带来小而亮的光斑。

  m2:反射色,控制光斑的强度。强反射表面拥有较大的m2值,粗糙表面拥有较小的m2值。

  当有多个光源时,对所有光源求和即可。

Blinn-Phong

  相比于Phong,镜面光照公式改为下面这个:

  MidVec*Normal*kSpecularColor。

  MidVec指LiVec和ViewVec的中间向量。Blinn-Phong比Phong略快。

光的衰减

  现实世界里,光强度反比于物体和光源距离的平方。可以用一个简单的衰减模型来替代。用D_min、D_max把距离分为3段,小于D_min时,光强为1;大于D_max时光强为0;在D_min、D_max中进行插值。

  一旦计算出衰减系数i,则用i乘以Phone模型计算出的(镜面反射+漫反射)颜色,即可模型光的衰减。记住环境光是没有衰减的。

  参考《3D数学基础》15.4.7光的衰减

参考:

1、http://en.wikipedia.org/wiki/Phong_shading

2、http://en.wikipedia.org/wiki/Phong_reflection_model

3、http://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model

posted on 2014-08-03 11:09  Tekkaman  阅读(1172)  评论(0编辑  收藏  举报