|
|
?????????????????????????????????????????????
??3D??
???????????????????????????????????????????: ??,??????????????????????????Mesh
????????????????????Mesh????????????????????
??????????????????????????????????????????????????????????????????? Mesh,????????????????????????????
?????????Mesh??????????????????????Mesh????????????????????????????????????????????????????????Max Maya????????????????????
???????Introduction?????????
???????????????????????????????????????????????
??????????????????????????
????????
1.Texture Coordinates ????
Direct3D???????????????U???????? V????UV??????texel????????V??????????(?6.2)
???????????????
??????????????[0,1],??Direct3D?????????????
????3D?????????????????????3D????(??6.3)
????????????????????????????????
struct Vertex{ float _x,_y,_z; float nx,ny,nz; float _u,_v; static const DWORD FVF; };
const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL |D3DFVF_TEX1
<???????D3DFVF_TEX1????????????????????????????????/p>
???????????????????????
???????
??????????????????????IDirect3DTexture9?????????????D3DX??:
D3DXCreateTextureFromFile(LPDIRECT3DDEVICE9 pDevice, LPCSTR pSrcFile,LPDIRECT3DTEXTURE9* ppTexture);
????????????????BMP,DDS,DIB,JPG,PNG,?TGA
??????????????wall.bmp,??????????:
IDirect3DTexture9* stonewall;
D3DXCreateTextureFromFile(device,"stonewall.bmp",&stonewall);
?????????????????:
IDirect3DDevice9::SetTexture(DWORD State,IDirect3DBaseTexture9* pTexture);
??:
Device->SetTexture(0,stonewall)
??:?Direct3D,?????8????????????????????????????????????????? stage?0????
??????stage???????pTexture?0????????????????????????:
device->SetTexture(0,0);
renderObjectWithoutTexture();
?????????????????????????????????:
device->SetTexture(0,tex0);
drawTrisUsingTex0();
Device->SetTexture(0,tex1);
drawTrisUsingTex1();
???
????
????
???? Linear Filtering
??????
????????????????????????????????????????????????????????????????????????????????????????????????????????Direct3D?????????????????
Direct3D???????????????????????????????????????????????????????????????SetSamplerState???
Nearest point sampling - ???????????????????????????????????????????
Linear filtering - ??????????????????????????????????????????????:
Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
Device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
Anisotropic filtering - ?????????????????????????
Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_ANISOTROPIC);
Device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_ANISOTROPIC);
?????????????????D3DSAMP_MAXANISOTROPY??????anisotropic????????????????D3DCAPS9?????????????????????4
Device->SetSampleState(0,D3DSAMP_MAXANISOTROPY,4);
Mipmaps - ??????
As said in section 6.3,????????????????????In an effort to make the size difference less drastic,????????????????????????????????????????????????????????
mipmap?????????
Device->SetSamplerState(0,D3DSAMP_MIPFILTER,Filter);
Filter??????
D3DTEXF_NONE - ??mipmap
D3DTEXF_POINT - ??Filter,Direct3D??????????????????min????????
D3DTEXF_LINEAR - ??Filter,Direct3D??????????????????????????????????????????
?Direct3D???Mipmaps
??Mipmaps??????????mipmaps???D3DXCreateTextureFromFile???????mipmap.???Direct3D?????????????????????mipmap???????????
????
??????????????[0,1]????????????????????????????[0,1]????Direct3D???????????????:wrap border color clamp ?mirror
?6.5 6.6 6.7 6.8??????
?????????????????????(0,0) (0,3) (3,0) (3,3)????UV???????????3x3?????????????????5x5??????????wrap?????????(0,0) (0,5) (5,0)?(5,5).
??????Wrap?????????(0,0)(0,5) (5,0) (5,5).
?????????????????????:
??????????3D???????????
??????????????????????D3DXCreateTextureFromFile
?????????????mipmap????????????
??????????0,1????????????????????clamp,?
2 ?? Blending
????????????????????????????????????????????????????????????????????????????????(?????)
?? - ??????????
??????Direct3D???????
????????????????Alpha??
???? The Blending Equation
???????????????????????
?????????????????????????????????????????????????????????????????????
??????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????
????????????????????????????;?????????????????Z-component.???????????????????????????
????????4D?????(r,g,b,a)?denotes component-wise????
OutputPixel - ??????
SourcePixel - ???????????????
SourceBlendFactor - [0,1]??????????????
DestPixel - ???????????
DestBlendFactor - ???????
????????????????????????????????????7.2????????????
????????;?????????????????
Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
?????????????????????????????????Alpha???????????????????????????????????????
????
???????????????????????????????????????????????????? D3DRS_SRCBLEND?D3DRS_DESTBLEND?????????:
Device->SetRenderState(D3DRS_SRCBLEND,Source);
Device->SetRenderState(D3DRS_DESTBLEND,Destination);
????????????????
?????????D3DBLEND_SRCALPHA?D3DBLEND_INVSRCALPHA?
??
???????????Alpha???????????????????????????????Alpha???????????????????????????????????????Alpha???Alpha?????????????????????8bit?Alpha??????Alpha????[0,255]???[0%,100%]???????????(0)??????????????128??????50%???????255
???Alpha????????????????????D3DBLEND_SRCALPHA????D3DBLEND_INVSRCALPHA,?????????
Alpha??
????Alpha??????????????Alpha-channel???Alpha?????Alpha?????????????texel??Alpha????Texture?????????Alpha???Alpha????????????Alpha???????????????7.3????8bitAlpha??????
???Alpha
?????????????Alpha???Alpha??Alpha?????????Alpha???Alpha???????????????(diffuse color?Alpha Channel)??????????
Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
Stenciling ??
???????????????????????stencil????????????????????????stencil?????resolution????????????ij-th???stencil??????ij-th????????????The stencil buffer has the same resolution as the back buffer and depth buffer so that the ij-th pixel in the stencil buffer corresponds with the ij-th pixel in the back buffer and depth buffer.???????stencil????????????????????????
???????????????????????????????????????????????????stencil????????????
stencil???Direct3D????????????????? blending,???????????????stencil???????????????????????????stencil?????????????????????????????????????????????????stencil(?????????????).
Objectives - ??
??stencil?????????????stencil????????stencil???
???????????stencil????????drawn????????
????????????????stencil???
Using the Stencil Buffer??????
?????????????????Direct3D????????????????8.1.1????stencil????????? D3DRS_STENCILENABLE????????????false.?????????????
Device->SetRenderState(D3DRS_STENCILENABLE,true);
Device->SetRenderState(D3DRS_STENCILENABLE,false);
????????DirectX9.0??????????????????????SDK???????
??????stencil?????????IDirect3DDevice9::Clear????????????????????
?????????D3DCLEAR_STENCIL??????????????????????????6???????????????0.
??????????????????????????????????NVIDIA???????????????? Mark J. Kigard
???????????????????????????????????????????????????????????????????????????????????????????????????????/??????:
?????????????????????D3DFMT_D32????32bit??????
???????????????????8bie?????
The Stencil Test
??????????????????????????????????????????????:
(ref & mask) ComparisonOperation (value & mask)
???????????????????????????:???(LHS)??ANDing????-???????(ref)?????
RHS-??????ANDing???????????????????
??????LHS?RHS,????????????????????????????????????????????????????????????????????????????????
Controlling the Stencil Test ????????
ZBuffer WBuffer StencilBuffer
????????Direct3D???????Stencil?????????????????????????????????????????????????????????????????????????????????
Stencil Reference Value?????
??????????0,??????????D3DRS_STENCILREF???????????????????
Device->SetRenderState(D3DRS_STENCILREF,0x1);
??????????????????????????????????????ANDing.
Stencil Mask ????
??????????mask(hide)???ref?value????????0xffffffff,????mask.??????mask?D3DRS_STENCILMASK?????????mask?16??:
Device->SetRenderState(D3DRS_STENCILMASK,0x0000ffff);
??:??????????masking,????????????????????bit-wise???
Stencil Value - ???
??????????????????????????????????ij-th??????????ij-th??????????????????????????????????????????????????????????????????????????????
Comparison Operation - ????
??????D3DRS_STENCILFUNC?????????????D3DCMPFUNC????:
?????? Updating the Stencil Buffer
|
|