深入理解光照计算模型(1)

By | 05月29日
Advertisement

Ambient Lighting (Direct3D 9)

Ambient lighting provides constant lighting for a scene. It lights all object vertices the same because it is not dependent on any other lighting factors such as vertex normals, light direction, light position, range, or attenuation. It is the fastest type of lighting but it produces the least realistic results. Direct3D contains a single global ambient light property that you can use without creating any light. Alternatively, you can set any light object to provide ambient lighting. The ambient lighting for a scene is described by the following equation.

Ambient Lighting = Ca * [Ga + sum(Atti * Spoti * Lai)]

Where:

Parameter Default value Type Description
Ca (0,0,0,0) D3DCOLORVALUE Material ambient color
Ga (0,0,0,0) D3DCOLORVALUE Global ambient color
Atteni (0,0,0,0) D3DCOLORVALUE Light attenuation of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).
Spoti (0,0,0,0) D3DVECTOR Spotlight factor of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).
sum N/A N/A Sum of the ambient light
Lai (0,0,0,0) D3DVECTOR Light ambient color of the ith light

The value for Ca is either:

  • vertex color1, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR1, and the first vertex color is supplied in the vertex declaration.
  • vertex color2, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR2, and the second vertex color is supplied in vertex declaration.
  • material ambient color.

Note If either AMBIENTMATERIALSOURCE option is used, and the vertex color is not provided, then the material ambient color is used.

To use the material ambient color, use SetMaterial as shown in the example code below.

Ga is the global ambient color. It is set using SetRenderState(D3DRS_AMBIENT). There is one global ambient color in a Direct3D scene. This parameter is not associated with a Direct3D light object.

Lai is the ambient color of the ith light in the scene. Each Direct3D light has a set of properties, one of which is the ambient color. The term, sum(Lai) is a sum of all the ambient colors in the scene.

Example

In this example, the object is colored using the scene ambient light and a material ambient color.

#define GRAY_COLOR    0x00bfbfbf  // create material D3DMATERIAL9 mtrl; ZeroMemory(&mtrl, sizeof(mtrl)); mtrl.Ambient.r = 0.75f; mtrl.Ambient.g = 0.0f; mtrl.Ambient.b = 0.0f; mtrl.Ambient.a = 0.0f; m_pd3dDevice->SetMaterial(&mtrl); m_pd3dDevice->SetRenderState(D3DRS_AMBIENT, GRAY_COLOR);

According to the equation, the resulting color for the object vertices is a combination of the material color and the light color.

These two images show the material color, which is gray, and the light color, which is bright red.

深入理解光照计算模型(1)

The resulting scene is shown below. The only object in the scene is a sphere. Ambient light lights all object vertices with the same color. It is not dependent on the vertex normal or the light direction. As a result, the sphere looks like a 2D circle because there is no difference in shading around the surface of the object.

深入理解光照计算模型(1)

To give objects a more realistic look, apply diffuse or specular lighting in addition to ambient lighting.

Attenuation and Spotlight Factor (Direct3D 9)

The diffuse and specular lighting components of the global illumination equation contain terms that describe light attenuation and the spotlight cone. These terms are described below.

Attenuation

The attenuation of a light depends on the type of light and the distance between the light and the vertex position. To calculate attenuation, use one of the following equations.

Atten = 1/( att0i + att1i * d + att2i * d2)

Where:

Parameter Default value Type Description Range
att0i 0.0 FLOAT Constant attenuation factor 0 to +infinity
att1i 0.0 FLOAT Linear attenuation factor 0 to +infinity
att2i 0.0 FLOAT Quadratic attenuation factor 0 to +infinity
d N/A FLOAT Distance from vertex position to light position N/A
  • Atten = 1, if the light is a directional light.
  • Atten = 0, if the distance between the light and the vertex exceeds the light's range.

The att0, att1, att2 values are specified by the Attenuation0, Attenuation1, and Attenuation2 members of D3DLIGHT9.

The distance between the light and the vertex position is always positive.

d = | Ldir |

Where:

Parameter Default value Type Description
Ldir N/A D3DVECTOR Direction vector from vertex position to the light position

If d is greater than the light's range, that is, the Range member of a D3DLIGHT9 structure, Direct3D makes no further attenuation calculations and applies no effects from the light to the vertex.

The attenuation constants act as coefficients in the formula - you can produce a variety of attenuation curves by making simple adjustments to them. You can set Attenuation1 to 1.0 to create a light that doesn't attenuate but is still limited by range, or you can experiment with different values to achieve various attenuation effects.

The attenuation at the maximum range of the light is not 0.0. To prevent lights from suddenly appearing when they are at the light range, an application can increase the light range. Or, the application can set up attenuation constants so that the attenuation factor is close to 0.0 at the light range. The attenuation value is multiplied by the red, green, and blue components of the light's color to scale the light's intensity as a factor of the distance light travels to a vertex.

Spotlight Factor

深入理解光照计算模型(1)

Parameter Default value Type Description Range
rhoi N/A FLOAT cosine(angle) for spotlight i N/A
phii 0.0 FLOAT Penumbra angle of spotlight i in radians [thetai, pi)
thetai 0.0 FLOAT Umbra angle of spotlight i in radians [0, pi)
falloff 0.0 FLOAT Falloff factor (-infinity, +infinity)

Where:

rho = norm(Ldcs) . norm(Ldir)

and:

Parameter Default value Type Description
Ldcs N/A D3DVECTOR The negative of the light direction in camera space
Ldir N/A D3DVECTOR Direction vector from vertex position to the light position

After computing the light attenuation, Direct3D also considers spotlight effects if applicable, the angle that the light reflects from a surface, and the reflectance of the current material to calculate the diffuse and specular components for that vertex. For more information, see SpotLight.

Similar Posts:

  • 通俗理解LDA主题模型(boss)

    0 前言 看完前面几篇简单的文章后,思路还是不清晰了,但是稍微理解了LDA,下面@Hcy开始详细进入boss篇.其中文章可以分为下述5个步骤: 一个函数:gamma函数 四个分布:二项分布.多项分布.beta分布.Dirichlet分布 一个概念和一个理念:共轭先验和贝叶斯框架 两个模型:pLSA.LDA(在本文第4 部分阐述) 一个采样:Gibbs采样 本文便按照上述5个步骤来阐述,希望读者看完本文后,能对LDA有个尽量清晰完整的了解.同时,本文基于邹博讲LDA的PPT.rickjin的LDA

  • <<深入理解java内存模型>>学习总结

    硬件内存模型 我们知道计算机处理器的运算速度远远高于它的存储和通信子系统的速度,大量的时间都花费在磁盘I/O,网络通信和数据库访问上.处理器运算时候,读取和存取数据必定需要与内存进行I/O交互.而对主存的访问是一项昂贵的操作,内存成了CPU的性能限制,这称为Memory Wall.所以不得不在处理器和内存之间引入一层读写速度尽可能接近处理器运算速度的高速缓存(Cache).简单来说就是在缓存中保存一份热点数据的拷贝供CPU尽快存取.这时又引入了另一个问题:缓存一致性(Cache coherenc

  • 9-2加上光照计算的GOURAUD shader多边形)

    9-2加上光照计算的GOURAUD shader多边形) 对于光照计算的颜色,就是考虑了法线和初始颜色. 对于固定着色的多边形,将多边形的颜色复制到lit_color[0]中:对于恒定着色的多边形,计算面法线,存储在lit_color[0]: GOURAUD着色计算顶点法线,存储在lit_color{0,1,2}中. 光照计算步骤 1只计算光照强度,并对顶点进行标记,以防重复计算 2使用多边形的初始颜色对顶点的光照强度调制. 另外, 提到了一个物体转换为多边形时,顶点结合性将丧失,说白了,就是重

  • 深入理解java内存模型(二)

    深入理解Java内存模型(二)-重排序 数据依赖性 如果两个操作访问同一个变量,且这两个操作中有一个为写操作,此时这两个操作之间就存在数据依赖性.数据依赖性分下列三种类型: 写后读:如a = 1; b = a; 写一个变量之后,再读这个位置. 写后写:如a = 1; a = 2;写一个变量之后,再写这个变量. 读后写:如a = b; b = 1;读一个变量之后,再写这个变量. 上面三种情况,只要重排序两个操作的执行顺序,执行结果就会发生改变. 前面提到过的,编译器和处理器可能会对操作做重排序.编

  • 《深入理解Java内存模型》读书总结

    概要 文章是<深入理解Java内容模型>读书笔记,该书总共包括了3部分的知识. 第1部分,基本概念 包括"并发.同步.主内存.本地内存.重排序.内存屏障.happens before规则.as-if-serial规则.数据依赖性.顺序一致性模型.JMM的含义和意义". 第2部分,同步机制 该部分中就介绍了"同步"的3种方式:volatile.锁.final.对于每一种方式,从该方式的"特性"."建立的happens befo

  • NOSQL(六)集群并发计算模型Map-Reduce

    <NoSQL精粹>读书笔记,转载请注明出处<jiq•钦's technical Blog> 面向聚合的数据库能够兴起,很大程度上是由于集群的增长.集群不仅改变了数据存储的规则,还改变了数据计算的方式. 集中式数据库通常两种方式处理计算逻辑:一种是在数据库服务器上执行数据计算.一种是在客户端计算机上执行数据计算.把数据库放到集群之后,采用的计算方式是将计算分布到多台计算机上,同时为了尝试减少网络传输的数据量,把节点所需的数据尽可能多地放到该节点上执行.这就是所谓的"Map-

  • Hou的图像显著性计算模型

    已下博文转自 http://www.cnblogs.com/CCBB/archive/2011/05/19/2051442.html 一种简单的图像显著性计算模型 <Saliency Detection: A Spectral Residual Approach>是上交高材生侯晓迪在07年的CVPR上发表的一篇论文.这篇文章提出了一个图像视觉显著性的简单计算模型.有关算法原理可以参见此篇论文以及作者主页:http://www.klab.caltech.edu/~xhou/projects/sp

  • DRILLNET 2.0------第十九章 欠平衡钻井水力参数计算模型

    第十九章 欠平衡钻井水水参数计算模型 19.1背景介绍 欠平衡钻井水力参数计算(UBD),空气/雾化/泡沫水力计算模型,最初是由莫尔科技公司开发.作为空气/雾化/泡沫和欠平衡钻井技术与DEA-101联合工业项目的一部分.对于欠平衡流体计算的水力参数来说,UBD是业界最广泛和容易使用的钻井工程的软件程序.这个程序被全球广泛使用,他是为设计和监控欠平衡钻井和完井作业而使用的. 泡沫已经被石油工业使用几十年.他作为一个循环流体已经被证明,他在井眼清洁和钻井作业过程中是十分经济和高效的一种流体.他同样也

  • 常见的共面阻抗计算模型

    所谓的"共面",即阻抗线和参考层在同一平面,即阻抗线被VCC/GND所包围, 周围的VCC/GND即为参考层. 相较于单端和差分阻抗模型,共面阻抗模型多了一个参数D1,即阻抗线和参 考层VCC/GND之间的间距. 在Palor Si9000中,下面红色标注的工具栏图标为coplanar模型组: 针对共面模型,下面只选几种典型模型来进行说明,更详细全面的内容 请参考同组笔记本下的"常见的阻抗模型---整理版". 另外注意,此组模型都是wavegide模式. 1. Su

  • spark部署、计算模型、内部执行原理、工作机制详解

    1.spark的安装和部署 第二章 安装和部署简单,不说了 =========================== 第三章: spark计算模型 blockManager管理rdd的物理分区,每个block就是节点上对应的一个数据块,可以存储在内存或者磁盘上,而rdd中的partition是一个逻辑数据块,对应相应的物理块block 本质上一个rdd在代码中相当于数据的一个元数据结构. 存储着数据分区以及逻辑结构映射关系. 存储着rdd之前的依赖转换关系. 在spark的执行过程中 在物理上,r

Tags: