Implement shadow blur

This commit is contained in:
Vincent Lejeune 2014-11-02 01:33:49 +01:00
parent 57b6d8e415
commit 6bf5c13bde
5 changed files with 39 additions and 3 deletions

View File

@ -165,7 +165,7 @@ unsigned GPUTimer::elapsedTimeus()
FrameBuffer::FrameBuffer() {}
FrameBuffer::FrameBuffer(const std::vector<GLuint> &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<GLuint> &RTTs, size_t w, size_t h, bo
}
FrameBuffer::FrameBuffer(const std::vector<GLuint> &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<GLuint> &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);

View File

@ -43,7 +43,7 @@ public:
class FrameBuffer
{
private:
GLuint fbo;
GLuint fbo, fbolayer;
std::vector<GLuint> RenderTargets;
GLuint DepthTexture;
size_t width, height;
@ -53,6 +53,7 @@ public:
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered = false);
~FrameBuffer();
void Bind();
void BindLayer(unsigned);
const std::vector<GLuint> &getRTT() const { return RenderTargets; }
GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; }
size_t getWidth() const { return width; }

View File

@ -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<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(1. / 1024., 1. / 1024.));
in_fbo.BindLayer(i);
FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_BLOOM_1024).getRTT()[0]);
DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(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());

View File

@ -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 */

View File

@ -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);
}