diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 584dd2174f..79eb785bb2 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -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 ); } } diff --git a/stepmania/src/ModelTypes.h b/stepmania/src/ModelTypes.h index 7d4ec48365..c93bd8a642 100644 --- a/stepmania/src/ModelTypes.h +++ b/stepmania/src/ModelTypes.h @@ -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 */ diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 66d298d70e..b6505f6d8f 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -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; diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 3ddc5f0f88..42693298df 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -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 ); +} diff --git a/stepmania/src/RageDisplay_D3D.h b/stepmania/src/RageDisplay_D3D.h index e248bad236..3833a9e6cb 100644 --- a/stepmania/src/RageDisplay_D3D.h +++ b/stepmania/src/RageDisplay_D3D.h @@ -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 ); diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index b2734a3006..e23d6b4f63 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -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); + } +} diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index f3979b4fe9..c41ebb3171 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -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 );