Use MSAA for shadowmap
This commit is contained in:
parent
937eb3baf8
commit
4e6a7b5192
@ -162,10 +162,10 @@ unsigned GPUTimer::elapsedTimeus()
|
||||
return result / 1000;
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer() {}
|
||||
FrameBuffer::FrameBuffer() : layerfbo(0) {}
|
||||
|
||||
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), layerfbo(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), layerfbo(0)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
@ -202,11 +202,16 @@ 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, &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);
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
class FrameBuffer
|
||||
{
|
||||
private:
|
||||
GLuint fbo;
|
||||
GLuint fbo, layerfbo;
|
||||
std::vector<GLuint> 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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user