青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

光照與材質(zhì)(3)

設(shè)置燈光

在Direct3D的一個場景中,最多可設(shè)置8個光源,設(shè)置光源由IDirect3DDevice9::SetLight()函數(shù)完成。該函數(shù)的聲明如下:

Assigns a set of lighting properties for this device.

HRESULT SetLight(
DWORD Index,
CONST D3DLight9 * pLight
);

Parameters

Index
[in] Zero-based index of the set of lighting properties to set. If a set of lighting properties exists at this index, it is overwritten by the new properties specified in pLight.
pLight
[in] Pointer to a D3DLIGHT9 structure, containing the lighting parameters to set.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

Set light properties by preparing a D3DLIGHT9 structure and then calling the IDirect3DDevice9::SetLight method. The IDirect3DDevice9::SetLight method accepts the index at which the device should place the set of light properties to its internal list of light properties, and the address of a prepared D3DLIGHT9 structure that defines those properties. You can call IDirect3DDevice9::SetLight with new information as needed to update the light's illumination properties.

The system allocates memory to accommodate a set of lighting properties each time you call the IDirect3DDevice9::SetLight method with an index that has never been assigned properties. Applications can set a number of lights, with only a subset of the assigned lights enabled at a time. Check the MaxActiveLights member of the D3DCAPS9 structure when you retrieve device capabilities to determine the maximum number of active lights supported by that device. If you no longer need a light, you can disable it or overwrite it with a new set of light properties.

The following example prepares and sets properties for a white point-light whose emitted light will not attenuate over distance.

// Assume d3dDevice is a valid pointer to an IDirect3DDevice9 interface.
D3DLight9 d3dLight;
HRESULT hr;

// Initialize the structure.
ZeroMemory(&D3dLight, sizeof(d3dLight));

// Set up a white point light.
d3dLight.Type = D3DLIGHT_POINT;
d3dLight.Diffuse.r = 1.0f;
d3dLight.Diffuse.g = 1.0f;
d3dLight.Diffuse.b = 1.0f;
d3dLight.Ambient.r = 1.0f;
d3dLight.Ambient.g = 1.0f;
d3dLight.Ambient.b = 1.0f;
d3dLight.Specular.r = 1.0f;
d3dLight.Specular.g = 1.0f;
d3dLight.Specular.b = 1.0f;

// Position it high in the scene and behind the user.
// Remember, these coordinates are in world space, so
// the user could be anywhere in world space, too.
// For the purposes of this example, assume the user
// is at the origin of world space.
d3dLight.Position.x = 0.0f;
d3dLight.Position.y = 1000.0f;
d3dLight.Position.z = -100.0f;

// Don't attenuate.
d3dLight.Attenuation0 = 1.0f;
d3dLight.Range = 1000.0f;

// Set the property information for the first light.
hr = d3dDevice->SetLight(0, &d3dLight);
if (SUCCEEDED(hr))
// Handle Success
else
// Handle failure

Enable a light source by calling the IDirect3DDevice9::LightEnable method for the device.

函數(shù)IDirect3DDevice9::SetLight()只是設(shè)置光源,在默認(rèn)情況下,設(shè)置的任何光源都還不起作用,具體使用哪些光源,由函數(shù)IDirect3DDevice9::LightEnable()確定,該函數(shù)聲明如下:

Enables or disables a set of lighting parameters within a device.

HRESULT LightEnable(
DWORD LightIndex,
BOOL bEnable
);

Parameters

LightIndex
[in] Zero-based index of the set of lighting parameters that are the target of this method.
bEnable
[in] Value that indicates if the set of lighting parameters are being enabled or disabled. Set this parameter to TRUE to enable lighting with the parameters at the specified index, or FALSE to disable it.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

If a value for LightIndex is outside the range of the light property sets assigned within the device, the IDirect3DDevice9::LightEnable method creates a light source represented by a D3DLIGHT9 structure with the following properties and sets its enabled state to the value specified in bEnable.

Member Default
Type D3DLIGHT_DIRECTIONAL
Diffuse (R:1, G:1, B:1, A:0)
Specular (R:0, G:0, B:0, A:0)
Ambient (R:0, G:0, B:0, A:0)
Position (0, 0, 0)
Direction (0, 0, 1)
Range 0
Falloff 0
Attenuation0 0
Attenuation1 0
Attenuation2 0
Theta 0
Phi 0

因為鏡面反射的計算量很大,所以Direct3D在默認(rèn)狀態(tài)下不進(jìn)行鏡面反射運算。如果想得到鏡面反射效果,可以先設(shè)置好結(jié)構(gòu)體D3DLIGHT9的Specular成員和物體表面材質(zhì)結(jié)構(gòu)體D3DMATERIAL9的Specular和Power成員,然后通過下面的代碼激活鏡面反射運算。

g_device->SetRenderState(D3DRS_SPECULARENABLE, TRUE);

如果需要進(jìn)行漫反射或鏡面反射運算,那么在頂點緩沖區(qū)中必須包含頂點的法向量信息,這是因為Direct3D在進(jìn)行光照運算時,要用到頂點法向量。

 

材質(zhì)

對于光照計算,光源和材質(zhì)兩者缺一不可,物體表面材質(zhì)屬性決定了它能反射什么顏色的光線以及能反射多少,在Direct3D中,物體表面材質(zhì)屬性由結(jié)構(gòu)體D3DMATERIAL9定義:

Specifies material properties.

typedef struct D3DMATERIAL9 {
D3DCOLORVALUE Diffuse;
D3DCOLORVALUE Ambient;
D3DCOLORVALUE Specular;
D3DCOLORVALUE Emissive;
float Power;
} D3DMATERIAL9, *LPD3DMATERIAL9;

Members

Diffuse
Value specifying the diffuse color of the material. See D3DCOLORVALUE.
Ambient
Value specifying the ambient color of the material. See D3DCOLORVALUE.
Specular
Value specifying the specular color of the material. See D3DCOLORVALUE.
Emissive
Value specifying the emissive color of the material. See D3DCOLORVALUE.
Power
Floating-point value specifying the sharpness of specular highlights. The higher the value, the sharper the highlight.

Remarks

To turn off specular highlights, set D3DRS_SPECULARENABLE to FALSE, using D3DRENDERSTATETYPE. This is the fastest option because no specular highlights will be calculated.

For more information about using the lighting engine to calculate specular lighting, see Specular Lighting (Direct3D 9).

浮點成員Power為鏡面反射指數(shù),即鏡面反射光照計算模型計算公式中的n,Power值越大,高光強(qiáng)度和周圍亮度相差越大。

Emissive表示物體自身的發(fā)光度,以R、G、B表示。

物體頂點的顏色亮度總和為:

Itotal = Iambient + Idiffuse + Ispecular + Iemissive

I表示物體的顏色值,上式表示物體的顏色總和 = 物體反射環(huán)境光 + 物體反射漫反射光 + 物體反射鏡面光 + 物體自發(fā)光。

 

設(shè)置材質(zhì)

函數(shù)IDirect3DDevice9::SetMaterial()用來設(shè)置Direct3D當(dāng)前材質(zhì)屬性,該函數(shù)聲明如下:

Sets the material properties for the device.

HRESULT SetMaterial(
CONST D3DMATERIAL9 * pMaterial
);

Parameters

pMaterial
[in] Pointer to a D3DMATERIAL9 structure, describing the material properties to set.

Return Values

If the method succeeds, the return value is D3D_OK. D3DERR_INVALIDCALL if the pMaterial parameter is invalid.

下面的示例代碼設(shè)置當(dāng)前材質(zhì)為能漫反射50%紅光、80%綠光和60%藍(lán)光的表面。

D3DMATERIAL9 material;
ZeroMemory(&material, sizeof(material));

material.Diffuse.r = 0.5f;
material.Diffuse.g = 0.8f;
material.Diffuse.b = 1.6f;
material.Diffuse.a = 0.0f;

g_device->SetMaterial(&material);

Direct3D圖形系統(tǒng)在進(jìn)行光照計算時,會根據(jù)3種光照計算模型分別進(jìn)行計算,然后將計算結(jié)果疊加在一起,作為頂點的光照顏色值,如果物體表面只能進(jìn)行漫反射,則鏡面反射系數(shù)應(yīng)當(dāng)為0,這時鏡面反射計算得到的顏色值顯然為0,從而使物體不具有鏡面反射效果,但是實際上鏡面反射計算也在進(jìn)行。因為鏡面反射計算量大,會對性能造成沖擊,所以如果物體表面不具有鏡面反射效果,就不要啟用鏡面反射計算。

如果應(yīng)用程序沒有指定材質(zhì)屬性,系統(tǒng)將使用默認(rèn)材質(zhì)。默認(rèn)材質(zhì)反射所有漫反射光,沒有環(huán)境反射和鏡面反射,也沒有自發(fā)光顏色。

默認(rèn)材質(zhì)的光照屬性

成員

默認(rèn)值

Diffuse (R:1, G:1, B:1, A:0)
Specular (R:0, G:0, B:0, A:0)
Ambient (R:0, G:0, B:0, A:0)
Emissive (R:0, G:0, B:0, A:0)
Power (0.0)

 

獲取材質(zhì)屬性

通過調(diào)用接口函數(shù)IDirect3DDevice9::GetMaterial()可獲取渲染設(shè)備當(dāng)前正在使用的材質(zhì)屬性。

Retrieves the current material properties for the device.

HRESULT GetMaterial(
D3DMATERIAL9 * pMaterial
);

Parameters

pMaterial
[out] Pointer to a D3DMATERIAL9 structure to fill with the currently set material properties.

Return Values

If the method succeeds, the return value is D3D_OK. D3DERR_INVALIDCALL if the pMaterial parameter is invalid.

Remarks

This method will not return device state for a device that is created using D3DCREATE_PUREDEVICE. If you want to use this method, you must create your device with any of the other values in D3DCREATE.


posted on 2008-05-04 14:48 lovedday 閱讀(1340) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一区二区三区无毛| 亚洲伊人久久综合| 久久久久久久久久码影片| 国产裸体写真av一区二区| 欧美影院视频| 久久五月天婷婷| 亚洲狼人精品一区二区三区| 亚洲精品中文字幕有码专区| 国产精品mv在线观看| 亚洲一区美女视频在线观看免费| 一区二区不卡在线视频 午夜欧美不卡'| 欧美日韩精品免费在线观看视频 | 欧美成人69av| 日韩午夜中文字幕| 一区二区三区蜜桃网| 国产在线播放一区二区三区| 男男成人高潮片免费网站| 欧美激情一区二区三区在线| 亚洲一品av免费观看| 欧美一二区视频| 亚洲乱码国产乱码精品精98午夜| 亚洲一区二区三区免费在线观看 | 国产欧美精品日韩精品| 久久久国产精品一区二区中文 | 久久成人综合视频| 亚洲激情欧美| 亚洲自拍都市欧美小说| 狠狠色丁香久久综合频道 | 亚洲专区在线| 久久精品夜色噜噜亚洲aⅴ| 日韩午夜黄色| 久久久久国产精品厨房| 亚洲深夜激情| 久久亚洲捆绑美女| 久久狠狠久久综合桃花| 久久久噜噜噜久久人人看| 日韩亚洲在线| 久久久www| 在线中文字幕不卡| 看欧美日韩国产| 性欧美大战久久久久久久久| 欧美精品999| 久久一二三四| 国产精品亚洲产品| 亚洲久色影视| 亚洲人成毛片在线播放| 久久9热精品视频| 欧美影院在线播放| 国产精品久久久久久久久免费| 欧美大片专区| 在线日韩欧美视频| 久久电影一区| 午夜宅男欧美| 欧美系列亚洲系列| 久久gogo国模裸体人体| 国产精品高潮呻吟久久av黑人| 亚洲级视频在线观看免费1级| 国产亚洲制服色| 亚洲欧美日韩国产综合| 亚洲欧美日韩天堂| 国产精品久久久久久妇女6080| 亚洲人被黑人高潮完整版| 亚洲精品久久久一区二区三区| 久久久久久亚洲综合影院红桃| 久久久久女教师免费一区| 国产视频在线观看一区二区| 香蕉久久夜色精品国产使用方法| 中国成人亚色综合网站| 欧美久久久久中文字幕| 亚洲电影免费观看高清完整版| 亚洲成在人线av| 免费在线国产精品| 亚洲欧洲日本在线| 一区二区三区不卡视频在线观看 | 亚洲人成人99网站| 一区二区三区导航| 国产精品高潮视频| 亚洲欧美一区二区精品久久久| 久久精品国产久精国产思思| 黄色国产精品| 欧美国产视频在线| 亚洲久久一区二区| 欧美在线视频不卡| 激情成人av| 欧美激情第4页| 99国产精品久久| 欧美一区影院| 在线精品一区二区| 久久综合国产精品台湾中文娱乐网| 国产一区二区久久久| 蜜臀av一级做a爰片久久| 91久久久在线| 午夜精品久久久久久99热| 国产亚洲激情视频在线| 亚洲视频在线播放| 亚洲欧美日韩视频二区| 激情成人综合网| 欧美国产日韩一二三区| 亚洲一二三级电影| 欧美国产视频在线| 亚洲欧美综合另类中字| 亚洲第一福利在线观看| 欧美午夜欧美| 每日更新成人在线视频| 亚洲午夜免费视频| 亚洲福利视频网| 久久av在线| 夜夜夜精品看看| 影音先锋中文字幕一区二区| 欧美日韩色综合| 久久久人成影片一区二区三区| 99re6热在线精品视频播放速度| 久久亚洲综合色| 亚洲综合导航| 亚洲精品一区二区三区蜜桃久| 国产日韩亚洲欧美| 欧美日韩三区四区| 欧美国产大片| 久久天天狠狠| 香蕉av777xxx色综合一区| 亚洲日韩欧美一区二区在线| 久久久综合网站| 亚洲欧美日韩精品久久| 99re在线精品| 亚洲区国产区| 玉米视频成人免费看| 国产欧美日韩一区| 国产精品v日韩精品v欧美精品网站| 久久综合伊人77777蜜臀| 午夜日韩在线| 亚洲欧美日韩一区二区三区在线观看| 亚洲国产另类精品专区| 久久影视三级福利片| 欧美一区二区三区另类| 午夜精品福利视频| 亚洲在线播放| 亚洲综合视频一区| 亚洲女优在线| 亚洲深夜福利网站| 99精品久久久| 99精品国产99久久久久久福利| 亚洲精品视频在线播放| 亚洲黄页视频免费观看| 亚洲激情视频在线观看| 亚洲经典一区| 亚洲精品久久嫩草网站秘色| 亚洲日本一区二区| 亚洲精品小视频在线观看| 亚洲精品之草原avav久久| 99国产精品私拍| 一本久久综合| 亚洲在线一区二区| 午夜精品成人在线视频| 欧美自拍偷拍| 米奇777在线欧美播放| 欧美成人a视频| 亚洲黄色有码视频| 一二三区精品福利视频| 亚洲欧美成人一区二区在线电影| 亚洲一级影院| 欧美中文字幕在线视频| 免费欧美电影| 欧美日韩国产成人在线免费| 国产精品乱码| 国内精品模特av私拍在线观看| 精品91久久久久| 亚洲日韩成人| 亚洲欧美三级伦理| 久久香蕉国产线看观看网| 亚洲二区在线视频| 夜夜夜久久久| 久久精品72免费观看| 欧美sm视频| 国产精品免费电影| 激情欧美一区二区| 一区二区三区蜜桃网| 久久激情一区| 91久久精品国产91性色tv| 亚洲欧美在线x视频| 免费久久久一本精品久久区| 国产精品成人观看视频国产奇米| 国产在线精品成人一区二区三区| 亚洲精品国产拍免费91在线| 欧美一区成人| 亚洲国产精品欧美一二99| 亚洲一区二区在线| 欧美成人首页| 国产在线播精品第三| 亚洲一区二区网站| 欧美大片一区二区| 午夜精品www| 欧美视频二区| 亚洲国产精品一区二区www| 香蕉av777xxx色综合一区| 亚洲国产精品久久91精品| 欧美影院成人| 国产精品男女猛烈高潮激情| 亚洲精品免费在线播放| 久久久蜜桃一区二区人| 久久久天天操|