光源概觀Lighting overview

當您使用 Direct3D 照明時,您可以允許 Direct3D 為您處理照明細節。When you use Direct3D lighting, you allow Direct3D to handle the details of illumination for you. 如有需要,進階使用者可以自行執行照明。Advanced users can perform lighting on their own, if desired.

當啟用照明時,Direct3D 會根據下列組合計算每個物件頂點的色彩︰When lighting is enabled, Direct3D calculates the color of each object vertex based on a combination of the following:

  • 紋素與紋理圖相關聯。The texels in an associated texture map.
  • 若有指定,為頂點的擴散和反射色彩。The diffuse and specular colors at the vertex, if specified.
  • 色彩和光線強度由場景光源或場景環境光線層級製造。The color and intensity of light produced by light sources in the scene or the scene's ambient light level.

您如何使用照明和材質,會使可呈現的場景外觀大不相同。How you work with lighting and materials makes a big difference in the appearance of the rendered scene. 材質決定光線對表面的反映。Materials define how light reflects off a surface. 直接光線和環境光線層級定義反映的光線。Direct light and ambient light levels define the light that is reflected. 如果已啟用照明,您必須使用材料來呈現場景。You must use materials to render a scene if lighting is enabled.

不需要用光線呈現場景,但沒有光線呈現的場景細節是無法顯現的。Lights are not required to render a scene, but details in a scene rendered without light are not visible. 呈現無光的場景,充其量會使場景中的物件產生剪影。At best, rendering an unlit scene results in a silhouette of the objects in the scene. 對大部分的用途而言,這仍不夠詳細。This is not enough detail for most purposes.

直接的光線,與環境光線Direct light vs. ambient light

雖然直接和環境光線會使場景中的物件亮起來,它們彼此之間各不相干,而且使用的是非常不同的效果,所以您最好以完全不同的方式來使用。Although both direct and ambient light illuminate objects in a scene, they are independent of one another, they have very different effects, and they require that you work with them in completely different ways.

直接光線直接照射物件。Direct light strikes the object directly. 直接光線一定有方向和顏色,它是陰影演算法的係數,例如 Gouraud Shading。Direct light always has direction and color, and it is a factor for shading algorithms, such as Gouraud shading. 不同類型的光線以不同方式發出直光,以建立特殊衰減效果。Different types of lights emit direct light in different ways, creating special attenuation effects.

環境光線對場景各處都能有有效作用。Ambient light is effectively everywhere in a scene. 環境光線為充滿整個場景的一般光線等級,無論物件與他們在場景中的位置為何。Ambient light is a general level of light that fills an entire scene, regardless of the objects and their locations in that scene. 環境光線沒有位置或方向,只有色彩和強度。Ambient light has no position or direction, only color and intensity. 每個光線加入場景中的整體環境光線。Each light adds to the overall ambient light in a scene.

環境光線的形式為 RGBA 值,其中每個元件是 0 至 255 的整數值。Ambient light color takes the form of an RGBA value, where each component is an integer value from 0 to 255. 這與 Direct3D 中大多數色彩值不相同。This is unlike most color values in Direct3D.

紅色、綠色及藍色元件組合成最終環境光線的色彩。The red, green, and blue components combine to make the final color of the ambient light. Alpha 元件控制色彩的透明度。The alpha component controls the transparency of the color. 使用硬體加速或 RGB 模擬時,會忽略 alpha 元件。When using hardware acceleration or RGB emulation, the alpha component is ignored.

與本質的 Direct3D 淺模型Direct3D light model vs. nature

在自然界,當從來源發光時,就算沒有數千或數百萬計的物件,在到達使用者的眼睛前,也會有數百種反映。In nature, when light is emitted from a source, it is reflected off of hundreds, if not thousands or millions of objects before reaching the user's eye. 每次反映時,有些光會被表面吸收,有些隨機分散,而其餘部分不是移至另一個表面,就是移至使用者的眼睛。Each time it is reflected, some light is absorbed by a surface, some is scattered in random directions, and the rest goes on to another surface or to the user's eye. 這個程序會繼續,直到光線縮小變沒有,或使用者感受到光線。This process continues until the light is reduced to nothing or a user perceives the light.

很明顯的,需要經過計算才能完美模擬光線的行為,用於即時 Direct3D 圖形太耗時。Obviously, the calculations required to perfectly simulate the natural behavior of light are too time-consuming to use for real-time Direct3D graphics. 因此,記住速度的同時,Direct3D 光線模型近似光線在自然界運作的方式。Therefore, with speed in mind, the Direct3D light model approximates the way light works in the natural world. Direct3D 描述光線的紅色、綠色及藍色元件結合並建立最後色彩。Direct3D describes light in terms of red, green, and blue components that combine to create a final color.

在 Direct3D 中,當光線反映表面,淺色與表面以數學方式互動,終而建立最後顯示在螢幕上的色彩。In Direct3D, when light reflects off a surface, the light color interacts mathematically with the surface itself to create the color eventually displayed on the screen. 關於 Direct3D 使用的特定演算法詳細資訊,請參閱光源的數學計算For specific information about the algorithms Direct3D uses, see Mathematics of lighting.

Direct3D 光線模型可以將光線概括成兩種類型︰ 環境光線和直接光線。The Direct3D light model generalizes light into two types: ambient light and direct light. 每一個都有不同屬性,而每一個會用不同的方式與表面材質互動。Each has different attributes, and each interacts with the material of a surface in different ways. 環境光線是已經分散到方向和來源都變得不確定的光線︰ 它在各處會維持低強度。Ambient light is light that has been scattered so much that its direction and source are indeterminate: it maintains a low level of intensity everywhere. 攝影師間接使用的照明是使用環境光線的範例。The indirect lighting used by photographers is a good example of ambient light.

Direct3D 的環境光線如自然界光線一樣沒有真實方向或來源,只有色彩和強度。Ambient light in Direct3D, as in nature, has no real direction or source, only a color and intensity. 事實上,環境光線等級與產生光線之場景中任何物件完全無關。In fact, the ambient light level is completely independent of any objects in a scene that generate light. 環境光線不會有反射反映。Ambient light does not contribute to specular reflection.

直接光線是由場景內的來源產生的,永遠具有色彩和強度,並以指定方向行進。Direct light is the light generated by a source within a scene; it always has color and intensity, and it travels in a specified direction. 直接光線與表面材質互動來建立反射高光,而其方向在陰影運算中被當成係數來使用,包括 Gouraud shading。Direct light interacts with the material of a surface to create specular highlights, and its direction is used as a factor in shading algorithms, including Gouraud shading. 當反映直接光線時,並不會作用成場景中的環境光線等級。When direct light is reflected, it does not contribute to the ambient light level in a scene. 場景中產生直接光線的來源具備不同特性,影響他們照亮場景的方式。The sources in a scene that generate direct light have different characteristics that affect how they illuminate a scene.

除此之外,多邊形的材質具有會影響多邊形如何反映接收到的光線的屬性。Additionally, a polygon's material has properties that affect how that polygon reflects the light it receives. 您設定單一反射率特徵,其描述材質如何反映環境光線,而您設定個別特徵來判斷材質的反射和擴散反射率。You set a single reflectance trait that describes how the material reflects ambient light, and you set individual traits to determine the material's specular and diffuse reflectance.

光線和材質的色彩值Color values for lights and materials

Direct3D 描述結合成最後色彩的四個元件 (紅色、綠色、藍色及 alpha) 的色彩。Direct3D describes color in terms of four components (red, green, blue, and alpha), that combine to make a final color. 每個元件範圍從 0.0 到 1.0。Each component ranges from 0.0 to 1.0. 雖然光線和材質使用相同的結構來描述色彩,光線和材質使用值的方式有點不同。Although both lights and materials use the same structure to describe color, the values are used a little differently by lights versus materials.

光源的色彩值表示其發出的特定光線元件量。Color values for light sources represent the amount of a particular light component it emits. 由於光線不使用 alpha 元件,只有紅色、綠色和藍色的色彩元件相關。Because lights don't use an alpha component, only the red, green, and blue components of the color are relevant. 您可以在投影電視上視覺化三個元件,分別為紅色、綠色和藍色濾鏡。You can visualize the three components as the red, green, and blue lenses on a projection television. 每個濾鏡可能會關閉 (適當成員的 0.0 值),可能會非常亮 (1.0 值),或介於之間。Each lens might be off (a 0.0 value in the appropriate member), it might be as bright as possible (a 1.0 value), or it might be some level in between.

透過濾鏡將色彩結合成光線的最終色彩。The colors coming through the lenses combine to make the light's final color. R(1.0)、G(1.0)、 B(1.0) 組合成白光,R(0.0)、G(0.0)、B(0.0) 完全無法發光。A combination like R(1.0), G(1.0), B(1.0) creates a white light, where R(0.0), G(0.0), B(0.0) doesn't emit light at all. 您可以發出只有一個元件的光線,例如產生純紅色、綠色或藍色光;光線無法使用組合來發出像黃色或紫色的色彩。You can make a light that emits only one component, resulting in a pure red, green, or blue light; or, the light could use combinations to emit colors like yellow or purple. 您甚至可以設定負片色彩元件值,建立「深色光」,實際上是將場景的光線移除。You can even set negative color component values to create a "dark light" that actually removes light from a scene. 或者,您可能設定元件的值大於 1.0 以建立非常亮的光。Or, you might set the components to some value larger than 1.0 to create an extremely bright light.

另一方面,在使用材質時,色彩值代表使用該材質的表面反映出多少光線元件。With materials, on the other hand, color values represent how much of a light component is reflected by a surface that is rendered with that material. 色彩元件為 R(1.0)、G(1.0)、B(1.0) 和 A(1.0) 的材質,反映了所有的光線。A material whose color components are R(1.0), G(1.0), B(1.0), A(1.0) reflects all the light that comes its way. 同樣地,R(0.0)、G(1.0)、B(0.0)、A(1.0) 反映出所有照射而來的綠光。Likewise, a material with R(0.0), G(1.0), B(0.0), A(1.0) reflects all the green light that is directed at it. 材質有多個反射值,可建立各種效果。Materials have multiple reflectance values to create various types of effects.

請參閱光線類型光線屬性See Light types and Light properties.

相關主題Related topics

光線和材質Lights and materials