mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Support conditional expressions in shader effect XML files. Consolidate fixed-function model rendering into the shader system. Remove lots of now-obsolete renderer code. Move shader defines from std::map to new class with interned data, for performance. Move texture from model into material. Alleviate singletonitis. Remove obsolete lodbias setting. Remove unused terrain shadow transparency. This was SVN commit r11423.
129 lines
4.1 KiB
C++
129 lines
4.1 KiB
C++
/* Copyright (C) 2012 Wildfire Games.
|
|
* This file is part of 0 A.D.
|
|
*
|
|
* 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
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/*
|
|
* Implementation of common RenderModifiers
|
|
*/
|
|
|
|
#include "precompiled.h"
|
|
|
|
#include "lib/ogl.h"
|
|
#include "maths/Vector3D.h"
|
|
#include "maths/Vector4D.h"
|
|
#include "maths/Matrix3D.h"
|
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "graphics/GameView.h"
|
|
#include "graphics/LightEnv.h"
|
|
#include "graphics/LOSTexture.h"
|
|
#include "graphics/Model.h"
|
|
#include "graphics/TextureManager.h"
|
|
|
|
#include "renderer/RenderModifiers.h"
|
|
#include "renderer/Renderer.h"
|
|
#include "renderer/ShadowMap.h"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
// LitRenderModifier implementation
|
|
|
|
LitRenderModifier::LitRenderModifier()
|
|
: m_Shadow(0), m_LightEnv(0)
|
|
{
|
|
}
|
|
|
|
LitRenderModifier::~LitRenderModifier()
|
|
{
|
|
}
|
|
|
|
// Set the shadow map for subsequent rendering
|
|
void LitRenderModifier::SetShadowMap(const ShadowMap* shadow)
|
|
{
|
|
m_Shadow = shadow;
|
|
}
|
|
|
|
// Set the light environment for subsequent rendering
|
|
void LitRenderModifier::SetLightEnv(const CLightEnv* lightenv)
|
|
{
|
|
m_LightEnv = lightenv;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
// ShaderRenderModifier implementation
|
|
|
|
ShaderRenderModifier::ShaderRenderModifier()
|
|
{
|
|
}
|
|
|
|
void ShaderRenderModifier::BeginPass(const CShaderProgramPtr& shader)
|
|
{
|
|
shader->Uniform("transform", g_Renderer.GetViewCamera().GetViewProjection());
|
|
|
|
if (GetShadowMap() && shader->GetTextureBinding("shadowTex").Active())
|
|
{
|
|
shader->BindTexture("shadowTex", GetShadowMap()->GetTexture());
|
|
shader->Uniform("shadowTransform", GetShadowMap()->GetTextureMatrix());
|
|
|
|
const float* offsets = GetShadowMap()->GetFilterOffsets();
|
|
shader->Uniform("shadowOffsets1", offsets[0], offsets[1], offsets[2], offsets[3]);
|
|
shader->Uniform("shadowOffsets2", offsets[4], offsets[5], offsets[6], offsets[7]);
|
|
}
|
|
|
|
if (GetLightEnv())
|
|
{
|
|
shader->Uniform("ambient", GetLightEnv()->m_UnitsAmbientColor);
|
|
shader->Uniform("sunDir", GetLightEnv()->GetSunDir());
|
|
shader->Uniform("sunColor", GetLightEnv()->m_SunColor);
|
|
}
|
|
|
|
if (shader->GetTextureBinding("losTex").Active())
|
|
{
|
|
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
|
|
shader->BindTexture("losTex", los.GetTexture());
|
|
// Don't bother sending the whole matrix, we just need two floats (scale and translation)
|
|
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
|
|
}
|
|
|
|
m_BindingInstancingTransform = shader->GetUniformBinding("instancingTransform");
|
|
m_BindingShadingColor = shader->GetUniformBinding("shadingColor");
|
|
m_BindingObjectColor = shader->GetUniformBinding("objectColor");
|
|
m_BindingPlayerColor = shader->GetUniformBinding("playerColor");
|
|
m_BindingBaseTex = shader->GetTextureBinding("baseTex");
|
|
}
|
|
|
|
void ShaderRenderModifier::PrepareTexture(const CShaderProgramPtr& shader, CTexture& texture)
|
|
{
|
|
if (m_BindingBaseTex.Active())
|
|
shader->BindTexture(m_BindingBaseTex, texture.GetHandle());
|
|
}
|
|
|
|
void ShaderRenderModifier::PrepareModel(const CShaderProgramPtr& shader, CModel* model)
|
|
{
|
|
if (m_BindingInstancingTransform.Active())
|
|
shader->Uniform(m_BindingInstancingTransform, model->GetTransform());
|
|
|
|
if (m_BindingShadingColor.Active())
|
|
shader->Uniform(m_BindingShadingColor, model->GetShadingColor());
|
|
|
|
if (m_BindingObjectColor.Active())
|
|
shader->Uniform(m_BindingObjectColor, model->GetMaterial().GetObjectColor());
|
|
|
|
if (m_BindingPlayerColor.Active())
|
|
shader->Uniform(m_BindingPlayerColor, g_Game->GetPlayerColour(model->GetPlayerID()));
|
|
}
|