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

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

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

設(shè)置燈光

在Direct3D的一個(gè)場(chǎng)景中,最多可設(shè)置8個(gè)光源,設(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

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

g_device->SetRenderState(D3DRS_SPECULARENABLE, TRUE);

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

 

材質(zhì)

對(duì)于光照計(jì)算,光源和材質(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).

浮點(diǎn)成員Power為鏡面反射指數(shù),即鏡面反射光照計(jì)算模型計(jì)算公式中的n,Power值越大,高光強(qiáng)度和周?chē)炼认嗖钤酱蟆?/p>

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

物體頂點(diǎn)的顏色亮度總和為:

Itotal = Iambient + Idiffuse + Ispecular + Iemissive

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

 

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

函數(shù)IDirect3DDevice9::SetMaterial()用來(lái)設(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ì)算時(shí),會(huì)根據(jù)3種光照計(jì)算模型分別進(jìn)行計(jì)算,然后將計(jì)算結(jié)果疊加在一起,作為頂點(diǎn)的光照顏色值,如果物體表面只能進(jìn)行漫反射,則鏡面反射系數(shù)應(yīng)當(dāng)為0,這時(shí)鏡面反射計(jì)算得到的顏色值顯然為0,從而使物體不具有鏡面反射效果,但是實(shí)際上鏡面反射計(jì)算也在進(jìn)行。因?yàn)殓R面反射計(jì)算量大,會(huì)對(duì)性能造成沖擊,所以如果物體表面不具有鏡面反射效果,就不要啟用鏡面反射計(jì)算。

如果應(yīng)用程序沒(méi)有指定材質(zhì)屬性,系統(tǒng)將使用默認(rèn)材質(zhì)。默認(rèn)材質(zhì)反射所有漫反射光,沒(méi)有環(huán)境反射和鏡面反射,也沒(méi)有自發(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ì)屬性

通過(guò)調(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 閱讀(1345) 評(píng)論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(lèi)(178)

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

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            羞羞漫画18久久大片| 亚洲电影天堂av| 亚洲欧洲综合| 欧美一区国产在线| 99在线精品观看| 欧美激情视频在线播放 | 日韩视频一区二区三区在线播放| 久久久久久久综合| 亚洲国产精品一区制服丝袜| 六月婷婷久久| 亚洲大片在线| 亚洲国产aⅴ天堂久久| 国产亚洲精品v| 久久久久综合| 国产欧美日韩在线播放| 久久先锋资源| 欧美成人中文字幕| 亚洲一级网站| 亚洲一区二区三区精品在线| 国产精品视频免费一区| 香蕉精品999视频一区二区| 欧美一区二区三区久久精品茉莉花 | 久久夜色精品亚洲噜噜国产mv| 国内激情久久| 亚洲第一精品在线| 18成人免费观看视频| 久久久久网站| 亚洲视频中文字幕| 欧美影院精品一区| 亚洲精品国产拍免费91在线| 亚洲视频在线一区| 亚洲成人资源网| 久久婷婷久久一区二区三区| 久久亚洲视频| 91久久精品一区| 欧美精品七区| 一区二区三区**美女毛片| 韩日视频一区| 一区二区三区高清视频在线观看| 在线一区二区三区四区五区| 午夜久久电影网| 久久亚洲精品欧美| 亚洲成人在线免费| 欧美精品三区| 亚洲伊人网站| 蜜臀久久久99精品久久久久久| 欧美激情在线| 一区二区三区四区在线| 亚洲精品乱码久久久久久黑人| 欧美成人嫩草网站| 妖精视频成人观看www| 欧美一区二区三区免费大片| 国产主播精品在线| 欧美+亚洲+精品+三区| 久久久久久黄| 亚洲精品网站在线播放gif| 欧美成人免费全部观看天天性色| 亚洲精品日韩久久| 亚洲福利小视频| 久久国产精品第一页| 香蕉成人伊视频在线观看| 狠狠久久婷婷| 欧美人妖在线观看| 亚洲国产精品久久人人爱蜜臀 | 亚洲手机成人高清视频| 久久久久久亚洲精品杨幂换脸 | 影音国产精品| 久久国产精品毛片| 亚洲电影在线看| 欧美一二三区在线观看| 亚洲国产成人tv| 国产精品麻豆va在线播放| 亚洲免费电影在线观看| 日韩视频在线免费观看| 久久综合五月天婷婷伊人| 久久综合久色欧美综合狠狠| 国产精品久久综合| 久久综合中文字幕| 亚洲综合视频1区| 欧美一级专区| 亚洲美女在线国产| 国内自拍视频一区二区三区| 欧美日韩国产一区| 一本色道久久综合亚洲二区三区| 久久久久国产精品人| 亚洲一区自拍| 国产美女精品视频免费观看| 午夜精品美女自拍福到在线| 新狼窝色av性久久久久久| 最新日韩在线| 激情久久久久| 欧美激情综合五月色丁香小说| 欧美一区二区三区视频免费播放 | 欧美激情黄色片| 91久久精品视频| 黄色一区二区三区四区| 国产精品视频精品| 欧美日韩裸体免费视频| 亚洲视频电影图片偷拍一区| 欧美激情综合色| 美女精品国产| 免播放器亚洲一区| 久久精品一二三区| 欧美一级电影久久| 亚洲免费在线视频| 原创国产精品91| 国产在线成人| 国产亚洲欧美日韩日本| 国产精品久久久久久久久久妞妞 | 欧美日韩视频在线第一区| 久久综合中文字幕| 欧美1区3d| 欧美成人日本| 欧美精品久久久久a| 欧美—级高清免费播放| 欧美精品一区二区三区一线天视频 | 99精品欧美一区二区三区综合在线| 欧美国产另类| 亚洲免费一在线| 亚洲欧美电影院| 午夜日韩福利| 亚洲精品欧美| 亚洲一二三区在线观看| 亚洲一二三区精品| 久久精品国内一区二区三区| 亚洲精品一区二区三| 日韩写真在线| 亚洲欧美日韩一区二区| 午夜国产精品视频免费体验区| 小处雏高清一区二区三区 | 亚洲婷婷在线| 性欧美videos另类喷潮| 久久精品女人天堂| 亚洲午夜电影网| 欧美影视一区| 欧美大片18| 国产精品亚洲精品| 尹人成人综合网| 亚洲最黄网站| 亚洲国产婷婷香蕉久久久久久| 国产一区二区久久久| 亚洲电影免费观看高清完整版| 亚洲精选一区二区| 小辣椒精品导航| 欧美成人午夜| 亚洲一区二区三区色| 久久久伊人欧美| 欧美色欧美亚洲高清在线视频| 免费人成精品欧美精品| 欧美天天视频| 亚洲第一中文字幕在线观看| 一本一本久久| 老司机免费视频一区二区| 99精品国产在热久久| 久久久久久久久伊人| 国产精品第13页| 国产精品久久久久国产精品日日 | 国产丝袜美腿一区二区三区| 国产精品久久一卡二卡| 亚洲国产一区二区三区a毛片| 亚洲欧美中日韩| 亚洲福利电影| 久久疯狂做爰流白浆xx| 欧美日韩在线播放三区四区| 亚洲电影免费观看高清完整版| 亚洲免费在线视频| 亚洲欧洲日本一区二区三区| 亚洲精品久久久久久一区二区| 亚洲国产精品成人精品| 亚洲欧美在线高清| 欧美日产国产成人免费图片| 国内成人精品2018免费看 | 亚洲国产精品久久久久秋霞影院| 亚洲欧美日产图| 国产精品国产一区二区| 亚洲精品久久久久中文字幕欢迎你| 欧美在线免费一级片| 久久久久久夜| 亚洲图色在线| 欧美视频在线免费| 一区二区三区四区五区视频| 欧美成人免费大片| 久久国产乱子精品免费女| 国产精品主播| 亚洲欧美日韩直播| 在线亚洲精品| 欧美性片在线观看| 激情久久综艺| 久久夜色精品亚洲噜噜国产mv| 亚洲综合二区| 国产乱码精品一区二区三区av| 亚洲影视九九影院在线观看| 日韩一级在线| 国产精品高清免费在线观看| 亚洲天堂成人在线视频| 99精品国产在热久久婷婷| 欧美经典一区二区| 一区二区三区精密机械公司| 日韩视频在线免费观看| 欧美无乱码久久久免费午夜一区|