Add the ceasefire settings to the new simulation settings system.
[0ad.git] / source / renderer / RenderModifiers.cpp
blobbd2f0c9676be907c3f6490b9928fd8bac411731e
1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Implementation of common RenderModifiers
22 #include "precompiled.h"
24 #include "lib/ogl.h"
25 #include "maths/Vector3D.h"
26 #include "maths/Vector4D.h"
27 #include "maths/Matrix3D.h"
29 #include "ps/Game.h"
31 #include "graphics/GameView.h"
32 #include "graphics/LightEnv.h"
33 #include "graphics/LOSTexture.h"
34 #include "graphics/Model.h"
35 #include "graphics/TextureManager.h"
37 #include "renderer/RenderModifiers.h"
38 #include "renderer/Renderer.h"
39 #include "renderer/ShadowMap.h"
41 #include <boost/algorithm/string.hpp>
43 ///////////////////////////////////////////////////////////////////////////////////////////////
44 // LitRenderModifier implementation
46 LitRenderModifier::LitRenderModifier()
47 : m_Shadow(0), m_LightEnv(0)
51 LitRenderModifier::~LitRenderModifier()
55 // Set the shadow map for subsequent rendering
56 void LitRenderModifier::SetShadowMap(const ShadowMap* shadow)
58 m_Shadow = shadow;
61 // Set the light environment for subsequent rendering
62 void LitRenderModifier::SetLightEnv(const CLightEnv* lightenv)
64 m_LightEnv = lightenv;
67 ///////////////////////////////////////////////////////////////////////////////////////////////
68 // ShaderRenderModifier implementation
70 ShaderRenderModifier::ShaderRenderModifier()
74 void ShaderRenderModifier::BeginPass(const CShaderProgramPtr& shader)
76 shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
77 shader->Uniform(str_cameraPos, g_Renderer.GetViewCamera().GetOrientation().GetTranslation());
79 if (GetShadowMap() && shader->GetTextureBinding(str_shadowTex).Active())
81 shader->BindTexture(str_shadowTex, GetShadowMap()->GetTexture());
82 shader->Uniform(str_shadowTransform, GetShadowMap()->GetTextureMatrix());
83 int width = GetShadowMap()->GetWidth();
84 int height = GetShadowMap()->GetHeight();
85 shader->Uniform(str_shadowScale, width, height, 1.0f / width, 1.0f / height);
88 if (GetLightEnv())
90 shader->Uniform(str_ambient, GetLightEnv()->m_UnitsAmbientColor);
91 shader->Uniform(str_sunDir, GetLightEnv()->GetSunDir());
92 shader->Uniform(str_sunColor, GetLightEnv()->m_SunColor);
94 shader->Uniform(str_fogColor, GetLightEnv()->m_FogColor);
95 shader->Uniform(str_fogParams, GetLightEnv()->m_FogFactor, GetLightEnv()->m_FogMax, 0.f, 0.f);
98 if (shader->GetTextureBinding(str_losTex).Active())
100 CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
101 shader->BindTexture(str_losTex, los.GetTextureSmooth());
102 // Don't bother sending the whole matrix, we just need two floats (scale and translation)
103 shader->Uniform(str_losTransform, los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
106 m_BindingInstancingTransform = shader->GetUniformBinding(str_instancingTransform);
107 m_BindingShadingColor = shader->GetUniformBinding(str_shadingColor);
108 m_BindingPlayerColor = shader->GetUniformBinding(str_playerColor);
111 void ShaderRenderModifier::PrepareModel(const CShaderProgramPtr& shader, CModel* model)
113 if (m_BindingInstancingTransform.Active())
114 shader->Uniform(m_BindingInstancingTransform, model->GetTransform());
116 if (m_BindingShadingColor.Active())
117 shader->Uniform(m_BindingShadingColor, model->GetShadingColor());
119 if (m_BindingPlayerColor.Active())
120 shader->Uniform(m_BindingPlayerColor, g_Game->GetPlayerColor(model->GetPlayerID()));