Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/ModelRenderer.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
void ModelRenderer::CopyPositionAndNormals( | void ModelRenderer::CopyPositionAndNormals( | ||||
const CModelDefPtr& mdef, | const CModelDefPtr& mdef, | ||||
const VertexArrayIterator<CVector3D>& Position, | const VertexArrayIterator<CVector3D>& Position, | ||||
const VertexArrayIterator<CVector3D>& Normal) | const VertexArrayIterator<CVector3D>& Normal) | ||||
{ | { | ||||
size_t numVertices = mdef->GetNumVertices(); | size_t numVertices = mdef->GetNumVertices(); | ||||
SModelVertex* vertices = mdef->GetVertices(); | SModelVertex* vertices = mdef->GetVertices(); | ||||
for(size_t j = 0; j < numVertices; ++j) | for (size_t j = 0; j < numVertices; ++j) | ||||
{ | { | ||||
Position[j] = vertices[j].m_Coords; | Position[j] = vertices[j].m_Coords; | ||||
Normal[j] = vertices[j].m_Norm; | Normal[j] = vertices[j].m_Norm; | ||||
} | } | ||||
} | } | ||||
// Helper function to transform position and normal vectors into world-space. | // Helper function to transform position and normal vectors into world-space. | ||||
void ModelRenderer::BuildPositionAndNormals( | void ModelRenderer::BuildPositionAndNormals( | ||||
CModel* model, | CModel* model, | ||||
const VertexArrayIterator<CVector3D>& Position, | const VertexArrayIterator<CVector3D>& Position, | ||||
const VertexArrayIterator<CVector3D>& Normal) | const VertexArrayIterator<CVector3D>& Normal) | ||||
{ | { | ||||
CModelDefPtr mdef = model->GetModelDef(); | CModelDefPtr mdef = model->GetModelDef(); | ||||
size_t numVertices = mdef->GetNumVertices(); | size_t numVertices = mdef->GetNumVertices(); | ||||
SModelVertex* vertices=mdef->GetVertices(); | SModelVertex* vertices = mdef->GetVertices(); | ||||
if (model->IsSkinned()) | if (model->IsSkinned()) | ||||
{ | { | ||||
// boned model - calculate skinned vertex positions/normals | // boned model - calculate skinned vertex positions/normals | ||||
// Avoid the noisy warnings that occur inside SkinPoint/SkinNormal in | // Avoid the noisy warnings that occur inside SkinPoint/SkinNormal in | ||||
// some broken situations | // some broken situations | ||||
if (numVertices && vertices[0].m_Blend.m_Bone[0] == 0xff) | if (numVertices && vertices[0].m_Blend.m_Bone[0] == 0xff) | ||||
Show All 10 Lines | #if HAVE_SSE | ||||
else | else | ||||
#endif | #endif | ||||
{ | { | ||||
CModelDef::SkinPointsAndNormals(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); | CModelDef::SkinPointsAndNormals(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
PROFILE( "software transform" ); | PROFILE("software transform"); | ||||
// just copy regular positions, transform normals to world space | // just copy regular positions, transform normals to world space | ||||
const CMatrix3D& transform = model->GetTransform(); | const CMatrix3D& transform = model->GetTransform(); | ||||
const CMatrix3D& invtransform = model->GetInvTransform(); | const CMatrix3D& invtransform = model->GetInvTransform(); | ||||
for (size_t j=0; j<numVertices; ++j) | for (size_t j = 0; j < numVertices; ++j) | ||||
{ | { | ||||
transform.Transform(vertices[j].m_Coords,Position[j]); | transform.Transform(vertices[j].m_Coords, Position[j]); | ||||
invtransform.RotateTransposed(vertices[j].m_Norm,Normal[j]); | invtransform.RotateTransposed(vertices[j].m_Norm, Normal[j]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Helper function for lighting | // Helper function for lighting | ||||
void ModelRenderer::BuildColor4ub( | void ModelRenderer::BuildColor4ub( | ||||
CModel* model, | CModel* model, | ||||
const VertexArrayIterator<CVector3D>& Normal, | const VertexArrayIterator<CVector3D>& Normal, | ||||
const VertexArrayIterator<SColor4ub>& Color) | const VertexArrayIterator<SColor4ub>& Color) | ||||
{ | { | ||||
PROFILE( "lighting vertices" ); | PROFILE("lighting vertices"); | ||||
CModelDefPtr mdef = model->GetModelDef(); | CModelDefPtr mdef = model->GetModelDef(); | ||||
size_t numVertices = mdef->GetNumVertices(); | size_t numVertices = mdef->GetNumVertices(); | ||||
const CLightEnv& lightEnv = g_Renderer.GetLightEnv(); | const CLightEnv& lightEnv = g_Renderer.GetLightEnv(); | ||||
CColor shadingColor = model->GetShadingColor(); | CColor shadingColor = model->GetShadingColor(); | ||||
for (size_t j = 0; j < numVertices; ++j) | for (size_t j = 0; j < numVertices; ++j) | ||||
{ | { | ||||
Show All 17 Lines | |||||
void ModelRenderer::BuildUV( | void ModelRenderer::BuildUV( | ||||
const CModelDefPtr& mdef, | const CModelDefPtr& mdef, | ||||
const VertexArrayIterator<float[2]>& UV, | const VertexArrayIterator<float[2]>& UV, | ||||
int UVset) | int UVset) | ||||
{ | { | ||||
size_t numVertices = mdef->GetNumVertices(); | size_t numVertices = mdef->GetNumVertices(); | ||||
SModelVertex* vertices = mdef->GetVertices(); | SModelVertex* vertices = mdef->GetVertices(); | ||||
for (size_t j=0; j < numVertices; ++j) | for (size_t j = 0; j < numVertices; ++j) | ||||
{ | { | ||||
UV[j][0] = vertices[j].m_UVs[UVset * 2]; | UV[j][0] = vertices[j].m_UVs[UVset * 2]; | ||||
UV[j][1] = 1.0-vertices[j].m_UVs[UVset * 2 + 1]; | UV[j][1] = 1.0 - vertices[j].m_UVs[UVset * 2 + 1]; | ||||
} | } | ||||
} | } | ||||
// Build default indices array. | // Build default indices array. | ||||
void ModelRenderer::BuildIndices( | void ModelRenderer::BuildIndices( | ||||
const CModelDefPtr& mdef, | const CModelDefPtr& mdef, | ||||
const VertexArrayIterator<u16>& Indices) | const VertexArrayIterator<u16>& Indices) | ||||
{ | { | ||||
size_t idxidx = 0; | size_t idxidx = 0; | ||||
SModelFace* faces = mdef->GetFaces(); | SModelFace* faces = mdef->GetFaces(); | ||||
for (size_t j = 0; j < mdef->GetNumFaces(); ++j) { | for (size_t j = 0; j < mdef->GetNumFaces(); ++j) | ||||
{ | |||||
SModelFace& face=faces[j]; | SModelFace& face = faces[j]; | ||||
Indices[idxidx++]=face.m_Verts[0]; | Indices[idxidx++] = face.m_Verts[0]; | ||||
Indices[idxidx++]=face.m_Verts[1]; | Indices[idxidx++] = face.m_Verts[1]; | ||||
Indices[idxidx++]=face.m_Verts[2]; | Indices[idxidx++] = face.m_Verts[2]; | ||||
} | } | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// ShaderModelRenderer implementation | // ShaderModelRenderer implementation | ||||
▲ Show 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | for (MaterialBuckets_t::iterator it = materialBuckets.begin(); it != materialBuckets.end(); ++it) | ||||
continue; | continue; | ||||
if (tech->GetSortByDistance()) | if (tech->GetSortByDistance()) | ||||
{ | { | ||||
// Add the tech into a vector so we can index it | // Add the tech into a vector so we can index it | ||||
// (There might be duplicates in this list, but that doesn't really matter) | // (There might be duplicates in this list, but that doesn't really matter) | ||||
if (sortByDistTechs.empty() || sortByDistTechs.back() != tech) | if (sortByDistTechs.empty() || sortByDistTechs.back() != tech) | ||||
sortByDistTechs.push_back(tech); | sortByDistTechs.push_back(tech); | ||||
size_t techIdx = sortByDistTechs.size()-1; | size_t techIdx = sortByDistTechs.size() - 1; | ||||
// Add each model into sortByDistItems | // Add each model into sortByDistItems | ||||
for (size_t i = 0; i < it->second.size(); ++i) | for (size_t i = 0; i < it->second.size(); ++i) | ||||
{ | { | ||||
SMRSortByDistItem itemWithDist; | SMRSortByDistItem itemWithDist; | ||||
itemWithDist.techIdx = techIdx; | itemWithDist.techIdx = techIdx; | ||||
CModel* model = it->second[i]; | CModel* model = it->second[i]; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (!sortByDistItems.empty()) | ||||
for (size_t end = 0; end < sortByDistItems.size(); ++end) | for (size_t end = 0; end < sortByDistItems.size(); ++end) | ||||
{ | { | ||||
sortByDistModels.push_back(sortByDistItems[end].model); | sortByDistModels.push_back(sortByDistItems[end].model); | ||||
size_t techIdx = sortByDistItems[end].techIdx; | size_t techIdx = sortByDistItems[end].techIdx; | ||||
if (techIdx != currentTechIdx) | if (techIdx != currentTechIdx) | ||||
{ | { | ||||
// Start of a new run - push the old run into a new tech bucket | // Start of a new run - push the old run into a new tech bucket | ||||
SMRTechBucket techBucket = { sortByDistTechs[currentTechIdx], &sortByDistModels[start], end-start }; | SMRTechBucket techBucket = { sortByDistTechs[currentTechIdx], &sortByDistModels[start], end - start }; | ||||
techBuckets.push_back(techBucket); | techBuckets.push_back(techBucket); | ||||
start = end; | start = end; | ||||
currentTechIdx = techIdx; | currentTechIdx = techIdx; | ||||
} | } | ||||
} | } | ||||
// Add the tech bucket for the final run | // Add the tech bucket for the final run | ||||
SMRTechBucket techBucket = { sortByDistTechs[currentTechIdx], &sortByDistModels[start], sortByDistItems.size()-start }; | SMRTechBucket techBucket = { sortByDistTechs[currentTechIdx], &sortByDistModels[start], sortByDistItems.size() - start }; | ||||
techBuckets.push_back(techBucket); | techBuckets.push_back(techBucket); | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
PROFILE3("rendering bucketed submissions"); | PROFILE3("rendering bucketed submissions"); | ||||
size_t idxTechStart = 0; | size_t idxTechStart = 0; | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | while (idxTechStart < techBuckets.size()) | ||||
{ | { | ||||
CShaderRenderQueries::RenderQuery rq = renderQueries.GetItem(q); | CShaderRenderQueries::RenderQuery rq = renderQueries.GetItem(q); | ||||
if (rq.first == RQUERY_TIME) | if (rq.first == RQUERY_TIME) | ||||
{ | { | ||||
CShaderProgram::Binding binding = shader->GetUniformBinding(rq.second); | CShaderProgram::Binding binding = shader->GetUniformBinding(rq.second); | ||||
if (binding.Active()) | if (binding.Active()) | ||||
{ | { | ||||
double time = g_Renderer.GetTimeManager().GetGlobalTime(); | double time = g_Renderer.GetTimeManager().GetGlobalTime(); | ||||
shader->Uniform(binding, time, 0,0,0); | shader->Uniform(binding, time, 0.0f, 0.0f, 0.0f); | ||||
} | } | ||||
} | } | ||||
else if (rq.first == RQUERY_WATER_TEX) | else if (rq.first == RQUERY_WATER_TEX) | ||||
{ | { | ||||
WaterManager* WaterMgr = g_Renderer.GetWaterManager(); | WaterManager* WaterMgr = g_Renderer.GetWaterManager(); | ||||
double time = WaterMgr->m_WaterTexTimer; | double time = WaterMgr->m_WaterTexTimer; | ||||
double period = 1.6; | double period = 1.6; | ||||
int curTex = (int)(time*60/period) % 60; | int curTex = static_cast<int>(time * 60.0 / period) % 60; | ||||
if (WaterMgr->m_RenderWater && WaterMgr->WillRenderFancyWater()) | if (WaterMgr->m_RenderWater && WaterMgr->WillRenderFancyWater()) | ||||
shader->BindTexture(str_waterTex, WaterMgr->m_NormalMap[curTex]); | shader->BindTexture(str_waterTex, WaterMgr->m_NormalMap[curTex]); | ||||
else | else | ||||
shader->BindTexture(str_waterTex, g_Renderer.GetTextureManager().GetErrorTexture()); | shader->BindTexture(str_waterTex, g_Renderer.GetTextureManager().GetErrorTexture()); | ||||
} | } | ||||
else if (rq.first == RQUERY_SKY_CUBE) | else if (rq.first == RQUERY_SKY_CUBE) | ||||
{ | { | ||||
Show All 22 Lines |
Wildfire Games · Phabricator