Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/ModelRenderer.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
} | } | ||||
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) | ||||
{ | { | ||||
RGBColor tempcolor = lightEnv.EvaluateUnitScaled(Normal[j]); | RGBColor tempcolor = lightEnv.EvaluateUnitScaled(Normal[j]); | ||||
tempcolor.X *= shadingColor.r; | tempcolor.X *= shadingColor.r; | ||||
tempcolor.Y *= shadingColor.g; | tempcolor.Y *= shadingColor.g; | ||||
tempcolor.Z *= shadingColor.b; | tempcolor.Z *= shadingColor.b; | ||||
Color[j] = ConvertRGBColorTo4ub(tempcolor); | Color[j] = ConvertRGBColorTo4ub(tempcolor); | ||||
} | } | ||||
} | } | ||||
void ModelRenderer::GenTangents(const CModelDefPtr& mdef, std::vector<float>& newVertices, bool gpuSkinning) | void ModelRenderer::GenTangents(const CModelDefPtr& mdef, std::vector<float>& newVertices, bool gpuSkinning) | ||||
{ | { | ||||
MikkTSpace ms(mdef, newVertices, gpuSkinning); | MikkTSpace ms(mdef, newVertices, gpuSkinning); | ||||
ms.Generate(); | |||||
ms.generate(); | |||||
} | } | ||||
// Copy UV coordinates | // Copy UV coordinates | ||||
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) | ||||
▲ Show 20 Lines • Show All 556 Lines • ▼ Show 20 Lines | while (idxTechStart < techBuckets.size()) | ||||
if (newStaticUniforms != currentStaticUniforms) | if (newStaticUniforms != currentStaticUniforms) | ||||
{ | { | ||||
currentStaticUniforms = newStaticUniforms; | currentStaticUniforms = newStaticUniforms; | ||||
currentStaticUniforms.BindUniforms(shader); | currentStaticUniforms.BindUniforms(shader); | ||||
} | } | ||||
const CShaderRenderQueries& renderQueries = model->GetMaterial().GetRenderQueries(); | const CShaderRenderQueries& renderQueries = model->GetMaterial().GetRenderQueries(); | ||||
for (size_t q = 0; q < renderQueries.GetSize(); q++) | for (size_t q = 0; q < renderQueries.GetSize(); ++q) | ||||
{ | { | ||||
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(); | ||||
Show All 39 Lines |
Wildfire Games · Phabricator