// 셰이더를 통해 화면을 그린다. void cMesh::RenderShader(cRenderer &renderer, cShader &shader, const Matrix44 &parentTm) { RET(!IsRender()); RET(!m_buffers); const cLight &mainLight = cLightManager::Get()->GetMainLight(); mainLight.Bind(shader); shader.SetMatrix( "mVP", cMainCamera::Get()->GetViewProjectionMatrix()); shader.SetVector( "vEyePos", cMainCamera::Get()->GetEyePos()); if (m_buffers->GetAttributes().empty()) { const Matrix44 tm = m_localTM * m_aniTM * m_TM * parentTm; shader.SetMatrix("mWorld", tm); Matrix44 wit = tm.Inverse(); wit.Transpose(); shader.SetMatrix("mWIT", wit); const bool isNormalMapping = (!m_normalMap.empty()) && (m_normalMap[ 0] && m_normalMap[ 0]->GetTexture()); const bool isSpecularMapping = (!m_specularMap.empty()) && (m_specularMap[ 0] && m_specularMap[ 0]->GetTexture()); const bool isSelfIllumMapping = (!m_selfIllumMap.empty()) && (m_selfIllumMap[ 0] && m_selfIllumMap[ 0]->GetTexture()); if (!m_mtrls.empty()) m_mtrls[ 0].Bind(shader); if (!m_colorMap.empty()) m_colorMap[ 0]->Bind(shader, "colorMapTexture"); if (isNormalMapping) m_normalMap[ 0]->Bind(shader, "normalMapTexture"); if (isSpecularMapping) m_specularMap[ 0]->Bind(shader, "specularMapTexture"); if (isSelfIllumMapping) m_selfIllumMap[ 0]->Bind(shader, "selfIllumMapTexture"); shader.SetRenderPass(isNormalMapping? 4 : 0); m_buffers->Bind(renderer); shader.Begin(); shader.BeginPass(); renderer.GetDevice()->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_buffers->GetVertexBuffer().GetVertexCount(), 0, m_buffers->GetIndexBuffer().GetFaceCount()); shader.End(); shader.EndPass(); } else { const Matrix44 tm = m_localTM * m_aniTM * m_TM * parentTm; shader.SetMatrix("mWorld", tm); Matrix44 wit = tm.Inverse(); wit.Transpose(); shader.SetMatrix("mWIT", wit); shader.Begin(); m_buffers->Bind(renderer); for (u_int i=0; i < m_buffers->GetAttributes().size(); ++i) { const int mtrlId = m_buffers->GetAttributes()[ i].attribId; if ((int)m_mtrls.size() <= mtrlId) continue; const bool isNormalMapping = m_normalMap[ mtrlId] && m_normalMap[ mtrlId]->GetTexture(); const bool isSpecularMapping = m_specularMap[ mtrlId] && m_specularMap[ mtrlId]->GetTexture(); const bool isSelfIllumMapping = m_selfIllumMap[ mtrlId] && m_selfIllumMap[ mtrlId]->GetTexture(); m_mtrls[ mtrlId].Bind(shader); if (m_colorMap[ mtrlId]) m_colorMap[ mtrlId]->Bind(shader, "colorMapTexture"); if (isNormalMapping) m_normalMap[ mtrlId]->Bind(shader, "normalMapTexture"); if (isSpecularMapping) m_specularMap[ mtrlId]->Bind(shader, "specularMapTexture"); if (isSelfIllumMapping) m_selfIllumMap[ mtrlId]->Bind(shader, "selfIllumMapTexture"); shader.SetRenderPass(isNormalMapping? 4 : 0); shader.BeginPass(); renderer.GetDevice()->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_buffers->GetVertexBuffer().GetVertexCount(), m_buffers->GetAttributes()[ i].faceStart*3, m_buffers->GetAttributes()[ i].faceCount); shader.EndPass(); } shader.End(); } }