衰减和聚焦因素Attenuation and spotlight factor

全局照明公式的漫射和反射光分量涉及介绍光线衰减和聚焦锥形的术语。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.

输入 = 1 / (att0+ att1 * d + att2 * d²)Atten = 1/( att0i + att1i * d + att2i * d²)

其中:Where:

参数Parameter 默认值Default value 在任务栏的搜索框中键入Type 描述Description 范围Range
att0iatt0i 0.00.0 浮点Floating point 恒定衰减系数Constant attenuation factor 0 至正无穷0 to +infinity
att1iatt1i 0.00.0 浮点Floating point 线性衰减因素Linear attenuation factor 0 至正无穷0 to +infinity
att2iatt2i 0.00.0 浮点Floating point 二次衰减因素Quadratic attenuation factor 0 至正无穷0 to +infinity
dd 不适用N/A 浮点Floating point 顶点位置至光线位置的距离Distance from vertex position to light position 不适用N/A

 

  • 如果光线是定向光,则 Atten = 1。Atten = 1, if the light is a directional light.
  • 如果光线与顶点之间的距离超出光线范围,则 Atten = 0。Atten = 0, if the distance between the light and the vertex exceeds the light's range.

光线与顶点位置之间的距离始终为正。The distance between the light and the vertex position is always positive.

d = | Ldir |d = | Ldir |

其中:Where:

参数Parameter 默认值Default value 在任务栏的搜索框中键入Type 描述Description
LdirLdir 不适用N/A 含 x、y 和 z 浮点值的 3D 矢量3D vector with x, y, and z floating-point values 从顶点位置到光线位置的方向矢量Direction vector from vertex position to the light position

 

如果 d 大于光线范围,Direct3D 不再进行衰减计算,也不再对从光线到顶点的区域应用效果。If d is greater than the light's range, 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. 你可以将 Attenuation1 设置为 1.0,以创建不会衰减但仍然受制于范围的光线,也可以测试不同的值以实现不同的衰减效果。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.

光线的最大范围处的衰减不是 0.0。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. 或者,应用程序可以设置衰减常量,以便光线范围内的衰减因素接近 0.0。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

以下公式指定了聚焦因素。The following equation specifies the spotlight factor.

聚焦因素的公式

参数Parameter 默认值Default value 在任务栏的搜索框中键入Type 描述Description 范围Range
rhoirhoi 不适用N/A 浮点Floating point 聚焦 i 的余弦(角度)cosine(angle) for spotlight i 不适用N/A
phiiphii 0.00.0 浮点Floating point 聚焦 i 的 Penumbra 角度(以弧度为单位)Penumbra angle of spotlight i in radians [theta,pi)[thetai, pi)
thetaithetai 0.00.0 浮点Floating point 聚焦 i 的 Umbra 角度(以弧度为单位)Umbra angle of spotlight i in radians [0,pi)[0, pi)
衰减falloff 0.00.0 浮点Floating point 衰减因素Falloff factor (负无穷,正无穷)(-infinity, +infinity)

 

其中:Where:

rho = norm(Ldcs).norm(Ldir)rho = norm(Ldcs).norm(Ldir)

且:and:

参数Parameter 默认值Default value 在任务栏的搜索框中键入Type 描述Description
LdcsLdcs 不适用N/A 含 x、y 和 z 浮点值的 3D 矢量3D vector with x, y, and z floating-point values 相机空间中光线方向的负数The negative of the light direction in camera space
LdirLdir 不适用N/A 含 x、y 和 z 浮点值的 3D 矢量3D vector with x, y, and z floating-point values 从顶点位置到光线位置的方向矢量Direction vector from vertex position to the light position

 

计算光线衰减后,为计算顶点的漫射和反射分量,Direct3D 还会考虑聚焦效果(如果适用)、光线从表面反射的角度和当前材料的反射率。After computing the light attenuation, to calculate the diffuse and specular components for the vertex, Direct3D also considers spotlight effects if applicable, the angle that the light reflects from a surface, and the reflectance of the current material. 光线类型中,请参阅“聚焦”。In Light types, see "Spotlight".

相关主题Related topics

照明的数学Mathematics of lighting