Skip to content

Commit

Permalink
UPBGE: Call ProcessLighting only when detecting custom shader.
Browse files Browse the repository at this point in the history
Previously ProcessLighting was called in RAS_MeshSlot all the time if
no override shader were used, but only the custom shader are actually
needing this function to update potentially used OpenGL lighting builtins.
In most of the case the update was useless, to avoid spend time on this,
ProcessLighting is called inside KX_BlenderMaterial::ActivateMeshSlot
so that we can detect if we actually use a custom shader.
In the same time it removes the management of node data m_useLighting.
  • Loading branch information
panzergame committed Sep 22, 2017
1 parent 44f58dc commit 6314b1f
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 13 deletions.
4 changes: 3 additions & 1 deletion source/gameengine/Ketsji/KX_BlenderMaterial.cpp
Expand Up @@ -343,11 +343,13 @@ bool KX_BlenderMaterial::UsesLighting() const
return true;
}

void KX_BlenderMaterial::ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty)
void KX_BlenderMaterial::ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty, const MT_Transform& camtrans)
{
if (m_shader && m_shader->Ok()) {
m_shader->Update(rasty, ms);
m_shader->ApplyShader();
// Update OpenGL lighting builtins.
rasty->ProcessLighting(UsesLighting(), camtrans);
}
else if (m_blenderShader) {
m_blenderShader->Update(ms, rasty);
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_BlenderMaterial.h
Expand Up @@ -42,7 +42,7 @@ class KX_BlenderMaterial : public CValue, public RAS_IPolyMaterial
virtual void Desactivate(RAS_Rasterizer *rasty);
virtual void ActivateInstancing(RAS_Rasterizer *rasty, void *matrixoffset, void *positionoffset, void *coloroffset, unsigned int stride);
virtual void DesactivateInstancing();
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty);
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty, const MT_Transform& camtrans);

void ActivateShaders(RAS_Rasterizer *rasty);

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_TextMaterial.cpp
Expand Up @@ -56,7 +56,7 @@ void KX_TextMaterial::DesactivateInstancing()
{
}

void KX_TextMaterial::ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty)
void KX_TextMaterial::ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty, const MT_Transform& camtrans)
{
}

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_TextMaterial.h
Expand Up @@ -40,7 +40,7 @@ class KX_TextMaterial : public RAS_IPolyMaterial
virtual void Desactivate(RAS_Rasterizer *rasty);
virtual void ActivateInstancing(RAS_Rasterizer *rasty, void *matrixoffset, void *positionoffset, void *coloroffset, unsigned int stride);
virtual void DesactivateInstancing();
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty);
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty, const MT_Transform& camtrans);

virtual const std::string GetTextureName() const;
virtual Material *GetBlenderMaterial() const;
Expand Down
1 change: 0 additions & 1 deletion source/gameengine/Rasterizer/Node/RAS_RenderNode.h
Expand Up @@ -61,7 +61,6 @@ struct RAS_MaterialNodeData
{
RAS_IPolyMaterial *m_material;
int m_drawingMode;
bool m_useLighting;
bool m_cullFace;
bool m_zsort;
bool m_text;
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
Expand Up @@ -99,7 +99,7 @@ class RAS_IPolyMaterial
virtual void Desactivate(RAS_Rasterizer *rasty) = 0;
virtual void ActivateInstancing(RAS_Rasterizer *rasty, void *matrixoffset, void *positionoffset, void *coloroffset, unsigned int stride) = 0;
virtual void DesactivateInstancing() = 0;
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty) = 0;
virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_Rasterizer *rasty, const MT_Transform& camtrans) = 0;

bool IsAlpha() const;
bool IsAlphaDepth() const;
Expand Down
5 changes: 0 additions & 5 deletions source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
Expand Up @@ -93,8 +93,6 @@ void RAS_MaterialBucket::UpdateShader()
for (RAS_DisplayArrayBucket *arrayBucket : m_displayArrayBucketList) {
arrayBucket->DestructStorageInfo();
}

m_nodeData.m_useLighting = m_material->UsesLighting();
}

void RAS_MaterialBucket::RemoveActiveMeshSlots()
Expand Down Expand Up @@ -133,9 +131,6 @@ void RAS_MaterialBucket::GenerateTree(RAS_ManagerDownwardNode& downwardRoot, RAS
if (sort) {
m_upwardNode.SetParent(&upwardRoot);
}

// Use lighting flag changes when user specified a valid custom shader.
m_nodeData.m_useLighting = m_material->UsesLighting();
}

void RAS_MaterialBucket::BindNode(const RAS_MaterialNodeTuple& tuple)
Expand Down
3 changes: 1 addition & 2 deletions source/gameengine/Rasterizer/RAS_MeshSlot.cpp
Expand Up @@ -82,8 +82,7 @@ void RAS_MeshSlot::RunNode(const RAS_MeshSlotNodeTuple& tuple)


if (!managerData->m_shaderOverride) {
rasty->ProcessLighting(materialData->m_useLighting, managerData->m_trans);
materialData->m_material->ActivateMeshSlot(this, rasty);
materialData->m_material->ActivateMeshSlot(this, rasty, managerData->m_trans);

RAS_IStorageInfo *storage = displayArrayData->m_storageInfo;
if (materialData->m_zsort && storage) {
Expand Down

0 comments on commit 6314b1f

Please sign in to comment.