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

Phong Shading的更多相关文章

  1. 如何在Unity中分别实现Flat Shading(平面着色)、Gouraud Shading(高洛德着色)、Phong Shading(冯氏着色)

    写在前面: 先说一下为什么决定写这篇文章,我也是这两年开始学习3D物体的光照还有着色方式的,对这个特别感兴趣,在Wiki还有NVIDIA官网看了相关资料后,基本掌握了渲染物体时的渲染管道(The re ...

  2. What is Away3D

    做了几个基于Flash平台的3D的项目,一路走来收获颇多.Away3D作为一个开源的Flash3D引擎,在3D页游领域,无疑是当前OGRE在国内的地位. 翻译出了多年前做Away3D中国社区的时候翻译 ...

  3. OpenGL Shader in OpenCASCADE

    OpenGL Shader in OpenCASCADE eryar@163.com Abstract. As implementation of one of the strategic steps ...

  4. OpenCascade Ray Tracing Rendering

    OpenCascade Ray Tracing Rendering eryar@163.com 摘要Abstract:OpenCascade6.7.0中引入了光线跟踪算法的实现.使用光线跟踪算法可实现 ...

  5. Unity3d《Shader篇》法线贴图

    效果图 贴图 法线贴图 //代码 Shader "Custom/NormalMap" { Properties { _MainTex ("Texture", 2 ...

  6. 解读Unity中的CG编写Shader系列十 (光滑的镜面反射(冯氏着色))

    前文完成了最基本的镜面反射着色器,单平行光源下的逐顶点着色(per-vertex lighting),又称为古罗着色(Gouraud shading).这篇文章作为后续讨论更光滑的镜面反射方式,逐像素 ...

  7. Opengles 管线编程介绍

      OpenGL ES 2.0可编程管道 上图橙色部分(Vertex Shader和Fragment Shader)为此管道的可编程部分.整个管道包含以下两个规范: 1)         OpenGL ...

  8. [ZZ] 基于DirectX shader的Per-pixel lighting实现

    这个特效需要用到DX11 UAV吗? http://blog.tianya.cn/blogger/post_show.asp?BlogID=510979&PostID=5665974 Intr ...

  9. OpenGL 开始学习指南

    近期需要做一个涌潮的预报与仿真模拟,为了使模型更具有真实感,且逼真,使用起来更灵活.感觉还是得从基础的OpenGL学习.鉴于Direct3D技术存在的众多不确定性,且评论不太好的原因,决定用OpenG ...

随机推荐

  1. grpc rust 项目基本使用

    1. 安装依赖(rust 基本依赖就不说了,需要配置环境变量) protoc 参考: https://github.com/google/protobuf/releases/tag/v3.5.1 2. ...

  2. Promise的一些相关讲解

    在javascrpit的语言特性上 有明确的一个特性指出,该语言的是单线程进程.这就意味着JavaScript的所有网络操作,浏览器事件,都必须是异步执行. 如下面的例子,可以感受到单线程与异步回调: ...

  3. Qt学习之秒表的实现(StopWatch) (转)

    秒表对于我来说并不陌生,在之前自己学习单片机时,实现过秒表和数字钟:基本思路:开启单片机带的定时器,并设置它没10ms溢出一次,分别用三个变量hour,minute,secong记录秒表的时分秒,然后 ...

  4. Java语言与C语言混合编程(1)--Java native 关键字

    一. 什么是 native Method 简单地讲,一个 native Method 就是一个java调用非java代码的接口.一个 native Method 是这样一个java的方法:该方法的实现 ...

  5. 数组与指针的区别,以及在STL中传递数组/指针

    数组和指针在作为实参传入T[] 或T*的形参时没有区别 void f(int pi[]) { cout << sizeof(pi) << endl; } int a[5] = ...

  6. mysql索引相关理解

    1.索引是高效获取数据的数据结构, 2.唯一索引,索引值不重复unique create unique index 索引名 on 表名(字段) alter table 表名 add unique in ...

  7. C#操作MySql数据库帮助类(Dapper,T-Sql)

    using System.Text; using MySql.Data.MySqlClient; using System.Data; using Dapper; using System.Refle ...

  8. Servlet 前端后台交互

    一. URL地址传值   1.1. 地址传值 http://localhost:8080/xj/123/name.json servlet 对应接受方法 @RequestMapping(value=& ...

  9. springmvc和activemq的整合使用

    1.简介:ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台 ...

  10. 20181105_线程之Task

    Task是基于.net Framework3.0框架, Task使用的线程也是来自于ThreadPool 多线程的两个意义: 优化体验(常见于不卡界面), 提升运行速度(不同线程可以分担运算任务) 总 ...