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

天行健 君子當自強而不息

D3D中的紋理映射(1)

紋理映射是一種允許我們為三角形賦予圖象數據的技術;這讓我們能夠更細膩更真實地表現我們的場景。例如,我們能夠創建一個立方體并且通過對它的每個面創建一個紋理來把它變成一個木箱(如圖6.1)。

在Direct3D中一個紋理是通過IDirect3DTexture9接口來表現的。一個紋理是一個類似像素矩陣的表面它能夠被映射到三角形上。

 

6.1 紋理坐標

Direct3D使用一個紋理坐標系統,它是由用水平方向的u軸和豎直方向v軸構成。由u,v坐標決定紋理上的元素,它被叫做texel。注意v軸是向下的(如圖6.2)。

 

同樣,注意規格化的坐標間隔,[0,1],它被使用是因為它給Direct3D一個固定的范圍用于在不同尺寸的紋理上工作。

對每一個3D三角形,我們都希望在給它貼圖的紋理上定義一個用相應的三角形。(如圖6.3)。

 

我們再一次修改原來的頂點結構,添加一個用于在紋理上定位的紋理坐標。

struct Vertex

{

       float _x, _y, _z;

       float _nx, _ny, _nz;

       float _u, _v; // texture coordinates

       static const DWORD FVF;

};

const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;

我們在頂點格式中添加了一個D3DFVF_TEX1,它是說我們的頂點結構中包含了一個紋理坐標。

現在每個三角形都通過頂點的三個對象來建立,同時也通過紋理坐標定義了一個相應的紋理三角形。

 

6.2創建并賦予材質

紋理數據通常是從存儲在磁盤中的圖片文件中讀取的,且被讀進IDirect3DTexture9對象中。我們能夠使用下面的D3DX函數完成這項工作:

Creates a texture from a file.

HRESULT D3DXCreateTextureFromFile(
LPDIRECT3DDEVICE9 pDevice,
LPCTSTR pSrcFile,
LPDIRECT3DTEXTURE9 * ppTexture
);

Parameters

pDevice
[in] Pointer to an IDirect3DDevice9 interface, representing the device to be associated with the texture.
pSrcFile
[in] Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
ppTexture
[out] Address of a pointer to an IDirect3DTexture9 interface, representing the created texture object.

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following:

D3DERR_NOTAVAILABLED3DERR_OUTOFVIDEOMEMORYD3DERR_INVALIDCALLD3DXERR_INVALIDDATAE_OUTOFMEMORY

Remarks

The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXCreateTextureFromFileW. Otherwise, the function call resolves to D3DXCreateTextureFromFileA because ANSI strings are being used.

This function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. See D3DXIMAGE_FILEFORMAT.

The function is equivalent to D3DXCreateTextureFromFileEx(pDevice, pSrcFile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture).

Mipmapped textures automatically have each level filled with the loaded texture.

When loading images into mipmapped textures, some devices are unable to go to a 1x1 image and this function will fail. If this happens, the images need to be loaded manually.

Note that a resource created with this function will be placed in the memory class denoted by D3DPOOL_MANAGED.

Filtering is automatically applied to a texture created using this method. The filtering is equivalent to D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER in D3DX_FILTER.

For the best performance when using D3DXCreateTextureFromFile:

  1. Doing image scaling and format conversion at load time can be slow. Store images in the format and resolution they will be used. If the target hardware requires power of two dimensions, create and store images using power of two dimensions.
  2. Consider using DirectDraw surface (DDS) files. Because DDS files can be used to represent any Direct3D 9 texture format, they are very easy for D3DX to read. Also, they can store mipmaps, so any mipmap-generation algorithms can be used to author the images.

這個函數能夠讀取下面圖片格式中的任意一種:BMP,DDS,DIB,JPG,PNG,TGA。

例如,用一個名為stonewall.bmp的圖片創建一個紋理,我們將按照下面的例子來寫:

IDirect3Dtexture9* _stonewall;

D3DXCreateTextureFromFile(_device, "stonewall.bmp", &_stonewall);

 

設置當前紋理,我們使用下面的方法:

Assigns a texture to a stage for a device.

HRESULT SetTexture(
DWORD Sampler,
IDirect3DBaseTexture9 * pTexture
);

Parameters

Sampler

Zero based sampler number. Textures are bound to samplers; samplers define sampling state such as the filtering mode and the address wrapping mode. Textures are referenced differently by the programmable and the fixed function pipeline:

  • Programmable shaders reference textures using the sampler number. The number of samplers available to a programmable shader is dependent on the shader version. .
  • The fixed function pipeline on the other hand, references textures by texture stage number. The maximum number of samplers is determined from two caps: MaxSimultaneousTextures and MaxTextureBlendStages of the D3DCAPS9 structure.
[in] There are two other special cases for stage/sampler numbers.
  • A special number called D3DDMAPSAMPLER is used for Displacement Mapping (Direct3D 9).
  • A programmable vertex shader uses a special number defined by a D3DVERTEXTEXTURESAMPLER when accessing Vertex Textures in vs_3_0 (Direct3D 9).

 

pTexture
[in] Pointer to an IDirect3DBaseTexture9 interface, representing the texture being 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

IDirect3DDevice9::SetTexture is not allowed if the texture is created with a pool type of D3DPOOL_SCRATCH. IDirect3DDevice9::SetTexture is not allowed with a pool type of D3DPOOL_SYSTEMMEM texture unless DevCaps is set with D3DDEVCAPS_TEXTURESYSTEMMEMORY.

例子:

Device->SetTexture(0, _stonewall);

注意:在Direct3D中,你能夠設置八個紋理,它們能夠組合起來創建更多細節的圖象。這又被叫做多重紋理。

 

為了銷毀一個紋理,我們設置pTexture為0。例如,假如不想用一個紋理來渲染物體,那么我們就這樣寫:

Device->SetTexture(0, 0);

renderObjectWithoutTexture();

假如場景中有使用不同紋理的三角形,我們就必須添加與下面類似的一些代碼:

Device->SetTexture(0, _tex0);

drawTrisUsingTex0();

 

Device->SetTexture(0, _tex1);

drawTrisUsingTex1();

 

6.3過濾器

       就象以前提及的,紋理被映射到屏幕中的三角形上。通常紋理三角形和屏幕三角形是不一樣大的。當紋理三角形比屏幕三角形小時,紋理三角形會被適當放大。當紋理三角形比屏幕三角形大時,紋理三角形會被適當縮小。這兩種情況,變形都將會出現。過濾(Filtering)是一種Direct3D用它來幫助這些變形變的平滑的技術。

       Direct3D提供了三種不同的過濾器;每種都提供了一個不同的品質級別。越好的品質越慢,因此你必須在品質與速度之間取得一個平衡。紋理過濾器是用IDirect3DDevice9::SetSamplerState方法來設置的。

Sets the sampler state value.

HRESULT SetSamplerState(
DWORD Sampler,
D3DSAMPLERSTATETYPE Type,
DWORD Value
);

Parameters

Sampler
[in] The sampler stage index.
Type
[in] This parameter can be any member of the D3DSAMPLERSTATETYPE enumerated type.
Value
[in] State value to set. The meaning of this value is determined by the Type parameter.

Return Values

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

  •  Nearest point sampling——這是默認的過濾方法且返回最差的效果,但是它的計算是最快的。下面的代碼就是設置Nearest point sampling作為縮小放大的過濾器:

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);

Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);

  •  Linear filtering——這種過濾產生還算比較好的效果,在今天的硬件上處理它還是非常快的。它是被推薦使用的。下面的代碼就是設置Linear filtering作為縮小放大的過濾器。

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

  •  Anisotropic filtering——這種過濾產生最好的效果,但是處理時間也是最長的。下面的代碼就是設置Anisotropic filtering作為縮小放大的過濾器。

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);

Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);

當使用Anisotropic filtering時,我們必須設置D3DSAMP_MAXANISOTROPY等級,它決定處理的質量。該值越高處理的效果越好。檢查D3DCAPS9結構確認你的顯卡是否支持此功能。下面的代碼設置該值為4:

Device->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 4);


posted on 2008-03-17 11:17 lovedday 閱讀(1492) 評論(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在线观看| 久久av免费一区| 欧美ed2k| 欧美一级视频免费在线观看| 在线免费日韩片| 欧美日韩综合一区| 久久一区视频| 亚洲自拍都市欧美小说| 亚洲国产毛片完整版| 免费成人在线观看视频| 亚洲永久字幕| 亚洲国产一成人久久精品| 欧美国产成人在线| 久久高清一区| 亚洲一区二区成人在线观看| 在线视频你懂得一区| 亚洲国产清纯| 国产一区视频在线看| 国产精品久久久久一区二区| 欧美激情1区2区3区| 久久久999成人| 欧美一区免费视频| 亚洲一区二区三区四区视频| 香蕉国产精品偷在线观看不卡 | 国产一区二区三区日韩欧美| 国产精品jizz在线观看美国| 欧美成人综合一区| 久久精品国产综合| 欧美日韩大片| 欧美日韩妖精视频| 女人香蕉久久**毛片精品| 久久国产精品久久久久久| 午夜精品免费| 亚洲自拍16p| 欧美a级一区二区| 国产日韩欧美日韩| 国产一区二区精品久久91| 亚洲高清123| 亚洲国产婷婷香蕉久久久久久99| 中国成人黄色视屏| 亚洲一区二区视频在线观看| 亚洲国产天堂久久综合| 亚洲系列中文字幕| 欧美激情视频免费观看| 亚洲激情网站| 亚洲麻豆av| 亚洲综合精品一区二区| 久久一日本道色综合久久| 欧美一级视频一区二区| 久久爱www| 国产精品都在这里| 欧美午夜不卡视频| 91久久国产综合久久蜜月精品| 亚洲激情视频在线| 久久久久久久激情视频| 午夜在线观看免费一区| 欧美视频精品在线| 一本久道久久综合中文字幕| 性色av一区二区三区| 日韩视频免费观看| 亚洲免费在线播放| 欧美午夜精品久久久久久浪潮| 日韩视频在线观看| 久久精品视频99| 亚洲激情视频在线| 欧美高清在线视频| 亚洲免费不卡| 久久久久国产精品麻豆ai换脸 | 一区二区三区波多野结衣在线观看| 中国成人亚色综合网站| 久久激情视频久久| 国产专区精品视频| 久久青青草综合| 一区二区欧美视频| 欧美日韩在线不卡一区| 亚洲自拍电影| 欧美一区二区三区另类 | 亚洲一本视频| 亚洲综合国产激情另类一区| 国产色产综合产在线视频| 久久久免费精品| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲精品九九| 久久综合福利| 亚洲免费影院| 影音先锋亚洲视频| 欧美一级淫片aaaaaaa视频| 亚洲欧美在线播放| 在线观看欧美亚洲| 99在线精品观看| 免费观看久久久4p| 99精品欧美一区二区蜜桃免费| 一区二区欧美精品| 激情欧美日韩| 久热精品在线视频| 香蕉久久精品日日躁夜夜躁| 依依成人综合视频| 99精品国产一区二区青青牛奶| 国产午夜精品理论片a级大结局| 欧美成人激情视频免费观看| 欧美日韩一区二区三区免费| 久久一区国产| 国产精品毛片va一区二区三区 | 亚洲黄页视频免费观看| 欧美一区激情| 91久久久国产精品| 亚洲宅男天堂在线观看无病毒| 国产在线乱码一区二区三区| 亚洲第一网站免费视频| 性色av一区二区三区| 亚洲国产一区视频| 亚洲在线播放电影| 日韩视频一区二区在线观看 | 亚洲免费在线观看视频| 一本色道久久综合亚洲精品婷婷| 国产欧美一区视频| 亚洲精品中文字幕在线| 在线播放日韩欧美| 欧美亚洲一区二区三区| 亚洲永久免费av| 欧美日韩aaaaa| 亚洲欧洲日韩女同| 亚洲国产成人精品女人久久久| 午夜精品理论片| 亚洲欧美日韩成人高清在线一区| 麻豆久久精品| 女同性一区二区三区人了人一| 国产视频丨精品|在线观看| 亚洲少妇诱惑| 亚洲综合色网站| 国产精品成av人在线视午夜片| 亚洲精品国产精品乱码不99按摩 | 亚洲在线成人| 欧美精品在线一区二区三区| 午夜精品久久久久久久久久久| 欧美一区二区三区在线播放| 亚洲免费人成在线视频观看| 欧美日韩另类一区| 亚洲最新视频在线| 在线视频精品一| 欧美视频在线一区| 亚洲视频在线观看免费| 激情一区二区三区| 欧美一区二区福利在线| 久久亚洲国产精品一区二区| 国内精品久久久久影院色| 久久国产婷婷国产香蕉| 美日韩精品视频免费看| 欧美午夜精品久久久| 一本久久a久久精品亚洲| 日韩一级二级三级| 欧美午夜宅男影院在线观看| 亚洲欧美日韩国产| 美女亚洲精品| 日韩视频一区二区三区在线播放| 欧美精品色一区二区三区| 久久久精品视频成人| 国产一区二区日韩精品欧美精品 | 老司机精品视频一区二区三区| 性欧美暴力猛交69hd| 亚洲一区二区精品视频| 欧美激情精品久久久久久久变态| 亚洲国产精品一区| 亚洲一区二区三区午夜| 国产麻豆日韩欧美久久| 亚洲人成网在线播放| 亚洲精品女人| 国产精品免费一区二区三区在线观看 | 欧美日韩免费看| 亚洲免费视频在线观看| 噜噜噜噜噜久久久久久91| 99v久久综合狠狠综合久久| 国产精品视频免费| 亚洲精品一区二区在线| 小黄鸭视频精品导航| 激情欧美一区| 欧美日韩一二三四五区| 久久精品女人| 制服诱惑一区二区| 欧美.www| 欧美在线999| 国产三级欧美三级| 欧美高清视频在线播放| 午夜精品一区二区三区在线播放| 欧美成人国产| 久久精品久久99精品久久| 久久天堂av综合合色| 1000部精品久久久久久久久| 久久天天躁夜夜躁狠狠躁2022| 久久久久欧美| 亚洲视屏在线播放| 国产一区在线观看视频| 欧美国产日本高清在线| 欧美亚洲一区二区在线| 99国产精品视频免费观看一公开| 久久久综合免费视频| 亚洲一区二区在线免费观看|