From 04fc4c3be7c164380f111b1b2691f67eedf94ec1 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 23 Feb 2014 20:02:15 +0100 Subject: [PATCH] Reenable Godray (on all track atm) --- data/shaders/godfade.frag | 2 +- data/shaders/godray.frag | 2 +- src/graphics/irr_driver.cpp | 4 +- src/graphics/irr_driver.hpp | 7 ++- src/graphics/post_processing.cpp | 104 +++++++++++++++++++------------ src/graphics/render.cpp | 5 +- 6 files changed, 76 insertions(+), 48 deletions(-) diff --git a/data/shaders/godfade.frag b/data/shaders/godfade.frag index cb16f93ab..c56fac332 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/data/shaders/godray.frag b/data/shaders/godray.frag index b83e2bd12..c0063e81d 100644 --- a/data/shaders/godray.frag +++ b/data/shaders/godray.frag @@ -14,7 +14,7 @@ void main() vec2 texc = uv; vec2 tosun = sunpos - texc; - if (dot(tosun, tosun) > 0.49) discard; +// if (dot(tosun, tosun) > 0.49) discard; vec2 dist = tosun * 1.0/(float(SAMPLES) * 1.12); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index b0d89c27a..bb1b7edca 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -461,7 +461,7 @@ void IrrDriver::initDevice() gl_driver->extGlGenQueries(1, &m_lensflare_query); scene::IMesh * const sphere = m_scene_manager->getGeometryCreator()->createSphereMesh(1, 16, 16); - m_sun_interposer = m_scene_manager->addMeshSceneNode(sphere); + m_sun_interposer = new STKMeshSceneNode(sphere, m_scene_manager->getRootSceneNode(), NULL, -1); m_sun_interposer->grab(); m_sun_interposer->setParent(NULL); m_sun_interposer->setScale(core::vector3df(20)); @@ -469,7 +469,7 @@ void IrrDriver::initDevice() m_sun_interposer->getMaterial(0).Lighting = false; m_sun_interposer->getMaterial(0).ColorMask = video::ECP_NONE; m_sun_interposer->getMaterial(0).ZWriteEnable = false; - m_sun_interposer->getMaterial(0).MaterialType = m_shaders->getShader(ES_PASSFAR); + m_sun_interposer->getMaterial(0).MaterialType = m_shaders->getShader(ES_OBJECTPASS); sphere->drop(); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index dba63df2c..ceb1de35f 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -49,6 +49,7 @@ 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" @@ -171,7 +172,7 @@ private: unsigned object_count[PASS_COUNT]; u32 m_renderpass; u32 m_lensflare_query; - scene::IMeshSceneNode *m_sun_interposer; + class STKMeshSceneNode *m_sun_interposer; scene::CLensFlareSceneNode *m_lensflare; scene::ICameraSceneNode *m_suncam; @@ -212,7 +213,6 @@ private: std::vector& glows, const core::aabbox3df& cambox, int cam); - void renderSkybox(); void renderLights(const core::aabbox3df& cambox, scene::ICameraSceneNode * const camnode, video::SOverrideMaterial &overridemat, @@ -225,6 +225,7 @@ public: ~IrrDriver(); void initDevice(); void reset(); + void renderSkybox(); void setPhase(STKRenderingPass); STKRenderingPass getPhase() const; const std::vector &getShadowViewProj() const @@ -495,7 +496,7 @@ public: // ------------------------------------------------------------------------ void clearLights(); // ------------------------------------------------------------------------ - scene::IMeshSceneNode *getSunInterposer() { return m_sun_interposer; } + class STKMeshSceneNode *getSunInterposer() { return m_sun_interposer; } // ------------------------------------------------------------------------ void setViewMatrix(core::matrix4 matrix) { m_ViewMatrix = matrix; matrix.getInverse(m_InvViewMatrix); } const core::matrix4 &getViewMatrix() const { return m_ViewMatrix; } diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 6ba8a1a2c..617792c85 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -613,6 +613,40 @@ void PostProcessing::renderMotionBlur(unsigned cam, ITexture *in, ITexture *out) glDisable(GL_BLEND); } +static void renderGodFade(GLuint tex, const SColor &col) +{ + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + + glUseProgram(FullScreenShader::GodFadeShader::Program); + glBindVertexArray(FullScreenShader::GodFadeShader::vao); + setTexture(0, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::GodFadeShader::setUniforms(col, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); +} + +static void renderGodRay(GLuint tex, const core::vector2df &sunpos) +{ + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + + glUseProgram(FullScreenShader::GodRayShader::Program); + glBindVertexArray(FullScreenShader::GodRayShader::vao); + setTexture(0, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::GodRayShader::setUniforms(sunpos, 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() @@ -688,9 +722,6 @@ void PostProcessing::render() // 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(drv)->setRenderStates3DMode(); } // end if bloom in = irr_driver->getRTT(RTT_TMP1); @@ -699,33 +730,33 @@ void PostProcessing::render() PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00); - if (World::getWorld()->getTrack()->hasGodRays() && m_sunpixels > 30) // god rays + if (m_sunpixels > 30)//World::getWorld()->getTrack()->hasGodRays() && ) // god rays { // Grab the sky drv->setRenderTarget(out, true, false); - irr_driver->getSceneManager()->drawAll(ESNRP_SKY_BOX); +// irr_driver->getSceneManager()->drawAll(ESNRP_SKY_BOX); + irr_driver->renderSkybox(); // 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); +// 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 - IMeshSceneNode * const sun = irr_driver->getSunInterposer(); - sun->getMaterial(0).ColorMask = ECP_ALL; + STKMeshSceneNode *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; + 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); + drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), false, false); + renderGodFade(getTextureGLuint(out), col); + // Blur renderGaussian3Blur(irr_driver->getRTT(RTT_QUARTER1), @@ -733,6 +764,8 @@ void PostProcessing::render() 4.f / UserConfigParams::m_width, 4.f / UserConfigParams::m_height); + + // Calculate the sun's position in texcoords const core::vector3df pos = sun->getPosition(); float ndc[4]; @@ -747,39 +780,26 @@ void PostProcessing::render() 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); +// ((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); + renderGodRay(getTextureGLuint(irr_driver->getRTT(RTT_QUARTER1)), core::vector2df(sunx, suny)); // 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); + renderGaussian3Blur(irr_driver->getRTT(RTT_QUARTER2), + irr_driver->getRTT(RTT_QUARTER1), + 4.f / UserConfigParams::m_width, + 4.f / UserConfigParams::m_height); - drawQuad(cam, m_material); + // Blend + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); - 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); + renderPassThrough(irr_driver->getRTT(RTT_QUARTER2)); } PROFILER_POP_CPU_MARKER(); @@ -805,6 +825,10 @@ void PostProcessing::render() PROFILER_POP_CPU_MARKER(); } + m_material.MaterialType = irr_driver->getShader(ES_RAIN); + drv->setMaterial(m_material); + static_cast(drv)->setRenderStates3DMode(); + if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter. { PROFILER_PUSH_CPU_MARKER("- MLAA", 0xFF, 0x00, 0x00); @@ -870,7 +894,7 @@ void PostProcessing::render() if (irr_driver->getNormals()) renderPassThrough(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); else if (irr_driver->getSSAOViz()) - renderPassThrough(irr_driver->getRTT(RTT_SSAO)); + renderPassThrough(irr_driver->getRTT(RTT_TMP3)); else renderColorLevel(in); } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index cc472de0f..4d220035c 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -269,18 +269,21 @@ void IrrDriver::renderGLSL(float dt) // Is the lens flare enabled & visible? Check last frame's query. const bool hasflare = World::getWorld()->getTrack()->hasLensFlare(); const bool hasgodrays = World::getWorld()->getTrack()->hasGodRays(); - if (hasflare || hasgodrays) + if (true)//hasflare || hasgodrays) { 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); m_post_processing->setSunPixels(res); // Prepare the query for the next frame. + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); gl_driver->extGlBeginQuery(GL_SAMPLES_PASSED_ARB, m_lensflare_query); m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); m_scene_manager->drawAll(scene::ESNRP_CAMERA); + irr_driver->setPhase(GLOW_PASS); m_sun_interposer->render(); gl_driver->extGlEndQuery(GL_SAMPLES_PASSED_ARB);