From 9113aa7a392751cc8b1e08946a530355d5f6f2ea Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 1 Nov 2014 18:02:22 +0100 Subject: [PATCH 01/17] Implement Exponential Shadow map --- data/shaders/sunlightshadow.frag | 25 +++++++++++++++---------- src/graphics/render_geometry.cpp | 8 +------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 2c3064dee..7ab1772ef 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -42,16 +42,21 @@ float getShadowFactor(vec3 pos, float bias, int index) //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping - float sum = 0.; - for (float i = -1.5; i <= 1.5; i+= 1.) - { - for (float j = -1.5; j <= 1.5; j+= 1.) - { - float z = texture(shadowtex, vec3(shadowtexcoord +vec2(i, j) / 1024., float(index))).x; - sum += (z > 0.5 * shadowcoord.z + 0.5) ? 1. : 0.; - } - } - return sum / 16.; + +// float sum = 0.; +// for (float i = -1.5; i <= 1.5; i+= 1.) +// { +// for (float j = -1.5; j <= 1.5; j+= 1.) +// { +// float z = texture(shadowtex, vec3(shadowtexcoord +vec2(i, j) / 1024., float(index))).x; +// sum += (z > 0.5 * shadowcoord.z + 0.5) ? 1. : 0.; +// } +// } +// return sum / 16.; + + float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x; + float d = .5 * shadowcoord.z + .5; + return min(exp(1024 *(z - d)), 1.); } void main() { diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 0f3243104..b9e95ff0e 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,11 +978,8 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.5, 0.); m_rtts->getShadowFBO().Bind(); + glClearColor(1., 1., 1., 1.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClearColor(0., 0., 0., 0.); @@ -1022,9 +1019,6 @@ void IrrDriver::renderShadows() renderInstancedShadow(cascade); } } - - glDisable(GL_POLYGON_OFFSET_FILL); - glCullFace(GL_BACK); } From 937eb3baf8e2dc630b77199c509c5ef5ce55dc4a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 1 Nov 2014 19:00:02 +0100 Subject: [PATCH 02/17] Add trilinear + anisotropic on shadows --- src/graphics/render_geometry.cpp | 3 +++ src/graphics/rtts.cpp | 8 ++++---- src/graphics/shaders.cpp | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index b9e95ff0e..41cb883d6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1019,6 +1019,9 @@ void IrrDriver::renderShadows() renderInstancedShadow(cascade); } } + + glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); + glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 01193865f..09ac00922 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -24,13 +24,13 @@ #include "utils/log.hpp" #include -static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type) +static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type, unsigned mipmaplevel = 1) { GLuint result; glGenTextures(1, &result); glBindTexture(target, result); if (irr_driver->hasARBTextureStorage()) - glTexStorage3D(target, 1, internalFormat, w, h, d); + glTexStorage3D(target, mipmaplevel, internalFormat, w, h, d); else glTexImage3D(target, 0, internalFormat, w, h, d, 0, format, type, 0); return result; @@ -223,8 +223,8 @@ RTT::RTT(size_t width, size_t height) if (UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround()) { - shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT); - shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 10); + shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH_COMPONENT32, GL_DEPTH_STENCIL, GL_DEPTH_COMPONENT, 10); somevector.clear(); somevector.push_back(shadowColorTex); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 5fb9297d2..337daed5d 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -859,9 +859,13 @@ GLuint createShadowSampler() unsigned id; glGenSamplers(1, &id); glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); return id; #endif } From 4e6a7b51923a2b45912575741a25fc74b03296dd Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 1 Nov 2014 21:53:04 +0100 Subject: [PATCH 03/17] Use MSAA for shadowmap --- src/graphics/glwrap.cpp | 25 ++++++++++++++++++++++--- src/graphics/glwrap.hpp | 3 ++- src/graphics/render_geometry.cpp | 9 ++++++++- src/graphics/rtts.cpp | 11 +++++++++++ src/graphics/rtts.hpp | 4 +++- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index e13454bef..7ff0ff32b 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -162,10 +162,10 @@ unsigned GPUTimer::elapsedTimeus() return result / 1000; } -FrameBuffer::FrameBuffer() {} +FrameBuffer::FrameBuffer() : layerfbo(0) {} FrameBuffer::FrameBuffer(const std::vector &RTTs, size_t w, size_t h, bool layered) : - RenderTargets(RTTs), DepthTexture(0), width(w), height(h) +RenderTargets(RTTs), DepthTexture(0), width(w), height(h), layerfbo(0) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -184,7 +184,7 @@ FrameBuffer::FrameBuffer(const std::vector &RTTs, size_t w, size_t h, bo } FrameBuffer::FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, size_t h, bool layered) : - RenderTargets(RTTs), DepthTexture(DS), width(w), height(h) +RenderTargets(RTTs), DepthTexture(DS), width(w), height(h), layerfbo(0) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -202,11 +202,16 @@ FrameBuffer::FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, s } GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); + + if (layered) + glGenFramebuffers(1, &layerfbo); } FrameBuffer::~FrameBuffer() { glDeleteFramebuffers(1, &fbo); + if (layerfbo) + glDeleteFramebuffers(1, &layerfbo); } void FrameBuffer::Bind() @@ -227,6 +232,20 @@ void FrameBuffer::Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } +void FrameBuffer::BlitLayer(const FrameBuffer &Src, FrameBuffer &Dst, unsigned layer, GLbitfield mask, GLenum filter) +{ + glBindFramebuffer(GL_READ_FRAMEBUFFER, Src.layerfbo); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Src.RenderTargets[0], 0, layer); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, Src.DepthTexture, 0, layer); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Dst.layerfbo); + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Dst.RenderTargets[0], 0, layer); + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, Dst.DepthTexture, 0, layer); + glBlitFramebuffer(0, 0, (int)Src.width, (int)Src.height, 0, 0, + (int)Dst.width, (int)Dst.height, mask, filter); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); +} + void FrameBuffer::BlitToDefault(size_t x0, size_t y0, size_t x1, size_t y1) { glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 631fc4cf2..39233934b 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -43,7 +43,7 @@ public: class FrameBuffer { private: - GLuint fbo; + GLuint fbo, layerfbo; std::vector RenderTargets; GLuint DepthTexture; size_t width, height; @@ -59,6 +59,7 @@ public: size_t getHeight() const { return height; } static void Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST); void BlitToDefault(size_t, size_t, size_t, size_t); + static void BlitLayer(const FrameBuffer &Src, FrameBuffer &Dst, unsigned layer, GLbitfield mask, GLenum filter); }; class VertexUtils diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 41cb883d6..a720fcc01 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,12 +978,15 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - m_rtts->getShadowFBO().Bind(); + m_rtts->getShadowMSAAFBO().Bind(); glClearColor(1., 1., 1., 1.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClearColor(0., 0., 0., 0.); + + glEnable(GL_MULTISAMPLE); + for (unsigned cascade = 0; cascade < 4; cascade++) { ScopedGPUTimer Timer(getGPUTimer(Q_SHADOWS_CASCADE0 + cascade)); @@ -1020,6 +1023,10 @@ void IrrDriver::renderShadows() } } + glDisable(GL_MULTISAMPLE); + + for (unsigned i = 0; i < 4; i++) + FrameBuffer::BlitLayer(m_rtts->getShadowMSAAFBO(), m_rtts->getShadowFBO(), i, GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 09ac00922..687bc917e 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -229,6 +229,17 @@ RTT::RTT(size_t width, size_t height) somevector.clear(); somevector.push_back(shadowColorTex); m_shadow_FBO = new FrameBuffer(somevector, shadowDepthTex, 1024, 1024, true); + + glGenTextures(1, &shadowColorMSAATex); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, shadowColorMSAATex); + glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_R32F, 1024, 1024, 4, true); + glGenTextures(1, &shadowDepthMSAATex); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, shadowDepthMSAATex); + glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_DEPTH_COMPONENT32, 1024, 1024, 4, true); + + somevector.clear(); + somevector.push_back(shadowColorMSAATex); + m_shadowMSAA_FBO = new FrameBuffer(somevector, shadowDepthMSAATex, 1024, 1024, true); } if (UserConfigParams::m_gi) diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 3be79d37a..d912cb015 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -42,6 +42,7 @@ public: ~RTT(); FrameBuffer &getShadowFBO() { return *m_shadow_FBO; } + FrameBuffer &getShadowMSAAFBO() { return *m_shadowMSAA_FBO; } FrameBuffer &getRH() { return *m_RH_FBO; } FrameBuffer &getRSM() { return *m_RSM; } @@ -60,9 +61,10 @@ private: int m_height; unsigned shadowColorTex, shadowNormalTex, shadowDepthTex; + unsigned shadowColorMSAATex, shadowDepthMSAATex; unsigned RSM_Color, RSM_Normal, RSM_Depth; unsigned RH_Red, RH_Green, RH_Blue; - FrameBuffer* m_shadow_FBO, *m_RSM, *m_RH_FBO; + FrameBuffer* m_shadow_FBO, *m_shadowMSAA_FBO, *m_RSM, *m_RH_FBO; LEAK_CHECK(); }; From cedbb32a1761be8f08ef9abd42818bef24123801 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 00:00:21 +0100 Subject: [PATCH 04/17] Try to fix incomplete fbo attachement --- src/graphics/render_geometry.cpp | 2 +- src/graphics/rtts.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index a720fcc01..c4998bfc6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1026,7 +1026,7 @@ void IrrDriver::renderShadows() glDisable(GL_MULTISAMPLE); for (unsigned i = 0; i < 4; i++) - FrameBuffer::BlitLayer(m_rtts->getShadowMSAAFBO(), m_rtts->getShadowFBO(), i, GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT, GL_NEAREST); + FrameBuffer::BlitLayer(m_rtts->getShadowMSAAFBO(), m_rtts->getShadowFBO(), i, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 687bc917e..753b529cb 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -224,7 +224,7 @@ RTT::RTT(size_t width, size_t height) if (UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround()) { shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 10); - shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH_COMPONENT32, GL_DEPTH_STENCIL, GL_DEPTH_COMPONENT, 10); + shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 10); somevector.clear(); somevector.push_back(shadowColorTex); @@ -235,7 +235,7 @@ RTT::RTT(size_t width, size_t height) glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_R32F, 1024, 1024, 4, true); glGenTextures(1, &shadowDepthMSAATex); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, shadowDepthMSAATex); - glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_DEPTH_COMPONENT32, 1024, 1024, 4, true); + glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_DEPTH24_STENCIL8, 1024, 1024, 4, true); somevector.clear(); somevector.push_back(shadowColorMSAATex); From 57b6d8e4158e3dc55dc34346c5748b8897b8ccbd Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 00:20:13 +0100 Subject: [PATCH 05/17] Revert "Use MSAA for shadowmap" This reverts commit fce9fe4385aa488a6f02814790022828d5e8f8bf. Conflicts: src/graphics/render_geometry.cpp src/graphics/rtts.cpp --- src/graphics/glwrap.cpp | 25 +++---------------------- src/graphics/glwrap.hpp | 3 +-- src/graphics/render_geometry.cpp | 9 +-------- src/graphics/rtts.cpp | 11 ----------- src/graphics/rtts.hpp | 4 +--- 5 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 7ff0ff32b..e13454bef 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -162,10 +162,10 @@ unsigned GPUTimer::elapsedTimeus() return result / 1000; } -FrameBuffer::FrameBuffer() : layerfbo(0) {} +FrameBuffer::FrameBuffer() {} FrameBuffer::FrameBuffer(const std::vector &RTTs, size_t w, size_t h, bool layered) : -RenderTargets(RTTs), DepthTexture(0), width(w), height(h), layerfbo(0) + RenderTargets(RTTs), DepthTexture(0), width(w), height(h) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -184,7 +184,7 @@ RenderTargets(RTTs), DepthTexture(0), width(w), height(h), layerfbo(0) } FrameBuffer::FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, size_t h, bool layered) : -RenderTargets(RTTs), DepthTexture(DS), width(w), height(h), layerfbo(0) + RenderTargets(RTTs), DepthTexture(DS), width(w), height(h) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -202,16 +202,11 @@ RenderTargets(RTTs), DepthTexture(DS), width(w), height(h), layerfbo(0) } GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); - - if (layered) - glGenFramebuffers(1, &layerfbo); } FrameBuffer::~FrameBuffer() { glDeleteFramebuffers(1, &fbo); - if (layerfbo) - glDeleteFramebuffers(1, &layerfbo); } void FrameBuffer::Bind() @@ -232,20 +227,6 @@ void FrameBuffer::Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } -void FrameBuffer::BlitLayer(const FrameBuffer &Src, FrameBuffer &Dst, unsigned layer, GLbitfield mask, GLenum filter) -{ - glBindFramebuffer(GL_READ_FRAMEBUFFER, Src.layerfbo); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Src.RenderTargets[0], 0, layer); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, Src.DepthTexture, 0, layer); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Dst.layerfbo); - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Dst.RenderTargets[0], 0, layer); - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, Dst.DepthTexture, 0, layer); - glBlitFramebuffer(0, 0, (int)Src.width, (int)Src.height, 0, 0, - (int)Dst.width, (int)Dst.height, mask, filter); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -} - void FrameBuffer::BlitToDefault(size_t x0, size_t y0, size_t x1, size_t y1) { glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 39233934b..631fc4cf2 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -43,7 +43,7 @@ public: class FrameBuffer { private: - GLuint fbo, layerfbo; + GLuint fbo; std::vector RenderTargets; GLuint DepthTexture; size_t width, height; @@ -59,7 +59,6 @@ public: size_t getHeight() const { return height; } static void Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST); void BlitToDefault(size_t, size_t, size_t, size_t); - static void BlitLayer(const FrameBuffer &Src, FrameBuffer &Dst, unsigned layer, GLbitfield mask, GLenum filter); }; class VertexUtils diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index c4998bfc6..41cb883d6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,15 +978,12 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - m_rtts->getShadowMSAAFBO().Bind(); + m_rtts->getShadowFBO().Bind(); glClearColor(1., 1., 1., 1.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClearColor(0., 0., 0., 0.); - - glEnable(GL_MULTISAMPLE); - for (unsigned cascade = 0; cascade < 4; cascade++) { ScopedGPUTimer Timer(getGPUTimer(Q_SHADOWS_CASCADE0 + cascade)); @@ -1023,10 +1020,6 @@ void IrrDriver::renderShadows() } } - glDisable(GL_MULTISAMPLE); - - for (unsigned i = 0; i < 4; i++) - FrameBuffer::BlitLayer(m_rtts->getShadowMSAAFBO(), m_rtts->getShadowFBO(), i, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 753b529cb..5d51ea72f 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -229,17 +229,6 @@ RTT::RTT(size_t width, size_t height) somevector.clear(); somevector.push_back(shadowColorTex); m_shadow_FBO = new FrameBuffer(somevector, shadowDepthTex, 1024, 1024, true); - - glGenTextures(1, &shadowColorMSAATex); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, shadowColorMSAATex); - glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_R32F, 1024, 1024, 4, true); - glGenTextures(1, &shadowDepthMSAATex); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, shadowDepthMSAATex); - glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 8, GL_DEPTH24_STENCIL8, 1024, 1024, 4, true); - - somevector.clear(); - somevector.push_back(shadowColorMSAATex); - m_shadowMSAA_FBO = new FrameBuffer(somevector, shadowDepthMSAATex, 1024, 1024, true); } if (UserConfigParams::m_gi) diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index d912cb015..3be79d37a 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -42,7 +42,6 @@ public: ~RTT(); FrameBuffer &getShadowFBO() { return *m_shadow_FBO; } - FrameBuffer &getShadowMSAAFBO() { return *m_shadowMSAA_FBO; } FrameBuffer &getRH() { return *m_RH_FBO; } FrameBuffer &getRSM() { return *m_RSM; } @@ -61,10 +60,9 @@ private: int m_height; unsigned shadowColorTex, shadowNormalTex, shadowDepthTex; - unsigned shadowColorMSAATex, shadowDepthMSAATex; unsigned RSM_Color, RSM_Normal, RSM_Depth; unsigned RH_Red, RH_Green, RH_Blue; - FrameBuffer* m_shadow_FBO, *m_shadowMSAA_FBO, *m_RSM, *m_RH_FBO; + FrameBuffer* m_shadow_FBO, *m_RSM, *m_RH_FBO; LEAK_CHECK(); }; From 6bf5c13bde8e36a31a61d3e905dd1d48f338ded5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 01:33:49 +0100 Subject: [PATCH 06/17] Implement shadow blur --- src/graphics/glwrap.cpp | 18 ++++++++++++++++-- src/graphics/glwrap.hpp | 3 ++- src/graphics/post_processing.cpp | 19 +++++++++++++++++++ src/graphics/post_processing.hpp | 1 + src/graphics/render_geometry.cpp | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index e13454bef..1daf187f9 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -165,7 +165,7 @@ unsigned GPUTimer::elapsedTimeus() FrameBuffer::FrameBuffer() {} FrameBuffer::FrameBuffer(const std::vector &RTTs, size_t w, size_t h, bool layered) : - RenderTargets(RTTs), DepthTexture(0), width(w), height(h) +RenderTargets(RTTs), DepthTexture(0), width(w), height(h), fbolayer(0) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -184,7 +184,7 @@ FrameBuffer::FrameBuffer(const std::vector &RTTs, size_t w, size_t h, bo } FrameBuffer::FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, size_t h, bool layered) : - RenderTargets(RTTs), DepthTexture(DS), width(w), height(h) +RenderTargets(RTTs), DepthTexture(DS), width(w), height(h), fbolayer(0) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -202,11 +202,15 @@ FrameBuffer::FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, s } GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); + if (layered) + glGenFramebuffers(1, &fbolayer); } FrameBuffer::~FrameBuffer() { glDeleteFramebuffers(1, &fbo); + if (fbolayer) + glDeleteFramebuffers(1, &fbolayer); } void FrameBuffer::Bind() @@ -217,6 +221,16 @@ void FrameBuffer::Bind() glDrawBuffers((int)RenderTargets.size(), bufs); } +void FrameBuffer::BindLayer(unsigned i) +{ + glBindFramebuffer(GL_FRAMEBUFFER, fbolayer); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, RenderTargets[0], 0, i); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DepthTexture, 0, i); + glViewport(0, 0, (int)width, (int)height); + GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; + glDrawBuffers((int)RenderTargets.size(), bufs); +} + void FrameBuffer::Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask, GLenum filter) { glBindFramebuffer(GL_READ_FRAMEBUFFER, Src.fbo); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 631fc4cf2..bcfc89eb8 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -43,7 +43,7 @@ public: class FrameBuffer { private: - GLuint fbo; + GLuint fbo, fbolayer; std::vector RenderTargets; GLuint DepthTexture; size_t width, height; @@ -53,6 +53,7 @@ public: FrameBuffer(const std::vector &RTTs, GLuint DS, size_t w, size_t h, bool layered = false); ~FrameBuffer(); void Bind(); + void BindLayer(unsigned); const std::vector &getRTT() const { return RenderTargets; } GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; } size_t getWidth() const { return width; } diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 7a586b6ce..9655d1c29 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -314,6 +314,25 @@ void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxil } } +static GLuint LayerTex = 0; + +void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo) +{ + if (!LayerTex) + glGenTextures(1, &LayerTex); + for (unsigned i = 0; i < 4; i++) + { + // Used as temp + irr_driver->getFBO(FBO_BLOOM_1024).Bind(); + glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, i, 1); + FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(LayerTex); + DrawFullScreenEffect(core::vector2df(1. / 1024., 1. / 1024.)); + in_fbo.BindLayer(i); + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_BLOOM_1024).getRTT()[0]); + DrawFullScreenEffect(core::vector2df(1. / 1024., 1. / 1024.)); + } +} + void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) { assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight()); diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index e09a66451..dd8774f96 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 renderGaussian6BlurLayer(FrameBuffer &in_fbo); void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary); /** Render tex. Used for blit/texture resize */ diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 41cb883d6..13d2505c6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1020,6 +1020,7 @@ void IrrDriver::renderShadows() } } + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } From f4e0437106946e028ead358a35bc0bed4efab0f1 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 01:41:43 +0100 Subject: [PATCH 07/17] Fix textureview --- src/graphics/post_processing.cpp | 8 ++++---- src/graphics/rtts.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 9655d1c29..dc662d4e3 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -314,22 +314,22 @@ void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxil } } -static GLuint LayerTex = 0; - void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo) { - if (!LayerTex) - glGenTextures(1, &LayerTex); + for (unsigned i = 0; i < 4; i++) { // Used as temp irr_driver->getFBO(FBO_BLOOM_1024).Bind(); + GLuint LayerTex; + glGenTextures(1, &LayerTex); glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, i, 1); FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(LayerTex); DrawFullScreenEffect(core::vector2df(1. / 1024., 1. / 1024.)); in_fbo.BindLayer(i); FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_BLOOM_1024).getRTT()[0]); DrawFullScreenEffect(core::vector2df(1. / 1024., 1. / 1024.)); + glDeleteTextures(1, &LayerTex); } } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 5d51ea72f..4b6024975 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -223,8 +223,8 @@ RTT::RTT(size_t width, size_t height) if (UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround()) { - shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 10); - shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 10); + shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 1); + shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); somevector.clear(); somevector.push_back(shadowColorTex); From 1ecd8dcf4f5efd3ff86eebacf2f08ce77e318086 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 02:03:06 +0100 Subject: [PATCH 08/17] =?UTF-8?q?Fix=20moir=C3=A9=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/render_geometry.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 13d2505c6..33fe28409 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,6 +978,8 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); m_rtts->getShadowFBO().Bind(); glClearColor(1., 1., 1., 1.); @@ -1020,6 +1022,9 @@ void IrrDriver::renderShadows() } } + glCullFace(GL_BACK); + glDisable(GL_CULL_FACE); + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); From f5a44c0a19a558cf55b9a96255289d1b522ba47a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 02:42:44 +0100 Subject: [PATCH 09/17] Take more sample --- data/shaders/gaussian6h.frag | 2 +- data/shaders/gaussian6v.frag | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/shaders/gaussian6h.frag b/data/shaders/gaussian6h.frag index f8d43c27d..e90cfd132 100644 --- a/data/shaders/gaussian6h.frag +++ b/data/shaders/gaussian6h.frag @@ -20,7 +20,7 @@ void main() vec4 sum = texture(tex, vec2(X, Y)) * g0; g0 *= g1; g1 *= g2; - for (int i = 1; i < 3; i++) { + for (int i = 1; i < 6; i++) { sum += texture(tex, vec2(X - i * pixel.x, Y)) * g0; sum += texture(tex, vec2(X + i * pixel.x, Y)) * g0; g0 *= g1; diff --git a/data/shaders/gaussian6v.frag b/data/shaders/gaussian6v.frag index 7576c02b0..cf5ec0ce6 100644 --- a/data/shaders/gaussian6v.frag +++ b/data/shaders/gaussian6v.frag @@ -20,7 +20,7 @@ void main() vec4 sum = texture(tex, vec2(X, Y)) * g0; g0 *= g1; g1 *= g2; - for (int i = 1; i < 3; i++) { + for (int i = 1; i < 6; i++) { sum += texture(tex, vec2(X, Y - i * pixel.y)) * g0; sum += texture(tex, vec2(X, Y + i * pixel.y)) * g0; g0 *= g1; From b975b63eeace2363fc5865943f9bcc263a38e22e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 16:00:41 +0100 Subject: [PATCH 10/17] Use proper depth linear value --- data/shaders/instanced_shadowref.frag | 2 +- data/shaders/shadow.frag | 2 +- data/shaders/shadowref.frag | 2 +- data/shaders/sunlightshadow.frag | 4 ++-- src/graphics/render_geometry.cpp | 5 ----- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/data/shaders/instanced_shadowref.frag b/data/shaders/instanced_shadowref.frag index fc210c491..f303688b6 100644 --- a/data/shaders/instanced_shadowref.frag +++ b/data/shaders/instanced_shadowref.frag @@ -17,5 +17,5 @@ void main(void) vec4 col = texture(tex, uv); #endif if (col.a < 0.5) discard; - FragColor = vec4(gl_FragCoord.z); + FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); } diff --git a/data/shaders/shadow.frag b/data/shaders/shadow.frag index 1239ac3de..128b3e31c 100644 --- a/data/shaders/shadow.frag +++ b/data/shaders/shadow.frag @@ -2,5 +2,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(gl_FragCoord.z); + FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); } diff --git a/data/shaders/shadowref.frag b/data/shaders/shadowref.frag index ea29aafec..ec6905c6d 100644 --- a/data/shaders/shadowref.frag +++ b/data/shaders/shadowref.frag @@ -12,5 +12,5 @@ void main(void) { vec4 col = texture(tex, uv); if (col.a < 0.5) discard; - FragColor = vec4(gl_FragCoord.z); + FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); } diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 7ab1772ef..346f33f1c 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -30,7 +30,7 @@ float getShadowFactor(vec3 pos, float bias, int index) ); vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; + shadowcoord.xy /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; // shadowcoord = (shadowcoord * 0.5) + vec3(0.5); @@ -55,7 +55,7 @@ float getShadowFactor(vec3 pos, float bias, int index) // return sum / 16.; float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x; - float d = .5 * shadowcoord.z + .5; + float d = shadowcoord.z; return min(exp(1024 *(z - d)), 1.); } diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 33fe28409..13d2505c6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,8 +978,6 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); m_rtts->getShadowFBO().Bind(); glClearColor(1., 1., 1., 1.); @@ -1022,9 +1020,6 @@ void IrrDriver::renderShadows() } } - glCullFace(GL_BACK); - glDisable(GL_CULL_FACE); - m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); From c5186e3ab3857698e112f2f8a6049ec3fc950deb Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 16:26:46 +0100 Subject: [PATCH 11/17] Use depth in exp space --- data/shaders/instanced_shadowref.frag | 2 +- data/shaders/shadow.frag | 2 +- data/shaders/shadowref.frag | 2 +- data/shaders/sunlightshadow.frag | 2 +- src/graphics/render_geometry.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/shaders/instanced_shadowref.frag b/data/shaders/instanced_shadowref.frag index f303688b6..c9be0f7eb 100644 --- a/data/shaders/instanced_shadowref.frag +++ b/data/shaders/instanced_shadowref.frag @@ -17,5 +17,5 @@ void main(void) vec4 col = texture(tex, uv); #endif if (col.a < 0.5) discard; - FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); + FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadow.frag b/data/shaders/shadow.frag index 128b3e31c..ffa59b9ee 100644 --- a/data/shaders/shadow.frag +++ b/data/shaders/shadow.frag @@ -2,5 +2,5 @@ out vec4 FragColor; void main() { - FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); + FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadowref.frag b/data/shaders/shadowref.frag index ec6905c6d..915667c9c 100644 --- a/data/shaders/shadowref.frag +++ b/data/shaders/shadowref.frag @@ -12,5 +12,5 @@ void main(void) { vec4 col = texture(tex, uv); if (col.a < 0.5) discard; - FragColor = vec4((2. * gl_FragCoord.z - 1.) / gl_FragCoord.w); + FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 346f33f1c..30c98cd8e 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -56,7 +56,7 @@ float getShadowFactor(vec3 pos, float bias, int index) float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x; float d = shadowcoord.z; - return min(exp(1024 *(z - d)), 1.); + return min(pow(exp(-80. * d) * z, 4.), 1.); } void main() { diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 13d2505c6..93f8e9345 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1020,7 +1020,7 @@ void IrrDriver::renderShadows() } } - m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); +// m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } From ebe11370a2418770da76274e740a6dce0fe87328 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 16:30:44 +0100 Subject: [PATCH 12/17] Reenable bluring --- data/shaders/instanced_shadowref.frag | 2 +- data/shaders/shadow.frag | 2 +- data/shaders/shadowref.frag | 2 +- data/shaders/sunlightshadow.frag | 2 +- src/graphics/render_geometry.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/shaders/instanced_shadowref.frag b/data/shaders/instanced_shadowref.frag index c9be0f7eb..8595ee2b7 100644 --- a/data/shaders/instanced_shadowref.frag +++ b/data/shaders/instanced_shadowref.frag @@ -17,5 +17,5 @@ void main(void) vec4 col = texture(tex, uv); #endif if (col.a < 0.5) discard; - FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadow.frag b/data/shaders/shadow.frag index ffa59b9ee..39ccc5428 100644 --- a/data/shaders/shadow.frag +++ b/data/shaders/shadow.frag @@ -2,5 +2,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadowref.frag b/data/shaders/shadowref.frag index 915667c9c..c63761190 100644 --- a/data/shaders/shadowref.frag +++ b/data/shaders/shadowref.frag @@ -12,5 +12,5 @@ void main(void) { vec4 col = texture(tex, uv); if (col.a < 0.5) discard; - FragColor = vec4(exp(80. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 30c98cd8e..8b6337b86 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -56,7 +56,7 @@ float getShadowFactor(vec3 pos, float bias, int index) float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x; float d = shadowcoord.z; - return min(pow(exp(-80. * d) * z, 4.), 1.); + return min(pow(exp(-1. * d) * z, 240.), 1.); } void main() { diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 93f8e9345..13d2505c6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1020,7 +1020,7 @@ void IrrDriver::renderShadows() } } -// m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } From ddecd23472d12dd3d36c34dc6cf5c15cd3931997 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 2 Nov 2014 19:07:02 +0100 Subject: [PATCH 13/17] Tweak values --- data/shaders/instanced_shadowref.frag | 2 +- data/shaders/shadow.frag | 2 +- data/shaders/shadowref.frag | 2 +- data/shaders/sunlightshadow.frag | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/shaders/instanced_shadowref.frag b/data/shaders/instanced_shadowref.frag index 8595ee2b7..bf296e7ea 100644 --- a/data/shaders/instanced_shadowref.frag +++ b/data/shaders/instanced_shadowref.frag @@ -17,5 +17,5 @@ void main(void) vec4 col = texture(tex, uv); #endif if (col.a < 0.5) discard; - FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadow.frag b/data/shaders/shadow.frag index 39ccc5428..45118c085 100644 --- a/data/shaders/shadow.frag +++ b/data/shaders/shadow.frag @@ -2,5 +2,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/shadowref.frag b/data/shaders/shadowref.frag index c63761190..cce3b3be4 100644 --- a/data/shaders/shadowref.frag +++ b/data/shaders/shadowref.frag @@ -12,5 +12,5 @@ void main(void) { vec4 col = texture(tex, uv); if (col.a < 0.5) discard; - FragColor = vec4(exp(1. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); + FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w)); } diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 8b6337b86..0bb01c51d 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -56,7 +56,7 @@ float getShadowFactor(vec3 pos, float bias, int index) float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x; float d = shadowcoord.z; - return min(pow(exp(-1. * d) * z, 240.), 1.); + return min(pow(exp(-8. * d) * z, 256.), 1.); } void main() { From 61dd0fdc600d099a466314f87137dfeee80dded9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 3 Nov 2014 00:29:44 +0100 Subject: [PATCH 14/17] Reenable again culling for shadows --- src/graphics/render_geometry.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 13d2505c6..33fe28409 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,6 +978,8 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); m_rtts->getShadowFBO().Bind(); glClearColor(1., 1., 1., 1.); @@ -1020,6 +1022,9 @@ void IrrDriver::renderShadows() } } + glCullFace(GL_BACK); + glDisable(GL_CULL_FACE); + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); From 70f53a0e5160b8bd62320b9e6e90145cabcf716a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 3 Nov 2014 00:48:29 +0100 Subject: [PATCH 15/17] Revert "Reenable again culling for shadows" This reverts commit 61dd0fdc600d099a466314f87137dfeee80dded9. --- src/graphics/render_geometry.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 33fe28409..13d2505c6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -978,8 +978,6 @@ void IrrDriver::renderShadows() glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); m_rtts->getShadowFBO().Bind(); glClearColor(1., 1., 1., 1.); @@ -1022,9 +1020,6 @@ void IrrDriver::renderShadows() } } - glCullFace(GL_BACK); - glDisable(GL_CULL_FACE); - m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); From e5b269949ae8e1a351fd0dba60a2922ce0af72d1 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 3 Nov 2014 00:49:52 +0100 Subject: [PATCH 16/17] Use polygon offset --- src/graphics/render_geometry.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 13d2505c6..6ba414e1a 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -979,6 +979,10 @@ void IrrDriver::renderShadows() glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); m_rtts->getShadowFBO().Bind(); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.5, 0.); + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); glClearColor(1., 1., 1., 1.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); @@ -1020,6 +1024,8 @@ void IrrDriver::renderShadows() } } + glDisable(GL_POLYGON_OFFSET_FILL); + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); From f2da00954da38436cfdc1699ea40fb71f84e2aec Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 3 Nov 2014 00:57:07 +0100 Subject: [PATCH 17/17] Check if textureview is available before filtering --- src/graphics/irr_driver.cpp | 5 +++++ src/graphics/irr_driver.hpp | 6 ++++++ src/graphics/render_geometry.cpp | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 3a6575f9b..8f089fbdd 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -513,6 +513,7 @@ void IrrDriver::initDevice() hasDrawIndirect = false; hasComputeShaders = false; hasTextureStorage = false; + hasTextureView = false; // Default false value for hasVSLayer if --no-graphics argument is used #if !defined(__APPLE__) if (!ProfileWorld::isNoGraphics()) @@ -541,6 +542,10 @@ void IrrDriver::initDevice() hasTextureStorage = true; Log::info("GLDriver", "ARB Texture Storage enabled"); } + if (hasGLExtension("GL_ARB_texture_view")) { + hasTextureView = true; + Log::info("GLDriver", "ARB Texture View enabled"); + } } #endif diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 17740981a..1dc1f29e0 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -180,6 +180,7 @@ private: bool hasBuffserStorage; bool hasComputeShaders; bool hasTextureStorage; + bool hasTextureView; bool m_need_ubo_workaround; bool m_need_rh_workaround; bool m_need_srgb_workaround; @@ -311,6 +312,11 @@ public: return hasTextureStorage; } + bool hasARBTextureView() const + { + return hasTextureView; + } + video::SColorf getAmbientLight() const; struct GlowData { diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 6ba414e1a..d5fe29c4b 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -1026,7 +1026,8 @@ void IrrDriver::renderShadows() glDisable(GL_POLYGON_OFFSET_FILL); - m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); + if (irr_driver->hasARBTextureView()) + m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO()); glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); }