個人檔案Quake3 启示录相片部落格清單更多 工具 說明

部落格


7月19日

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.

环境光为场景提供了一种恒定不变的光照。环境光对所有物体的顶点的照明效果相同,因为它与其余光照因子,如顶点法向、光的方向、光的位置、范围或衰减等无关。环境光是最快的一种类型,但它提供的真实感最少。Direct3D 包含了一个全局的环境光属性,应用程序可以直接使用而无需创建任何光源。另外,应用程序也可以设定光源提供环境光照。场景中环境光的计算由以下公式描述。

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

Where:

参数 默认值 类型 描述
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).
第i个光源的衰减因子
Spoti (0,0,0,0) D3DVECTOR Spotlight factor of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).
第i个光源的聚光灯因子
sum N/A N/A Sum of the ambient light  环境光总和
Lai (0,0,0,0) D3DVECTOR Light ambient color of the ith light  第i个光源环境光颜色

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.
           m_pDevice9->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE , D3DMCS_MATERIAL);

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.

Ca的值可以是:

顶点颜色1,如果AMBIENTMATERIALSOURCE = D3DMCS_COLOR1,并且顶点声明中给出了第一个顶点的颜色。
顶点颜色2,如果AMBIENTMATERIALSOURCE = D3DMCS_COLOR2,并且顶点声明中给出了第二个顶点的颜色。
材质的环境反射色。

注意 如果使用了任何一种AMBIENTMATERIALSOURCE,但是没有提供顶点颜色,那么系统会使用材质的环境反射色。

要使用材质的环境反射色,按以下示例代码使用SetMaterial方法。

Ga为全局的环境反射色,通过SetRenderState(D3DRENDERSTATE_AMBIENT)设置。Direct3D场景中只有一个全局环境反射色,它与其余Direct3D光源无关。

Lai为场景中第i个光源的环境反射色。每个Direct3D光源都有一组属性,其中一个就是环境反射色。符号sum(Lai)表示场景中所有环境反射色的总和。

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.

untitled red

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.
渲染得到的场景如下所示。场景中唯一的物体是一个球体。环境光用相同的颜色对物体的所有顶点进行光照计算,它不依赖于顶点法向和光的方向。因此,球体看起来像是二维的圆,因为物体的表面没有明暗变化。

light

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

回應

請稍候...
很抱歉,您輸入的回應過長。請縮短您的回應。
您尚未輸入內容,請再試一次。
很抱歉,目前無法新增您的回應,請稍後再試。
若要新增回應,您的父母必須先給您權限。要求權限
您的家長已關閉回應功能。
很抱歉,目前無法刪除您的回應,請稍後再試。
您已超過每日回應上限次數,請於 24 小時後再試一次。
由於系統顯示您可能傳送垃圾郵件給其他使用者,因此您帳號中的回應功能已遭停用。 如果您認為自己帳號遭錯誤停用,請連絡 Windows Live 支援
請完成下列安全檢查,以完成回應。
您輸入的安全檢查字元必須與圖片或音訊中的字元相符。

若要新增回應,請以您的 Windows Live ID 登入 (若您使用 Hotmail、Messenger 或 Xbox LIVE,則您已擁有 Windows Live ID)。登入


沒有 Windows Live ID?註冊

引用通告

此內容的引用通告是:
http://topameng.spaces.live.com/blog/cns!F962D4854A8233D!460.trak
引述這則內容的部落格