add spherical environment mapping
This commit is contained in:
@@ -284,6 +284,8 @@ bool Model::LoadMilkshapeAscii( CString sPath )
|
||||
}
|
||||
strcpy( Material.szName, szName );
|
||||
|
||||
Material.bSphereMapped = ((CString)Material.szName).Find("sphere") != -1;
|
||||
|
||||
// ambient
|
||||
if( f.GetLine( szLine ) <= 0 )
|
||||
{
|
||||
@@ -663,6 +665,7 @@ void Model::DrawPrimitives()
|
||||
mat.Specular,
|
||||
mat.fShininess );
|
||||
DISPLAY->SetTexture( mat.aniTexture.GetCurrentTexture() );
|
||||
DISPLAY->SetSphereEnironmentMapping( mat.bSphereMapped );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -678,9 +681,11 @@ void Model::DrawPrimitives()
|
||||
specular,
|
||||
shininess );
|
||||
DISPLAY->SetTexture( NULL );
|
||||
DISPLAY->SetSphereEnironmentMapping( false );
|
||||
}
|
||||
|
||||
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
|
||||
DISPLAY->SetSphereEnironmentMapping( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ typedef struct msMaterial
|
||||
char szAlphaTexture[MS_MAX_PATH]; // not used in SM. Use alpha in diffuse texture instead
|
||||
int nName; // not used in SM. What is this for anyway?
|
||||
AnimatedTexture aniTexture;
|
||||
bool bSphereMapped; // true of "sphere" appears in the material name
|
||||
} msMaterial;
|
||||
|
||||
/* msPositionKey */
|
||||
|
||||
@@ -194,6 +194,8 @@ public:
|
||||
RageColor specular,
|
||||
RageVector3 dir ) = 0;
|
||||
|
||||
virtual void SetSphereEnironmentMapping( bool b ) = 0;
|
||||
|
||||
void DrawQuad( const RageSpriteVertex v[] ) { DrawQuads(v,4); } /* alias. upper-left, upper-right, lower-left, lower-right */
|
||||
virtual void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||
virtual void DrawFan( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||
|
||||
@@ -988,6 +988,11 @@ void RageDisplay_D3D::SetMaterial(
|
||||
g_pd3dDevice->SetMaterial( &mat );
|
||||
}
|
||||
|
||||
// need this?
|
||||
// device->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL);
|
||||
// device->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE,D3DMCS_MATERIAL);
|
||||
|
||||
|
||||
void RageDisplay_D3D::SetLighting( bool b )
|
||||
{
|
||||
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, b );
|
||||
@@ -1170,3 +1175,25 @@ RageMatrix RageDisplay_D3D::GetOrthoMatrix( float l, float r, float b, float t,
|
||||
return m;
|
||||
}
|
||||
|
||||
void RageDisplay_D3D::SetSphereEnironmentMapping( bool b )
|
||||
{
|
||||
// http://www.gamasutra.com/features/20000811/wyatt_03.htm
|
||||
|
||||
if( b )
|
||||
{
|
||||
RageMatrix tex = RageMatrix
|
||||
(
|
||||
0.40f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, -0.40f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.50, -0.50, 0.0f, 1.0f
|
||||
);
|
||||
g_pd3dDevice->SetTransform(D3DTS_TEXTURE0, (D3DMATRIX*)&tex);
|
||||
}
|
||||
|
||||
// Tell D3D to use transformed reflection vectors as texture co-ordinate 0
|
||||
// and then transform this coordinate by the specified texture matrix, also
|
||||
// tell D3D that only the first two coordinates of the output are valid.
|
||||
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, b ? D3DTTFF_COUNT2 : D3DTTFF_DISABLE );
|
||||
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, b ? D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR : D3DTSS_TCI_PASSTHRU );
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
RageColor specular,
|
||||
RageVector3 dir );
|
||||
|
||||
void SetSphereEnironmentMapping( bool b );
|
||||
|
||||
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
||||
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
||||
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
||||
|
||||
@@ -1440,3 +1440,19 @@ bool RageDisplay_OGL::SupportsTextureFormat( PixelFormat pixfmt, bool realtime )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void RageDisplay_OGL::SetSphereEnironmentMapping( bool b )
|
||||
{
|
||||
if( b )
|
||||
{
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
RageColor specular,
|
||||
RageVector3 dir );
|
||||
|
||||
void SetSphereEnironmentMapping( bool b );
|
||||
|
||||
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
||||
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
||||
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
||||
|
||||
Reference in New Issue
Block a user