1
0
forked from 0ad/0ad

Removes code duplications for binding shadows to shaders.

This was SVN commit r24710.
This commit is contained in:
Vladislav Belov 2021-01-19 19:19:04 +00:00
parent 4a2cc3273e
commit 5cbf8f04ec
4 changed files with 15 additions and 73 deletions

View File

@ -76,14 +76,8 @@ void ShaderRenderModifier::BeginPass(const CShaderProgramPtr& shader)
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
shader->Uniform(str_cameraPos, g_Renderer.GetViewCamera().GetOrientation().GetTranslation());
if (GetShadowMap() && shader->GetTextureBinding(str_shadowTex).Active())
{
shader->BindTexture(str_shadowTex, GetShadowMap()->GetTexture());
shader->Uniform(str_shadowTransform, GetShadowMap()->GetTextureMatrix());
int width = GetShadowMap()->GetWidth();
int height = GetShadowMap()->GetHeight();
shader->Uniform(str_shadowScale, width, height, 1.0f / width, 1.0f / height);
}
if (GetShadowMap())
GetShadowMap()->BindTo(shader);
if (GetLightEnv())
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -664,20 +664,16 @@ void ShadowMap::EndRender()
glColorMask(1,1,1,1);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Retrieve the texture handle and texture matrix for shadowing
GLuint ShadowMap::GetTexture() const
void ShadowMap::BindTo(const CShaderProgramPtr& shader) const
{
return m->Texture;
}
if (!shader->GetTextureBinding(str_shadowTex).Active())
return;
const CMatrix3D& ShadowMap::GetTextureMatrix() const
{
return m->TextureMatrix;
shader->BindTexture(str_shadowTex, m->Texture);
shader->Uniform(str_shadowTransform, m->TextureMatrix);
shader->Uniform(str_shadowScale, m->Width, m->Height, 1.0f / m->Width, 1.0f / m->Height);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Depth texture bits
int ShadowMap::GetDepthTextureBits() const
@ -700,18 +696,6 @@ void ShadowMap::SetDepthTextureBits(int bits)
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Depth texture size
int ShadowMap::GetWidth() const
{
return m->Width;
}
int ShadowMap::GetHeight() const
{
return m->Height;
}
//////////////////////////////////////////////////////////////////////////////
void ShadowMap::RenderDebugBounds()

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,6 +22,7 @@
#ifndef INCLUDED_SHADOWMAP
#define INCLUDED_SHADOWMAP
#include "graphics/ShaderProgramPtr.h"
#include "lib/ogl.h"
class CBoundingBoxAligned;
@ -68,20 +69,6 @@ public:
*/
void SetDepthTextureBits(int bits);
/**
* GetWidth: Return the width of the depth texture.
*
* @return depth texture width
*/
int GetWidth() const;
/**
* GetHeight: Return the height of the depth texture
*
* @return depth texture height
*/
int GetHeight() const;
/**
* SetupFrame: Configure light space for the given camera and light direction,
* create the shadow texture if necessary, etc.
@ -132,20 +119,9 @@ public:
void EndRender();
/**
* GetTexture: Retrieve the OpenGL texture object name that contains the shadow map.
*
* @return the texture name of the shadow map texture
* Binds all needed resources and uniforms to draw shadows using the shader.
*/
GLuint GetTexture() const;
/**
* GetTextureMatrix: Retrieve the world-space to shadow map texture coordinates
* transformation matrix.
*
* @return the matrix that transforms world-space coordinates into homogenous
* shadow map texture coordinates
*/
const CMatrix3D& GetTextureMatrix() const;
void BindTo(const CShaderProgramPtr& shader) const;
/**
* Visualize shadow mapping calculations to help in

View File

@ -261,13 +261,7 @@ void TerrainRenderer::PrepareShader(const CShaderProgramPtr& shader, ShadowMap*
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
if (shadow)
{
shader->BindTexture(str_shadowTex, shadow->GetTexture());
shader->Uniform(str_shadowTransform, shadow->GetTextureMatrix());
int width = shadow->GetWidth();
int height = shadow->GetHeight();
shader->Uniform(str_shadowScale, width, height, 1.0f / width, 1.0f / height);
}
shadow->BindTo(shader);
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture(str_losTex, los.GetTextureSmooth());
@ -599,13 +593,7 @@ bool TerrainRenderer::RenderFancyWater(const CShaderDefines& context, int cullGr
}
if (shadow)
{
m->fancyWaterShader->BindTexture(str_shadowTex, shadow->GetTexture());
m->fancyWaterShader->Uniform(str_shadowTransform, shadow->GetTextureMatrix());
int width = shadow->GetWidth();
int height = shadow->GetHeight();
m->fancyWaterShader->Uniform(str_shadowScale, width, height, 1.0f / width, 1.0f / height);
}
shadow->BindTo(m->fancyWaterShader);
std::vector<CPatchRData*>& visiblePatches = m->visiblePatches[cullGroup];
for (size_t i = 0; i < visiblePatches.size(); ++i)