From bea2586af30f73e94df83f52e1d4f1dbf5a81713 Mon Sep 17 00:00:00 2001 From: samuncle Date: Tue, 4 Nov 2014 21:12:26 +0100 Subject: [PATCH 1/8] Preparing lens flare branch --- src/graphics/irr_driver.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 1dc1f29e0..4860de85f 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -101,10 +101,15 @@ enum TypeFBO FBO_BLOOM_1024, FBO_BLOOM_512, FBO_TMP_512, + FBO_LENS_512, + FBO_BLOOM_256, - FBO_TMP_256, + FBO_TMP_256, + FBO_LENS_256, + FBO_BLOOM_128, FBO_TMP_128, + FBO_LENS_128, FBO_COUNT }; @@ -157,10 +162,13 @@ enum TypeRTT RTT_BLOOM_1024, RTT_BLOOM_512, RTT_TMP_512, + RTT_LENS_512, RTT_BLOOM_256, RTT_TMP_256, + RTT_LENS_256, RTT_BLOOM_128, RTT_TMP_128, + RTT_LENS_128, RTT_COUNT }; From 52bc4cebd45317ff8adbb8310c3fcd9b7fe9c39e Mon Sep 17 00:00:00 2001 From: samuncle Date: Tue, 4 Nov 2014 21:15:18 +0100 Subject: [PATCH 2/8] Add the lensflare shader --- data/shaders/lensblend.frag | 19 ++++++++++ src/graphics/post_processing.cpp | 59 ++++++++++++++++++++++++++++++-- src/graphics/post_processing.hpp | 1 + src/graphics/rtts.cpp | 18 ++++++++++ src/graphics/shaders.cpp | 20 +++++++++++ src/graphics/shaders.hpp | 13 +++++++ 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 data/shaders/lensblend.frag diff --git a/data/shaders/lensblend.frag b/data/shaders/lensblend.frag new file mode 100644 index 000000000..40ff2d117 --- /dev/null +++ b/data/shaders/lensblend.frag @@ -0,0 +1,19 @@ +uniform sampler2D tex_128; +uniform sampler2D tex_256; +uniform sampler2D tex_512; + +out vec4 FragColor; + +void main() +{ + vec2 uv = gl_FragCoord.xy / screen; + vec4 col = .125 * texture(tex_128, uv); + col += .25 * texture(tex_256, uv); + col += .5 * texture(tex_512, uv); + + float final = max(col.r,max(col.g,col.b)); + //final = final * 2; + vec3 blue = vec3(final * 0.1, final * 0.2, final); + + FragColor = vec4(col.rgb, 1.); +} diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 86a626103..d26530762 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -351,6 +351,48 @@ void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxil } } +void PostProcessing::renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) +{ + assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight()); + float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight(); + { + auxiliary.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } + { + in_fbo.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } + { + auxiliary.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } + { + in_fbo.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } + { + auxiliary.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } + { + in_fbo.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height)); + } +} + void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) { assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight()); @@ -710,13 +752,21 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, boo // Downsample FrameBuffer::Blit(irr_driver->getFBO(FBO_BLOOM_512), irr_driver->getFBO(FBO_BLOOM_256), GL_COLOR_BUFFER_BIT, GL_LINEAR); FrameBuffer::Blit(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getFBO(FBO_BLOOM_128), GL_COLOR_BUFFER_BIT, GL_LINEAR); + + // Copy for lens flare + FrameBuffer::Blit(irr_driver->getFBO(FBO_BLOOM_512), irr_driver->getFBO(FBO_LENS_512), GL_COLOR_BUFFER_BIT, GL_LINEAR); + FrameBuffer::Blit(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getFBO(FBO_LENS_256), GL_COLOR_BUFFER_BIT, GL_LINEAR); + FrameBuffer::Blit(irr_driver->getFBO(FBO_BLOOM_128), irr_driver->getFBO(FBO_LENS_128), GL_COLOR_BUFFER_BIT, GL_LINEAR); + // Blur renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_512), irr_driver->getFBO(FBO_TMP_512)); - renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getFBO(FBO_TMP_256)); - renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_128), irr_driver->getFBO(FBO_TMP_128)); + + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_512), irr_driver->getFBO(FBO_TMP_512)); + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_256), irr_driver->getFBO(FBO_TMP_256)); + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_128), irr_driver->getFBO(FBO_TMP_128)); // Additively blend on top of tmp1 in_fbo->Bind(); @@ -727,6 +777,11 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, boo irr_driver->getRenderTargetTexture(RTT_BLOOM_128), irr_driver->getRenderTargetTexture(RTT_BLOOM_256), irr_driver->getRenderTargetTexture(RTT_BLOOM_512)); DrawFullScreenEffect(); + + FullScreenShader::LensBlendShader::getInstance()->SetTextureUnits( + irr_driver->getRenderTargetTexture(RTT_LENS_128), irr_driver->getRenderTargetTexture(RTT_LENS_256), irr_driver->getRenderTargetTexture(RTT_LENS_512)); + DrawFullScreenEffect(); + glDisable(GL_BLEND); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } // end if bloom diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index dd8774f96..cced5ec2a 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -88,6 +88,7 @@ public: /** Blur the in texture */ void renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); void renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); + void renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); void renderGaussian6BlurLayer(FrameBuffer &in_fbo); void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 4b6024975..5dad9df4f 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -125,10 +125,15 @@ RTT::RTT(size_t width, size_t height) RenderTargetTextures[RTT_BLOOM_1024] = generateRTT(shadowsize0, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_BLOOM_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_TMP_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_LENS_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_BLOOM_256] = generateRTT(shadowsize2, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_TMP_256] = generateRTT(shadowsize2, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_LENS_256] = generateRTT(shadowsize2, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_BLOOM_128] = generateRTT(shadowsize3, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_TMP_128] = generateRTT(shadowsize3, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_LENS_128] = generateRTT(shadowsize3, GL_RGBA16F, GL_BGR, GL_FLOAT); std::vector somevector; somevector.push_back(RenderTargetTextures[RTT_SSAO]); @@ -208,17 +213,30 @@ RTT::RTT(size_t width, size_t height) somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_TMP_512]); FrameBuffers.push_back(new FrameBuffer(somevector, 512, 512)); + somevector.clear(); + somevector.push_back(RenderTargetTextures[RTT_LENS_512]); + FrameBuffers.push_back(new FrameBuffer(somevector, 512, 512)); + + somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_BLOOM_256]); FrameBuffers.push_back(new FrameBuffer(somevector, 256, 256)); somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_TMP_256]); FrameBuffers.push_back(new FrameBuffer(somevector, 256, 256)); + somevector.clear(); + somevector.push_back(RenderTargetTextures[RTT_LENS_256]); + FrameBuffers.push_back(new FrameBuffer(somevector, 256, 256)); + + somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_BLOOM_128]); FrameBuffers.push_back(new FrameBuffer(somevector, 128, 128)); somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_TMP_128]); + FrameBuffers.push_back(new FrameBuffer(somevector, 128, 128)); + somevector.clear(); + somevector.push_back(RenderTargetTextures[RTT_LENS_128]); FrameBuffers.push_back(new FrameBuffer(somevector, 128, 128)); if (UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround()) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 459f276d1..9e08d1f83 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1561,6 +1561,16 @@ namespace FullScreenShader AssignSamplerNames(Program, 0, "tex_128", 1, "tex_256", 2, "tex_512"); } + + LensBlendShader::LensBlendShader() + { + Program = LoadProgram(OBJECT, + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/lensblend.frag").c_str()); + AssignUniforms(); + + AssignSamplerNames(Program, 0, "tex_128", 1, "tex_256", 2, "tex_512"); + } ToneMapShader::ToneMapShader() { @@ -1706,6 +1716,16 @@ namespace FullScreenShader AssignSamplerNames(Program, 0, "tex"); } + + HorizontalBlurShader::HorizontalBlurShader() + { + Program = LoadProgram(OBJECT, + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian6h.frag").c_str()); + AssignUniforms("pixel"); + + AssignSamplerNames(Program, 0, "tex"); + } Gaussian3HBlurShader::Gaussian3HBlurShader() { diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 55b773d51..0a44751af 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -377,6 +377,13 @@ public: BloomBlendShader(); }; +class LensBlendShader : public ShaderHelperSingleton, public TextureRead +{ +public: + LensBlendShader(); +}; + + class ToneMapShader : public ShaderHelperSingleton, public TextureRead { public: @@ -455,6 +462,12 @@ public: Gaussian6HBlurShader(); }; +class HorizontalBlurShader : public ShaderHelperSingleton, public TextureRead +{ +public: + HorizontalBlurShader(); +}; + class Gaussian3HBlurShader : public ShaderHelperSingleton, public TextureRead { public: From 2a440bb2cbce605309ee6d0a44d69a68a7f8b9e3 Mon Sep 17 00:00:00 2001 From: samuncle Date: Fri, 7 Nov 2014 16:20:39 +0100 Subject: [PATCH 3/8] minor modification to the blueish mood of lens flare --- data/shaders/lensblend.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shaders/lensblend.frag b/data/shaders/lensblend.frag index 40ff2d117..0f388f42c 100644 --- a/data/shaders/lensblend.frag +++ b/data/shaders/lensblend.frag @@ -15,5 +15,5 @@ void main() //final = final * 2; vec3 blue = vec3(final * 0.1, final * 0.2, final); - FragColor = vec4(col.rgb, 1.); + FragColor = vec4(blue, 1.); } From 09fa1ee3cbce49ded728a568631745294c0d3101 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 8 Nov 2014 19:47:08 +0100 Subject: [PATCH 4/8] Implement scattering for point light --- data/shaders/pointlightscatter.frag | 46 +++++++++++++++++++++++++++++ src/graphics/irr_driver.hpp | 1 + src/graphics/render.cpp | 2 +- src/graphics/render_lighting.cpp | 35 ++++++++++++++++++++++ src/graphics/shaders.cpp | 35 ++++++++++++++++++++++ src/graphics/shaders.hpp | 8 +++++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 data/shaders/pointlightscatter.frag diff --git a/data/shaders/pointlightscatter.frag b/data/shaders/pointlightscatter.frag new file mode 100644 index 000000000..2d6ee6cba --- /dev/null +++ b/data/shaders/pointlightscatter.frag @@ -0,0 +1,46 @@ +uniform sampler2D dtex; +uniform float density; +uniform vec3 fogcol; + +flat in vec3 center; +flat in float energy; +flat in vec3 col; +flat in float radius; + +out vec4 Fog; + +vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); + +void main() +{ + vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0); + pseudocenter /= pseudocenter.w; + vec3 light_pos = pseudocenter.xyz; + vec3 light_col = col.xyz; + + // Compute pixel position + vec2 texc = 2. * gl_FragCoord.xy / screen; + float z = texture(dtex, texc).x; + vec4 pixelpos = getPosFromUVDepth(vec3(texc, z), InverseProjectionMatrix); + vec3 eyedir = -normalize(pixelpos.xyz); + + vec3 farthestpoint = - eyedir * (min(dot(-eyedir, light_pos) + radius, length(pixelpos.xyz))); + vec3 closestpoint = - eyedir * (dot(-eyedir, light_pos) - radius); + if (closestpoint.z < 1.) closestpoint = vec3(0.); + + float stepsize = length(farthestpoint - closestpoint) / 16; + vec3 fog = vec3(0.); + vec3 xpos = farthestpoint; + + for (int i = 0; i < 16; i++) + { + float d = distance(light_pos, xpos); + float l = (16 - i) * stepsize; + float att = energy * 20. / (1. + d * d); + att *= max((radius - d) / radius, 0.); + fog += density * light_col * att * exp(- density * d) * exp(- density * l) * stepsize; + xpos += stepsize * eyedir; + } + + Fog = vec4(fogcol * fog, 1.); +} diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index ca1747a20..d530002af 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -408,6 +408,7 @@ private: void renderGlow(std::vector& glows); void renderSSAO(); void renderLights(unsigned pointlightCount, bool hasShadow); + void renderLightsScatter(unsigned pointlightCount); void renderShadowsDebug(); void doScreenShot(); void PrepareDrawCalls(scene::ICameraSceneNode *camnode); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 654f8d6f5..10d9e9530 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -420,7 +420,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po World::getWorld()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00); - m_post_processing->renderFog(); + renderLightsScatter(pointlightcount); PROFILER_POP_CPU_MARKER(); } diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp index 0d0ac9a6e..32749a468 100644 --- a/src/graphics/render_lighting.cpp +++ b/src/graphics/render_lighting.cpp @@ -185,3 +185,38 @@ void IrrDriver::renderSSAO() m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R), irr_driver->getFBO(FBO_HALF2_R)); } + +void IrrDriver::renderLightsScatter(unsigned pointlightcount) +{ + getFBO(FBO_HALF1).Bind(); + glClearColor(0., 0., 0., 0.); + glClear(GL_COLOR_BUFFER_BIT); + m_post_processing->renderFog(); + + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + + const Track * const track = World::getWorld()->getTrack(); + + const float start = track->getFogStart(); + const video::SColor tmpcol = track->getFogColor(); + core::vector3df col(1., 1., 1.); + + glUseProgram(LightShader::PointLightScatterShader::getInstance()->Program); + glBindVertexArray(LightShader::PointLightScatterShader::getInstance()->vao); + + LightShader::PointLightScatterShader::getInstance()->SetTextureUnits(irr_driver->getDepthStencilTexture()); + LightShader::PointLightScatterShader::getInstance()->setUniforms(1. / (40. * start), col); + + glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, pointlightcount); + + glDisable(GL_BLEND); + m_post_processing->renderGaussian6Blur(getFBO(FBO_HALF1), getFBO(FBO_HALF2), 5., 5.); + + glEnable(GL_BLEND); + getFBO(FBO_COLORS).Bind(); + m_post_processing->renderPassThrough(getRenderTargetTexture(RTT_HALF1)); +} \ No newline at end of file diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 14f2cf4cf..9a575159f 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1468,6 +1468,41 @@ namespace LightShader glVertexAttribDivisorARB(attrib_Color, 1); glVertexAttribDivisorARB(attrib_Radius, 1); } + + PointLightScatterShader::PointLightScatterShader() + { + Program = LoadProgram(OBJECT, + GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlightscatter.frag").c_str()); + + AssignUniforms("density", "fogcol"); + AssignSamplerNames(Program, 0, "dtex"); + + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + glBindBuffer(GL_ARRAY_BUFFER, PointLightShader::getInstance()->vbo); + + GLuint attrib_Position = glGetAttribLocation(Program, "Position"); + GLuint attrib_Color = glGetAttribLocation(Program, "Color"); + GLuint attrib_Energy = glGetAttribLocation(Program, "Energy"); + GLuint attrib_Radius = glGetAttribLocation(Program, "Radius"); + + glEnableVertexAttribArray(attrib_Position); + glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), 0); + glEnableVertexAttribArray(attrib_Energy); + glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(3 * sizeof(float))); + glEnableVertexAttribArray(attrib_Color); + glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(4 * sizeof(float))); + glEnableVertexAttribArray(attrib_Radius); + glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(7 * sizeof(float))); + + glVertexAttribDivisorARB(attrib_Position, 1); + glVertexAttribDivisorARB(attrib_Energy, 1); + glVertexAttribDivisorARB(attrib_Color, 1); + glVertexAttribDivisorARB(attrib_Radius, 1); + } } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index e6bb2e07f..de0eb71bf 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -328,6 +328,14 @@ namespace LightShader GLuint vao; PointLightShader(); }; + + class PointLightScatterShader : public ShaderHelperSingleton, public TextureRead + { + public: + GLuint vbo; + GLuint vao; + PointLightScatterShader(); + }; } namespace ParticleShader From 192ed8a486e97066a26340d3e70e680f0e7252d3 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 11 Nov 2014 22:43:25 +0100 Subject: [PATCH 5/8] Fix classic fog --- data/shaders/fog.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shaders/fog.frag b/data/shaders/fog.frag index 3560b0a69..104b57d83 100644 --- a/data/shaders/fog.frag +++ b/data/shaders/fog.frag @@ -10,7 +10,7 @@ vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); void main() { - vec2 uv = gl_FragCoord.xy / screen; + vec2 uv = 2. * gl_FragCoord.xy / screen; float z = texture(tex, uv).x; vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix); From 9857eb46216f67657f9148f533cd51407c17ed97 Mon Sep 17 00:00:00 2001 From: samuncle Date: Wed, 12 Nov 2014 01:00:23 +0100 Subject: [PATCH 6/8] Try to tweak the lens flare without being too obvious --- src/graphics/post_processing.cpp | 24 +++++++++++++++++++++--- src/graphics/post_processing.hpp | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 0190fce43..020c5e3df 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -353,6 +353,24 @@ void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxil } } +void PostProcessing::renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) +{ + assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight()); + float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight(); + { + auxiliary.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height), 2.0); + } + { + in_fbo.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height), 2.0); + } +} + void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) { @@ -727,9 +745,9 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, boo renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getFBO(FBO_TMP_256), 1., 1.); renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_128), irr_driver->getFBO(FBO_TMP_128), 1., 1.); - renderGaussian6Blur(irr_driver->getFBO(FBO_LENS_512), irr_driver->getFBO(FBO_TMP_512), 0.01, 10.); - renderGaussian6Blur(irr_driver->getFBO(FBO_LENS_256), irr_driver->getFBO(FBO_TMP_256), 0.01, 10.); - renderGaussian6Blur(irr_driver->getFBO(FBO_LENS_128), irr_driver->getFBO(FBO_TMP_128), 0.01, 10.); + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_512), irr_driver->getFBO(FBO_TMP_512)); + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_256), irr_driver->getFBO(FBO_TMP_256)); + renderHorizontalBlur(irr_driver->getFBO(FBO_LENS_128), irr_driver->getFBO(FBO_TMP_128)); // Additively blend on top of tmp1 in_fbo->Bind(); diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index 702b7981c..430623036 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -89,6 +89,7 @@ public: void renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); void renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary, float sigmaV, float sigmaH); + void renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); void renderGaussian6BlurLayer(FrameBuffer &in_fbo); void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); From 1bd3ee24c66649dbe53e226f286de655cf1559be Mon Sep 17 00:00:00 2001 From: samuncle Date: Wed, 12 Nov 2014 01:22:33 +0100 Subject: [PATCH 7/8] Add a description to the shader --- data/shaders/lensblend.frag | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/shaders/lensblend.frag b/data/shaders/lensblend.frag index 0f388f42c..220d4898f 100644 --- a/data/shaders/lensblend.frag +++ b/data/shaders/lensblend.frag @@ -1,3 +1,8 @@ +/* +Lens flare blend +based on bloomblend.frag +author: samuncle +*/ uniform sampler2D tex_128; uniform sampler2D tex_256; uniform sampler2D tex_512; From 4b01d090c645d05d0bb603fa749da92296b1da4c Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 12 Nov 2014 12:25:33 +1100 Subject: [PATCH 8/8] Fixed track name for GP. --- data/grandprix/4_atworldsend.grandprix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/grandprix/4_atworldsend.grandprix b/data/grandprix/4_atworldsend.grandprix index 0341793a1..0aa43f1e2 100644 --- a/data/grandprix/4_atworldsend.grandprix +++ b/data/grandprix/4_atworldsend.grandprix @@ -4,7 +4,7 @@ - +