From f880d13175f905a77dd506b57feb8247ffa89101 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 20 Jan 2014 01:02:25 +0100 Subject: [PATCH 1/5] Fix FBO related queries with OGL3.2+ --- lib/irrlicht/source/Irrlicht/COpenGLDriver.h | 2 ++ lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.h b/lib/irrlicht/source/Irrlicht/COpenGLDriver.h index c556bd913..4f7f14310 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.h +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.h @@ -142,6 +142,8 @@ namespace video //! queries the features of the driver, returns true if feature is available virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const { + if (feature == EVDF_FRAMEBUFFER_OBJECT) + return true; return FeatureEnabled[feature] && COpenGLExtensionHandler::queryFeature(feature); } diff --git a/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.h b/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.h index effacd7bc..88ca596ab 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.h +++ b/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.h @@ -930,6 +930,8 @@ class COpenGLExtensionHandler //! queries the features of the driver, returns true if feature is available bool queryOpenGLFeature(EOpenGLFeatures feature) const { + if (COpenGLExtensionHandler::IRR_EXT_packed_depth_stencil) + return true; return FeatureAvailable[feature]; } From 271a26eaf0b3e05e5445f446a80f107633674feb Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 20 Jan 2014 18:07:18 +0100 Subject: [PATCH 2/5] OGL32CTX: Always return true when a feature is queried --- lib/irrlicht/source/Irrlicht/COpenGLDriver.h | 2 -- lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.h b/lib/irrlicht/source/Irrlicht/COpenGLDriver.h index 4f7f14310..c556bd913 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.h +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.h @@ -142,8 +142,6 @@ namespace video //! queries the features of the driver, returns true if feature is available virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const { - if (feature == EVDF_FRAMEBUFFER_OBJECT) - return true; return FeatureEnabled[feature] && COpenGLExtensionHandler::queryFeature(feature); } diff --git a/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.cpp b/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.cpp index ae64ffd58..d79567fc3 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLExtensionHandler.cpp @@ -94,7 +94,7 @@ COpenGLExtensionHandler::COpenGLExtensionHandler() : #endif // _IRR_OPENGL_USE_EXTPOINTER_ { for (u32 i=0; i Date: Tue, 21 Jan 2014 23:01:58 +0100 Subject: [PATCH 3/5] OGL32CTX: Replace a couple of draw2DImage/draw2DRectangle --- src/states_screens/cutscene_gui.cpp | 3 ++- src/states_screens/race_gui_overworld.cpp | 26 +++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/states_screens/cutscene_gui.cpp b/src/states_screens/cutscene_gui.cpp index 05c080126..5f8ee6a05 100644 --- a/src/states_screens/cutscene_gui.cpp +++ b/src/states_screens/cutscene_gui.cpp @@ -19,6 +19,7 @@ #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/glwrap.hpp" #include "states_screens/cutscene_gui.hpp" // ----------------------------------------------------------------------------- @@ -41,7 +42,7 @@ void CutsceneGUI::renderGlobal(float dt) { if (m_fade_level > 0.0f) { - irr_driver->getVideoDriver()->draw2DRectangle( + GL32_draw2DRectangle( video::SColor((int)(m_fade_level*255), 0,0,0), core::rect(0, 0, UserConfigParams::m_width, diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index ef16c31c8..6c4fda878 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -26,6 +26,7 @@ using namespace irr; #include "challenges/unlock_manager.hpp" #include "config/user_config.hpp" #include "graphics/camera.hpp" +#include "graphics/glwrap.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" #include "guiengine/engine.hpp" @@ -143,8 +144,7 @@ void RaceGUIOverworld::renderGlobal(float dt) !GUIEngine::ModalDialog::isADialogActive()) { static video::SColor black = video::SColor(255,0,0,0); - irr_driver->getVideoDriver() - ->draw2DRectangle(black, + GL32_draw2DRectangle(black, core::rect(UserConfigParams::m_width/2, UserConfigParams::m_height/2, UserConfigParams::m_width, @@ -233,7 +233,7 @@ void RaceGUIOverworld::drawTrophyPoints() if (!m_close_to_a_challenge) { - irr_driver->getVideoDriver()->draw2DImage(m_trophy1, dest, source, NULL, + draw2DImage(m_trophy1, dest, source, NULL, NULL, true /* alpha */); } @@ -248,7 +248,7 @@ void RaceGUIOverworld::drawTrophyPoints() dest += core::position2di(size*2, 0); if (!m_close_to_a_challenge) { - irr_driver->getVideoDriver()->draw2DImage(m_trophy2, dest, source, NULL, + draw2DImage(m_trophy2, dest, source, NULL, NULL, true /* alpha */); } @@ -263,7 +263,7 @@ void RaceGUIOverworld::drawTrophyPoints() dest += core::position2di(size*2, 0); if (!m_close_to_a_challenge) { - irr_driver->getVideoDriver()->draw2DImage(m_trophy3, dest, source, NULL, + draw2DImage(m_trophy3, dest, source, NULL, NULL, true /* alpha */); } dest += core::position2di((int)(size*1.5f), 0); @@ -277,7 +277,7 @@ void RaceGUIOverworld::drawTrophyPoints() dest = core::rect(pos.UpperLeftCorner.X - size - 5, pos.UpperLeftCorner.Y, pos.UpperLeftCorner.X - 5, pos.UpperLeftCorner.Y + size); - irr_driver->getVideoDriver()->draw2DImage(m_open_challenge, dest, source, NULL, + draw2DImage(m_open_challenge, dest, source, NULL, NULL, true /* alpha */); pos.LowerRightCorner.Y = dest.LowerRightCorner.Y; @@ -330,7 +330,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() core::rect dest(m_map_left, upper_y, m_map_left + m_map_width, lower_y); core::rect source(core::position2di(0, 0), mini_map->getOriginalSize()); - irr_driver->getVideoDriver()->draw2DImage(mini_map, dest, source, 0, 0, true); + draw2DImage(mini_map, dest, source, 0, 0, true); } Vec3 kart_xyz; @@ -376,11 +376,11 @@ void RaceGUIOverworld::drawGlobalMiniMap() const core::rect rect(core::position2d(0,0), m_icons_frame->getTexture()->getOriginalSize()); - irr_driver->getVideoDriver()->draw2DImage(m_icons_frame->getTexture(), position, + draw2DImage(m_icons_frame->getTexture(), position, rect, NULL, colors, true); } // if isPlayerController - irr_driver->getVideoDriver()->draw2DImage(m_marker, position, source, + draw2DImage(m_marker, position, source, NULL, NULL, true); } // for igetVideoDriver()->draw2DImage(m_icons[state], + draw2DImage(m_icons[state], dest, source, NULL, NULL, true); } @@ -546,7 +546,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart, x -= w; // Background - irr_driver->getVideoDriver()->draw2DImage(m_gauge_empty, core::rect(x, y, x+w, y+h) /* dest rect */, + draw2DImage(m_gauge_empty, core::rect(x, y, x+w, y+h) /* dest rect */, core::rect(0, 0, 64, 256) /* source rect */, NULL /* clip rect */, NULL /* colors */, true /* alpha */); @@ -565,7 +565,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart, if (state >= 1.0f) y1 = y; core::rect clip(x, y1, x + w, y + h); - irr_driver->getVideoDriver()->draw2DImage(m_gauge_goal, core::rect(x, y, x+w, y+h) /* dest rect */, + draw2DImage(m_gauge_goal, core::rect(x, y, x+w, y+h) /* dest rect */, core::rect(0, 0, 64, 256) /* source rect */, &clip, NULL /* colors */, true /* alpha */); } @@ -581,7 +581,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart, if (state >= 1.0f) y1 = y; core::rect clip(x, y1, x + w, y + h); - irr_driver->getVideoDriver()->draw2DImage(m_gauge_full, core::rect(x, y, x+w, y+h) /* dest rect */, + draw2DImage(m_gauge_full, core::rect(x, y, x+w, y+h) /* dest rect */, core::rect(0, 0, 64, 256) /* source rect */, &clip, NULL /* colors */, true /* alpha */); } From 4438db3bbfff6541df01fe5640c387fa77053f5a Mon Sep 17 00:00:00 2001 From: gl3nn Date: Tue, 21 Jan 2014 23:11:22 +0100 Subject: [PATCH 4/5] Fixes #11 --- src/guiengine/widgets/ribbon_widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index 3fbd09bc2..8f6c25861 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -594,7 +594,7 @@ void RibbonWidget::unfocused(const int playerID, Widget* new_focus) { if (new_focus != NULL && new_focus != this && !m_active_children.contains(new_focus)) { - if (m_selection[playerID] >= 0 && m_selection[playerID] < int(m_children.size())) + if (m_selection[playerID] >= 0 && m_selection[playerID] < int(m_active_children.size())) { m_active_children.get(m_selection[playerID])->unfocused(playerID, new_focus); } From 4cbbf91e4eed1b44e1a2bce21c0d16382e80f8df Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 21 Jan 2014 23:44:23 +0100 Subject: [PATCH 5/5] Light: Sunlight uses the new shaders. --- data/shaders/sunlight.frag | 24 +++++++++++------------- src/graphics/callbacks.hpp | 20 ++++++++++++++++++++ src/graphics/post_processing.cpp | 18 ++++++++++++++++++ src/graphics/post_processing.hpp | 2 +- src/graphics/render.cpp | 1 + src/graphics/shaders.cpp | 26 ++++++++++++++++++++++++++ src/graphics/shaders.hpp | 11 +++++++++++ src/graphics/sun.cpp | 7 +------ 8 files changed, 89 insertions(+), 20 deletions(-) diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index 9b8a6d255..4075937af 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -1,23 +1,21 @@ #version 130 uniform sampler2D ntex; -uniform sampler2D cloudtex; +//uniform sampler2D cloudtex; -uniform vec3 center; +uniform vec3 direction; uniform vec3 col; -uniform vec2 screen; uniform mat4 invproj; -uniform int hasclouds; -uniform vec2 wind; +//uniform int hasclouds; +//uniform vec2 wind; +in vec2 uv; out vec4 Diff; out vec4 Spec; out vec4 SpecularMap; void main() { - - vec2 texc = gl_FragCoord.xy / screen; - float z = texture(ntex, texc).a; - vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0; + float z = texture(ntex, uv).a; + vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; xpos = invproj * xpos; xpos.xyz /= xpos.w; @@ -29,11 +27,11 @@ void main() { return; } - vec3 norm = texture(ntex, texc).xyz; + vec3 norm = texture(ntex, uv).xyz; norm = (norm - 0.5) * 2.0; // Normalized on the cpu - vec3 L = center; + vec3 L = direction; float NdotL = max(0.0, dot(norm, L)); vec3 R = reflect(L, norm); @@ -42,14 +40,14 @@ void main() { vec3 outcol = NdotL * col; - if (hasclouds == 1) +/* if (hasclouds == 1) { vec2 cloudcoord = (xpos.xz * 0.00833333) + wind; float cloud = texture(cloudtex, cloudcoord).x; //float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y); outcol *= cloud; - } + }*/ Diff = vec4(NdotL * col, 1.); Spec = vec4(Specular * col, 1.); diff --git a/src/graphics/callbacks.hpp b/src/graphics/callbacks.hpp index d88802bfd..c68b355c8 100644 --- a/src/graphics/callbacks.hpp +++ b/src/graphics/callbacks.hpp @@ -368,6 +368,21 @@ public: m_color[1] = g; m_color[2] = b; } + + float getRed() const + { + return m_color[0]; + } + + float getGreen() const + { + return m_color[1]; + } + + float getBlue() const + { + return m_color[2]; + } void setPosition(float x, float y, float z) { @@ -383,6 +398,11 @@ public: m_pos[1] = pos.Y; m_pos[2] = pos.Z; } + + core::vector3df getPosition() const + { + return core::vector3df(m_pos[0], m_pos[1], m_pos[2]); + } void setShadowMatrix(const core::matrix4 &mat) { diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index e8b4fea69..5dbafc589 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -333,6 +333,24 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector &po glDisable(GL_BLEND); } +void PostProcessing::renderSunlight() +{ + SunLightProvider * const cb = (SunLightProvider *) irr_driver->getCallback(ES_SUNLIGHT); + + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + + glUseProgram(FullScreenShader::SunLightShader::Program); + glBindVertexArray(FullScreenShader::SunLightShader::vao); + GLuint ntex_id = static_cast(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(); + setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST); + FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); +} + void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug) { const SColorf s = irr_driver->getSceneManager()->getAmbientLight(); diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index e622118de..c5bda8df7 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -74,7 +74,7 @@ public: /** Generate diffuse and specular map */ void renderPointlight(video::ITexture *in, const std::vector &positions, const std::vector &colors, const std::vector &energy); - + void renderSunlight(); /** Blend all light related map */ void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 536c60d07..fc1d08d3d 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -740,6 +740,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, if (!m_lights[i]->isPointLight()) { m_lights[i]->render(); + m_post_processing->renderSunlight(); continue; } const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 02693608b..a43049f24 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -236,6 +236,7 @@ void Shaders::loadShaders() FullScreenShader::PointLightShader::init(); FullScreenShader::PPDisplaceShader::init(); FullScreenShader::SSAOShader::init(); + FullScreenShader::SunLightShader::init(); MeshShader::ColorizeShader::init(); MeshShader::NormalMapShader::init(); MeshShader::ObjectPass1Shader::init(); @@ -949,6 +950,31 @@ namespace FullScreenShader vao = createVAO(Program); } + GLuint SunLightShader::Program; + GLuint SunLightShader::uniform_ntex; + GLuint SunLightShader::uniform_direction; + GLuint SunLightShader::uniform_col; + GLuint SunLightShader::uniform_invproj; + GLuint SunLightShader::vao; + + void SunLightShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str()); + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_direction = glGetUniformLocation(Program, "direction"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + vao = createVAO(Program); + } + + void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex) + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); + glUniform3f(uniform_col, r, g, b); + glUniform1i(uniform_ntex, TU_ntex); + } + GLuint LightBlendShader::Program; GLuint LightBlendShader::uniform_diffuse; GLuint LightBlendShader::uniform_specular; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index a326a7565..b9c6ad5f9 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -274,6 +274,17 @@ public: static void init(); }; +class SunLightShader +{ +public: + static GLuint Program; + static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj; + static GLuint vao; + + static void init(); + static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex); +}; + class LightBlendShader { public: diff --git a/src/graphics/sun.cpp b/src/graphics/sun.cpp index 399896f3d..1013762ad 100644 --- a/src/graphics/sun.cpp +++ b/src/graphics/sun.cpp @@ -87,12 +87,7 @@ void SunNode::render() vector3df pos = getPosition(); cb->setPosition(pos.X, pos.Y, pos.Z); - - if (!UserConfigParams::m_shadows || !World::getWorld()->getTrack()->hasShadows()) - { - sq->render(false); - return; - } + return; array mrt; mrt.reallocate(2);