From 97c934ad1cb0a0bdf1a0abba2bac263e98d644e0 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 2 Apr 2011 12:04:19 +0000 Subject: [PATCH] Apply unit shading colour in shader renderpath. Don't adjust the shading colour of units in FoW (the shading comes from the LOS texture instead). This was SVN commit r9142. --- binaries/data/mods/public/shaders/model_common.fp | 5 +++-- binaries/data/mods/public/shaders/model_common.xml | 3 ++- .../mods/public/shaders/model_common_instancing.xml | 3 ++- binaries/data/mods/public/shaders/terrain_common.fp | 10 +++++++++- binaries/data/mods/public/shaders/terrain_decal.xml | 1 + source/renderer/DecalRData.cpp | 9 +++++---- source/renderer/DecalRData.h | 3 ++- source/renderer/TerrainRenderer.cpp | 4 ++-- source/simulation2/components/CCmpVisualActor.cpp | 6 +----- 9 files changed, 27 insertions(+), 17 deletions(-) diff --git a/binaries/data/mods/public/shaders/model_common.fp b/binaries/data/mods/public/shaders/model_common.fp index ea6142f7d1..c5151357a0 100644 --- a/binaries/data/mods/public/shaders/model_common.fp +++ b/binaries/data/mods/public/shaders/model_common.fp @@ -17,7 +17,8 @@ PARAM objectColor = program.local[0]; #endif -PARAM ambient = program.local[1]; +PARAM shadingColor = program.local[1]; +PARAM ambient = program.local[2]; TEMP tex; TEMP temp; @@ -59,6 +60,6 @@ TEX tex, fragment.texcoord[0], texture[0], 2D; TEX tex.a, fragment.texcoord[2], texture[2], 2D; MUL color.rgb, color, tex.a; -MOV result.color.rgb, color; +MUL result.color.rgb, color, shadingColor; END diff --git a/binaries/data/mods/public/shaders/model_common.xml b/binaries/data/mods/public/shaders/model_common.xml index 69bee47d8e..cd05ed83eb 100644 --- a/binaries/data/mods/public/shaders/model_common.xml +++ b/binaries/data/mods/public/shaders/model_common.xml @@ -17,7 +17,8 @@ - + + diff --git a/binaries/data/mods/public/shaders/model_common_instancing.xml b/binaries/data/mods/public/shaders/model_common_instancing.xml index 4702f02a45..ddb5d0b5f7 100644 --- a/binaries/data/mods/public/shaders/model_common_instancing.xml +++ b/binaries/data/mods/public/shaders/model_common_instancing.xml @@ -20,7 +20,8 @@ - + + diff --git a/binaries/data/mods/public/shaders/terrain_common.fp b/binaries/data/mods/public/shaders/terrain_common.fp index 0b1232493e..66e2083cc9 100644 --- a/binaries/data/mods/public/shaders/terrain_common.fp +++ b/binaries/data/mods/public/shaders/terrain_common.fp @@ -15,6 +15,10 @@ PARAM ambient = program.local[0]; +#ifdef DECAL + PARAM shadingColor = program.local[1]; +#endif + TEMP tex; TEMP temp; TEMP diffuse; @@ -57,6 +61,10 @@ TEX color, fragment.texcoord[0], texture[0], 2D; TEX tex.a, fragment.texcoord[3], texture[3], 2D; MUL color.rgb, color, tex.a; -MOV result.color.rgb, color; +#ifdef DECAL + MUL result.color.rgb, color, shadingColor; +#else + MOV result.color.rgb, color; +#endif END diff --git a/binaries/data/mods/public/shaders/terrain_decal.xml b/binaries/data/mods/public/shaders/terrain_decal.xml index ed234d5d18..11410e8162 100644 --- a/binaries/data/mods/public/shaders/terrain_decal.xml +++ b/binaries/data/mods/public/shaders/terrain_decal.xml @@ -15,6 +15,7 @@ + diff --git a/source/renderer/DecalRData.cpp b/source/renderer/DecalRData.cpp index 16a34b45eb..bd960a15fd 100644 --- a/source/renderer/DecalRData.cpp +++ b/source/renderer/DecalRData.cpp @@ -66,7 +66,7 @@ void CDecalRData::Update() } } -void CDecalRData::Render() +void CDecalRData::Render(const CShaderProgramPtr& shader) { m_Decal->m_Decal.m_Texture->Bind(0); @@ -86,9 +86,10 @@ void CDecalRData::Render() u8* indexBase = m_IndexArray.Bind(); - // TODO: make the shading color available to shader-based rendering - // (which uses the color array) too - glColor3fv(m_Decal->GetShadingColor().FloatArray()); + if (!shader) + glColor3fv(m_Decal->GetShadingColor().FloatArray()); + else + shader->Uniform("shadingColor", m_Decal->GetShadingColor()); glVertexPointer(3, GL_FLOAT, stride, base + m_Position.offset); glColorPointer(4, GL_UNSIGNED_BYTE, stride, base + m_DiffuseColor.offset); diff --git a/source/renderer/DecalRData.h b/source/renderer/DecalRData.h index 347509c4af..821c048b58 100644 --- a/source/renderer/DecalRData.h +++ b/source/renderer/DecalRData.h @@ -19,6 +19,7 @@ #define INCLUDED_DECALRDATA #include "graphics/RenderableObject.h" +#include "graphics/ShaderProgram.h" #include "renderer/VertexArray.h" class CModelDecal; @@ -31,7 +32,7 @@ public: void Update(); - void Render(); + void Render(const CShaderProgramPtr& shader); private: void BuildArrays(); diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 239d7349bb..30ecf1cfe9 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -256,7 +256,7 @@ void TerrainRenderer::RenderTerrain(ShadowMap* shadow) PROFILE_START("render terrain decals"); for (size_t i = 0; i < m->visibleDecals.size(); ++i) - m->visibleDecals[i]->Render(); + m->visibleDecals[i]->Render(CShaderProgramPtr()); PROFILE_END("render terrain decals"); @@ -608,7 +608,7 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow) PROFILE_START("render terrain decals"); for (size_t i = 0; i < m->visibleDecals.size(); ++i) - m->visibleDecals[i]->Render(); + m->visibleDecals[i]->Render(shaderDecal); PROFILE_END("render terrain decals"); shaderDecal->Unbind(); diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 840a0484bf..08c78f4caf 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.cpp @@ -455,11 +455,7 @@ void CCmpVisualActor::Interpolate(float frameTime, float frameOffset) if (m_Visibility != ICmpRangeManager::VIS_HIDDEN) { model.ValidatePosition(); - - if (m_Visibility == ICmpRangeManager::VIS_FOGGED) - model.SetShadingColor(CColor(0.5f * m_R.ToFloat(), 0.5f * m_G.ToFloat(), 0.5f * m_B.ToFloat(), 1.0f)); - else - model.SetShadingColor(CColor(m_R.ToFloat(), m_G.ToFloat(), m_B.ToFloat(), 1.0f)); + model.SetShadingColor(CColor(m_R.ToFloat(), m_G.ToFloat(), m_B.ToFloat(), 1.0f)); } }