Moved functions from render_lighting.cpp to ShaderBasedRenderer class
This commit is contained in:
@@ -196,10 +196,3 @@ void AbstractRenderer::drawJoint(bool drawline, bool drawname,
|
||||
|
||||
#endif //DEBUG
|
||||
|
||||
|
||||
AbstractRenderer::AbstractRenderer()
|
||||
{
|
||||
|
||||
m_wireframe = false;
|
||||
m_mipviz = false;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ class AbstractRenderer
|
||||
protected:
|
||||
irr::core::vector2df m_current_screen_size;
|
||||
|
||||
bool m_wireframe;
|
||||
bool m_mipviz;
|
||||
//bool m_wireframe;
|
||||
//bool m_mipviz;
|
||||
|
||||
#ifdef DEBUG
|
||||
void drawDebugMeshes() const;
|
||||
@@ -48,7 +48,6 @@ protected:
|
||||
|
||||
|
||||
public:
|
||||
AbstractRenderer();
|
||||
virtual ~AbstractRenderer(){}
|
||||
|
||||
virtual void addSkyBox(const std::vector<irr::video::ITexture*> &texture,
|
||||
@@ -74,6 +73,7 @@ public:
|
||||
|
||||
virtual void updateLightsInfo(irr::scene::ICameraSceneNode * const camnode,
|
||||
float dt) = 0;
|
||||
virtual void uploadLightingData() const {}
|
||||
|
||||
virtual void computeMatrixesAndCameras(irr::scene::ICameraSceneNode * const camnode,
|
||||
size_t width, size_t height) {}
|
||||
@@ -87,10 +87,11 @@ public:
|
||||
return m_current_screen_size;
|
||||
}
|
||||
|
||||
/*
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleWireframe() { m_wireframe = !m_wireframe; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleMipVisualization() { m_mipviz = !m_mipviz; }
|
||||
void toggleMipVisualization() { m_mipviz = !m_mipviz; }*/
|
||||
};
|
||||
|
||||
#endif //HEADER_ABSTRACT_RENDERER_HPP
|
||||
|
||||
@@ -544,45 +544,49 @@ public:
|
||||
m_boundingboxesviz = false;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleWireframe() { m_renderer->toggleWireframe(); }
|
||||
void toggleWireframe() { m_wireframe = !m_wireframe; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleMipVisualization() { m_renderer->toggleMipVisualization(); }
|
||||
bool getWireframe() { return m_wireframe; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleNormals() { m_normals = !m_normals; }
|
||||
void toggleMipVisualization() { m_mipviz = !m_mipviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getNormals() { return m_normals; }
|
||||
bool getMipViz() { return m_mipviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleNormals() { m_normals = !m_normals; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleSSAOViz() { m_ssaoviz = !m_ssaoviz; }
|
||||
bool getNormals() { return m_normals; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleLightViz() { m_lightviz = !m_lightviz; }
|
||||
void toggleSSAOViz() { m_ssaoviz = !m_ssaoviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getLightViz() { return m_lightviz; }
|
||||
void toggleLightViz() { m_lightviz = !m_lightviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getSSAOViz() { return m_ssaoviz; }
|
||||
bool getLightViz() { return m_lightviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleRSM() { m_rsm = !m_rsm; }
|
||||
bool getSSAOViz() { return m_ssaoviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getRSM() { return m_rsm; }
|
||||
void toggleRSM() { m_rsm = !m_rsm; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleRH() { m_rh = !m_rh; }
|
||||
bool getRSM() { return m_rsm; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getRH() { return m_rh; }
|
||||
void toggleRH() { m_rh = !m_rh; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleGI() { m_gi = !m_gi; }
|
||||
bool getRH() { return m_rh; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getGI() { return m_gi; }
|
||||
void toggleGI() { m_gi = !m_gi; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleShadowViz() { m_shadowviz = !m_shadowviz; }
|
||||
bool getGI() { return m_gi; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getShadowViz() { return m_shadowviz; }
|
||||
void toggleShadowViz() { m_shadowviz = !m_shadowviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleDistortViz() { m_distortviz = !m_distortviz; }
|
||||
bool getShadowViz() { return m_shadowviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getDistortViz() { return m_distortviz; }
|
||||
void toggleDistortViz() { m_distortviz = !m_distortviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getDistortViz() { return m_distortviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleBoundingBoxesViz() { m_boundingboxesviz = !m_boundingboxesviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getBoundingBoxesViz() { return m_boundingboxesviz; }
|
||||
bool getBoundingBoxesViz() { return m_boundingboxesviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
u32 getRenderPass() { return m_renderpass; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program 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 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/light.hpp"
|
||||
#include "graphics/post_processing.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shadow_matrices.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
|
||||
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Upload lighting info to the dedicated uniform buffer
|
||||
*/
|
||||
void IrrDriver::uploadLightingData()
|
||||
{
|
||||
float Lighting[36];
|
||||
Lighting[0] = m_sun_direction.X;
|
||||
Lighting[1] = m_sun_direction.Y;
|
||||
Lighting[2] = m_sun_direction.Z;
|
||||
Lighting[4] = m_suncolor.getRed();
|
||||
Lighting[5] = m_suncolor.getGreen();
|
||||
Lighting[6] = m_suncolor.getBlue();
|
||||
Lighting[7] = 0.54f;
|
||||
|
||||
const SHCoefficients* sh_coeff = irr_driver->getSHCoefficients();
|
||||
|
||||
if(sh_coeff) {
|
||||
memcpy(&Lighting[8], sh_coeff->blue_SH_coeff, 9 * sizeof(float));
|
||||
memcpy(&Lighting[17], sh_coeff->green_SH_coeff, 9 * sizeof(float));
|
||||
memcpy(&Lighting[26], sh_coeff->red_SH_coeff, 9 * sizeof(float));
|
||||
}
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
|
||||
} // uploadLightingData
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void IrrDriver::renderSSAO()
|
||||
{
|
||||
m_rtts->getFBO(FBO_SSAO).bind();
|
||||
glClearColor(1., 1., 1., 1.);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_post_processing->renderSSAO();
|
||||
// Blur it to reduce noise.
|
||||
FrameBuffer::Blit(m_rtts->getFBO(FBO_SSAO),
|
||||
m_rtts->getFBO(FBO_HALF1_R),
|
||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R),
|
||||
irr_driver->getFBO(FBO_HALF2_R));
|
||||
|
||||
} // renderSSAO
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ FrameBuffer* RTT::render(scene::ICameraSceneNode* camera, float dt)
|
||||
|
||||
irr_driver->getRenderer()->computeMatrixesAndCameras(camera, m_width, m_height);
|
||||
irr_driver->getRenderer()->updateLightsInfo(camera, dt);
|
||||
irr_driver->uploadLightingData();
|
||||
irr_driver->getRenderer()->uploadLightingData();
|
||||
irr_driver->getRenderer()->renderScene(camera, dt, false, true);
|
||||
FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false);
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ void ShaderBasedRenderer::setOverrideMaterial()
|
||||
overridemat.EnablePasses = scene::ESNRP_SOLID | scene::ESNRP_TRANSPARENT;
|
||||
overridemat.EnableFlags = 0;
|
||||
|
||||
if (m_wireframe)
|
||||
if (irr_driver->getWireframe())
|
||||
{
|
||||
overridemat.Material.Wireframe = 1;
|
||||
overridemat.EnableFlags |= video::EMF_WIREFRAME;
|
||||
}
|
||||
if (m_mipviz)
|
||||
if (irr_driver->getMipViz())
|
||||
{
|
||||
overridemat.Material.MaterialType = Shaders::getShader(ES_MIPVIZ);
|
||||
overridemat.EnableFlags |= video::EMF_MATERIAL_TYPE;
|
||||
@@ -156,6 +156,37 @@ void ShaderBasedRenderer::updateLightsInfo(scene::ICameraSceneNode * const camno
|
||||
m_lighting_passes.updateLightsInfo(camnode, dt);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Upload lighting info to the dedicated uniform buffer
|
||||
*/
|
||||
void ShaderBasedRenderer::uploadLightingData() const
|
||||
{
|
||||
float Lighting[36];
|
||||
|
||||
core::vector3df sun_direction = irr_driver->getSunDirection();
|
||||
video::SColorf sun_color = irr_driver->getSunColor();
|
||||
|
||||
Lighting[0] = sun_direction.X;
|
||||
Lighting[1] = sun_direction.Y;
|
||||
Lighting[2] = sun_direction.Z;
|
||||
Lighting[4] = sun_color.getRed();
|
||||
Lighting[5] = sun_color.getGreen();
|
||||
Lighting[6] = sun_color.getBlue();
|
||||
Lighting[7] = 0.54f;
|
||||
|
||||
const SHCoefficients* sh_coeff = irr_driver->getSHCoefficients();
|
||||
|
||||
if(sh_coeff) {
|
||||
memcpy(&Lighting[8], sh_coeff->blue_SH_coeff, 9 * sizeof(float));
|
||||
memcpy(&Lighting[17], sh_coeff->green_SH_coeff, 9 * sizeof(float));
|
||||
memcpy(&Lighting[26], sh_coeff->red_SH_coeff, 9 * sizeof(float));
|
||||
}
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
|
||||
} // uploadLightingData
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ShaderBasedRenderer::computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
|
||||
size_t width, size_t height)
|
||||
@@ -173,6 +204,22 @@ void ShaderBasedRenderer::renderSkybox(const scene::ICameraSceneNode *camera) co
|
||||
}
|
||||
} // renderSkybox
|
||||
|
||||
// ============================================================================
|
||||
void ShaderBasedRenderer::renderSSAO() const
|
||||
{
|
||||
RTT *rtts = irr_driver->getRTT();
|
||||
rtts->getFBO(FBO_SSAO).bind();
|
||||
glClearColor(1., 1., 1., 1.);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
irr_driver->getPostProcessing()->renderSSAO();
|
||||
// Blur it to reduce noise.
|
||||
FrameBuffer::Blit(rtts->getFBO(FBO_SSAO),
|
||||
rtts->getFBO(FBO_HALF1_R),
|
||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
irr_driver->getPostProcessing()->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R),
|
||||
irr_driver->getFBO(FBO_HALF2_R));
|
||||
|
||||
} // renderSSAO
|
||||
|
||||
// ============================================================================
|
||||
void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
|
||||
@@ -290,7 +337,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
|
||||
PROFILER_PUSH_CPU_MARKER("- SSAO", 0xFF, 0xFF, 0x00);
|
||||
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_SSAO));
|
||||
if (UserConfigParams::m_ssao)
|
||||
irr_driver->renderSSAO();
|
||||
renderSSAO();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
}
|
||||
|
||||
@@ -375,7 +422,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
|
||||
|
||||
PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00);
|
||||
// Render anything glowing.
|
||||
if (!m_mipviz && !m_wireframe && UserConfigParams::m_glow)
|
||||
if (!irr_driver->getWireframe() && !irr_driver->getMipViz() && UserConfigParams::m_glow)
|
||||
{
|
||||
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_GLOW));
|
||||
irr_driver->setPhase(GLOW_PASS);
|
||||
@@ -652,7 +699,7 @@ void ShaderBasedRenderer::render(float dt)
|
||||
PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0);
|
||||
computeMatrixesAndCameras(camnode, viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y);
|
||||
m_shadow_matrices.updateSunOrthoMatrices();
|
||||
irr_driver->uploadLightingData(); //TODO: move method; update "global" lighting (sun and spherical harmonics)
|
||||
uploadLightingData();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
renderScene(camnode, dt, track->hasShadows(), false);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
/** Static glowing things are loaded once per track.
|
||||
* Glowing items can appear ordisappear each frame */
|
||||
std::vector<GlowData> m_glowing;
|
||||
int m_nb_static_glowing;
|
||||
size_t m_nb_static_glowing;
|
||||
|
||||
irr::core::vector3df m_wind_dir;
|
||||
|
||||
@@ -57,6 +57,8 @@ private:
|
||||
|
||||
void updateLightsInfo(irr::scene::ICameraSceneNode * const camnode,
|
||||
float dt);
|
||||
|
||||
void uploadLightingData() const override;
|
||||
|
||||
void computeMatrixesAndCameras(scene::ICameraSceneNode * const camnode,
|
||||
size_t width, size_t height);
|
||||
@@ -68,6 +70,8 @@ private:
|
||||
|
||||
void prepareDrawCalls(scene::ICameraSceneNode *camnode);
|
||||
|
||||
void renderSSAO() const;
|
||||
|
||||
void renderScene(irr::scene::ICameraSceneNode * const camnode,
|
||||
float dt, bool hasShadows, bool forceRTT);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user