From 5339f4f920599a37db388a59cef6ab34da158575 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 24 Dec 2003 21:07:50 +0000 Subject: [PATCH] add glow support to Model --- stepmania/src/Model.cpp | 143 ++++++++++++++++++++++++++----------- stepmania/src/ModelTypes.h | 8 +-- 2 files changed, 107 insertions(+), 44 deletions(-) diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index fb25424717..584dd2174f 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -593,54 +593,20 @@ void Model::DrawPrimitives() return; // bail early /* Don't if we're fully transparent */ - if( m_pTempState->diffuse[0].a <= 0.001f ) + if( m_pTempState->diffuse[0].a < 0.001f && m_pTempState->glow.a < 0.001f ) return; Actor::SetRenderStates(); // set Actor-specified render states DISPLAY->Scale( 1, -1, 1 ); // flip Y so positive is up - - ////////////////////// - // render the diffuse pass - ////////////////////// - - DISPLAY->SetTextureModeModulate(); - + // + // process vertices + // for (int i = 0; i < (int)m_Meshes.size(); i++) { msMesh *pMesh = &m_Meshes[i]; RageModelVertexVector& TempVertices = m_vTempVerticesByBone[i]; - - // apply material - if( pMesh->nMaterialIndex != -1 ) - { - msMaterial& mat = m_Materials[ pMesh->nMaterialIndex ]; - DISPLAY->SetMaterial( - mat.Emissive, - mat.Ambient, - mat.Diffuse, - mat.Specular, - mat.fShininess ); - DISPLAY->SetTexture( mat.aniTexture.GetCurrentTexture() ); - } - else - { - float emissive[4] = {0,0,0,0}; - float ambient[4] = {0.2f,0.2f,0.2f,1}; - float diffuse[4] = {0.7f,0.7f,0.7f,1}; - float specular[4] = {0.2f,0.2f,0.2f,1}; - float shininess = 1; - DISPLAY->SetMaterial( - emissive, - ambient, - diffuse, - specular, - shininess ); - DISPLAY->SetTexture( NULL ); - } - - // process vertices for (int j = 0; j < (int)pMesh->Vertices.size(); j++) { RageModelVertex& tempVert = TempVertices[j]; @@ -663,8 +629,59 @@ void Model::DrawPrimitives() RageVec3TransformCoord( &tempVert.p, &originalVert.Vertex, &m_pBones[bone].mFinal ); } } + } - DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 ); + ////////////////////// + // render the diffuse pass + ////////////////////// + if( m_pTempState->diffuse[0].a > 0 ) + { + DISPLAY->SetTextureModeModulate(); + + for (int i = 0; i < (int)m_Meshes.size(); i++) + { + msMesh *pMesh = &m_Meshes[i]; + RageModelVertexVector& TempVertices = m_vTempVerticesByBone[i]; + + // apply material + if( pMesh->nMaterialIndex != -1 ) + { + msMaterial& mat = m_Materials[ pMesh->nMaterialIndex ]; + + RageColor Emissive = mat.Emissive; + RageColor Ambient = mat.Ambient; + RageColor Diffuse = mat.Diffuse; + + Emissive.a = m_pTempState->diffuse[0].a; + Ambient.a = m_pTempState->diffuse[0].a; + Diffuse.a = m_pTempState->diffuse[0].a; + + DISPLAY->SetMaterial( + Emissive, + Ambient, + Diffuse, + mat.Specular, + mat.fShininess ); + DISPLAY->SetTexture( mat.aniTexture.GetCurrentTexture() ); + } + else + { + RageColor emissive( 0,0,0,0 ); + RageColor ambient( 0.2f,0.2f,0.2f,1 ); + RageColor diffuse( 0.7f,0.7f,0.7f,1 ); + RageColor specular( 0.2f,0.2f,0.2f,1 ); + float shininess = 1; + DISPLAY->SetMaterial( + emissive, + ambient, + diffuse, + specular, + shininess ); + DISPLAY->SetTexture( NULL ); + } + + DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 ); + } } ////////////////////// @@ -672,7 +689,53 @@ void Model::DrawPrimitives() ////////////////////// if( m_pTempState->glow.a > 0.0001f ) { - // TODO: Support glow. + DISPLAY->SetTextureModeGlow(); + + for (int i = 0; i < (int)m_Meshes.size(); i++) + { + msMesh *pMesh = &m_Meshes[i]; + RageModelVertexVector& TempVertices = m_vTempVerticesByBone[i]; + + // apply material + if( pMesh->nMaterialIndex != -1 ) + { + msMaterial& mat = m_Materials[ pMesh->nMaterialIndex ]; + + RageColor Emissive = mat.Emissive; + RageColor Ambient = mat.Ambient; + RageColor Diffuse = mat.Diffuse; + + Emissive = m_pTempState->glow; + Ambient = m_pTempState->glow; + Diffuse = m_pTempState->glow; + + DISPLAY->SetMaterial( + Emissive, + Ambient, + Diffuse, + mat.Specular, + mat.fShininess ); + DISPLAY->SetTexture( mat.aniTexture.GetCurrentTexture() ); + } + else + { + RageColor emissive = m_pTempState->glow; + RageColor ambient = m_pTempState->glow; + RageColor diffuse = m_pTempState->glow; + RageColor specular = m_pTempState->glow; + float shininess = 1; + DISPLAY->SetMaterial( + emissive, + ambient, + diffuse, + specular, + shininess ); + DISPLAY->SetTexture( NULL ); + } + + DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 ); + } + } } diff --git a/stepmania/src/ModelTypes.h b/stepmania/src/ModelTypes.h index fd3320634e..7d4ec48365 100644 --- a/stepmania/src/ModelTypes.h +++ b/stepmania/src/ModelTypes.h @@ -109,10 +109,10 @@ typedef struct msMaterial { int nFlags; char szName[MS_MAX_NAME]; - RageVector4 Ambient; - RageVector4 Diffuse; - RageVector4 Specular; - RageVector4 Emissive; + RageColor Ambient; + RageColor Diffuse; + RageColor Specular; + RageColor Emissive; float fShininess; float fTransparency; char szDiffuseTexture[MS_MAX_PATH];