From 2d1acf5353fe995604a4c2c15b75dcfcdef8cf0b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 23 Feb 2014 20:16:03 +0100 Subject: [PATCH] Godray: improve the effect and its stability. --- data/shaders/godfade.frag | 2 +- src/graphics/irr_driver.cpp | 1 + src/graphics/irr_driver.hpp | 2 +- src/graphics/post_processing.cpp | 11 ++++++----- src/graphics/render.cpp | 8 +++++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/data/shaders/godfade.frag b/data/shaders/godfade.frag index c56fac332..cb16f93ab 100644 --- a/data/shaders/godfade.frag +++ b/data/shaders/godfade.frag @@ -14,7 +14,7 @@ void main() mul = step(mul, 0.02); mul *= 0.97; -// res = res * vec4(mul); + res = res * vec4(mul); FragColor = res; } diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index bb1b7edca..6e63c4eae 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -459,6 +459,7 @@ void IrrDriver::initDevice() irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver(); gl_driver->extGlGenQueries(1, &m_lensflare_query); + m_query_issued = false; scene::IMesh * const sphere = m_scene_manager->getGeometryCreator()->createSphereMesh(1, 16, 16); m_sun_interposer = new STKMeshSceneNode(sphere, m_scene_manager->getRootSceneNode(), NULL, -1); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index ceb1de35f..4b2166e46 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -49,7 +49,6 @@ class ShadowImportanceProvider; #include "graphics/rtts.hpp" #include "graphics/shaders.hpp" -#include "graphics/stkmeshscenenode.hpp" #include "graphics/wind.hpp" #include "io/file_manager.hpp" #include "utils/aligned_array.hpp" @@ -172,6 +171,7 @@ private: unsigned object_count[PASS_COUNT]; u32 m_renderpass; u32 m_lensflare_query; + bool m_query_issued; class STKMeshSceneNode *m_sun_interposer; scene::CLensFlareSceneNode *m_lensflare; scene::ICameraSceneNode *m_suncam; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 617792c85..46fe6ad25 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -24,6 +24,7 @@ #include "graphics/irr_driver.hpp" #include "graphics/mlaa_areamap.hpp" #include "graphics/shaders.hpp" +#include "graphics/stkmeshscenenode.hpp" #include "io/file_manager.hpp" #include "karts/abstract_kart.hpp" #include "karts/kart_model.hpp" @@ -739,18 +740,18 @@ void PostProcessing::render() // Set the sun's color const SColor col = World::getWorld()->getTrack()->getSunColor(); -// ColorizeProvider * const colcb = (ColorizeProvider *) irr_driver->getCallback(ES_COLORIZE); -// colcb->setColor(col.getRed() / 255.0f, col.getGreen() / 255.0f, col.getBlue() / 255.0f); + ColorizeProvider * const colcb = (ColorizeProvider *) irr_driver->getCallback(ES_COLORIZE); + colcb->setColor(col.getRed() / 255.0f, col.getGreen() / 255.0f, col.getBlue() / 255.0f); // The sun interposer STKMeshSceneNode *sun = irr_driver->getSunInterposer(); /* sun->getMaterial(0).ColorMask = ECP_ALL; + irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_SOLID);*/ irr_driver->getSceneManager()->drawAll(ESNRP_CAMERA); - irr_driver->getSceneManager()->setCurrentRendertime(ESNRP_SOLID); - + irr_driver->setPhase(GLOW_PASS); sun->render(); - sun->getMaterial(0).ColorMask = ECP_NONE;*/ + //sun->getMaterial(0).ColorMask = ECP_NONE; // Fade to quarter diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 4d220035c..348958f9f 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -35,6 +35,7 @@ #include "graphics/screenquad.hpp" #include "graphics/shaders.hpp" #include "graphics/shadow_importance.hpp" +#include "graphics/stkmeshscenenode.hpp" #include "graphics/wind.hpp" #include "io/file_manager.hpp" #include "items/item.hpp" @@ -273,9 +274,9 @@ void IrrDriver::renderGLSL(float dt) { irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver(); - GLuint res; - gl_driver->extGlGetQueryObjectuiv(m_lensflare_query, GL_QUERY_RESULT, &res); - printf("pixel is %d\n", res); + GLuint res = 0; + if (m_query_issued) + gl_driver->extGlGetQueryObjectuiv(m_lensflare_query, GL_QUERY_RESULT, &res); m_post_processing->setSunPixels(res); // Prepare the query for the next frame. @@ -286,6 +287,7 @@ void IrrDriver::renderGLSL(float dt) irr_driver->setPhase(GLOW_PASS); m_sun_interposer->render(); gl_driver->extGlEndQuery(GL_SAMPLES_PASSED_ARB); + m_query_issued = true; m_lensflare->setStrength(res / 4000.0f);