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

天行健 君子當自強而不息

高級紋理映射技術(2)

紋理階段混合操作

紋理映射本質上就是從紋理中獲取顏色值,然后應用到物體的表面,多層紋理映射本質上就是混合多層紋理的顏色,然后應用到物體表面。為了處理上的方便,Direct3D將顏色的RGB通道和alpha通道分別進行處理,具體的操作方法通過紋理階段狀態進行設置。

設置紋理顏色混合操作的代碼大致如下:

// i表示紋理階段序號
pd3dDevice->SetTextureStageState(i, D3DTSS_COLORARG1, arg1);
pd3dDevice->SetTextureStageState(i, D3DTSS_COLORARG2, arg2);
pd3dDevice->SetTextureStageState(i, D3DTSS_COLOROP, op);

一般的,用D3DTSS_COLORARG1指定當前紋理層的顏色,用D3DTSS_COLORARG2指定已經過顏色混合處理后的前面所有紋理層的顏色,用D3DTSS_COLOROP指定混合方式。Direct3D使用下面的方式進行紋理混合:

Colorstage = D3DTSS_COLOROP(D3DTSS_COLORARG1, D3DTSS_COLORARG2)

渲染狀態D3DTSS_COLOROP用來指定紋理RGB通道混合方式,它們是屬于枚舉類型D3DTEXTUREOP的常量,D3DTEXTUREOP定義如下:

Defines per-stage texture-blending operations.

typedef enum D3DTEXTUREOP
{
D3DTOP_DISABLE = 1,
D3DTOP_SELECTARG1 = 2,
D3DTOP_SELECTARG2 = 3,
D3DTOP_MODULATE = 4,
D3DTOP_MODULATE2X = 5,
D3DTOP_MODULATE4X = 6,
D3DTOP_ADD = 7,
D3DTOP_ADDSIGNED = 8,
D3DTOP_ADDSIGNED2X = 9,
D3DTOP_SUBTRACT = 10,
D3DTOP_ADDSMOOTH = 11,
D3DTOP_BLENDDIFFUSEALPHA = 12,
D3DTOP_BLENDTEXTUREALPHA = 13,
D3DTOP_BLENDFACTORALPHA = 14,
D3DTOP_BLENDTEXTUREALPHAPM = 15,
D3DTOP_BLENDCURRENTALPHA = 16,
D3DTOP_PREMODULATE = 17,
D3DTOP_MODULATEALPHA_ADDCOLOR = 18,
D3DTOP_MODULATECOLOR_ADDALPHA = 19,
D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20,
D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21,
D3DTOP_BUMPENVMAP = 22,
D3DTOP_BUMPENVMAPLUMINANCE = 23,
D3DTOP_DOTPRODUCT3 = 24,
D3DTOP_MULTIPLYADD = 25,
D3DTOP_LERP = 26,
D3DTOP_FORCE_DWORD = 0x7fffffff,
} D3DTEXTUREOP, *LPD3DTEXTUREOP;

Constants

D3DTOP_DISABLE
Disables output from this texture stage and all stages with a higher index. To disable texture mapping, set this as the color operation for the first texture stage (stage 0). Alpha operations cannot be disabled when color operations are enabled. Setting the alpha operation to D3DTOP_DISABLE when color blending is enabled causes undefined behavior.
 
D3DTOP_SELECTARG1
Use this texture stage's first color or alpha argument, unmodified, as the output. This operation affects the color argument when used with the D3DTSS_COLOROP texture-stage state, and the alpha argument when used with D3DTSS_ALPHAOP.

SRGBA = Arg1
 

D3DTOP_SELECTARG2
Use this texture stage's second color or alpha argument, unmodified, as the output. This operation affects the color argument when used with the D3DTSS_COLOROP texture stage state, and the alpha argument when used with D3DTSS_ALPHAOP.

SRGBA = Arg2
 

D3DTOP_MODULATE
Multiply the components of the arguments.

SRGBA = Arg1 x Arg2
 

D3DTOP_MODULATE2X
Multiply the components of the arguments, and shift the products to the left 1 bit (effectively multiplying them by 2) for brightening.

SRGBA = (Arg1 x Arg2) << 1
 

D3DTOP_MODULATE4X
Multiply the components of the arguments, and shift the products to the left 2 bits (effectively multiplying them by 4) for brightening.

SRGBA = (Arg1 x Arg2) << 2
 

D3DTOP_ADD
Add the components of the arguments.

SRGBA = Arg1 + Arg2
 

D3DTOP_ADDSIGNED
Add the components of the arguments with a - 0.5 bias, making the effective range of values from - 0.5 through 0.5.

SRGBA = Arg1 + Arg2 - 0.5
 

D3DTOP_ADDSIGNED2X
Add the components of the arguments with a - 0.5 bias, and shift the products to the left 1 bit.

SRGBA = (Arg1 + Arg2 - 0.5) << 1
 

D3DTOP_SUBTRACT
Subtract the components of the second argument from those of the first argument.

SRGBA = Arg1 - Arg2
 

D3DTOP_ADDSMOOTH
Add the first and second arguments; then subtract their product from the sum.

SRGBA = Arg1 + Arg2 - Arg1 x Arg2 = Arg1 + Arg2 x (1 - Arg1)

D3DTA

Texture argument constants are used as values for the following members of the D3DTEXTURESTAGESTATETYPE enumerated type:

  • D3DTSS_ALPHAARG0
  • D3DTSS_ALPHAARG1
  • D3DTSS_ALPHAARG2
  • D3DTSS_COLORARG0
  • D3DTSS_COLORARG1
  • D3DTSS_COLORARG2
  • D3DTSS_RESULTARG

Set and retrieve texture arguments by calling the IDirect3DDevice9::SetTextureStageState and IDirect3DDevice9::GetTextureStageState methods.

Argument flags

You can combine an argument flag with a modifier, but two argument flags cannot be combined.

#define Description
D3DTA_CONSTANT Select a constant from a texture stage. The default value is 0xffffffff.
D3DTA_CURRENT The texture argument is the result of the previous blending stage. In the first texture stage (stage 0), this argument is equivalent to D3DTA_DIFFUSE. If the previous blending stage uses a bump-map texture (the D3DTOP_BUMPENVMAP operation), the system chooses the texture from the stage before the bump-map texture. If s represents the current texture stage and s - 1 contains a bump-map texture, this argument becomes the result output by texture stage s - 2. Permissions are read/write.
D3DTA_DIFFUSE The texture argument is the diffuse color interpolated from vertex components during Gouraud shading. If the vertex does not contain a diffuse color, the default color is 0xffffffff. Permissions are read-only.
D3DTA_SELECTMASK Mask value for all arguments; not used when setting texture arguments.
D3DTA_SPECULAR The texture argument is the specular color interpolated from vertex components during Gouraud shading. If the vertex does not contain a specular color, the default color is 0xffffffff. Permissions are read-only.
D3DTA_TEMP The texture argument is a temporary register color for read or write. D3DTA_TEMP is supported if the D3DPMISCCAPS_TSSARGTEMP device capability is present. The default value for the register is (0.0, 0.0, 0.0, 0.0). Permissions are read/write.
D3DTA_TEXTURE The texture argument is the texture color for this texture stage. Permissions are read-only.
D3DTA_TFACTOR The texture argument is the texture factor set in a previous call to the IDirect3DDevice9::SetRenderState with the D3DRS_TEXTUREFACTOR render-state value. Permissions are read-only.

Modifier flags

An argument flag may be combined with one of the following modifier flags.

#define Description
D3DTA_ALPHAREPLICATE Replicate the alpha information to all color channels before the operation completes. This is a read modifier.
D3DTA_COMPLEMENT Take the complement of the argument x, (1.0 - x). This is a read modifier.

 

黑暗映射

在Direct3D的坐標變換和光照流水線中,光照效果是基于所謂的"逐頂點(per-vertex)"方式計算的,也就是說,參與實際數計算的是三角形的每個頂點,而不是針對每個像素進行。有時這會造成一些較為明顯的視覺錯誤,例如,有一個很大的三角形,其表面近處有一個光源,當光源靠近該三角形的一個頂點時,就會看到這個三角形的受光效果;當光源向三角形的重心靠近時,三角形的受光效果便會逐漸消失。最壞的情況是,當光源位于三角形的中央時,整個三角形只受非常少的光照,而在三角形的中央會有一個亮點。由此可見,如果頂點未受光照,則無法計算出正確的三角形面的顏色。為了解決這個問題,可以采用基于像素的光照計算,但是基于像素的光照計算其計算量比較大,通常采用紋理貼圖的方式模擬基于逐像素光照效果,其中紋理貼圖的內容正式所期望的類型光源照射在一張漆黑表面上的結果。

通過紋理映射來模擬逐像素光照效果,通常是將第一層紋理設置為物體原來的表面紋理,將第二層紋理設置為光照紋理,然后將兩張紋理的顏色相乘,所以有時將兩張紋理的顏色相乘稱為光照映射(light mapping)。由于這種技術經常被用于使一張紋理變暗,有時也稱為黑暗映射(dark mapping)。示例代碼如下:

pd3dDevice->SetTexture(0, g_base_texture);
pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

pd3dDevice->SetTexture(1, g_dark_texture);
pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);

物體紋理

光照紋理

 

黑暗映射的效果:

這種類型的多層紋理之所以稱為"黑暗映射",是因為最終結果中未受到"光照"的紋理元素比原圖中的紋理元素更暗。

黑暗映射通常有三種調制操作:D3DTOP_MODULATE,D3DTOP_MODULATE2X,D3DTOP_MODULATE4X。

當應用程序選擇了一張紋理作為當前紋理,也就是指示Direct3D將該紋理應用于此后所有將要渲染的圖元,直到再次改變當前紋理為止。如果一個三維場景中的每個圖元都有各自不同的紋理,則必須在渲染每個圖元之前先設置相應的紋理。


posted on 2008-05-20 13:10 lovedday 閱讀(2961) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美日韩视频在线观看一区二区三区 | 亚洲美女在线视频| 久久综合九九| 久久婷婷综合激情| 亚洲韩国一区二区三区| 欧美a级一区| 欧美激情欧美狂野欧美精品| 99视频在线精品国自产拍免费观看 | 亚洲一区二区三| 亚洲免费电影在线| 国产精品一区久久久| 久久免费视频观看| 快射av在线播放一区| 亚洲美女视频网| 一区二区欧美激情| 国产午夜精品全部视频播放| 老司机午夜精品视频在线观看| 久久精品中文字幕免费mv| 亚洲国产精品一区二区第一页| 亚洲国产色一区| 欧美美女bb生活片| 性欧美暴力猛交另类hd| 久久国产精品99久久久久久老狼| 亚洲国产精品黑人久久久| 亚洲美女网站| 国产亚洲视频在线观看| 亚洲国产精品久久| 国产精品揄拍500视频| 欧美激情中文字幕一区二区| 欧美午夜激情视频| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美日韩国产影院| 久久久人人人| 欧美午夜精品一区| 欧美xxx成人| 国产精品久久综合| 亚洲高清资源| 国产综合在线看| 一区二区福利| 亚洲国产精品久久久久秋霞不卡| 一区二区三区四区国产| 亚洲二区在线视频| 西西裸体人体做爰大胆久久久| 日韩午夜在线| 久久中文久久字幕| 久久都是精品| 国产精品久久久久aaaa樱花| 欧美v日韩v国产v| 国产欧美日韩精品一区| 99精品99久久久久久宅男| 亚洲大片一区二区三区| 欧美在线播放| 午夜亚洲视频| 欧美亚洲成人精品| 亚洲人精品午夜在线观看| 国模一区二区三区| 欧美一区二区三区日韩| 欧美主播一区二区三区美女 久久精品人| 久久综合国产精品| 嫩草国产精品入口| 一区二区亚洲精品国产| 欧美一级片一区| 久久精品91久久香蕉加勒比| 国产精品第13页| 一本综合精品| 亚洲综合电影| 欧美视频在线不卡| 一区二区三区欧美在线| 亚洲免费高清| 欧美日韩国产精品| 亚洲精品乱码久久久久久| 99视频一区| 欧美揉bbbbb揉bbbbb| 亚洲视频一二区| 亚洲欧美日韩一区在线观看| 国产精品永久免费观看| 欧美一区二区福利在线| 久久精品国产亚洲精品| 国产一区欧美日韩| 久久久久成人精品| 欧美成人中文字幕| 亚洲精品系列| 国产精品国色综合久久| 亚洲视频一区二区免费在线观看| 亚洲欧美成人精品| 国产视频在线一区二区| 久久久久在线| 亚洲国产天堂久久综合网| 中文在线一区| 国产美女精品视频| 另类尿喷潮videofree| 亚洲人成亚洲人成在线观看图片 | 国产精品三区www17con| 性娇小13――14欧美| 欧美a级一区| 亚洲一级电影| 国产一区二区精品久久91| 久久亚洲美女| 亚洲视频免费在线| 久久亚洲精品一区| 99国产精品国产精品毛片| 国产精品午夜av在线| 久久影院亚洲| 亚洲一区激情| 亚洲第一黄网| 久久国内精品自在自线400部| 在线电影一区| 国产精品久久久久久久久久免费 | 国产小视频国产精品| 免费国产自线拍一欧美视频| 亚洲免费成人| 欧美黄色一区二区| 欧美一区1区三区3区公司| 亚洲国产视频a| 国产精品试看| 欧美巨乳在线| 久久久久国产一区二区三区| 亚洲天堂av综合网| 亚洲国产精品成人综合| 久久精品国产久精国产一老狼| 日韩一二三在线视频播| 国产在线麻豆精品观看| 国产精品v日韩精品| 蜜桃久久精品乱码一区二区| 欧美一二三视频| 亚洲视频在线二区| 亚洲精品久久久久中文字幕欢迎你 | 在线看片第一页欧美| 国产精品一区二区久久精品| 欧美不卡在线| 久久综合狠狠综合久久激情| 亚洲一区在线免费观看| 亚洲毛片在线免费观看| 欧美激情视频一区二区三区在线播放| 欧美一区二区三区四区视频| 夜夜夜精品看看| 亚洲日本免费| 亚洲欧洲中文日韩久久av乱码| 精品成人一区二区| 国产日韩视频| 国产一区自拍视频| 国产亚洲精品高潮| 国产日韩在线一区| 国产精品亚洲综合天堂夜夜| 欧美深夜影院| 欧美视频在线一区| 欧美体内谢she精2性欧美| 欧美日韩国产专区| 欧美日韩久久| 欧美亚州在线观看| 国产精品无码永久免费888| 国产精品色婷婷| 国产日韩欧美夫妻视频在线观看| 国产精品美女一区二区| 国产精品视频自拍| 国产在线欧美日韩| 亚洲福利免费| 一区二区欧美视频| 亚洲在线一区二区| 欧美专区日韩专区| 久久视频一区二区| 欧美激情一二区| 日韩视频二区| 一区二区三区日韩精品| 欧美一区91| 久久蜜臀精品av| 欧美激情精品久久久久久| 欧美精品福利| 国产精品久在线观看| 国产一区二区三区四区五区美女| 狠狠入ady亚洲精品| 亚洲每日更新| 欧美一区二区三区婷婷月色 | 一本久道综合久久精品| 亚洲综合三区| 免费观看成人网| 亚洲美女尤物影院| 欧美一区二区网站| 欧美精品一区二区三区久久久竹菊| 欧美日在线观看| 伊人久久大香线蕉av超碰演员| 亚洲日本久久| 久久久91精品国产| 亚洲福利专区| 欧美一区二区三区另类 | 99亚洲精品| 久久久久国内| 国产精品视频久久一区| 亚洲国产你懂的| 欧美影院成人| 亚洲理论在线| 久久天天综合| 国产九九精品视频| 一区二区三区国产盗摄| 久久亚洲春色中文字幕| 中文av一区二区| 欧美黄色aaaa| 亚洲大片av| 久久视频在线免费观看| 亚洲香蕉视频|