Skybox边线消除的解决办法
生活随笔
收集整理的這篇文章主要介紹了
Skybox边线消除的解决办法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Skybox搞好后,發現在邊線有很明顯的裂縫,一開始時不知道如何解決,后來問了人,有人說把紋理采樣改成Point,有人說紋理坐標改成0.001到0.999,這兩樣我都試過,發現改成Point裂縫是消除了,但看起來很不好看,改成0.001到0.999也有裂縫。
??? 后來再問了一位高手,他就說了句,把Texture Addressing改了就行了。然后叫我直接查看DX SDK,我看了幾種texture的address模式,終于領悟了,要采用紋理尋址的Clamp Texture Address Mode,可查看SDK。再把紋理坐標改成是0.001到0.999。問題就完美解決了。
??? 渲染代碼如下:
p3DDevice9->SetSamplerState(0,?D3DSAMP_ADDRESSU,?D3DTADDRESS_CLAMP);
????p3DDevice9->SetSamplerState(0,?D3DSAMP_ADDRESSV,?D3DTADDRESS_CLAMP);??? 創建VB代碼如下:
CUSTOMVERTEX_TXT?cvVertices[]?=
????{
????????//上面的點
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.001f,},?//Vertex?2?-?Red
????????{vTBottomRight,?D3DCOLOR_XRGB(255,?255,?0),?0.999f,?0.001f,},?//Vertex?3?-?Green
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?0?-?Blue?
????????//前面
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue?
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?1?-?Red?
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?2?-?Red?
????????{vBTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?3?-?Green?
????????//右面
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue
????????{vTBottomRight,?D3DCOLOR_XRGB(0,?255,?0),?0.999f,?0.001f,},?//Vertex?3?-?Green
????????{vBTopRight,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.999f,},?//Vertex?2?-?Red?
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red?
????????//后面
????????{vTBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?0?-?Blue
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vBBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red?
????????//左面
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue?
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?0?-?Blue?
????????{vBBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red
????????//下面
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.001f,},?//Vertex?4?-?Red?
????????{vBTopRight,?D3DCOLOR_XRGB(0,?0,?255),?0.999f,?0.001f,},?//Vertex?5?-?Blue?
????????{vBBottomLeft,?D3DCOLOR_XRGB(0,?255,?0),?0.001f,?0.999f,},?//Vertex?6?-?Green?
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?0,?0),?0.999f,?0.999f,},?//Vertex?7?-?Red?
????};
????if(FAILED(p3DDevice9->CreateVertexBuffer(24?*?sizeof(CUSTOMVERTEX_TXT),
????????0,?D3DFVF_CUSTOMVERTEX,
????????D3DPOOL_DEFAULT,?&m_pVertexBuffer,?NULL)))
????{
????????return?FALSE;
????}
????VOID*?pVertices?=?NULL;
????if(FAILED(m_pVertexBuffer->Lock(0,?sizeof(cvVertices),?(void**)&pVertices,?0)))
????{
????????return?FALSE;
????}
????//Copy?our?stored?vertices?values?into?the?vertex?buffer
????memcpy(pVertices,?cvVertices,?sizeof(cvVertices));
????//Unlock?the?vertex?buffer
????m_pVertexBuffer->Unlock();
??? 后來再問了一位高手,他就說了句,把Texture Addressing改了就行了。然后叫我直接查看DX SDK,我看了幾種texture的address模式,終于領悟了,要采用紋理尋址的Clamp Texture Address Mode,可查看SDK。再把紋理坐標改成是0.001到0.999。問題就完美解決了。
??? 渲染代碼如下:
p3DDevice9->SetSamplerState(0,?D3DSAMP_ADDRESSU,?D3DTADDRESS_CLAMP);
????p3DDevice9->SetSamplerState(0,?D3DSAMP_ADDRESSV,?D3DTADDRESS_CLAMP);??? 創建VB代碼如下:
CUSTOMVERTEX_TXT?cvVertices[]?=
????{
????????//上面的點
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.001f,},?//Vertex?2?-?Red
????????{vTBottomRight,?D3DCOLOR_XRGB(255,?255,?0),?0.999f,?0.001f,},?//Vertex?3?-?Green
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?0?-?Blue?
????????//前面
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue?
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?1?-?Red?
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?2?-?Red?
????????{vBTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?3?-?Green?
????????//右面
????????{vTTopRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue
????????{vTBottomRight,?D3DCOLOR_XRGB(0,?255,?0),?0.999f,?0.001f,},?//Vertex?3?-?Green
????????{vBTopRight,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.999f,},?//Vertex?2?-?Red?
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red?
????????//后面
????????{vTBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?0?-?Blue
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vBBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red?
????????//左面
????????{vTBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.001f,},?//Vertex?0?-?Blue?
????????{vTTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.001f,},?//Vertex?0?-?Blue?
????????{vBBottomLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.001f,?0.999f,},?//Vertex?1?-?Red?
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?255,?255),?0.999f,?0.999f,},?//Vertex?1?-?Red
????????//下面
????????{vBTopLeft,?D3DCOLOR_XRGB(255,?0,?0),?0.001f,?0.001f,},?//Vertex?4?-?Red?
????????{vBTopRight,?D3DCOLOR_XRGB(0,?0,?255),?0.999f,?0.001f,},?//Vertex?5?-?Blue?
????????{vBBottomLeft,?D3DCOLOR_XRGB(0,?255,?0),?0.001f,?0.999f,},?//Vertex?6?-?Green?
????????{vBBottomRight,?D3DCOLOR_XRGB(255,?0,?0),?0.999f,?0.999f,},?//Vertex?7?-?Red?
????};
????if(FAILED(p3DDevice9->CreateVertexBuffer(24?*?sizeof(CUSTOMVERTEX_TXT),
????????0,?D3DFVF_CUSTOMVERTEX,
????????D3DPOOL_DEFAULT,?&m_pVertexBuffer,?NULL)))
????{
????????return?FALSE;
????}
????VOID*?pVertices?=?NULL;
????if(FAILED(m_pVertexBuffer->Lock(0,?sizeof(cvVertices),?(void**)&pVertices,?0)))
????{
????????return?FALSE;
????}
????//Copy?our?stored?vertices?values?into?the?vertex?buffer
????memcpy(pVertices,?cvVertices,?sizeof(cvVertices));
????//Unlock?the?vertex?buffer
????m_pVertexBuffer->Unlock();
轉載于:https://www.cnblogs.com/lancidie/archive/2011/03/17/1987261.html
總結
以上是生活随笔為你收集整理的Skybox边线消除的解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二层及三层MTU浅析
- 下一篇: 团队项目开发编码规范之一:概述