环境光Ambient lighting

环境光为场景提供恒定照明。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. 环境光在所有方向都是恒定的,并且会无差别地为某个对象的所有像素上色。Ambient lighting is constant in all directions and it colors all pixels of an object the same. 这是一种快速计算,但会让对象看上去扁平且不逼真。It is fast to calculate but leaves objects looking flat and unrealistic.

环境光是最快速的照明类型,但会产生最不逼真的结果。Ambient lighting is the fastest type of lighting but it produces the least realistic results. Direct3D 包含一个单独的全局环境光,无需创造任何光线就能使用。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.

环境照明 = C ₐ * [ g ₐ + Sum (Atteni * 点焊i * Lai) ]Ambient Lighting = Cₐ*[Gₐ + sum(Atteni*Spoti*Lai)]

其中:Where:

参数Parameter 默认值Default value 类型Type 说明Description
CₐCₐ (0,0,0,0)(0,0,0,0) D3DCOLORVALUED3DCOLORVALUE 材料环境颜色Material ambient color
GₐGₐ (0,0,0,0)(0,0,0,0) D3DCOLORVALUED3DCOLORVALUE 全局环境颜色Global ambient color
AtteniAtteni (0,0,0,0)(0,0,0,0) D3DCOLORVALUED3DCOLORVALUE 第 i 道光的光线衰减。Light attenuation of the ith light. 请参阅衰减和聚焦因素See Attenuation and spotlight factor.
专色iSpoti (0,0,0,0)(0,0,0,0) D3DVECTORD3DVECTOR 第 i 道光的聚焦因素。Spotlight factor of the ith light. 请参阅衰减和聚焦因素See Attenuation and spotlight factor.
sumsum 不适用N/A 不适用N/A 环境光的总和Sum of the ambient light
LaiLai (0,0,0,0)(0,0,0,0) D3DVECTORD3DVECTOR 第 i 道光的光环境颜色Light ambient color of the ith light

 

Cₐ 的值为:The value for Cₐ is either:

  • 顶点 color1,如果 AMBIENTMATERIALSOURCE = D3DMCS _ color1,则在顶点声明中提供第一个顶点颜色。vertex color1, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR1, and the first vertex color is supplied in the vertex declaration.
  • 顶点 color2 (如果 AMBIENTMATERIALSOURCE = D3DMCS _ color2)和第二个顶点颜色是在顶点声明中提供的。vertex color2, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR2, and the second vertex color is supplied in vertex declaration.
  • 材料环境颜色。material ambient color.

注意   如果使用了任一 AMBIENTMATERIALSOURCE 选项,并且未提供顶点颜色,则使用材料环境颜色。Note   If either AMBIENTMATERIALSOURCE option is used, and the vertex color is not provided, then the material ambient color is used.

 

若要使用材料环境颜色,请使用 SetMaterial,如以下示例代码所示。To use the material ambient color, use SetMaterial as shown in the example code below.

Gₐ 是全局环境颜色。Gₐ is the global ambient color. 它使用 SetRenderState (D3DRS _ 环境) 进行设置。It is set using SetRenderState(D3DRS_AMBIENT). Direct3D 场景中有一种全局环境颜色。There is one global ambient color in a Direct3D scene. 此参数不与 Direct3D 光对象关联。This parameter is not associated with a Direct3D light object.

Lai 是场景中第 i 道光的环境颜色。Lai is the ambient color of the ith light in the scene. 每个 Direct3D 灯都有一组属性,其中一个属性是环境光。Each Direct3D light has a set of properties, one of which is the ambient color. sum(Lai) 术语是场景中所有环境光的总和。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

Ambient.r = 0.75f;
Ambient.g = 0.0f;
Ambient.b = 0.0f;
Ambient.a = 0.0f;

根据公式,生成的对象顶点颜色是材料颜色和光颜色的组合。According to the equation, the resulting color for the object vertices is a combination of the material color and the light color.

下面两个图例显示了材料颜色(灰色)和光颜色(鲜红色)。The following two illustrations show the material color, which is gray, and the light color, which is bright red.

灰色球体的图例红色球体的图例

生成的场景显示在以下图例中。The resulting scene is shown in the following illustration. 场景中的唯一对象是一个球体。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. 因此,球体看起来像 2D 圆形,因为对象表面周围的着色没有差别。As a result, the sphere looks like a 2D circle because there is no difference in shading around the surface of the object.

有环境光的球体图例

若要为对象提供更逼真的外观,除环境光外,请应用漫射或镜面反射。To give objects a more realistic look, apply diffuse or specular lighting in addition to ambient lighting.

相关主题Related topics

照明的数学运算Mathematics of lighting