摘要: Direct3D紋理對象生成后,紋理對象指針指向的紋理資源指針還沒有被有效賦值,如果想要通過磁盤圖形文件載入紋理,那么必須將磁盤圖形文件的內容載入Direct3D紋理資源,因為不同的文件具有不同的格式,所以為了將文件內容載入到Direct3D紋理資源,就要了解各種圖形文件的格式,并針對不同的格式編寫不同的代碼將文件內容載入到紋理資源中。
從磁盤文件生成并載入紋理相當繁瑣,它涉及到各種圖形文件的存儲格式。幸運的是,Direct3D擴展實用庫函數D3DXCreateTextureFromFile()為我們提供了從磁盤圖形文件創建紋理并載入紋理內容的快捷方法。
閱讀全文
摘要: 為了使渲染的圖形看起來更真實,Direct3D提供了在物體表面繪制紋理的功能。一般說來,紋理是表示物體表面細節的一幅或幾幅二維圖形,也稱紋理貼圖(texture)。當把紋理按照特定的方式映射到物體表面的時候,能使物體看上去更加真實。當前流行的圖形系統中,紋理繪制已經成為一種必不可少的渲染方法。在理解紋理映射時,可以將紋理看作應用程序在物體表面的像素顏色。在真實世界中,紋理表示一個對象的顏色、圖案以及觸覺特征。但在Direct3D 中,紋理只表示對象表面的彩色圖案,它不能改變對象的幾何形式。更進一步說,它只是一種高強度計算行為。
閱讀全文
摘要: 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.
閱讀全文
摘要: Emissive lighting is described by a single term.
Emissive Lighting = Ce
閱讀全文
摘要: Modeling specular reflection requires that the system not only know in what direction light is traveling, but also the direction to the viewer's eye. The system uses a simplified version of the Phong specular-reflection model, which employs a halfway vector to approximate the intensity of specular reflection.
閱讀全文
摘要: After adjusting the light intensity for any attenuation effects, the lighting engine computes how much of the remaining light reflects from a vertex, given the angle of the vertex normal and the direction of the incident light. The lighting engine skips to this step for directional lights because they do not attenuate over distance. The system considers two reflection types, diffuse and specular, and uses a different formula to determine how much light is reflected for each. After calculating th
閱讀全文
摘要: 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
閱讀全文
摘要: 在三維圖形程序中使用光照效果能夠有效地增強場景的真實感。在Direct3D中,通過計算場景中的光線和物體表面材質反射光線顏色的數學交互,可使光線模型接近于真實世界的照明系統。
在真實世界中,光線在到達眼睛之前經過了物體表面的多次反射,每次反射時,物體表面都會吸收一些光,有些被隨機反射擴散出去,其余的到達下一個物體的表面或眼睛。真實世界中光線反射的效果就是光線跟蹤算法需要模擬實現的。盡管光線跟蹤算法能夠創建非常逼真的與自然界中觀察到極為相似的景象,但是還沒有實時程序能夠完成這些運算。考慮到實時渲染的需要,Direct3D使用更簡單的方法進行光照計算。Direct3D光照計算模型包括4種:環境光、漫反射光、鏡面反射光和自發光。它們的結合能靈活高效地解決三維圖形程序中的光照問題。
閱讀全文
摘要: 在示例程序MultiLights中一共使用了三個光源,分別是漫反射方向光光源、漫反射點光源、鏡面反射方向光光源,而且可以控制分別使用三個光源和同時使用三個光源的顯示效果。為了測試不同光源的光照效果,在示例程序中通過鍵盤上的數字鍵來控制3個光源的啟用。
閱讀全文
摘要: 在程序中可以根據需要按以下步驟添加光照效果:
(1)激活光照運算。
(2)設置物體表面材質。材質屬性是針對整個圖形系統的,如果場景中的物體具有不同的材質屬性,在渲染物體前要分別設置其材質屬性。
(3)設置光源。Direct3D在一個場景中最多支持8個光源,對每個設置好的光源還要設置是否啟用。
閱讀全文