3d 绘制中的光照
2016-04-04 09:37
357 查看
In order to start constructing realistic scenes, we need a way to model how light interacts with surfaces. Fortunately, much of computer graphics concerns itself with figuring out clever ways to approximate the behavior of light. We will use an approximation
consisting of three terms to model different species of light that occur in a scene: ambient, diffuse, and specular. Each pixel’s color will be the sum of these three terms. Here is the equation representing that relationship at the highest level:
Above,
stands
for intensity, specifically, outgoing radiant intensity. We’ll use
to
signify properties of the light source, and
to
signify properties of the material. None of these values have a precise physical basis. Our first attempt at approximating illumination involves a lot of shortcuts. Therefore, the values we choose for these quantities will be based on aesthetics rather than
physical exactitude.
The types of lights we will be dealing with are directional; they do not have a defined position in
space. Instead, we imagine that they are far enough away to be characterized exclusively by the direction in which they emit light. The sun is an example of such a directional light.
Ambient light is a non-directional kind of light that is not associated with a particular light source. Instead, it is an approximation used to model indirect light (light that has bounced off other surfaces in the scene), which is not captured by the other
terms. Ambient lighting prevents the parts of geometry that are not directly lit from being completely black. The contribution of ambient light is normally subtle.
Ambient light is calculated as the product of the ambient intensity of the light and the ambient response of the surface:
Usually, the material will have a fairly low ambient response, to represent the fact that ambient light is a minor contribution to the overall reflected intensity.
Diffuse light follows Lambert’s
cosine law, which states that the intensity of reflected light is directly proportional to the cosine of the angle between the direction of the incident light and the normal of the surface. The normal is a vector that is perpendicular to the surface. Light
that is head-on is reflected to a greater degree than light that arrives at a shallow angle of incidence.
Diffuse reflection is modeled by the following simplified equation:
If we assume that the normal vector and incident light direction vector are unit vectors, we can use the familiar dot product to calculate this term:
The specular light term is used to model “shiny” surfaces. It models the tendency of the material to reflect light in a particular direction rather than scattering it in all directions. Shiny materials create specular highlights,
which are a powerful visual cue for illustrating how rough or shiny surfaces are. “Shininess” is quantified by a parameter called thespecular
power. For example a specular power of 5 corresponds with a rather matte surface, while a specular power of 50 corresponds to a rather shiny surface.
There are a couple of popular ways to compute the specular term, but here we will use a Blinn-Phong approximation. The Blinn-Phong specular term uses an intermediate vector called the halfway
vector that points halfway between the direction to the light source and the direction from which the surface is being viewed:
Once we have the halfway vector in hand, we compute the dot product between the the surface normal and the halfway vector, and raise this quantity to the specular
power of the material.
This exponentiation is what controls how “tight” the resulting specular highlights are; the higher the specular power, the sharper the highlights will appear.
Now that we’ve computed all three terms of our lighting equation, we sum together the results at each pixel to find its final color. In the next few sections, we’ll talk about how to actually achieve this effect with the Metal shading language.
转载自: http://metalbyexample.com/up-and-running-3/
consisting of three terms to model different species of light that occur in a scene: ambient, diffuse, and specular. Each pixel’s color will be the sum of these three terms. Here is the equation representing that relationship at the highest level:
Above,
stands
for intensity, specifically, outgoing radiant intensity. We’ll use
to
signify properties of the light source, and
to
signify properties of the material. None of these values have a precise physical basis. Our first attempt at approximating illumination involves a lot of shortcuts. Therefore, the values we choose for these quantities will be based on aesthetics rather than
physical exactitude.
The types of lights we will be dealing with are directional; they do not have a defined position in
space. Instead, we imagine that they are far enough away to be characterized exclusively by the direction in which they emit light. The sun is an example of such a directional light.
Ambient Light
Ambient light is a non-directional kind of light that is not associated with a particular light source. Instead, it is an approximation used to model indirect light (light that has bounced off other surfaces in the scene), which is not captured by the otherterms. Ambient lighting prevents the parts of geometry that are not directly lit from being completely black. The contribution of ambient light is normally subtle.
Ambient light is calculated as the product of the ambient intensity of the light and the ambient response of the surface:
Usually, the material will have a fairly low ambient response, to represent the fact that ambient light is a minor contribution to the overall reflected intensity.
Diffuse Light
Diffuse light follows Lambert’scosine law, which states that the intensity of reflected light is directly proportional to the cosine of the angle between the direction of the incident light and the normal of the surface. The normal is a vector that is perpendicular to the surface. Light
that is head-on is reflected to a greater degree than light that arrives at a shallow angle of incidence.
Diffuse reflection is modeled by the following simplified equation:
If we assume that the normal vector and incident light direction vector are unit vectors, we can use the familiar dot product to calculate this term:
Specular Light
The specular light term is used to model “shiny” surfaces. It models the tendency of the material to reflect light in a particular direction rather than scattering it in all directions. Shiny materials create specular highlights,which are a powerful visual cue for illustrating how rough or shiny surfaces are. “Shininess” is quantified by a parameter called thespecular
power. For example a specular power of 5 corresponds with a rather matte surface, while a specular power of 50 corresponds to a rather shiny surface.
There are a couple of popular ways to compute the specular term, but here we will use a Blinn-Phong approximation. The Blinn-Phong specular term uses an intermediate vector called the halfway
vector that points halfway between the direction to the light source and the direction from which the surface is being viewed:
Once we have the halfway vector in hand, we compute the dot product between the the surface normal and the halfway vector, and raise this quantity to the specular
power of the material.
This exponentiation is what controls how “tight” the resulting specular highlights are; the higher the specular power, the sharper the highlights will appear.
The Result
Now that we’ve computed all three terms of our lighting equation, we sum together the results at each pixel to find its final color. In the next few sections, we’ll talk about how to actually achieve this effect with the Metal shading language.转载自: http://metalbyexample.com/up-and-running-3/
相关文章推荐
- 3D设计 Adobe Acrobat 3D 8.1.0 英文版 下载
- jquery带翻页动画的电子杂志代码分享
- jquery 3D 标签云示例代码
- jQuery+CSS3实现3D立方体旋转效果
- jquery实现叠层3D文字特效代码分享
- Android编程实现3D滑动旋转效果的方法
- Android编程实现3D旋转效果实例
- Android利用Camera实现中轴3D卡牌翻转效果
- 一个很有趣3D球状标签云兼容IE8
- javascript实现3D变换的立体圆圈实例
- 原生javascript+css3编写的3D魔方动画旋扭特效
- JS实现3D图片旋转展示效果代码
- js实现3D图片逐张轮播幻灯片特效代码分享
- Ubuntu 3D 桌面
- CSS3中3D综合应用及分析
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关