From: <vin...@us...> - 2014-01-13 00:11:35
|
Revision: 15032 http://sourceforge.net/p/supertuxkart/code/15032 Author: vincentlj Date: 2014-01-13 00:11:31 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Clean color_level shader providers. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 00:04:53 UTC (rev 15031) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 00:11:31 UTC (rev 15032) @@ -154,26 +154,6 @@ } //------------------------------------- - -void ColorLevelsProvider::OnSetConstants(IMaterialRendererServices *srv, int userData) -{ - - m_inlevel = World::getWorld()->getTrack()->getColorLevelIn(); - m_outlevel = World::getWorld()->getTrack()->getColorLevelOut(); - - srv->setVertexShaderConstant("inlevel", &m_inlevel.X, 3); - srv->setVertexShaderConstant("outlevel", &m_outlevel.X, 2); - - if (!firstdone) - { - s32 tex = 0; - srv->setVertexShaderConstant("tex", &tex, 1); - - firstdone = true; - } -} - -//------------------------------------- void SkyboxProvider::OnSetConstants(IMaterialRendererServices *srv, int) { const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 00:04:53 UTC (rev 15031) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 00:11:31 UTC (rev 15032) @@ -139,23 +139,6 @@ // -class ColorLevelsProvider: public CallBase -{ -public: - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); - - - ColorLevelsProvider() - { - } - -private: - core::vector3df m_inlevel; - core::vector2df m_outlevel; -}; - -// - class SkyboxProvider: public CallBase { public: Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 00:04:53 UTC (rev 15031) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 00:11:31 UTC (rev 15032) @@ -38,7 +38,6 @@ m_callbacks[ES_SPLATTING] = new SplattingProvider(); m_callbacks[ES_WATER] = new WaterShaderProvider(); m_callbacks[ES_GRASS] = new GrassShaderProvider(); - m_callbacks[ES_COLOR_LEVELS] = new ColorLevelsProvider(); m_callbacks[ES_BUBBLES] = new BubbleEffectProvider(); m_callbacks[ES_RAIN] = new RainEffectProvider(); m_callbacks[ES_MOTIONBLUR] = new MotionBlurProvider(); @@ -137,9 +136,6 @@ 0, EMT_SOLID); m_shaders[ES_FLIP_ADDITIVE] = glslmat(std::string(""), dir + "flip.frag", 0, EMT_TRANSPARENT_ADD_COLOR); - - m_shaders[ES_COLOR_LEVELS] = glslmat(std::string(""), dir + "color_levels.frag", - m_callbacks[ES_COLOR_LEVELS], EMT_SOLID); m_shaders[ES_COLORIZE] = glslmat(std::string(""), dir + "colorize.frag", m_callbacks[ES_COLORIZE], EMT_SOLID); Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 00:04:53 UTC (rev 15031) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 00:11:31 UTC (rev 15032) @@ -40,7 +40,6 @@ ACT(ES_MIPVIZ) \ ACT(ES_FLIP) \ ACT(ES_FLIP_ADDITIVE) \ - ACT(ES_COLOR_LEVELS) \ ACT(ES_GAUSSIAN6H) \ ACT(ES_GAUSSIAN6V) \ ACT(ES_COLORIZE) \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 12:56:31
|
Revision: 15036 http://sourceforge.net/p/supertuxkart/code/15036 Author: vincentlj Date: 2014-01-13 12:56:27 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Lights: Use custom gl calls. Modified Paths: -------------- main/trunk/src/graphics/glwrap.cpp main/trunk/src/graphics/glwrap.hpp main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp main/trunk/src/graphics/render.cpp Modified: main/trunk/src/graphics/glwrap.cpp =================================================================== --- main/trunk/src/graphics/glwrap.cpp 2014-01-13 11:35:12 UTC (rev 15035) +++ main/trunk/src/graphics/glwrap.cpp 2014-01-13 12:56:27 UTC (rev 15036) @@ -37,6 +37,8 @@ PFNGLUNIFORM1IPROC glUniform1i; PFNGLUNIFORM3IPROC glUniform3i; PFNGLUNIFORM4IPROC glUniform4i; +PFNGLUNIFORM1FVPROC glUniform1fv; +PFNGLUNIFORM4FVPROC glUniform4fv; PFNGLGETPROGRAMIVPROC glGetProgramiv; PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; @@ -169,6 +171,8 @@ glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)IRR_OGL_LOAD_EXTENSION("glBindVertexArray"); glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)IRR_OGL_LOAD_EXTENSION("glDeleteVertexArrays"); glTexBuffer = (PFNGLTEXBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glTexBuffer"); + glUniform1fv = (PFNGLUNIFORM1FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform1fv"); + glUniform4fv = (PFNGLUNIFORM4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fv"); #endif #if ENABLE_ARB_DEBUG_OUTPUT glDebugMessageCallbackARB(debugCallback, NULL); Modified: main/trunk/src/graphics/glwrap.hpp =================================================================== --- main/trunk/src/graphics/glwrap.hpp 2014-01-13 11:35:12 UTC (rev 15035) +++ main/trunk/src/graphics/glwrap.hpp 2014-01-13 12:56:27 UTC (rev 15036) @@ -52,6 +52,8 @@ extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; extern PFNGLUNIFORM1FPROC glUniform1f; extern PFNGLUNIFORM3FPROC glUniform3f; +extern PFNGLUNIFORM1FVPROC glUniform1fv; +extern PFNGLUNIFORM4FVPROC glUniform4fv; extern PFNGLDELETESHADERPROC glDeleteShader; extern PFNGLGETSHADERIVPROC glGetShaderiv; extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-13 11:35:12 UTC (rev 15035) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-13 12:56:27 UTC (rev 15036) @@ -1,884 +1,951 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2011-2013 the 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 "post_processing.hpp" - -#include "config/user_config.hpp" -#include "graphics/callbacks.hpp" -#include "graphics/camera.hpp" -#include "graphics/glwrap.hpp" -#include "graphics/irr_driver.hpp" -#include "graphics/mlaa_areamap.hpp" -#include "graphics/shaders.hpp" -#include "io/file_manager.hpp" -#include "karts/abstract_kart.hpp" -#include "karts/kart_model.hpp" -#include "modes/world.hpp" -#include "race/race_manager.hpp" -#include "tracks/track.hpp" -#include "utils/log.hpp" -#include "graphics/glwrap.hpp" - -#include <SViewFrustum.h> - -using namespace video; -using namespace scene; - -PostProcessing::PostProcessing(IVideoDriver* video_driver) -{ - // Initialization - m_material.Wireframe = false; - m_material.Lighting = false; - m_material.ZWriteEnable = false; - m_material.ZBuffer = ECFN_ALWAYS; - m_material.setFlag(EMF_TRILINEAR_FILTER, true); - - for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) - { - m_material.TextureLayer[i].TextureWrapU = - m_material.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE; - } - - // Load the MLAA area map - io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()-> - createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33), - "AreaMap33", false); - if (!areamap) Log::fatal("postprocessing", "Failed to load the areamap"); - m_areamap = irr_driver->getVideoDriver()->getTexture(areamap); - areamap->drop(); - -} // PostProcessing - -// ---------------------------------------------------------------------------- -PostProcessing::~PostProcessing() -{ - // TODO: do we have to delete/drop anything? -} // ~PostProcessing - -// ---------------------------------------------------------------------------- -/** Initialises post processing at the (re-)start of a race. This sets up - * the vertices, normals and texture coordinates for each - */ -void PostProcessing::reset() -{ - const u32 n = Camera::getNumCameras(); - m_boost_time.resize(n); - m_vertices.resize(n); - m_center.resize(n); - m_direction.resize(n); - - MotionBlurProvider * const cb = (MotionBlurProvider *) irr_driver-> - getCallback(ES_MOTIONBLUR); - - for(unsigned int i=0; i<n; i++) - { - m_boost_time[i] = 0.0f; - - const core::recti &vp = Camera::getCamera(i)->getViewport(); - // Map viewport to [-1,1] x [-1,1]. First define the coordinates - // left, right, top, bottom: - float right = vp.LowerRightCorner.X < UserConfigParams::m_width - ? 0.0f : 1.0f; - float left = vp.UpperLeftCorner.X > 0.0f ? 0.0f : -1.0f; - float top = vp.UpperLeftCorner.Y > 0.0f ? 0.0f : 1.0f; - float bottom = vp.LowerRightCorner.Y < UserConfigParams::m_height - ? 0.0f : -1.0f; - - // Use left etc to define 4 vertices on which the rendered screen - // will be displayed: - m_vertices[i].v0.Pos = core::vector3df(left, bottom, 0); - m_vertices[i].v1.Pos = core::vector3df(left, top, 0); - m_vertices[i].v2.Pos = core::vector3df(right, top, 0); - m_vertices[i].v3.Pos = core::vector3df(right, bottom, 0); - // Define the texture coordinates of each vertex, which must - // be in [0,1]x[0,1] - m_vertices[i].v0.TCoords = core::vector2df(left ==-1.0f ? 0.0f : 0.5f, - bottom==-1.0f ? 0.0f : 0.5f); - m_vertices[i].v1.TCoords = core::vector2df(left ==-1.0f ? 0.0f : 0.5f, - top == 1.0f ? 1.0f : 0.5f); - m_vertices[i].v2.TCoords = core::vector2df(right == 0.0f ? 0.5f : 1.0f, - top == 1.0f ? 1.0f : 0.5f); - m_vertices[i].v3.TCoords = core::vector2df(right == 0.0f ? 0.5f : 1.0f, - bottom==-1.0f ? 0.0f : 0.5f); - // Set normal and color: - core::vector3df normal(0,0,1); - m_vertices[i].v0.Normal = m_vertices[i].v1.Normal = - m_vertices[i].v2.Normal = m_vertices[i].v3.Normal = normal; - SColor white(0xFF, 0xFF, 0xFF, 0xFF); - m_vertices[i].v0.Color = m_vertices[i].v1.Color = - m_vertices[i].v2.Color = m_vertices[i].v3.Color = white; - - m_center[i].X=(m_vertices[i].v0.TCoords.X - +m_vertices[i].v2.TCoords.X) * 0.5f; - - // Center is around 20 percent from bottom of screen: - const float tex_height = m_vertices[i].v1.TCoords.Y - - m_vertices[i].v0.TCoords.Y; - m_direction[i].X = m_center[i].X; - m_direction[i].Y = m_vertices[i].v0.TCoords.Y + 0.7f*tex_height; - - setMotionBlurCenterY(i, 0.2f); - - cb->setDirection(i, m_direction[i].X, m_direction[i].Y); - cb->setMaxHeight(i, m_vertices[i].v1.TCoords.Y); - } // for i <number of cameras -} // reset - -void PostProcessing::setMotionBlurCenterY(const u32 num, const float y) -{ - MotionBlurProvider * const cb = (MotionBlurProvider *) irr_driver-> - getCallback(ES_MOTIONBLUR); - - const float tex_height = m_vertices[num].v1.TCoords.Y - m_vertices[num].v0.TCoords.Y; - m_center[num].Y = m_vertices[num].v0.TCoords.Y + y * tex_height; - - cb->setCenter(num, m_center[num].X, m_center[num].Y); -} - -// ---------------------------------------------------------------------------- -/** Setup some PP data. - */ -void PostProcessing::begin() -{ - m_any_boost = false; - for (u32 i = 0; i < m_boost_time.size(); i++) - m_any_boost |= m_boost_time[i] > 0.01f; -} // beginCapture - -// ---------------------------------------------------------------------------- -/** Set the boost amount according to the speed of the camera */ -void PostProcessing::giveBoost(unsigned int camera_index) -{ - if (irr_driver->isGLSL()) - { - m_boost_time[camera_index] = 0.75f; - - MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver-> - getCallback(ES_MOTIONBLUR); - cb->setBoostTime(camera_index, m_boost_time[camera_index]); - } -} // giveBoost - -// ---------------------------------------------------------------------------- -/** Updates the boost times for all cameras, called once per frame. - * \param dt Time step size. - */ -void PostProcessing::update(float dt) -{ - if (!irr_driver->isGLSL()) - return; - - MotionBlurProvider* const cb = - (MotionBlurProvider*) irr_driver->getCallback(ES_MOTIONBLUR); - - if (cb == NULL) return; - - for (unsigned int i=0; i<m_boost_time.size(); i++) - { - if (m_boost_time[i] > 0.0f) - { - m_boost_time[i] -= dt; - if (m_boost_time[i] < 0.0f) m_boost_time[i] = 0.0f; - } - - cb->setBoostTime(i, m_boost_time[i]); - } -} // update - -// ---------------------------------------------------------------------------- -/** Render the post-processed scene, solids only, color to color, no stencil */ -void PostProcessing::renderSolid(const u32 cam) -{ - if (!irr_driver->isGLSL()) return; - - IVideoDriver * const drv = irr_driver->getVideoDriver(); - if (World::getWorld()->getTrack()->isFogEnabled()) - { - m_material.MaterialType = irr_driver->getShader(ES_FOG); - m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - - // Overlay - m_material.BlendOperation = EBO_ADD; - m_material.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA); - - drv->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false); - drawQuad(cam, m_material); - - m_material.BlendOperation = EBO_NONE; - m_material.MaterialTypeParam = 0; - } -} - -GLuint quad_vbo = 0; - -static void initQuadVBO() -{ - initGL(); - const float quad_vertex[] = { - -1., -1., 0., 0., // UpperLeft - -1., 1., 0., 1., // LowerLeft - 1., -1., 1., 0., // UpperRight - 1., 1., 1., 1., // LowerRight - }; - glGenBuffers(1, &quad_vbo); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -namespace BloomShader -{ - GLuint Program = 0; - GLuint attrib_position, attrib_texcoord; - GLuint uniform_texture, uniform_low; - GLuint vao = 0; - - void init() - { - initGL(); - Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/bloom.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_texture = glGetUniformLocation(Program, "tex"); - uniform_low = glGetUniformLocation(Program, "low"); - - if (!quad_vbo) - initQuadVBO(); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - } -} - -namespace BloomBlendShader -{ - GLuint Program = 0; - GLuint attrib_position, attrib_texcoord; - GLuint uniform_texture, uniform_low; - GLuint vao = 0; - - void init() - { - initGL(); - Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/bloomblend.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_texture = glGetUniformLocation(Program, "tex"); - - if (!quad_vbo) - initQuadVBO(); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - } -} - -namespace PPDisplaceShader -{ - GLuint Program = 0; - GLuint attrib_position, attrib_texcoord; - GLuint uniform_tex, uniform_dtex, uniform_viz; - GLuint vao = 0; - - void init() - { - initGL(); - Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/ppdisplace.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_viz = glGetUniformLocation(Program, "viz"); - - if (!quad_vbo) - initQuadVBO(); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - } -} - -namespace ColorLevelShader -{ - GLuint Program = 0; - GLuint attrib_position, attrib_texcoord; - GLuint uniform_tex, uniform_inlevel, uniform_outlevel; - GLuint vao = 0; - - void init() - { - initGL(); - Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/color_levels.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_inlevel = glGetUniformLocation(Program, "inlevel"); - uniform_outlevel = glGetUniformLocation(Program, "outlevel"); - - if (!quad_vbo) - initQuadVBO(); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - } -} - - -static -void renderBloom(ITexture *in) -{ - if (!BloomShader::Program) - BloomShader::init(); - - const float threshold = World::getWorld()->getTrack()->getBloomThreshold(); - glUseProgram(BloomShader::Program); - glBindVertexArray(BloomShader::vao); - glUniform1f(BloomShader::uniform_low, threshold); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); - glUniform1i(BloomShader::uniform_texture, 0); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - -static -void renderBloomBlend(ITexture *in) -{ - if (!BloomBlendShader::Program) - BloomBlendShader::init(); - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE, GL_ONE); - glDisable(GL_DEPTH_TEST); - - glUseProgram(BloomBlendShader::Program); - glBindVertexArray(BloomBlendShader::vao); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); - glUniform1i(BloomBlendShader::uniform_texture, 0); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glEnable(GL_DEPTH_TEST); - glDisable(GL_BLEND); -} - -static -void renderPPDisplace(ITexture *in) -{ - if (!PPDisplaceShader::Program) - PPDisplaceShader::init(); - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE, GL_ONE); - glDisable(GL_DEPTH_TEST); - - glUseProgram(PPDisplaceShader::Program); - glBindVertexArray(PPDisplaceShader::vao); - glUniform1i(PPDisplaceShader::uniform_viz, irr_driver->getDistortViz()); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); - glUniform1i(PPDisplaceShader::uniform_tex, 0); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_DISPLACE))->getOpenGLTextureName()); - glUniform1i(PPDisplaceShader::uniform_dtex, 1); - - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glEnable(GL_DEPTH_TEST); - glDisable(GL_BLEND); -} - -static -void renderColorLevel(ITexture *in) +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2011-2013 the 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 "post_processing.hpp" + +#include "config/user_config.hpp" +#include "graphics/callbacks.hpp" +#include "graphics/camera.hpp" +#include "graphics/glwrap.hpp" +#include "graphics/irr_driver.hpp" +#include "graphics/mlaa_areamap.hpp" +#include "graphics/shaders.hpp" +#include "io/file_manager.hpp" +#include "karts/abstract_kart.hpp" +#include "karts/kart_model.hpp" +#include "modes/world.hpp" +#include "race/race_manager.hpp" +#include "tracks/track.hpp" +#include "utils/log.hpp" +#include "graphics/glwrap.hpp" + +#include <SViewFrustum.h> + +using namespace video; +using namespace scene; + +PostProcessing::PostProcessing(IVideoDriver* video_driver) { + // Initialization + m_material.Wireframe = false; + m_material.Lighting = false; + m_material.ZWriteEnable = false; + m_material.ZBuffer = ECFN_ALWAYS; + m_material.setFlag(EMF_TRILINEAR_FILTER, true); + + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) + { + m_material.TextureLayer[i].TextureWrapU = + m_material.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE; + } + + // Load the MLAA area map + io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()-> + createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33), + "AreaMap33", false); + if (!areamap) Log::fatal("postprocessing", "Failed to load the areamap"); + m_areamap = irr_driver->getVideoDriver()->getTexture(areamap); + areamap->drop(); + +} // PostProcessing + +// ---------------------------------------------------------------------------- +PostProcessing::~PostProcessing() +{ + // TODO: do we have to delete/drop anything? +} // ~PostProcessing + +// ---------------------------------------------------------------------------- +/** Initialises post processing at the (re-)start of a race. This sets up + * the vertices, normals and texture coordinates for each + */ +void PostProcessing::reset() +{ + const u32 n = Camera::getNumCameras(); + m_boost_time.resize(n); + m_vertices.resize(n); + m_center.resize(n); + m_direction.resize(n); + + MotionBlurProvider * const cb = (MotionBlurProvider *) irr_driver-> + getCallback(ES_MOTIONBLUR); + + for(unsigned int i=0; i<n; i++) + { + m_boost_time[i] = 0.0f; + + const core::recti &vp = Camera::getCamera(i)->getViewport(); + // Map viewport to [-1,1] x [-1,1]. First define the coordinates + // left, right, top, bottom: + float right = vp.LowerRightCorner.X < UserConfigParams::m_width + ? 0.0f : 1.0f; + float left = vp.UpperLeftCorner.X > 0.0f ? 0.0f : -1.0f; + float top = vp.UpperLeftCorner.Y > 0.0f ? 0.0f : 1.0f; + float bottom = vp.LowerRightCorner.Y < UserConfigParams::m_height + ? 0.0f : -1.0f; + + // Use left etc to define 4 vertices on which the rendered screen + // will be displayed: + m_vertices[i].v0.Pos = core::vector3df(left, bottom, 0); + m_vertices[i].v1.Pos = core::vector3df(left, top, 0); + m_vertices[i].v2.Pos = core::vector3df(right, top, 0); + m_vertices[i].v3.Pos = core::vector3df(right, bottom, 0); + // Define the texture coordinates of each vertex, which must + // be in [0,1]x[0,1] + m_vertices[i].v0.TCoords = core::vector2df(left ==-1.0f ? 0.0f : 0.5f, + bottom==-1.0f ? 0.0f : 0.5f); + m_vertices[i].v1.TCoords = core::vector2df(left ==-1.0f ? 0.0f : 0.5f, + top == 1.0f ? 1.0f : 0.5f); + m_vertices[i].v2.TCoords = core::vector2df(right == 0.0f ? 0.5f : 1.0f, + top == 1.0f ? 1.0f : 0.5f); + m_vertices[i].v3.TCoords = core::vector2df(right == 0.0f ? 0.5f : 1.0f, + bottom==-1.0f ? 0.0f : 0.5f); + // Set normal and color: + core::vector3df normal(0,0,1); + m_vertices[i].v0.Normal = m_vertices[i].v1.Normal = + m_vertices[i].v2.Normal = m_vertices[i].v3.Normal = normal; + SColor white(0xFF, 0xFF, 0xFF, 0xFF); + m_vertices[i].v0.Color = m_vertices[i].v1.Color = + m_vertices[i].v2.Color = m_vertices[i].v3.Color = white; + + m_center[i].X=(m_vertices[i].v0.TCoords.X + +m_vertices[i].v2.TCoords.X) * 0.5f; + + // Center is around 20 percent from bottom of screen: + const float tex_height = m_vertices[i].v1.TCoords.Y + - m_vertices[i].v0.TCoords.Y; + m_direction[i].X = m_center[i].X; + m_direction[i].Y = m_vertices[i].v0.TCoords.Y + 0.7f*tex_height; + + setMotionBlurCenterY(i, 0.2f); + + cb->setDirection(i, m_direction[i].X, m_direction[i].Y); + cb->setMaxHeight(i, m_vertices[i].v1.TCoords.Y); + } // for i <number of cameras +} // reset + +void PostProcessing::setMotionBlurCenterY(const u32 num, const float y) +{ + MotionBlurProvider * const cb = (MotionBlurProvider *) irr_driver-> + getCallback(ES_MOTIONBLUR); + + const float tex_height = m_vertices[num].v1.TCoords.Y - m_vertices[num].v0.TCoords.Y; + m_center[num].Y = m_vertices[num].v0.TCoords.Y + y * tex_height; + + cb->setCenter(num, m_center[num].X, m_center[num].Y); +} + +// ---------------------------------------------------------------------------- +/** Setup some PP data. + */ +void PostProcessing::begin() +{ + m_any_boost = false; + for (u32 i = 0; i < m_boost_time.size(); i++) + m_any_boost |= m_boost_time[i] > 0.01f; +} // beginCapture + +// ---------------------------------------------------------------------------- +/** Set the boost amount according to the speed of the camera */ +void PostProcessing::giveBoost(unsigned int camera_index) +{ + if (irr_driver->isGLSL()) + { + m_boost_time[camera_index] = 0.75f; + + MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver-> + getCallback(ES_MOTIONBLUR); + cb->setBoostTime(camera_index, m_boost_time[camera_index]); + } +} // giveBoost + +// ---------------------------------------------------------------------------- +/** Updates the boost times for all cameras, called once per frame. + * \param dt Time step size. + */ +void PostProcessing::update(float dt) +{ + if (!irr_driver->isGLSL()) + return; + + MotionBlurProvider* const cb = + (MotionBlurProvider*) irr_driver->getCallback(ES_MOTIONBLUR); + + if (cb == NULL) return; + + for (unsigned int i=0; i<m_boost_time.size(); i++) + { + if (m_boost_time[i] > 0.0f) + { + m_boost_time[i] -= dt; + if (m_boost_time[i] < 0.0f) m_boost_time[i] = 0.0f; + } + + cb->setBoostTime(i, m_boost_time[i]); + } +} // update + +// ---------------------------------------------------------------------------- +/** Render the post-processed scene, solids only, color to color, no stencil */ +void PostProcessing::renderSolid(const u32 cam) +{ + if (!irr_driver->isGLSL()) return; + + IVideoDriver * const drv = irr_driver->getVideoDriver(); + if (World::getWorld()->getTrack()->isFogEnabled()) + { + m_material.MaterialType = irr_driver->getShader(ES_FOG); + m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); + + // Overlay + m_material.BlendOperation = EBO_ADD; + m_material.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA); + + drv->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false); + drawQuad(cam, m_material); + + m_material.BlendOperation = EBO_NONE; + m_material.MaterialTypeParam = 0; + } +} + +GLuint quad_vbo = 0; + +static void initQuadVBO() +{ + initGL(); + const float quad_vertex[] = { + -1., -1., 0., 0., // UpperLeft + -1., 1., 0., 1., // LowerLeft + 1., -1., 1., 0., // UpperRight + 1., 1., 1., 1., // LowerRight + }; + glGenBuffers(1, &quad_vbo); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +namespace BloomShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_texture, uniform_low; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/bloom.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_texture = glGetUniformLocation(Program, "tex"); + uniform_low = glGetUniformLocation(Program, "low"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + +namespace BloomBlendShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_texture, uniform_low; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/bloomblend.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_texture = glGetUniformLocation(Program, "tex"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + +namespace PPDisplaceShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_tex, uniform_dtex, uniform_viz; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/ppdisplace.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_viz = glGetUniformLocation(Program, "viz"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + +namespace ColorLevelShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_tex, uniform_inlevel, uniform_outlevel; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/color_levels.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_inlevel = glGetUniformLocation(Program, "inlevel"); + uniform_outlevel = glGetUniformLocation(Program, "outlevel"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + +namespace PointLightShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_ntex, uniform_center, uniform_col, uniform_energy, uniform_spec, uniform_screen, uniform_invproj, uniform_viewm; + + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/pointlight.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_center = glGetUniformLocation(Program, "center[0]"); + uniform_col = glGetUniformLocation(Program, "col[0]"); + uniform_energy = glGetUniformLocation(Program, "energy[0]"); + uniform_spec = glGetUniformLocation(Program, "spec"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + uniform_viewm = glGetUniformLocation(Program, "viewm"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + + +static +void renderBloom(ITexture *in) +{ + if (!BloomShader::Program) + BloomShader::init(); + + const float threshold = World::getWorld()->getTrack()->getBloomThreshold(); + glUseProgram(BloomShader::Program); + glBindVertexArray(BloomShader::vao); + glUniform1f(BloomShader::uniform_low, threshold); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(BloomShader::uniform_texture, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + +static +void renderBloomBlend(ITexture *in) +{ + if (!BloomBlendShader::Program) + BloomBlendShader::init(); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glDisable(GL_DEPTH_TEST); + + glUseProgram(BloomBlendShader::Program); + glBindVertexArray(BloomBlendShader::vao); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(BloomBlendShader::uniform_texture, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); +} + +static +void renderPPDisplace(ITexture *in) +{ + if (!PPDisplaceShader::Program) + PPDisplaceShader::init(); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glDisable(GL_DEPTH_TEST); + + glUseProgram(PPDisplaceShader::Program); + glBindVertexArray(PPDisplaceShader::vao); + glUniform1i(PPDisplaceShader::uniform_viz, irr_driver->getDistortViz()); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(PPDisplaceShader::uniform_tex, 0); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_DISPLACE))->getOpenGLTextureName()); + glUniform1i(PPDisplaceShader::uniform_dtex, 1); + + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); +} + +static +void renderColorLevel(ITexture *in) +{ core::vector3df m_inlevel = World::getWorld()->getTrack()->getColorLevelIn(); - core::vector2df m_outlevel = World::getWorld()->getTrack()->getColorLevelOut(); - - - if (!ColorLevelShader::Program) - ColorLevelShader::init(); - glDisable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - - glUseProgram(ColorLevelShader::Program); - glBindVertexArray(ColorLevelShader::vao); - glUniform3f(ColorLevelShader::uniform_inlevel, m_inlevel.X, m_inlevel.Y, m_inlevel.Z); - glUniform2f(ColorLevelShader::uniform_outlevel, m_outlevel.X, m_outlevel.Y); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); - glUniform1i(ColorLevelShader::uniform_tex, 0); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glEnable(GL_DEPTH_TEST); -} - -// ---------------------------------------------------------------------------- -/** Render the post-processed scene */ -void PostProcessing::render() -{ - if (!irr_driver->isGLSL()) return; - - IVideoDriver * const drv = irr_driver->getVideoDriver(); - drv->setTransform(ETS_WORLD, core::IdentityMatrix); - drv->setTransform(ETS_VIEW, core::IdentityMatrix); - drv->setTransform(ETS_PROJECTION, core::IdentityMatrix); - - MotionBlurProvider * const mocb = (MotionBlurProvider *) irr_driver-> - getCallback(ES_MOTIONBLUR); - GaussianBlurProvider * const gacb = (GaussianBlurProvider *) irr_driver-> - getCallback(ES_GAUSSIAN3H); - - const u32 cams = Camera::getNumCameras(); - for(u32 cam = 0; cam < cams; cam++) - { - scene::ICameraSceneNode * const camnode = - Camera::getCamera(cam)->getCameraSceneNode(); - mocb->setCurrentCamera(cam); - ITexture *in = irr_driver->getRTT(RTT_COLOR); - ITexture *out = irr_driver->getRTT(RTT_TMP1); - // Each effect uses these as named, and sets them up for the next effect. - // This allows chaining effects where some may be disabled. - - // As the original color shouldn't be touched, the first effect can't be disabled. - - if (1) // bloom - { - // Blit the base to tmp1 - m_material.MaterialType = EMT_SOLID; - m_material.setTexture(0, in); - drv->setRenderTarget(out, true, false); - - drawQuad(cam, m_material); - - const bool globalbloom = World::getWorld()->getTrack()->getBloom(); - - BloomPowerProvider * const bloomcb = (BloomPowerProvider *) - irr_driver-> - getCallback(ES_BLOOM_POWER); - - if (globalbloom) - { - drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false); - renderBloom(in); - } - - // Do we have any forced bloom nodes? If so, draw them now - const std::vector<IrrDriver::BloomData> &blooms = irr_driver->getForcedBloom(); - const u32 bloomsize = blooms.size(); - - if (!globalbloom && bloomsize) - drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false); - - - if (globalbloom || bloomsize) - { - // Clear the alpha to a suitable value, stencil - glClearColor(0, 0, 0, 0.1f); - glColorMask(0, 0, 0, 1); - - glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - - glClearColor(0, 0, 0, 0); - glColorMask(1, 1, 1, 1); - - // The forced-bloom objects are drawn again, to know which pixels to pick. - // While it's more drawcalls, there's a cost to using four MRTs over three, - // and there shouldn't be many such objects in a track. - // The stencil is already in use for the glow. The alpha channel is best - // reserved for other use (specular, etc). - // - // They are drawn with depth and color writes off, giving 4x-8x drawing speed. - if (bloomsize) - { - const core::aabbox3df &cambox = camnode-> - getViewFrustum()-> - getBoundingBox(); - - irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_SOLID); - SOverrideMaterial &overridemat = drv->getOverrideMaterial(); - overridemat.EnablePasses = ESNRP_SOLID; - overridemat.EnableFlags = EMF_MATERIAL_TYPE | EMF_ZWRITE_ENABLE | EMF_COLOR_MASK; - overridemat.Enabled = true; - - overridemat.Material.MaterialType = irr_driver->getShader(ES_BLOOM_POWER); - overridemat.Material.ZWriteEnable = false; - overridemat.Material.ColorMask = ECP_ALPHA; - - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, ~0); - glEnable(GL_STENCIL_TEST); - - camnode->render(); - - for (u32 i = 0; i < bloomsize; i++) - { - scene::ISceneNode * const cur = blooms[i].node; - - // Quick box-based culling - const core::aabbox3df nodebox = cur->getTransformedBoundingBox(); - if (!nodebox.intersectsWithBox(cambox)) - continue; - - bloomcb->setPower(blooms[i].power); - - cur->render(); - } - - // Second pass for transparents. No-op for solids. - irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_TRANSPARENT); - for (u32 i = 0; i < bloomsize; i++) - { - scene::ISceneNode * const cur = blooms[i].node; - - // Quick box-based culling - const core::aabbox3df nodebox = cur->getTransformedBoundingBox(); - if (!nodebox.intersectsWithBox(cambox)) - continue; - - bloomcb->setPower(blooms[i].power); - - cur->render(); - } - - overridemat.Enabled = 0; - overridemat.EnablePasses = 0; - - // Ok, we have the stencil; now use it to blit from color to bloom tex - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, 1, ~0); - m_material.MaterialType = EMT_SOLID; - m_material.setTexture(0, irr_driver->getRTT(RTT_COLOR)); - - // Just in case. - glColorMask(1, 1, 1, 0); - drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), false, false); - - m_material.ColorMask = ECP_RGB; - drawQuad(cam, m_material); - m_material.ColorMask = ECP_ALL; - - glColorMask(1, 1, 1, 1); - glDisable(GL_STENCIL_TEST); - } // end forced bloom - - // To half - m_material.MaterialType = EMT_SOLID; - m_material.setTexture(0, irr_driver->getRTT(RTT_TMP3)); - drv->setRenderTarget(irr_driver->getRTT(RTT_HALF1), true, false); - - drawQuad(cam, m_material); - - // To quarter - m_material.MaterialType = EMT_SOLID; - m_material.setTexture(0, irr_driver->getRTT(RTT_HALF1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false); - - drawQuad(cam, m_material); - - // To eighth - m_material.MaterialType = EMT_SOLID; - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), true, false); - - drawQuad(cam, m_material); - - // Blur it for distribution. - { - gacb->setResolution(UserConfigParams::m_width / 8, - UserConfigParams::m_height / 8); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6V); - m_material.setTexture(0, irr_driver->getRTT(RTT_EIGHTH1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH2), true, false); - - drawQuad(cam, m_material); - - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6H); - m_material.setTexture(0, irr_driver->getRTT(RTT_EIGHTH2)); - drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), false, false); - - drawQuad(cam, m_material); - } - - // Additively blend on top of tmp1 - drv->setRenderTarget(out, false, false); - renderBloomBlend(irr_driver->getRTT(RTT_EIGHTH1)); - } // end if bloom - - in = irr_driver->getRTT(RTT_TMP1); - out = irr_driver->getRTT(RTT_TMP2); - } - - if (World::getWorld()->getTrack()->hasGodRays() && m_sunpixels > 30) // god rays - { - // Grab the sky - drv->setRenderTarget(out, true, false); - irr_driver->getSceneManager()->drawAll(ESNRP_SKY_BOX); - - // Set the sun's color - ColorizeProvider * const colcb = (ColorizeProvider *) irr_driver->getCallback(ES_COLORIZE); - const SColor col = World::getWorld()->getTrack()->getSunColor(); - colcb->setColor(col.getRed() / 255.0f, col.getGreen() / 255.0f, col.getBlue() / 255.0f); - - // The sun interposer - IMeshSceneNode * const sun = irr_driver->getSunInterposer(); - sun->getMaterial(0).ColorMask = ECP_ALL; - irr_driver->getSceneManager()->drawAll(ESNRP_CAMERA); - irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_SOLID); - - sun->render(); - - sun->getMaterial(0).ColorMask = ECP_NONE; - - // Fade to quarter - m_material.MaterialType = irr_driver->getShader(ES_GODFADE); - m_material.setTexture(0, out); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), false, false); - - drawQuad(cam, m_material); - - // Blur - { - gacb->setResolution(UserConfigParams::m_width / 4, - UserConfigParams::m_height / 4); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3V); - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER2), true, false); - - drawQuad(cam, m_material); - - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3H); - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER2)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), false, false); - - drawQuad(cam, m_material); - } - - // Calculate the sun's position in texcoords - const core::vector3df pos = sun->getPosition(); - float ndc[4]; - core::matrix4 trans = camnode->getProjectionMatrix(); - trans *= camnode->getViewMatrix(); - - trans.transformVect(ndc, pos); - - const float texh = m_vertices[cam].v1.TCoords.Y - m_vertices[cam].v0.TCoords.Y; - const float texw = m_vertices[cam].v3.TCoords.X - m_vertices[cam].v0.TCoords.X; - - const float sunx = ((ndc[0] / ndc[3]) * 0.5f + 0.5f) * texw; - const float suny = ((ndc[1] / ndc[3]) * 0.5f + 0.5f) * texh; - - ((GodRayProvider *) irr_driver->getCallback(ES_GODRAY))-> - setSunPosition(sunx, suny); - - // Rays please - m_material.MaterialType = irr_driver->getShader(ES_GODRAY); - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER2), true, false); - - drawQuad(cam, m_material); - - // Blur - { - gacb->setResolution(UserConfigParams::m_width / 4, - UserConfigParams::m_height / 4); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3V); - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER2)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false); - - drawQuad(cam, m_material); - - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3H); - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER2), false, false); - - drawQuad(cam, m_material); - } - - // Overlay - m_material.MaterialType = EMT_TRANSPARENT_ADD_COLOR; - m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER2)); - drv->setRenderTarget(in, false, false); - - drawQuad(cam, m_material); - } - - if (UserConfigParams::m_motionblur && m_any_boost) // motion blur - { - // Calculate the kart's Y position on screen - const core::vector3df pos = - Camera::getCamera(cam)->getKart()->getNode()->getPosition(); - float ndc[4]; - core::matrix4 trans = camnode->getProjectionMatrix(); - trans *= camnode->getViewMatrix(); - - trans.transformVect(ndc, pos); - const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f; - setMotionBlurCenterY(cam, karty); - - - m_material.MaterialType = irr_driver->getShader(ES_MOTIONBLUR); - m_material.setTexture(0, in); - drv->setRenderTarget(out, true, false); - - drawQuad(cam, m_material); - - ITexture *tmp = in; - in = out; - out = tmp; - } - - if (irr_driver->getDisplacingNodes().size()) // Displacement - { - drv->setRenderTarget(out, true, false); - renderPPDisplace(in); - - ITexture *tmp = in; - in = out; - out = tmp; - } - - if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter. - { - drv->setRenderTarget(out, false, false); - - glEnable(GL_STENCIL_TEST); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - glStencilFunc(GL_ALWAYS, 1, ~0); - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - - // Pass 1: color edge detection - m_material.setFlag(EMF_BILINEAR_FILTER, false); - m_material.setFlag(EMF_TRILINEAR_FILTER, false); - m_material.MaterialType = irr_driver->getShader(ES_MLAA_COLOR1); - m_material.setTexture(0, in); - - drawQuad(cam, m_material); - m_material.setFlag(EMF_BILINEAR_FILTER, true); - m_material.setFlag(EMF_TRILINEAR_FILTER, true); - - glStencilFunc(GL_EQUAL, 1, ~0); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - - // Pass 2: blend weights - drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false); - - m_material.MaterialType = irr_driver->getShader(ES_MLAA_BLEND2); - m_material.setTexture(0, out); - m_material.setTexture(1, m_areamap); - m_material.TextureLayer[1].BilinearFilter = false; - m_material.TextureLayer[1].TrilinearFilter = false; - - drawQuad(cam, m_material); - - m_material.TextureLayer[1].BilinearFilter = true; - m_material.TextureLayer[1].TrilinearFilter = true; - m_material.setTexture(1, 0); - - // Pass 3: gather - drv->setRenderTarget(in, false, false); - - m_material.setFlag(EMF_BILINEAR_FILTER, false); - m_material.setFlag(EMF_TRILINEAR_FILTER, false); - m_material.MaterialType = irr_driver->getShader(ES_MLAA_NEIGH3); - m_material.setTexture(0, irr_driver->getRTT(RTT_TMP3)); - m_material.setTexture(1, irr_driver->getRTT(RTT_COLOR)); - - drawQuad(cam, m_material); - - m_material.setFlag(EMF_BILINEAR_FILTER, true); - m_material.setFlag(EMF_TRILINEAR_FILTER, true); - m_material.setTexture(1, 0); - - // Done. - glDisable(GL_STENCIL_TEST); - } - - // Final blit - drv->setRenderTarget(ERT_FRAME_BUFFER, false, false); - if (irr_driver->getNormals()) - { - m_material.MaterialType = irr_driver->getShader(ES_FLIP); - m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - drawQuad(cam, m_material); - } else if (irr_driver->getSSAOViz()) - { - m_material.MaterialType = irr_driver->getShader(ES_FLIP); - m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO)); - drawQuad(cam, m_material); - } else if (irr_driver->getShadowViz()) - { - m_material.MaterialType = irr_driver->getShader(ES_FLIP); - m_material.setTexture(0, irr_driver->getRTT(RTT_DISPLACE)); - drawQuad(cam, m_material); - } else - { - renderColorLevel(in); - } - } -} // render - -void PostProcessing::drawQuad(u32 cam, const SMaterial &mat) -{ - const u16 indices[6] = {0, 1, 2, 3, 0, 2}; - IVideoDriver * const drv = irr_driver->getVideoDriver(); - - drv->setTransform(ETS_WORLD, core::IdentityMatrix); - drv->setTransform(ETS_VIEW, core::IdentityMatrix); - drv->setTransform(ETS_PROJECTION, core::IdentityMatrix); - - drv->setMaterial(mat); - drv->drawIndexedTriangleList(&(m_vertices[cam].v0), - 4, indices, 2); -} + core::vector2df m_outlevel = World::getWorld()->getTrack()->getColorLevelOut(); + + + if (!ColorLevelShader::Program) + ColorLevelShader::init(); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + + glUseProgram(ColorLevelShader::Program); + glBindVertexArray(ColorLevelShader::vao); + glUniform3f(ColorLevelShader::uniform_inlevel, m_inlevel.X, m_inlevel.Y, m_inlevel.Z); + glUniform2f(ColorLevelShader::uniform_outlevel, m_outlevel.X, m_outlevel.Y); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(ColorLevelShader::uniform_tex, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); +} + +void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy) +{ + float width = (float)UserConfigParams::m_width; + float height = (float)UserConfigParams::m_height; + if (!PointLightShader::Program) + PointLightShader::init(); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + + glUseProgram(PointLightShader::Program); + glBindVertexArray(PointLightShader::vao); + + glUniform4fv(PointLightShader::uniform_center, 16, positions.data()); + glUniform4fv(PointLightShader::uniform_col, 16, colors.data()); + glUniform1fv(PointLightShader::uniform_energy, 16, energy.data()); + glUniform1f(PointLightShader::uniform_spec, 200); + glUniform2f(PointLightShader::uniform_screen, width, height); + glUniformMatrix4fv(PointLightShader::uniform_invproj, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer()); + glUniformMatrix4fv(PointLightShader::uniform_viewm, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(PointLightShader::uniform_ntex, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); +} + +// ---------------------------------------------------------------------------- +/** Render the post-processed scene */ +void PostProcessing::render() +{ + if (!irr_driver->isGLSL()) return; + + IVideoDriver * const drv = irr_driver->getVideoDriver(); + drv->setTransform(ETS_WORLD, core::IdentityMatrix); + drv->setTransform(ETS_VIEW, core::IdentityMatrix); + drv->setTransform(ETS_PROJECTION, core::IdentityMatrix); + + MotionBlurProvider * const mocb = (MotionBlurProvider *) irr_driver-> + getCallback(ES_MOTIONBLUR); + GaussianBlurProvider * const gacb = (GaussianBlurProvider *) irr_driver-> + getCallback(ES_GAUSSIAN3H); + + const u32 cams = Camera::getNumCameras(); + for(u32 cam = 0; cam < cams; cam++) + { + scene::ICameraSceneNode * const camnode = + Camera::getCamera(cam)->getCameraSceneNode(); + mocb->setCurrentCamera(cam); + ITexture *in = irr_driver->getRTT(RTT_COLOR); + ITexture *out = irr_driver->getRTT(RTT_TMP1); + // Each effect uses these as named, and sets them up for the next effect. + // This allows chaining effects where some may be disabled. + + // As the original color shouldn't be touched, the first effect can't be disabled. + + if (1) // bloom + { + // Blit the base to tmp1 + m_material.MaterialType = EMT_SOLID; + m_material.setTexture(0, in); + drv->setRenderTarget(out, true, false); + + drawQuad(cam, m_material); + + const bool globalbloom = World::getWorld()->getTrack()->getBloom(); + + BloomPowerProvider * const bloomcb = (BloomPowerProvider *) + irr_driver-> + getCallback(ES_BLOOM_POWER); + + if (globalbloom) + { + drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false); + renderBloom(in); + } + + // Do we have any forced bloom nodes? If so, draw them now + const std::vector<IrrDriver::BloomData> &blooms = irr_driver->getForcedBloom(); + const u32 bloomsize = blooms.size(); + + if (!globalbloom && bloomsize) + drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false); + + + if (globalbloom || bloomsize) + { + // Clear the alpha to a suitable value, stencil + glClearColor(0, 0, 0, 0.1f); + glColorMask(0, 0, 0, 1); + + glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + + glClearColor(0, 0, 0, 0); + glColorMask(1, 1, 1, 1); + + // The forced-bloom objects are drawn again, to know which pixels to pick. + // While it's more drawcalls, there's a cost to using four MRTs over three, + // and there shouldn't be many such objects in a track. + // The stencil is already in use for the glow. The alpha channel is best + // reserved for other use (specular, etc). + // + // They are drawn with depth and color writes off, giving 4x-8x drawing speed. + if (bloomsize) + { + const core::aabbox3df &cambox = camnode-> + getViewFrustum()-> + getBoundingBox(); + + irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_SOLID); + SOverrideMaterial &overridemat = drv->getOverrideMaterial(); + overridemat.EnablePasses = ESNRP_SOLID; + overridemat.EnableFlags = EMF_MATERIAL_TYPE | EMF_ZWRITE_ENABLE | EMF_COLOR_MASK; + overridemat.Enabled = true; + + overridemat.Material.MaterialType = irr_driver->getShader(ES_BLOOM_POWER); + overridemat.Material.ZWriteEnable = false; + overridemat.Material.ColorMask = ECP_ALPHA; + + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + glStencilFunc(GL_ALWAYS, 1, ~0); + glEnable(GL_STENCIL_TEST); + + camnode... [truncated message content] |
From: <vin...@us...> - 2014-01-13 13:07:17
|
Revision: 15037 http://sourceforge.net/p/supertuxkart/code/15037 Author: vincentlj Date: 2014-01-13 13:07:12 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Clean PointLight Provider and snow provider. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/light.cpp main/trunk/src/graphics/light.hpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -269,15 +269,6 @@ //------------------------------------- -void SnowEffectProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; - - srv->setVertexShaderConstant("time", &time, 1); -} - -//------------------------------------- - void MotionBlurProvider::OnSetConstants(IMaterialRendererServices *srv, int) { // We need the maximum texture coordinates: @@ -412,30 +403,6 @@ //------------------------------------- -void PointLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - srv->setVertexShaderConstant("screen", m_screen, 2); - srv->setVertexShaderConstant("spec", &m_specular, 1); - srv->setVertexShaderConstant("invproj", irr_driver->getInvProjMatrix().pointer(), 16); - srv->setVertexShaderConstant("energy[0]", m_energy.data(), m_energy.size()); - srv->setVertexShaderConstant("col[0]", m_color.data(), m_color.size()); - srv->setVertexShaderConstant("center[0]", m_pos.data(), m_pos.size()); - srv->setVertexShaderConstant("viewm", irr_driver->getViewMatrix().pointer(), 16); - - if (!firstdone) - { - int tex = 0; - srv->setVertexShaderConstant("ntex", &tex, 1); - - tex = 1; - srv->setVertexShaderConstant("dtex", &tex, 1); - - firstdone = true; - } -} - -//------------------------------------- - void SunLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) { const int hasclouds = World::getWorld()->getTrack()->hasClouds() && Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -236,14 +236,6 @@ // -class SnowEffectProvider: public CallBase -{ -public: - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); -}; - -// - class MotionBlurProvider: public CallBase { public: @@ -371,49 +363,7 @@ }; // -class PointLightProvider: public CallBase -{ -public: - PointLightProvider() - { - m_screen[0] = (float)UserConfigParams::m_width; - m_screen[1] = (float)UserConfigParams::m_height; - m_specular = 200; - } - - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); - - void setColor(const std::vector<float> &col) - { - m_color = col; - } - - void setPosition(const std::vector<float> &pos) - { - m_pos = pos; - return; - } - - void setSpecular(float s) - { - m_specular = s; - } - - void setEnergy(const std::vector<float> &e) { - m_energy = e; - } - -private: - std::vector<float> m_color; - std::vector<float> m_pos; - std::vector<float> m_energy; - float m_screen[2]; - float m_specular; -}; - -// - class SunLightProvider: public CallBase { public: Modified: main/trunk/src/graphics/light.cpp =================================================================== --- main/trunk/src/graphics/light.cpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/light.cpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -57,45 +57,6 @@ return; } -void LightNode::renderLightSet(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy) -{ - assert (colors.size() == positions.size() && positions.size() == (energy.size() * 4)); - ScreenQuad *sq = new ScreenQuad(irr_driver->getVideoDriver()); - SMaterial &mat = sq->getMaterial(); - - mat.Lighting = false; - mat.MaterialType = irr_driver->getShader(ES_POINTLIGHT); - - mat.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - - for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) - { - mat.TextureLayer[i].TextureWrapU = - mat.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE; - } - - mat.setFlag(EMF_BILINEAR_FILTER, false); - mat.setFlag(EMF_ZWRITE_ENABLE, false); - - mat.MaterialTypeParam = pack_textureBlendFunc(EBF_ONE, EBF_ONE); - mat.BlendOperation = EBO_ADD; - - PointLightProvider * const cb = (PointLightProvider *) irr_driver->getCallback(ES_POINTLIGHT); - cb->setColor(colors); - cb->setPosition(positions); - cb->setEnergy(energy); - // Irrlicht's ScreenQuad reset the matrixes, we need to keep them - IVideoDriver * const drv = irr_driver->getVideoDriver(); - matrix4 tmpworld = drv->getTransform(ETS_WORLD); - matrix4 tmpview = drv->getTransform(ETS_VIEW); - matrix4 tmpproj = drv->getTransform(ETS_PROJECTION); - sq->render(false); - drv->setTransform(ETS_WORLD, tmpworld); - drv->setTransform(ETS_VIEW, tmpview); - drv->setTransform(ETS_PROJECTION, tmpproj); - return; -} - void LightNode::OnRegisterSceneNode() { // This node is only drawn manually. Modified: main/trunk/src/graphics/light.hpp =================================================================== --- main/trunk/src/graphics/light.hpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/light.hpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -44,7 +44,6 @@ virtual ~LightNode(); virtual void render() OVERRIDE; - static void renderLightSet(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); virtual const core::aabbox3d<f32>& getBoundingBox() const OVERRIDE { Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -47,7 +47,6 @@ m_callbacks[ES_GLOW] = new GlowProvider(); m_callbacks[ES_OBJECTPASS] = new ObjectPassProvider(); m_callbacks[ES_LIGHTBLEND] = new LightBlendProvider(); - m_callbacks[ES_POINTLIGHT] = new PointLightProvider(); m_callbacks[ES_SUNLIGHT] = new SunLightProvider(); m_callbacks[ES_MLAA_COLOR1] = new MLAAColor1Provider(); m_callbacks[ES_MLAA_BLEND2] = new MLAABlend2Provider(); @@ -160,9 +159,6 @@ m_shaders[ES_LIGHTBLEND] = glslmat(dir + "pass.vert", dir + "lightblend.frag", m_callbacks[ES_LIGHTBLEND], EMT_ONETEXTURE_BLEND); - m_shaders[ES_POINTLIGHT] = glslmat(dir + "pass.vert", dir + "pointlight.frag", - m_callbacks[ES_POINTLIGHT], EMT_ONETEXTURE_BLEND); - m_shaders[ES_SUNLIGHT] = glslmat(std::string(""), dir + "sunlight.frag", m_callbacks[ES_SUNLIGHT], EMT_SOLID); m_shaders[ES_SUNLIGHT_SHADOW] = glslmat(dir + "pass.vert", dir + "sunlightshadow.frag", Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 12:56:27 UTC (rev 15036) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 13:07:12 UTC (rev 15037) @@ -50,7 +50,6 @@ ACT(ES_OBJECTPASS) \ ACT(ES_OBJECTPASS_REF) \ ACT(ES_LIGHTBLEND) \ - ACT(ES_POINTLIGHT) \ ACT(ES_SUNLIGHT) \ ACT(ES_SUNLIGHT_SHADOW) \ ACT(ES_OBJECTPASS_RIMLIT) \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 13:39:03
|
Revision: 15039 http://sourceforge.net/p/supertuxkart/code/15039 Author: vincentlj Date: 2014-01-13 13:38:59 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Lights: Also use direct calls for lightblend. Modified Paths: -------------- main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp main/trunk/src/graphics/render.cpp Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-13 13:15:51 UTC (rev 15038) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-13 13:38:59 UTC (rev 15039) @@ -393,7 +393,40 @@ } } +namespace LightBlendShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_diffuse, uniform_specular, uniform_ambient_occlusion, uniform_specular_map, uniform_ambient; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/lightblend.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_diffuse = glGetUniformLocation(Program, "diffuse"); + uniform_specular = glGetUniformLocation(Program, "specular"); + uniform_ambient_occlusion = glGetUniformLocation(Program, "ambient_occlusion"); + uniform_specular_map = glGetUniformLocation(Program, "specular_map"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + + static void renderBloom(ITexture *in) { @@ -533,6 +566,45 @@ glDisable(GL_BLEND); } +void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug) +{ + const SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + if (!LightBlendShader::Program) + LightBlendShader::init(); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + if (debug) + glBlendFunc(GL_ONE, GL_ZERO); + else + glBlendFunc(GL_DST_COLOR, GL_ZERO); + glDisable(GL_DEPTH_TEST); + + glUseProgram(LightBlendShader::Program); + glBindVertexArray(LightBlendShader::vao); + + glUniform3f(LightBlendShader::uniform_ambient, s.r, s.g, s.b); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(diffuse)->getOpenGLTextureName()); + glUniform1i(LightBlendShader::uniform_diffuse, 0); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specular)->getOpenGLTextureName()); + glUniform1i(LightBlendShader::uniform_specular, 1); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(ao)->getOpenGLTextureName()); + glUniform1i(LightBlendShader::uniform_ambient_occlusion, 2); + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specmap)->getOpenGLTextureName()); + glUniform1i(LightBlendShader::uniform_specular_map, 3); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); +} + // ---------------------------------------------------------------------------- /** Render the post-processed scene */ void PostProcessing::render() Modified: main/trunk/src/graphics/post_processing.hpp =================================================================== --- main/trunk/src/graphics/post_processing.hpp 2014-01-13 13:15:51 UTC (rev 15038) +++ main/trunk/src/graphics/post_processing.hpp 2014-01-13 13:38:59 UTC (rev 15039) @@ -78,6 +78,9 @@ /** Generate diffuse and specular map */ void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); + /** Blend all light related map */ + void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug); + /** Render the post-processed scene */ void render(); Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 13:15:51 UTC (rev 15038) +++ main/trunk/src/graphics/render.cpp 2014-01-13 13:38:59 UTC (rev 15039) @@ -808,30 +808,9 @@ m_post_processing->drawQuad(cam, m_material); } - // Blend lights to the image - video::SMaterial lightmat; - lightmat.Lighting = false; - lightmat.ZWriteEnable = false; - lightmat.ZBuffer = video::ECFN_ALWAYS; - lightmat.setFlag(video::EMF_BILINEAR_FILTER, false); - lightmat.setTexture(0, m_rtts->getRTT(RTT_TMP1)); - lightmat.setTexture(1, m_rtts->getRTT(RTT_TMP2)); - lightmat.setTexture(2, m_rtts->getRTT(RTT_SSAO)); - lightmat.setTexture(3, m_rtts->getRTT(RTT_SPECULARMAP)); - - lightmat.MaterialType = m_shaders->getShader(ES_LIGHTBLEND); - if (!m_lightviz) - lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_DST_COLOR, video::EBF_ZERO); - else - lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_ONE, video::EBF_ZERO); - lightmat.BlendOperation = video::EBO_ADD; - - lightmat.TextureLayer[0].TextureWrapU = - lightmat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); if (!m_mipviz) - m_post_processing->drawQuad(cam, lightmat); + m_post_processing->renderLightbBlend(m_rtts->getRTT(RTT_TMP1), m_rtts->getRTT(RTT_TMP2), m_rtts->getRTT(RTT_SSAO), m_rtts->getRTT(RTT_SPECULARMAP), m_lightviz); } // ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 13:43:22
|
Revision: 15040 http://sourceforge.net/p/supertuxkart/code/15040 Author: vincentlj Date: 2014-01-13 13:43:18 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Lights: Clean lightblend provider. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 13:38:59 UTC (rev 15039) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 13:43:18 UTC (rev 15040) @@ -384,25 +384,6 @@ //------------------------------------- -void LightBlendProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - const SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - - float ambient[3] = { s.r, s.g, s.b }; - srv->setVertexShaderConstant("ambient", ambient, 3); - - int tex = 0; - srv->setVertexShaderConstant("diffuse", &tex, 1); - tex = 1; - srv->setVertexShaderConstant("specular", &tex, 1); - tex = 2; - srv->setVertexShaderConstant("ambient_occlusion", &tex, 1); - tex = 3; - srv->setVertexShaderConstant("specular_map", &tex, 1); -} - -//------------------------------------- - void SunLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) { const int hasclouds = World::getWorld()->getTrack()->hasClouds() && Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 13:38:59 UTC (rev 15039) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 13:43:18 UTC (rev 15040) @@ -356,14 +356,6 @@ // -class LightBlendProvider: public CallBase -{ -public: - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); -}; - -// - class SunLightProvider: public CallBase { public: Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 13:38:59 UTC (rev 15039) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 13:43:18 UTC (rev 15040) @@ -46,7 +46,6 @@ m_callbacks[ES_COLORIZE] = new ColorizeProvider(); m_callbacks[ES_GLOW] = new GlowProvider(); m_callbacks[ES_OBJECTPASS] = new ObjectPassProvider(); - m_callbacks[ES_LIGHTBLEND] = new LightBlendProvider(); m_callbacks[ES_SUNLIGHT] = new SunLightProvider(); m_callbacks[ES_MLAA_COLOR1] = new MLAAColor1Provider(); m_callbacks[ES_MLAA_BLEND2] = new MLAABlend2Provider(); @@ -156,9 +155,6 @@ m_shaders[ES_OBJECTPASS_RIMLIT] = glslmat(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag", m_callbacks[ES_OBJECTPASS], EMT_SOLID); - m_shaders[ES_LIGHTBLEND] = glslmat(dir + "pass.vert", dir + "lightblend.frag", - m_callbacks[ES_LIGHTBLEND], EMT_ONETEXTURE_BLEND); - m_shaders[ES_SUNLIGHT] = glslmat(std::string(""), dir + "sunlight.frag", m_callbacks[ES_SUNLIGHT], EMT_SOLID); m_shaders[ES_SUNLIGHT_SHADOW] = glslmat(dir + "pass.vert", dir + "sunlightshadow.frag", Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 13:38:59 UTC (rev 15039) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 13:43:18 UTC (rev 15040) @@ -49,7 +49,6 @@ ACT(ES_GLOW) \ ACT(ES_OBJECTPASS) \ ACT(ES_OBJECTPASS_REF) \ - ACT(ES_LIGHTBLEND) \ ACT(ES_SUNLIGHT) \ ACT(ES_SUNLIGHT_SHADOW) \ ACT(ES_OBJECTPASS_RIMLIT) \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 14:23:35
|
Revision: 15041 http://sourceforge.net/p/supertuxkart/code/15041 Author: vincentlj Date: 2014-01-13 14:23:30 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Use direct call for Gaussian 6 Blur. Modified Paths: -------------- main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp main/trunk/src/graphics/render.cpp Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-13 13:43:18 UTC (rev 15040) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-13 14:23:30 UTC (rev 15041) @@ -426,7 +426,65 @@ } } +namespace Gaussian6HBlurShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_tex, uniform_pixel; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/gaussian6h.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + +namespace Gaussian6VBlurShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_tex, uniform_pixel; + + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/gaussian6v.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + + static void renderBloom(ITexture *in) { @@ -605,6 +663,46 @@ glDisable(GL_BLEND); } +void PostProcessing::renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height) +{ + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + { + if (!Gaussian6VBlurShader::Program) + Gaussian6VBlurShader::init(); + irr_driver->getVideoDriver()->setRenderTarget(temprtt, false, false); + glUseProgram(Gaussian6VBlurShader::Program); + glBindVertexArray(Gaussian6VBlurShader::vao); + + glUniform2f(Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glUniform1i(Gaussian6VBlurShader::uniform_tex, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + { + if (!Gaussian6HBlurShader::Program) + Gaussian6HBlurShader::init(); + irr_driver->getVideoDriver()->setRenderTarget(in, false, false); + glUseProgram(Gaussian6HBlurShader::Program); + glBindVertexArray(Gaussian6HBlurShader::vao); + + glUniform2f(Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(temprtt)->getOpenGLTextureName()); + glUniform1i(Gaussian6HBlurShader::uniform_tex, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); +} + // ---------------------------------------------------------------------------- /** Render the post-processed scene */ void PostProcessing::render() @@ -776,25 +874,14 @@ drawQuad(cam, m_material); // Blur it for distribution. - { - gacb->setResolution(UserConfigParams::m_width / 8, - UserConfigParams::m_height / 8); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6V); - m_material.setTexture(0, irr_driver->getRTT(RTT_EIGHTH1)); - drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH2), true, false); + renderGaussian6Blur(irr_driver->getRTT(RTT_EIGHTH1), irr_driver->getRTT(RTT_EIGHTH2), 8.f / UserConfigParams::m_width, 8.f / UserConfigParams::m_height); - drawQuad(cam, m_material); - - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6H); - m_material.setTexture(0, irr_driver->getRTT(RTT_EIGHTH2)); - drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), false, false); - - drawQuad(cam, m_material); - } - // Additively blend on top of tmp1 drv->setRenderTarget(out, false, false); renderBloomBlend(irr_driver->getRTT(RTT_EIGHTH1)); + m_material.MaterialType = irr_driver->getShader(ES_RAIN); + drv->setMaterial(m_material); + static_cast<irr::video::COpenGLDriver*>(drv)->setRenderStates3DMode(); } // end if bloom in = irr_driver->getRTT(RTT_TMP1); Modified: main/trunk/src/graphics/post_processing.hpp =================================================================== --- main/trunk/src/graphics/post_processing.hpp 2014-01-13 13:43:18 UTC (rev 15040) +++ main/trunk/src/graphics/post_processing.hpp 2014-01-13 14:23:30 UTC (rev 15041) @@ -81,6 +81,9 @@ /** Blend all light related map */ void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug); + /** Blur the in texture */ + void renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height); + /** Render the post-processed scene */ void render(); Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 13:43:18 UTC (rev 15040) +++ main/trunk/src/graphics/render.cpp 2014-01-13 14:23:30 UTC (rev 15041) @@ -794,20 +794,9 @@ m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER4)); m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false); m_post_processing->drawQuad(cam, m_material); - } else if (UserConfigParams::m_ssao == 2) { - gacb->setResolution(UserConfigParams::m_width, - UserConfigParams::m_height); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6V); - m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO)); - m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_TMP4), true, false); - m_post_processing->drawQuad(cam, m_material); + } else if (UserConfigParams::m_ssao == 2) + m_post_processing->renderGaussian6Blur(irr_driver->getRTT(RTT_SSAO), irr_driver->getRTT(RTT_TMP4), 1.f / UserConfigParams::m_width, 1.f / UserConfigParams::m_height); - m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6H); - m_material.setTexture(0, irr_driver->getRTT(RTT_TMP4)); - m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false); - m_post_processing->drawQuad(cam, m_material); - } - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); if (!m_mipviz) m_post_processing->renderLightbBlend(m_rtts->getRTT(RTT_TMP1), m_rtts->getRTT(RTT_TMP2), m_rtts->getRTT(RTT_SSAO), m_rtts->getRTT(RTT_SPECULARMAP), m_lightviz); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 14:31:34
|
Revision: 15042 http://sourceforge.net/p/supertuxkart/code/15042 Author: vincentlj Date: 2014-01-13 14:31:31 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Clean GaussianBlur6 shaders. Modified Paths: -------------- main/trunk/src/graphics/render.cpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 14:23:30 UTC (rev 15041) +++ main/trunk/src/graphics/render.cpp 2014-01-13 14:31:31 UTC (rev 15042) @@ -502,13 +502,13 @@ m_rtts->getRTT(RTT_WARPV)->getSize().Height, m_rtts->getRTT(RTT_WARPV)->getSize().Height); - sq.setMaterialType(m_shaders->getShader(ES_GAUSSIAN6H)); +/* sq.setMaterialType(m_shaders->getShader(ES_GAUSSIAN6H)); sq.setTexture(m_rtts->getRTT(RTT_WARPH)); sq.render(m_rtts->getRTT(curh)); sq.setMaterialType(m_shaders->getShader(ES_GAUSSIAN6V)); sq.setTexture(m_rtts->getRTT(RTT_WARPV)); - sq.render(m_rtts->getRTT(curv)); + sq.render(m_rtts->getRTT(curv));*/ // Convert importance maps to warp maps // @@ -649,20 +649,8 @@ m_post_processing->drawQuad(cam, minimat); // Blur it - ((GaussianBlurProvider *) m_shaders->m_callbacks[ES_GAUSSIAN3H])->setResolution( - UserConfigParams::m_width / 4, - UserConfigParams::m_height / 4); + m_post_processing->renderGaussian6Blur(m_rtts->getRTT(RTT_QUARTER1), m_rtts->getRTT(RTT_QUARTER2), 4.f / UserConfigParams::m_width, 4.f / UserConfigParams::m_height); - minimat.MaterialType = m_shaders->getShader(ES_GAUSSIAN6H); - minimat.setTexture(0, m_rtts->getRTT(RTT_QUARTER1)); - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_QUARTER2), false, false); - m_post_processing->drawQuad(cam, minimat); - - minimat.MaterialType = m_shaders->getShader(ES_GAUSSIAN6V); - minimat.setTexture(0, m_rtts->getRTT(RTT_QUARTER2)); - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_QUARTER1), false, false); - m_post_processing->drawQuad(cam, minimat); - // The glows will be rendered in the transparent phase m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 14:23:30 UTC (rev 15041) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 14:31:31 UTC (rev 15042) @@ -122,11 +122,6 @@ m_shaders[ES_GAUSSIAN3V] = glslmat(dir + "pass.vert", dir + "gaussian3v.frag", m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); - m_shaders[ES_GAUSSIAN6H] = glslmat(dir + "pass.vert", dir + "gaussian6h.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); - m_shaders[ES_GAUSSIAN6V] = glslmat(dir + "pass.vert", dir + "gaussian6v.frag", - m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); - m_shaders[ES_MIPVIZ] = glslmat(std::string(""), dir + "mipviz.frag", m_callbacks[ES_MIPVIZ], EMT_SOLID); Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 14:23:30 UTC (rev 15041) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 14:31:31 UTC (rev 15042) @@ -40,8 +40,6 @@ ACT(ES_MIPVIZ) \ ACT(ES_FLIP) \ ACT(ES_FLIP_ADDITIVE) \ - ACT(ES_GAUSSIAN6H) \ - ACT(ES_GAUSSIAN6V) \ ACT(ES_COLORIZE) \ ACT(ES_COLORIZE_REF) \ ACT(ES_PASS) \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 15:28:41
|
Revision: 15046 http://sourceforge.net/p/supertuxkart/code/15046 Author: vincentlj Date: 2014-01-13 15:28:37 +0000 (Mon, 13 Jan 2014) Log Message: ----------- OGL32CTX: Some fixes. The track is now displayed (even with light) but not the karts, animations... Modified Paths: -------------- main/trunk/src/graphics/glwrap.cpp main/trunk/src/graphics/stkmesh.cpp Modified: main/trunk/src/graphics/glwrap.cpp =================================================================== --- main/trunk/src/graphics/glwrap.cpp 2014-01-13 15:22:58 UTC (rev 15045) +++ main/trunk/src/graphics/glwrap.cpp 2014-01-13 15:28:37 UTC (rev 15046) @@ -174,7 +174,7 @@ glUniform1fv = (PFNGLUNIFORM1FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform1fv"); glUniform4fv = (PFNGLUNIFORM4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fv"); #endif -#if ENABLE_ARB_DEBUG_OUTPUT +#ifdef ENABLE_ARB_DEBUG_OUTPUT glDebugMessageCallbackARB(debugCallback, NULL); #endif const float quad_vertex[] = { Modified: main/trunk/src/graphics/stkmesh.cpp =================================================================== --- main/trunk/src/graphics/stkmesh.cpp 2014-01-13 15:22:58 UTC (rev 15045) +++ main/trunk/src/graphics/stkmesh.cpp 2014-01-13 15:28:37 UTC (rev 15046) @@ -321,14 +321,18 @@ video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType); bool transparent = (rnd && rnd->isTransparent()); +#ifdef OGL32CTX // only render transparent buffer if this is the transparent render pass // and solid only in solid pass -/* if (isObject(material.MaterialType) && !isTransparentPass && !transparent) + if (isObject(material.MaterialType) && !isTransparentPass && !transparent) { initvaostate(GLmeshes[i], material.MaterialType); draw(GLmeshes[i], material.MaterialType); } - else*/ if (transparent == isTransparentPass) + else if (transparent == isTransparentPass) +#else + if (transparent == isTransparentPass) +#endif { driver->setMaterial(material); driver->drawMeshBuffer(mb); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 16:05:50
|
Revision: 15048 http://sourceforge.net/p/supertuxkart/code/15048 Author: vincentlj Date: 2014-01-13 16:05:46 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Remove rain effect provider it's not used anymore. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/shaders.cpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 16:05:26 UTC (rev 15047) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 16:05:46 UTC (rev 15048) @@ -247,28 +247,6 @@ //------------------------------------- -void RainEffectProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - const float screenw = (float)UserConfigParams::m_width; - const float time = irr_driver->getDevice()->getTimer()->getTime() / 90.0f; - const vector3df campos = irr_driver->getSceneManager()->getActiveCamera()->getPosition(); - float screen[2] = { (float)UserConfigParams::m_width, - (float)UserConfigParams::m_height }; - - srv->setVertexShaderConstant("screenw", &screenw, 1); - srv->setVertexShaderConstant("time", &time, 1); - srv->setVertexShaderConstant("viewm", irr_driver->getViewMatrix().pointer(), 16); - srv->setVertexShaderConstant("campos", &campos.X, 3); - srv->setPixelShaderConstant("invproj", irr_driver->getInvProjMatrix().pointer(), 16); - srv->setPixelShaderConstant("screen", screen, 2); - s32 tex = 0; - srv->setPixelShaderConstant("tex", &tex, 1); - tex = 1; - srv->setPixelShaderConstant("normals_and_depth", &tex, 1); -} - -//------------------------------------- - void MotionBlurProvider::OnSetConstants(IMaterialRendererServices *srv, int) { // We need the maximum texture coordinates: Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 16:05:26 UTC (rev 15047) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 16:05:46 UTC (rev 15048) @@ -228,14 +228,6 @@ // -class RainEffectProvider: public CallBase -{ -public: - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); -}; - -// - class MotionBlurProvider: public CallBase { public: Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 16:05:26 UTC (rev 15047) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 16:05:46 UTC (rev 15048) @@ -39,7 +39,6 @@ m_callbacks[ES_WATER] = new WaterShaderProvider(); m_callbacks[ES_GRASS] = new GrassShaderProvider(); m_callbacks[ES_BUBBLES] = new BubbleEffectProvider(); - m_callbacks[ES_RAIN] = new RainEffectProvider(); m_callbacks[ES_MOTIONBLUR] = new MotionBlurProvider(); m_callbacks[ES_GAUSSIAN3V] = m_callbacks[ES_GAUSSIAN3H] = new GaussianBlurProvider(); m_callbacks[ES_MIPVIZ] = new MipVizProvider(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 17:30:29
|
Revision: 15051 http://sourceforge.net/p/supertuxkart/code/15051 Author: vincentlj Date: 2014-01-13 17:30:25 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Use custom gl calls for fog. Modified Paths: -------------- main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp main/trunk/src/graphics/render.cpp Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-13 16:54:48 UTC (rev 15050) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-13 17:30:25 UTC (rev 15051) @@ -199,30 +199,6 @@ } } // update -// ---------------------------------------------------------------------------- -/** Render the post-processed scene, solids only, color to color, no stencil */ -void PostProcessing::renderSolid(const u32 cam) -{ - if (!irr_driver->isGLSL()) return; - - IVideoDriver * const drv = irr_driver->getVideoDriver(); - if (World::getWorld()->getTrack()->isFogEnabled()) - { - m_material.MaterialType = irr_driver->getShader(ES_FOG); - m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - - // Overlay - m_material.BlendOperation = EBO_ADD; - m_material.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA); - - drv->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false); - drawQuad(cam, m_material); - - m_material.BlendOperation = EBO_NONE; - m_material.MaterialTypeParam = 0; - } -} - GLuint quad_vbo = 0; static void initQuadVBO() @@ -570,7 +546,43 @@ } } +namespace FogShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_campos, uniform_ipvmat; + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/fog.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_fogmax = glGetUniformLocation(Program, "fogmax"); + uniform_startH = glGetUniformLocation(Program, "startH"); + uniform_endH = glGetUniformLocation(Program, "endH"); + uniform_start = glGetUniformLocation(Program, "start"); + uniform_end = glGetUniformLocation(Program, "end"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_campos = glGetUniformLocation(Program, "campos"); + uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + } +} + + static void renderBloom(ITexture *in) { @@ -852,6 +864,55 @@ } // ---------------------------------------------------------------------------- +/** Render the post-processed scene, solids only, color to color, no stencil */ +void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat) +{ + irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false); + const Track * const track = World::getWorld()->getTrack(); + + // This function is only called once per frame - thus no need for setters. + const float fogmax = track->getFogMax(); + const float startH = track->getFogStartHeight(); + const float endH = track->getFogEndHeight(); + const float start = track->getFogStart(); + const float end = track->getFogEnd(); + const SColor tmpcol = track->getFogColor(); + + const float col[3] = { tmpcol.getRed() / 255.0f, + tmpcol.getGreen() / 255.0f, + tmpcol.getBlue() / 255.0f }; + + if (!FogShader::Program) + FogShader::init(); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glUseProgram(FogShader::Program); + glBindVertexArray(FogShader::vao); + + glUniform1f(FogShader::uniform_fogmax, fogmax); + glUniform1f(FogShader::uniform_startH, startH); + glUniform1f(FogShader::uniform_endH, endH); + glUniform1f(FogShader::uniform_start, start); + glUniform1f(FogShader::uniform_end, end); + glUniform3f(FogShader::uniform_col, col[0], col[1], col[2]); + glUniform3f(FogShader::uniform_campos, campos.X, campos.Y, campos.Z); + glUniformMatrix4fv(FogShader::uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName()); + glUniform1i(FogShader::uniform_tex, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); +} + +// ---------------------------------------------------------------------------- /** Render the post-processed scene */ void PostProcessing::render() { Modified: main/trunk/src/graphics/post_processing.hpp =================================================================== --- main/trunk/src/graphics/post_processing.hpp 2014-01-13 16:54:48 UTC (rev 15050) +++ main/trunk/src/graphics/post_processing.hpp 2014-01-13 17:30:25 UTC (rev 15051) @@ -72,15 +72,14 @@ void begin(); void update(float dt); - /** Render the post-processed scene, solids only, color to color, no stencil */ - void renderSolid(const u32 cam); - /** Generate diffuse and specular map */ void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); /** Blend all light related map */ void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug); + void renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat); + /** Blur the in texture */ void renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height); void renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height); Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 16:54:48 UTC (rev 15050) +++ main/trunk/src/graphics/render.cpp 2014-01-13 17:30:25 UTC (rev 15051) @@ -255,8 +255,9 @@ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } - // Render the post-processed scene for solids - m_post_processing->renderSolid(cam); + // Render fog on top of solid + if (World::getWorld()->getTrack()->isFogEnabled()) + m_post_processing->renderFog(camnode->getAbsolutePosition(), irr_driver->getInvProjViewMatrix()); // We need to re-render camera due to the per-cam-node hack. m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT | This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 17:37:36
|
Revision: 15052 http://sourceforge.net/p/supertuxkart/code/15052 Author: vincentlj Date: 2014-01-13 17:37:33 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Clean Fog provider. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/render.cpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 17:30:25 UTC (rev 15051) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 17:37:33 UTC (rev 15052) @@ -717,32 +717,4 @@ srv->setVertexShaderConstant("dir2", m_dir2, 2); srv->setVertexShaderConstant("screen", m_screen, 2); -} - -//------------------------------------- - -void FogProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - const Track * const track = World::getWorld()->getTrack(); - - // This function is only called once per frame - thus no need for setters. - const float fogmax = track->getFogMax(); - const float startH = track->getFogStartHeight(); - const float endH = track->getFogEndHeight(); - const float start = track->getFogStart(); - const float end = track->getFogEnd(); - const SColor tmpcol = track->getFogColor(); - - const float col[3] = { tmpcol.getRed() / 255.0f, - tmpcol.getGreen() / 255.0f, - tmpcol.getBlue() / 255.0f }; - - srv->setPixelShaderConstant("fogmax", &fogmax, 1); - srv->setPixelShaderConstant("startH", &startH, 1); - srv->setPixelShaderConstant("endH", &endH, 1); - srv->setPixelShaderConstant("start", &start, 1); - srv->setPixelShaderConstant("end", &end, 1); - srv->setPixelShaderConstant("col", col, 3); - srv->setVertexShaderConstant("ipvmat", m_invprojview.pointer(), 16); - srv->setVertexShaderConstant("campos", m_campos, 3); -} +} \ No newline at end of file Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 17:30:25 UTC (rev 15051) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 17:37:33 UTC (rev 15052) @@ -608,32 +608,4 @@ float m_dir[2], m_dir2[2]; }; -// - -class FogProvider: public CallBase -{ -public: - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); - - void updateIPVMatrix() - { - // Update the campos and IPV matrix, only once per frame since it's costly - const core::vector3df &campos = - irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition(); - m_campos[0] = campos.X; - m_campos[1] = campos.Y; - m_campos[2] = campos.Z; - - const video::IVideoDriver * const drv = irr_driver->getVideoDriver(); - - m_invprojview = drv->getTransform(video::ETS_PROJECTION); - m_invprojview *= drv->getTransform(video::ETS_VIEW); - m_invprojview.makeInverse(); - } - -private: - core::matrix4 m_invprojview; - float m_campos[3]; -}; - #endif Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 17:30:25 UTC (rev 15051) +++ main/trunk/src/graphics/render.cpp 2014-01-13 17:37:33 UTC (rev 15052) @@ -674,11 +674,7 @@ video::SColor(0, 0, 0, 0)); m_scene_manager->drawAll(scene::ESNRP_CAMERA); - FogProvider * const fogcb = (FogProvider *) irr_driver-> - getCallback(ES_FOG); - fogcb->updateIPVMatrix(); - const u32 lightcount = m_lights.size(); const core::vector3df &campos = irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition(); Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 17:30:25 UTC (rev 15051) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 17:37:33 UTC (rev 15052) @@ -59,7 +59,6 @@ m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider(); m_callbacks[ES_CAUSTICS] = new CausticsProvider(); m_callbacks[ES_DISPLACE] = new DisplaceProvider(); - m_callbacks[ES_FOG] = new FogProvider(); for(s32 i=0 ; i < ES_COUNT ; i++) m_shaders[i] = -1; @@ -197,9 +196,6 @@ m_shaders[ES_PASSFAR] = glsl(dir + "farplane.vert", dir + "colorize.frag", m_callbacks[ES_COLORIZE]); - m_shaders[ES_FOG] = glslmat(dir + "pass.vert", dir + "fog.frag", - m_callbacks[ES_FOG], EMT_ONETEXTURE_BLEND); - // Check that all successfully loaded for (s32 i = 0; i < ES_COUNT; i++) { Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 17:30:25 UTC (rev 15051) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 17:37:33 UTC (rev 15052) @@ -67,7 +67,6 @@ ACT(ES_CAUSTICS) \ ACT(ES_DISPLACE) \ ACT(ES_PASSFAR) \ - ACT(ES_FOG) #define ENUM(a) a, #define STR(a) #a, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 17:56:09
|
Revision: 15054 http://sourceforge.net/p/supertuxkart/code/15054 Author: vincentlj Date: 2014-01-13 17:56:05 +0000 (Mon, 13 Jan 2014) Log Message: ----------- SSAO: Use direct gl calls. Modified Paths: -------------- main/trunk/src/graphics/post_processing.cpp main/trunk/src/graphics/post_processing.hpp main/trunk/src/graphics/render.cpp Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-13 17:41:19 UTC (rev 15053) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-13 17:56:05 UTC (rev 15054) @@ -546,6 +546,59 @@ } } +namespace SSAOShader +{ + GLuint Program = 0; + GLuint attrib_position, attrib_texcoord; + GLuint uniform_normals_and_depth, uniform_invprojm, uniform_projm, uniform_samplePoints; + float SSAOSamples[64]; + + GLuint vao = 0; + + void init() + { + initGL(); + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/ssao.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_normals_and_depth = glGetUniformLocation(Program, "normals_and_depth"); + uniform_invprojm = glGetUniformLocation(Program, "invprojm"); + uniform_projm = glGetUniformLocation(Program, "projm"); + uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); + if (!quad_vbo) + initQuadVBO(); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + + for (unsigned i = 0; i < 16; i++) { + // Generate x/y component between -1 and 1 + // Use double to avoid denorm and get a true uniform distribution + double x = rand(); + x /= RAND_MAX; + x = 2 * x - 1; + double y = rand(); + y /= RAND_MAX; + y = 2 * y - 1; + + // compute z so that norm (x,y,z) is one + double z = sqrt(x * x + y * y); + // Norm factor + double w = rand(); + w /= RAND_MAX; + SSAOSamples[4 * i] = (float)x; + SSAOSamples[4 * i + 1] = (float)y; + SSAOSamples[4 * i + 2] = (float)z; + SSAOSamples[4 * i + 3] = (float)w; + } + } +} + namespace FogShader { GLuint Program = 0; @@ -863,8 +916,31 @@ glDisable(GL_BLEND); } -// ---------------------------------------------------------------------------- -/** Render the post-processed scene, solids only, color to color, no stencil */ + +void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm) +{ + if (!SSAOShader::Program) + SSAOShader::init(); + glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + + glUseProgram(SSAOShader::Program); + glBindVertexArray(SSAOShader::vao); + glUniformMatrix4fv(SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer()); + glUniformMatrix4fv(SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer()); + glUniform4fv(SSAOShader::uniform_samplePoints, 16, SSAOShader::SSAOSamples); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName()); + glUniform1i(SSAOShader::uniform_normals_and_depth, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); +} + void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat) { irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false); Modified: main/trunk/src/graphics/post_processing.hpp =================================================================== --- main/trunk/src/graphics/post_processing.hpp 2014-01-13 17:41:19 UTC (rev 15053) +++ main/trunk/src/graphics/post_processing.hpp 2014-01-13 17:56:05 UTC (rev 15054) @@ -79,6 +79,7 @@ void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug); void renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat); + void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm); /** Blur the in texture */ void renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height); Modified: main/trunk/src/graphics/render.cpp =================================================================== --- main/trunk/src/graphics/render.cpp 2014-01-13 17:41:19 UTC (rev 15053) +++ main/trunk/src/graphics/render.cpp 2014-01-13 17:56:05 UTC (rev 15054) @@ -749,16 +749,10 @@ } m_post_processing->renderPointlight(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH) , accumulatedLightPos, accumulatedLightColor, accumulatedLightEnergy); // Handle SSAO - SMaterial m_material; - - m_material.ZWriteEnable = false; - m_material.MaterialType = irr_driver->getShader(ES_SSAO); - m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), true, false, SColor(255, 255, 255, 255)); - m_post_processing->drawQuad(cam, m_material); + m_post_processing->renderSSAO(irr_driver->getInvProjMatrix(), irr_driver->getProjMatrix()); // Blur it to reduce noise. if(UserConfigParams::m_ssao == 1) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 18:02:42
|
Revision: 15055 http://sourceforge.net/p/supertuxkart/code/15055 Author: vincentlj Date: 2014-01-13 18:02:39 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Clean SSAO Provider. Modified Paths: -------------- main/trunk/src/graphics/callbacks.cpp main/trunk/src/graphics/callbacks.hpp main/trunk/src/graphics/shaders.cpp main/trunk/src/graphics/shaders.hpp Modified: main/trunk/src/graphics/callbacks.cpp =================================================================== --- main/trunk/src/graphics/callbacks.cpp 2014-01-13 17:56:05 UTC (rev 15054) +++ main/trunk/src/graphics/callbacks.cpp 2014-01-13 18:02:39 UTC (rev 15055) @@ -496,26 +496,6 @@ //------------------------------------- -void SSAOProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - srv->setPixelShaderConstant("invprojm", irr_driver->getInvProjMatrix().pointer(), 16); - srv->setPixelShaderConstant("projm", irr_driver->getProjMatrix().pointer(), 16); - srv->setPixelShaderConstant("samplePoints[0]", array, 64); - - if (!firstdone) - { - int tex = 0; - srv->setPixelShaderConstant("normals_and_depth", &tex, 1); - - tex = 1; - srv->setPixelShaderConstant("depth", &tex, 1); - - firstdone = true; - } -} - -//------------------------------------- - void GodRayProvider::OnSetConstants(IMaterialRendererServices *srv, int) { srv->setPixelShaderConstant("sunpos", m_sunpos, 2); Modified: main/trunk/src/graphics/callbacks.hpp =================================================================== --- main/trunk/src/graphics/callbacks.hpp 2014-01-13 17:56:05 UTC (rev 15054) +++ main/trunk/src/graphics/callbacks.hpp 2014-01-13 18:02:39 UTC (rev 15055) @@ -422,39 +422,6 @@ // -class SSAOProvider: public CallBase -{ -private: - float array[64]; -public: - SSAOProvider() : CallBase() { - for (unsigned i = 0; i < 16; i++) { - // Generate x/y component between -1 and 1 - // Use double to avoid denorm and get a true uniform distribution - double x = rand(); - x /= RAND_MAX; - x = 2 * x - 1; - double y = rand(); - y /= RAND_MAX; - y = 2 * y - 1; - - // compute z so that norm (x,y,z) is one - double z = sqrt(x * x + y * y); - // Norm factor - double w = rand(); - w /= RAND_MAX; - array[4 * i] = (float)x; - array[4 * i + 1] = (float)y; - array[4 * i + 2] = (float)z; - array[4 * i + 3] = (float)w; - } - } - - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); -}; - -// - class GodRayProvider: public CallBase { public: Modified: main/trunk/src/graphics/shaders.cpp =================================================================== --- main/trunk/src/graphics/shaders.cpp 2014-01-13 17:56:05 UTC (rev 15054) +++ main/trunk/src/graphics/shaders.cpp 2014-01-13 18:02:39 UTC (rev 15055) @@ -49,7 +49,6 @@ m_callbacks[ES_MLAA_COLOR1] = new MLAAColor1Provider(); m_callbacks[ES_MLAA_BLEND2] = new MLAABlend2Provider(); m_callbacks[ES_MLAA_NEIGH3] = new MLAANeigh3Provider(); - m_callbacks[ES_SSAO] = new SSAOProvider(); m_callbacks[ES_GODRAY] = new GodRayProvider(); m_callbacks[ES_SHADOWPASS] = new ShadowPassProvider(); m_callbacks[ES_SHADOW_IMPORTANCE] = new ShadowImportanceProvider(); @@ -155,8 +154,6 @@ m_shaders[ES_MLAA_NEIGH3] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_neigh3.frag", m_callbacks[ES_MLAA_NEIGH3]); - m_shaders[ES_SSAO] = glsl(dir + "pass.vert", dir + "ssao.frag", m_callbacks[ES_SSAO]); - m_shaders[ES_GODFADE] = glsl(std::string(""), dir + "godfade.frag", m_callbacks[ES_COLORIZE]); m_shaders[ES_GODRAY] = glsl(std::string(""), dir + "godray.frag", m_callbacks[ES_GODRAY]); Modified: main/trunk/src/graphics/shaders.hpp =================================================================== --- main/trunk/src/graphics/shaders.hpp 2014-01-13 17:56:05 UTC (rev 15054) +++ main/trunk/src/graphics/shaders.hpp 2014-01-13 18:02:39 UTC (rev 15055) @@ -51,7 +51,6 @@ ACT(ES_MLAA_COLOR1) \ ACT(ES_MLAA_BLEND2) \ ACT(ES_MLAA_NEIGH3) \ - ACT(ES_SSAO) \ ACT(ES_GODFADE) \ ACT(ES_GODRAY) \ ACT(ES_SHADOWPASS) \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-13 23:57:05
|
Revision: 15065 http://sourceforge.net/p/supertuxkart/code/15065 Author: vincentlj Date: 2014-01-13 23:56:59 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Fix windows build Modified Paths: -------------- main/trunk/src/graphics/glwrap.cpp main/trunk/src/graphics/glwrap.hpp Modified: main/trunk/src/graphics/glwrap.cpp =================================================================== --- main/trunk/src/graphics/glwrap.cpp 2014-01-13 23:19:47 UTC (rev 15064) +++ main/trunk/src/graphics/glwrap.cpp 2014-01-13 23:56:59 UTC (rev 15065) @@ -50,6 +50,7 @@ PFNGLBINDVERTEXARRAYPROC glBindVertexArray; PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; PFNGLTEXBUFFERPROC glTexBuffer; +PFNGLBUFFERSUBDATAPROC glBufferSubData; #endif static GLuint quad_buffer; @@ -174,6 +175,7 @@ glTexBuffer = (PFNGLTEXBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glTexBuffer"); glUniform1fv = (PFNGLUNIFORM1FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform1fv"); glUniform4fv = (PFNGLUNIFORM4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fv"); + glBufferSubData = (PFNGLBUFFERSUBDATAPROC)IRR_OGL_LOAD_EXTENSION("glBufferSubData"); #endif #ifdef ENABLE_ARB_DEBUG_OUTPUT glDebugMessageCallbackARB(debugCallback, NULL); Modified: main/trunk/src/graphics/glwrap.hpp =================================================================== --- main/trunk/src/graphics/glwrap.hpp 2014-01-13 23:19:47 UTC (rev 15064) +++ main/trunk/src/graphics/glwrap.hpp 2014-01-13 23:56:59 UTC (rev 15065) @@ -73,8 +73,10 @@ extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; extern PFNGLTEXBUFFERPROC glTexBuffer; +extern PFNGLBUFFERSUBDATAPROC glBufferSubData; #endif + // core::rect<s32> needs these includes #include <rect.h> #include "utils/vec3.hpp" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |