游戏开发论坛

 找回密码
 立即注册
搜索
查看: 6459|回复: 3

???????

[复制链接]

125

主题

364

帖子

396

积分

中级会员

Rank: 3Rank: 3

积分
396
QQ
发表于 2006-4-26 22:50:00 | 显示全部楼层 |阅读模式
?????????????????????????????????????????????

??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

125

主题

364

帖子

396

积分

中级会员

Rank: 3Rank: 3

积分
396
QQ
 楼主| 发表于 2006-4-26 22:51:00 | 显示全部楼层

Re:???????

?????????????????????????????entry???????????:

??????ij-th???????????????ijentry??????????????D3DRS_STENCILFAIL????:

Device->SetRenderState(D3DRS_STENCILFAIL,StencilOperation);

?????ij-th???????????????ij-th??????D3DRS_STENCILZFALL????

Device->SetRenderState(D3DRS_STENCILZFALL,StencilOperation);

?????????????ij-th?????????????ij-th???????D3DRS_STENCILPASS????:

Device->SetRenderState(D3DRS_STENCILPASS,StencilOperation);

?StencilOperation??????????:

????Mask

????????????????mask???????????0xffffffff.????????mask??D3DRS_STENCILWRITEMASK????????????16bits/p>

Device->SetRenderState(D3DRS_STENCILWRITEMASK,0x0000ffff);

????Stencil???????????????

????:??

??????????????????????????????3D????????????????????????????????????????;????????????????????????????????????????????-????????????????

????????????????,??????????????????????????????????????????????????????????????????????????????????????????8.1,????????

??????????????????????????????????????????????????????????????????????-???

?????

?????????v'=(vx'vy'vz')????v=(vx,vy,vz)??????n^.p_d = 0.????????

D3DX??????????R?????????????:

D3DXMatrixReflect(D3DXMATRIX *pOut,CONST D3DXPLANE *pPlane);

?????????????????????????????????????????yz,xz,xy???????????

??????yz????????????Z-component.?????????xz?????????y-component.?????????xy??????Z-component????????????????????

??????

???????????????????????????????????????????????????????????????????????????????????8.1??????????????????(????),????????????????????????????????????????????????????????????????????????????????????:

1.????????-??,???????-?????????????????????

2.???????0??8.3??????????????

3.??????????????????????????????????????1???????????????????????????0??????-????8.4????????????????????????????

4.???????????????????????????????????????????????????????????????????????1??????????????????????????????????????????1???????????????

?????

???RenderMirror????????????????????????????????????????We walk through the RenderMiror function almost line by line ????????????????

?????8.2.2???? to serve as an overall guide to the code,????1?2??????3?????????????????????????????

????????????????????????????

????

????????????????????:

void RenderMirror(){ Device->SetRenderState(D3DRS_STENCILENABLE,true); Device->SetRenderState(D3DRS_STENCILFUNC,D3DCMP_ALWAYS); Device->SetRenderState(D3DRS_STENCILREF,0x1); Device->SetRenderState(D3DRS_STENCILMASK,0xffffffff); Device->SetRenderState(D3DRS_STENCILWRITEMASK,0xffffffff); Device->SetRenderState(D3DRS_STENCILZFAIL,D3DSTENCILOP_KEEP); Device->SetRenderState(D3DRS_STENCILFAIL,D3DSTENCILOP_KEEP); Device->SetRenderState(D3DRS_STENCILPASS,D3DSTENCILOP_REPALCE); }

???????????????????D3DCMP_ALWAYS,???????????

?????????????D3DSTENCILOP_KEEP,??????????????????????????????????????????????????????????????????????

?????D3DSTENCILOP_KEEP????????????????????????????????????D3DCMP_ALWAYS.???????????????????????????we just do it now.

????????????????D3DSTENCILOP_REPLACE????????????0x1

????

??????????????????????????????D3DRS_ZWRITEENABLE???????????????????????D3DBLEND_ZERO?????D3DBLEND_ONE.???????????????????????:

Device->SetRenderState(D3DRS_ZWRITEENABLE,false);

Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);

Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ZERO);

Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);

Device->SetStreamSource(0,VB,0,sizeof(Vertex));

Device->SetFVF(Vertex::FVF);

Device->SetMaterial(&MirrorMtrl);

Device->SetTexture(0,MirrorTex);

D3DXMATRIX i;

D3DXMatrixIdentity(&i);

Device->SetTransform(D3DTS_WORLD,&I);

Device->DrawPrimitive(D3DPT_TRIANGLELIST,18,2);

Device->SetRenderState(D3DRS_ZWRITEENABLE,true);

?????

??????????????????0x1?????????????????????????????????????????????????????????????????????

??????????0x1????????????0x1?????????????????????????????????????????????

???????D3DRS_STENCILPASS????D3DSTENCILOP_KEEP,???????????????????????????????????????(?????D3DSTENCILOP_KEEP)???????????????????????

????

??????????????:

?????????????????????????????????XY???????????????

????

????????,??????????????????????????????????????????????????????????????????????????????????:

????????????????????????????????????????????????????????????????????????????????????????????????????????:

???????????????????????????????????????????:

?????????????

??8.2.3.4??w????????????????????????????????????????????????????????;?????????????????????Direct3D?????????????????????????????????????????????

???????????????????????:

????lanar Shadows - ????

?????????????????????????????????????????????????-????????????(?8.5)

??????????????????????????????????????????????????????DirectX SDK???????????

?????????????????????????????????????????????3D???????????????????????????????50%?????????????????"????",?????????????????????????

Parallel ?? - ????

?8.6???????????????????????????????L,???????P?r(t) = p + tL.???????r(t)???n*p + d = 0?s.???????r(t)???????????????????????s??????/???????:

?????:

?8.7??????L??????????????p??r(t) = p + t(p-L).????r(t)???n.p + d = 0?s.???????????????????????s???????????????

????

????8.6??????????????????????????????8.7??????????????????n.p+d=0???????

?????????p?????s???n.p+d=0????????????????????????????????????????

?(nxnynzd)4D??????????????????????L=(LxLyLzLw)?4D????????????????????w?????:

1.??w=0,??L?????????

??w=1,??L?????????

??????????????k=(nxnynzd).(LxLyLzLw)=nxLx+nyLy+nzLz+dLw,

???????p?????s?????????:

??????????????????we do not show how to derive this matrix.?????????????6,"???????",Jim Blinn's Corner:A Trip Down the Graphics Pipeline,?????????????

D3DX???????????????????????????????????w=9????w=1:

D3DXMATRIX *D3DXMatrixShadow(D3DXMATRIX *pOut,CONST D3DXVECTOR4 *pLight, CONST D3DXPLANE *pPlane);

???????????

?????????????????????????????????????????(????)????????????????????????????????8.8???????

?????????????????????????????????????????????????????????????????????????????????????????(??????????),??????????????????????????????

?????

?????????????????

RenderShadow?????????????????0?

???????????????????????D3DCMP_EQUAL?D3DRS_STENCILREF?????0x0,???????????????????????0x0.

????????0???????????????????????;????????D3DRS_STENCILPASS?D3DSTENCILOP_INCR,????????????????????????????????????0x1????????????????????????????????????????????????

?????????????????????????

????????????50%?????????????????????????????Alpha????????????????z-fighting,??????????????????????????????;??????????????????????????????????????z-fignting????????????????????????????????????????

??:?????????????????????Z???

D3DRS_DEPTHBIAS?D3DRS_SLOPESCAILDEPTHBIAS?????SDK????

??

???????????????????????????depth/stencil?????D3DFORMAT???

????????????????????????????????????????????????

????????????????????

????????????????:

???????????????????????

??Z-fighting????????

17

主题

73

帖子

77

积分

注册会员

Rank: 2

积分
77
发表于 2006-4-27 00:46:00 | 显示全部楼层

Re:???????

??????????

1

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2011-7-24 09:05:00 | 显示全部楼层

Re: ???????

??????????????? [em15]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-18 01:37

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表