bjone Insert booze to continue | http://forum.hardware.fr/hardwaref [...] 55-170.htm
Problème de corruption géométrique rencontré avec des cubemaps dans cas particuliers.
liens du biniou:
http://site.voila.fr/bjone/DansElmuro.zip le fichier de technique employé:
Code :
- texture CubeTexture;
- matrix matNormals;
- technique CubeMappedFrustum
- {
- pass P0
- {
-
- VertexShader =
- decl
- {
- stream 0;
- float v0[4]; // position X,Y,Z,RHW
- float v1[3]; // normal
- }
- asm
- {
- vs.1.0;
- mov oPos, v0;
- m3x3 oT0, v1, c0;
- };
-
- VertexShaderConstant4[0] = <matNormals>;
-
- Lighting = False;
- ZEnable = False;
- CullMode = None;
- Texture[0] = <CubeTexture>;
- MinFilter[0] = None;
- MagFilter[0] = Linear;
- AddressU[0] = Clamp;
- AddressV[0] = Clamp;
- AddressW[0] = Clamp;
-
- ColorOp[0] = SelectArg1;
- ColorArg1[0] = Texture;
- AlphaOp[0] = Disable;
- ColorOp[1] = Disable;
- TexCoordIndex[0] = PassThru;
- TextureTransformFlags[0] = Count3;
- }
- }
|
la classe c++ coté appli:
Code :
- class CubeMappedFrustum
- {
- public:
- VertexBuffer VB;
- IndexBuffer IB;
- ID3DXEffect *Effect;
- int xsteps;
- int ysteps;
- D3DXMATRIX matProject;
- float distance,xangle,yangle;
- CubeMappedFrustum();
- ~CubeMappedFrustum();
- void Generate( float xangle, float yangle, float distance, D3DXMATRIX &matProject, unsigned int xsteps=20, unsigned int ysteps=20 );
- void Render( D3DXMATRIX &matNormals, IDirect3DCubeTexture8 *CubeTexture );
- };
|
implémentation:
Code :
- class CMF_vertex
- {
- public:
- float x,y,z,w, nx,ny,nz;
- };
- void CubeMappedFrustum::Generate( float xangle, float yangle, float distance, D3DXMATRIX &matProject, unsigned int xsteps, unsigned int ysteps )
- {
- if( this->matProject == matProject && this->xangle == xangle && this->yangle == yangle &&
- this->xsteps == xsteps && this->ysteps == ysteps && this->distance==distance )
- return;
- this->matProject=matProject;
- this->distance=distance;
- this->xangle=xangle;
- this->yangle=yangle;
- if( this->xsteps != xsteps || this->ysteps != ysteps )
- {
- VB.Release();
- IB.Release();
- this->xsteps=xsteps;
- this->ysteps=ysteps;
- VB.Create( xsteps*ysteps, sizeof(CMF_vertex), D3DFVF_XYZRHW|D3DFVF_NORMAL ); // HACK pas de FVF, vertexshader derrière
- IB.Create( (xsteps-1)*(ysteps-1)*6 ); // nombre de segments * 6 indices (3 par triangles,2 triangles par segments)
- }
- CMF_vertex *V=(CMF_vertex*) VB.Lock();
- float yinc=yangle/(ysteps-1);
- float xinc=xangle/(xsteps-1);
- float y=-yangle/2;
- for( unsigned int i=0 ; i < ysteps ; i++ )
- {
- float x=-xangle/2;
- float ny=sin(y); // Y
- for( unsigned int j=0 ; j < xsteps ; j++ )
- {
- float nx=sin(x); // X
- float nz=-sqrt(1-nx*nx - ny*ny); // Z RightHand (Z négatif dans le champ de vision)
- // normale
- V->nx=nx;
- V->ny=ny;
- V->nz=nz;
- // position
- float Vtx[3];
- Vtx[0]=nx*distance;
- Vtx[1]=ny*distance;
- Vtx[2]=nz*distance;
- // projection de la position
- D3DXVec3Transform( (D3DXVECTOR4*)V,(D3DXVECTOR3*)Vtx, &matProject );
- x+=xinc;
- V++;
- }
- y+=yinc;
- }
- VB.Unlock();
- ////////////////
- WORD *I=(WORD*)IB.Lock();
- for(unsigned int j=0 ; j < ysteps-1 ; j++ )
- {
- int base=j*xsteps; // positionnement début de ligne (1ère colonne)
- for( unsigned int i=0 ; i < xsteps-1 ; i++ )
- {
- *I++=base;
- *I++=base+1,
- *I++=base+xsteps;
- *I++=base+xsteps;
- *I++=base+1;
- *I++=base+1+xsteps;
- base++; // colonne suivante
- }
- }
- IB.Unlock();
- }
- void CubeMappedFrustum::Render( D3DXMATRIX &matNormals, IDirect3DCubeTexture8 *CubeTexture )
- {
- VB.SetStreamSource();
- IB.SetIndices();
- Effect->SetTexture("CubeTexture",CubeTexture);
- Effect->SetMatrix("matNormals",&matNormals);
- unsigned int Passes;
- if( Effect->Begin(&Passes,0) == D3D_OK )
- {
- for( unsigned int i=0 ; i < Passes ; i++ )
- {
- if( Effect->Pass(i) == S_OK )
- d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,VB.GetSize(),0, IB.GetSize()/3);
- }
- Effect->End();
- }
- }
|
Message édité par bjone le 08-02-2004 à 23:45:13
|