Encapsulate fbos in a class
This commit is contained in:
parent
f4a5949198
commit
ecca6911d1
@ -476,15 +476,6 @@ void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum
|
||||
glGetError();
|
||||
}
|
||||
|
||||
void blitFBO(GLuint Src, GLuint Dst, size_t width, size_t height)
|
||||
{
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, Src);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Dst);
|
||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
ScopedGPUTimer::ScopedGPUTimer(GPUTimer &timer)
|
||||
{
|
||||
if (!UserConfigParams::m_profiler_enabled) return;
|
||||
@ -525,6 +516,64 @@ unsigned GPUTimer::elapsedTimeus()
|
||||
return result / 1000;
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer() {}
|
||||
|
||||
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, size_t w, size_t h) :
|
||||
DepthTexture(0), RenderTargets(RTTs), width(w), height(h)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
for (unsigned i = 0; i < RTTs.size(); i++)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
|
||||
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, size_t h) :
|
||||
DepthTexture(DS), RenderTargets(RTTs), width(w), height(h)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
for (unsigned i = 0; i < RTTs.size(); i++)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DS, 0);
|
||||
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer()
|
||||
{
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
}
|
||||
|
||||
void FrameBuffer::Bind()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glViewport(0, 0, width, height);
|
||||
irr::video::COpenGLDriver *gl_driver = (irr::video::COpenGLDriver*)irr_driver->getDevice()->getVideoDriver();
|
||||
GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||
gl_driver->extGlDrawBuffers(RenderTargets.size(), bufs);
|
||||
}
|
||||
|
||||
void FrameBuffer::Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask, GLenum filter)
|
||||
{
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, Src.fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Dst.fbo);
|
||||
glBlitFramebuffer(0, 0, Src.width, Src.height, 0, 0, Dst.width, Dst.height, mask, filter);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void FrameBuffer::BlitToDefault()
|
||||
{
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
||||
void draw3DLine(const core::vector3df& start,
|
||||
const core::vector3df& end, irr::video::SColor color)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
# include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include "utils/log.hpp"
|
||||
|
||||
// already includes glext.h, which defines useful GL constants.
|
||||
@ -180,6 +181,27 @@ public:
|
||||
unsigned elapsedTimeus();
|
||||
};
|
||||
|
||||
class FrameBuffer
|
||||
{
|
||||
private:
|
||||
GLuint fbo;
|
||||
std::vector<GLuint> RenderTargets;
|
||||
GLuint DepthTexture;
|
||||
size_t width, height;
|
||||
public:
|
||||
FrameBuffer();
|
||||
FrameBuffer(const std::vector <GLuint> &RTTs, size_t w, size_t h);
|
||||
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h);
|
||||
~FrameBuffer();
|
||||
void Bind();
|
||||
std::vector<GLuint> &getRTT() { return RenderTargets; }
|
||||
GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; }
|
||||
size_t getWidth() const { return width; }
|
||||
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();
|
||||
};
|
||||
|
||||
// core::rect<s32> needs these includes
|
||||
#include <rect.h>
|
||||
#include "utils/vec3.hpp"
|
||||
@ -190,7 +212,6 @@ void resetTextureTable();
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = false);
|
||||
bool loadCompressedTexture(const std::string& compressed_tex);
|
||||
void saveCompressedTexture(const std::string& compressed_tex);
|
||||
void blitFBO(GLuint Src, GLuint Dst, size_t width, size_t height);
|
||||
|
||||
void draw3DLine(const core::vector3df& start,
|
||||
const core::vector3df& end, irr::video::SColor color);
|
||||
|
@ -478,7 +478,7 @@ public:
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
inline GLuint getRenderTargetTexture(TypeRTT which) { return m_rtts->getRenderTarget(which); }
|
||||
inline GLuint getFBO(TypeFBO which) { return m_rtts->getFBO(which); }
|
||||
inline FrameBuffer& getFBO(TypeFBO which) { return m_rtts->getFBO(which); }
|
||||
inline GLuint getDepthStencilTexture() { return m_rtts->getDepthStencilTexture(); }
|
||||
// ------------------------------------------------------------------------
|
||||
inline bool isGLSL() const { return m_glsl; }
|
||||
|
@ -317,17 +317,18 @@ void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &su
|
||||
}
|
||||
|
||||
|
||||
void PostProcessing::renderGaussian3Blur(GLuint in_fbo, GLuint in_tex, GLuint tmp_fbo, GLuint tmp_tex, size_t width, size_t height)
|
||||
void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
|
||||
{
|
||||
float inv_width = 1.0f / width, inv_height = 1.0f / height;
|
||||
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();
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fbo);
|
||||
auxiliary.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian3VBlurShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian3VBlurShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian3VBlurShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, in_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian3VBlurShader::uniform_tex, 0);
|
||||
@ -335,13 +336,13 @@ void PostProcessing::renderGaussian3Blur(GLuint in_fbo, GLuint in_tex, GLuint tm
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, in_fbo);
|
||||
in_fbo.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian3HBlurShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian3HBlurShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian3HBlurShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, tmp_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian3HBlurShader::uniform_tex, 0);
|
||||
@ -350,17 +351,18 @@ void PostProcessing::renderGaussian3Blur(GLuint in_fbo, GLuint in_tex, GLuint tm
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcessing::renderGaussian6Blur(GLuint in_fbo, GLuint in_tex, GLuint tmp_fbo, GLuint tmp_tex, size_t width, size_t height)
|
||||
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
|
||||
{
|
||||
float inv_width = 1.f / width, inv_height = 1.f / height;
|
||||
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();
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fbo);
|
||||
auxiliary.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian6VBlurShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian6VBlurShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, in_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian6VBlurShader::uniform_tex, 0);
|
||||
@ -368,13 +370,13 @@ void PostProcessing::renderGaussian6Blur(GLuint in_fbo, GLuint in_tex, GLuint tm
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, in_fbo);
|
||||
in_fbo.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian6HBlurShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian6HBlurShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, tmp_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian6HBlurShader::uniform_tex, 0);
|
||||
@ -383,17 +385,18 @@ void PostProcessing::renderGaussian6Blur(GLuint in_fbo, GLuint in_tex, GLuint tm
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcessing::renderGaussian17TapBlur(unsigned in_fbo, unsigned in_tex, unsigned tmp_fbo, unsigned tmp_tex, size_t width, size_t height)
|
||||
void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
|
||||
{
|
||||
float inv_width = 1.f / width, inv_height = 1.f / height;
|
||||
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();
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fbo);
|
||||
auxiliary.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian17TapHShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian17TapHShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian17TapHShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, in_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian17TapHShader::uniform_tex, 0);
|
||||
@ -401,13 +404,13 @@ void PostProcessing::renderGaussian17TapBlur(unsigned in_fbo, unsigned in_tex, u
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, in_fbo);
|
||||
in_fbo.Bind();
|
||||
glUseProgram(FullScreenShader::Gaussian17TapVShader::Program);
|
||||
glBindVertexArray(FullScreenShader::Gaussian17TapVShader::vao);
|
||||
|
||||
glUniform2f(FullScreenShader::Gaussian17TapVShader::uniform_pixel, inv_width, inv_height);
|
||||
|
||||
setTexture(0, tmp_tex, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glUniform1i(FullScreenShader::Gaussian17TapVShader::uniform_tex, 0);
|
||||
@ -452,13 +455,13 @@ void PostProcessing::renderSSAO()
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
// Generate linear depth buffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_LINEAR_DEPTH));
|
||||
irr_driver->getFBO(FBO_LINEAR_DEPTH).Bind();
|
||||
glUseProgram(FullScreenShader::LinearizeDepthShader::Program);
|
||||
glBindVertexArray(FullScreenShader::LinearizeDepthShader::vao);
|
||||
setTexture(0, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR);
|
||||
FullScreenShader::LinearizeDepthShader::setUniforms(irr_driver->getSceneManager()->getActiveCamera()->getNearValue(), irr_driver->getSceneManager()->getActiveCamera()->getFarValue(), 0);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_SSAO));
|
||||
irr_driver->getFBO(FBO_SSAO).Bind();
|
||||
|
||||
if (!noise_tex)
|
||||
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str());
|
||||
@ -510,9 +513,8 @@ void PostProcessing::renderFog()
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void PostProcessing::renderMotionBlur(unsigned cam, GLuint in_rtt, GLuint out_fbo)
|
||||
void PostProcessing::renderMotionBlur(unsigned cam, FrameBuffer &in_fbo, FrameBuffer &out_fbo)
|
||||
{
|
||||
|
||||
MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver->
|
||||
getCallback(ES_MOTIONBLUR);
|
||||
|
||||
@ -529,18 +531,18 @@ void PostProcessing::renderMotionBlur(unsigned cam, GLuint in_rtt, GLuint out_fb
|
||||
const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f;
|
||||
setMotionBlurCenterY(cam, karty);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, out_fbo);
|
||||
out_fbo.Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(FullScreenShader::MotionBlurShader::Program);
|
||||
glBindVertexArray(FullScreenShader::MotionBlurShader::vao);
|
||||
|
||||
setTexture(0, in_rtt, GL_NEAREST, GL_NEAREST);
|
||||
setTexture(0, in_fbo.getRTT()[0], GL_NEAREST, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
FullScreenShader::MotionBlurShader
|
||||
::setUniforms(cb->getBoostTime(cam), cb->getCenter(cam),
|
||||
cb->getDirection(cam), 0.15f,
|
||||
cb->getDirection(cam), 0.15f,
|
||||
cb->getMaxHeight(cam) * 0.7f, 0);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
@ -566,9 +568,9 @@ static void renderGodRay(GLuint tex, const core::vector2df &sunpos)
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
static void toneMap(GLuint fbo, GLuint rtt)
|
||||
static void toneMap(FrameBuffer &fbo, GLuint rtt)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
fbo.Bind();
|
||||
glUseProgram(FullScreenShader::ToneMapShader::Program);
|
||||
glBindVertexArray(FullScreenShader::ToneMapShader::vao);
|
||||
setTexture(0, rtt, GL_NEAREST, GL_NEAREST);
|
||||
@ -578,10 +580,9 @@ static void toneMap(GLuint fbo, GLuint rtt)
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
static void renderDoF(GLuint fbo, GLuint rtt)
|
||||
static void renderDoF(FrameBuffer &fbo, GLuint rtt)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
fbo.Bind();
|
||||
glUseProgram(FullScreenShader::DepthOfFieldShader::Program);
|
||||
glBindVertexArray(FullScreenShader::DepthOfFieldShader::vao);
|
||||
setTexture(0, rtt, GL_LINEAR, GL_LINEAR);
|
||||
@ -600,8 +601,7 @@ static void averageTexture(GLuint tex)
|
||||
|
||||
static void computeLogLuminance(GLuint tex)
|
||||
{
|
||||
glViewport(0, 0, 1024, 1024);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_LOG_LUMINANCE));
|
||||
irr_driver->getFBO(FBO_LOG_LUMINANCE).Bind();
|
||||
glUseProgram(FullScreenShader::LogLuminanceShader::Program);
|
||||
glBindVertexArray(FullScreenShader::LogLuminanceShader::vao);
|
||||
setTexture(0, tex, GL_LINEAR, GL_LINEAR);
|
||||
@ -616,7 +616,7 @@ void PostProcessing::applyMLAA()
|
||||
{
|
||||
const core::vector2df &PIXEL_SIZE = core::vector2df(1.0f / UserConfigParams::m_width, 1.0f / UserConfigParams::m_height);
|
||||
IVideoDriver *const drv = irr_driver->getVideoDriver();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_TMP1_WITH_DS));
|
||||
irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind();
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
@ -635,7 +635,7 @@ void PostProcessing::applyMLAA()
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
// Pass 2: blend weights
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_TMP2_WITH_DS));
|
||||
irr_driver->getFBO(FBO_TMP2_WITH_DS).Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(FullScreenShader::MLAABlendWeightSHader::Program);
|
||||
@ -647,10 +647,10 @@ void PostProcessing::applyMLAA()
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
// Blit in to tmp1
|
||||
blitFBO(irr_driver->getFBO(FBO_MLAA_COLORS), irr_driver->getFBO(FBO_TMP1_WITH_DS), UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
FrameBuffer::Blit(irr_driver->getFBO(FBO_MLAA_COLORS), irr_driver->getFBO(FBO_TMP1_WITH_DS));
|
||||
|
||||
// Pass 3: gather
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_MLAA_COLORS));
|
||||
irr_driver->getFBO(FBO_MLAA_COLORS).Bind();
|
||||
|
||||
glUseProgram(FullScreenShader::MLAAGatherSHader::Program);
|
||||
setTexture(0, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_NEAREST, GL_NEAREST);
|
||||
@ -676,8 +676,8 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
GaussianBlurProvider * const gacb = (GaussianBlurProvider *) irr_driver->
|
||||
getCallback(ES_GAUSSIAN3H);
|
||||
|
||||
GLuint in_rtt = irr_driver->getRenderTargetTexture(RTT_COLOR), in_fbo = irr_driver->getFBO(FBO_COLORS);
|
||||
GLuint out_rtt = irr_driver->getRenderTargetTexture(RTT_TMP1), out_fbo = irr_driver->getFBO(FBO_TMP1_WITH_DS);
|
||||
FrameBuffer *in_fbo = &irr_driver->getFBO(FBO_COLORS);
|
||||
FrameBuffer *out_fbo = &irr_driver->getFBO(FBO_TMP1_WITH_DS);
|
||||
// Each effect uses these as named, and sets them up for the next effect.
|
||||
// This allows chaining effects where some may be disabled.
|
||||
|
||||
@ -687,8 +687,7 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
|
||||
if (UserConfigParams::m_dof)
|
||||
{
|
||||
renderDoF(out_fbo, in_rtt);
|
||||
std::swap(in_rtt, out_rtt);
|
||||
renderDoF(*out_fbo, in_fbo->getRTT()[0]);
|
||||
std::swap(in_fbo, out_fbo);
|
||||
}
|
||||
|
||||
@ -700,7 +699,7 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
// Grab the sky
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, out_fbo);
|
||||
out_fbo->Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
irr_driver->renderSkybox(camnode);
|
||||
|
||||
@ -717,17 +716,12 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Fade to quarter
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_QUARTER1));
|
||||
irr_driver->getFBO(FBO_QUARTER1).Bind();
|
||||
glViewport(0, 0, UserConfigParams::m_width / 4, UserConfigParams::m_height / 4);
|
||||
renderGodFade(out_rtt, col);
|
||||
renderGodFade(out_fbo->getRTT()[0], col);
|
||||
|
||||
// Blur
|
||||
renderGaussian3Blur(irr_driver->getFBO(FBO_QUARTER1), irr_driver->getRenderTargetTexture(RTT_QUARTER1),
|
||||
irr_driver->getFBO(FBO_QUARTER2), irr_driver->getRenderTargetTexture(RTT_QUARTER2),
|
||||
UserConfigParams::m_width / 4,
|
||||
UserConfigParams::m_height / 4);
|
||||
|
||||
|
||||
renderGaussian3Blur(irr_driver->getFBO(FBO_QUARTER1), irr_driver->getFBO(FBO_QUARTER2));
|
||||
|
||||
// Calculate the sun's position in texcoords
|
||||
const core::vector3df pos = sun->getPosition();
|
||||
@ -744,22 +738,18 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
const float suny = ((ndc[1] / ndc[3]) * 0.5f + 0.5f) * texh;
|
||||
|
||||
// Rays please
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_QUARTER2));
|
||||
irr_driver->getFBO(FBO_QUARTER2).Bind();
|
||||
renderGodRay(irr_driver->getRenderTargetTexture(RTT_QUARTER1), core::vector2df(sunx, suny));
|
||||
|
||||
// Blur
|
||||
renderGaussian3Blur(irr_driver->getFBO(FBO_QUARTER2), irr_driver->getRenderTargetTexture(RTT_QUARTER2),
|
||||
irr_driver->getFBO(FBO_QUARTER1), irr_driver->getRenderTargetTexture(RTT_QUARTER1),
|
||||
UserConfigParams::m_width / 4,
|
||||
UserConfigParams::m_height / 4);
|
||||
renderGaussian3Blur(irr_driver->getFBO(FBO_QUARTER2), irr_driver->getFBO(FBO_QUARTER1));
|
||||
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
// Blend
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, in_fbo);
|
||||
in_fbo->Bind();
|
||||
renderPassThrough(irr_driver->getRenderTargetTexture(RTT_QUARTER2));
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
@ -775,44 +765,24 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
{
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, in_fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_1024));
|
||||
glBlitFramebuffer(0, 0, UserConfigParams::m_width, UserConfigParams::m_height, 0, 0, 1024, 1024, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
FrameBuffer::Blit(*in_fbo, irr_driver->getFBO(FBO_BLOOM_1024), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_512));
|
||||
glViewport(0, 0, 512, 512);
|
||||
irr_driver->getFBO(FBO_BLOOM_512).Bind();
|
||||
renderBloom(irr_driver->getRenderTargetTexture(RTT_BLOOM_1024));
|
||||
|
||||
// Downsample
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_512));
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_256));
|
||||
glBlitFramebuffer(0, 0, 512, 512, 0, 0, 256, 256, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_256));
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getFBO(FBO_BLOOM_128));
|
||||
glBlitFramebuffer(0, 0, 256, 256, 0, 0, 128, 128, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
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);
|
||||
|
||||
// Blur
|
||||
glViewport(0, 0, 512, 512);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_512), irr_driver->getRenderTargetTexture(RTT_BLOOM_512),
|
||||
irr_driver->getFBO(FBO_TMP_512), irr_driver->getRenderTargetTexture(RTT_TMP_512), 512, 512);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_512), irr_driver->getFBO(FBO_TMP_512));
|
||||
|
||||
glViewport(0, 0, 256, 256);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getRenderTargetTexture(RTT_BLOOM_256),
|
||||
irr_driver->getFBO(FBO_TMP_256), irr_driver->getRenderTargetTexture(RTT_TMP_256), 256, 256);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_256), irr_driver->getFBO(FBO_TMP_256));
|
||||
|
||||
glViewport(0, 0, 128, 128);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_128), irr_driver->getRenderTargetTexture(RTT_BLOOM_128),
|
||||
irr_driver->getFBO(FBO_TMP_128), irr_driver->getRenderTargetTexture(RTT_TMP_128), 128, 128);
|
||||
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
renderGaussian6Blur(irr_driver->getFBO(FBO_BLOOM_128), irr_driver->getFBO(FBO_TMP_128));
|
||||
|
||||
// Additively blend on top of tmp1
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, in_fbo);
|
||||
in_fbo->Bind();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
@ -831,8 +801,7 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
{
|
||||
PROFILER_PUSH_CPU_MARKER("- Tonemap", 0xFF, 0x00, 0x00);
|
||||
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_TONEMAP));
|
||||
toneMap(out_fbo, in_rtt);
|
||||
std::swap(in_rtt, out_rtt);
|
||||
toneMap(*out_fbo, in_fbo->getRTT()[0]);
|
||||
std::swap(in_fbo, out_fbo);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
}
|
||||
@ -842,9 +811,8 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_MOTIONBLUR));
|
||||
if (UserConfigParams::m_motionblur && m_any_boost) // motion blur
|
||||
{
|
||||
renderMotionBlur(0, in_rtt, out_fbo);
|
||||
renderMotionBlur(0, *in_fbo, *out_fbo);
|
||||
std::swap(in_fbo, out_fbo);
|
||||
std::swap(in_rtt, out_rtt);
|
||||
}
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
}
|
||||
@ -867,18 +835,18 @@ void PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
{
|
||||
PROFILER_PUSH_CPU_MARKER("- MLAA", 0xFF, 0x00, 0x00);
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_MLAA_COLORS));
|
||||
renderPassThrough(in_rtt);
|
||||
irr_driver->getFBO(FBO_MLAA_COLORS).Bind();
|
||||
renderPassThrough(in_fbo->getRTT()[0]);
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
applyMLAA();
|
||||
blitFBO(irr_driver->getFBO(FBO_MLAA_COLORS), 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
irr_driver->getFBO(FBO_MLAA_COLORS).BlitToDefault();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
}
|
||||
else
|
||||
{
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
renderPassThrough(in_rtt);
|
||||
renderPassThrough(in_fbo->getRTT()[0]);
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
} // render
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "S3DVertex.h"
|
||||
#include "SMaterial.h"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -82,15 +83,15 @@ public:
|
||||
void renderDiffuseEnvMap(const float *bSHCoeff, const float *gSHCoeff, const float *rSHCoeff);
|
||||
|
||||
/** Blur the in texture */
|
||||
void renderGaussian3Blur(unsigned in_fbo, unsigned in_tex, unsigned tmp_fbo, unsigned tmp_tex, size_t inv_width, size_t inv_height);
|
||||
void renderGaussian6Blur(unsigned in_fbo, unsigned in_tex, unsigned tmp_fbo, unsigned tmp_tex, size_t width, size_t height);
|
||||
void renderGaussian17TapBlur(unsigned in_fbo, unsigned in_tex, unsigned tmp_fbo, unsigned tmp_tex, size_t width, size_t height);
|
||||
void renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
|
||||
void renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
|
||||
void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
|
||||
|
||||
/** Render tex. Used for blit/texture resize */
|
||||
void renderPassThrough(unsigned tex);
|
||||
void applyMLAA();
|
||||
|
||||
void renderMotionBlur(unsigned cam, unsigned in_rtt, unsigned out_fbo);
|
||||
void renderMotionBlur(unsigned cam, FrameBuffer &in_fbo, FrameBuffer &out_fbo);
|
||||
void renderGlow(unsigned tex);
|
||||
|
||||
/** Render the post-processed scene */
|
||||
|
@ -286,9 +286,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, std::vector
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_COLORS));
|
||||
}
|
||||
m_rtts->getFBO(FBO_COLORS).Bind();
|
||||
renderSolidSecondPass();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
@ -456,8 +454,7 @@ void IrrDriver::computeSunVisibility()
|
||||
|
||||
void IrrDriver::renderSolidFirstPass()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS));
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
|
||||
glClearColor(0., 0., 0., 0.);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
@ -712,7 +709,7 @@ void IrrDriver::renderShadows()
|
||||
void IrrDriver::renderGlow(std::vector<GlowData>& glows)
|
||||
{
|
||||
m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_TMP1_WITH_DS));
|
||||
m_rtts->getFBO(FBO_TMP1_WITH_DS).Bind();
|
||||
glClearStencil(0);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
@ -749,25 +746,18 @@ void IrrDriver::renderGlow(std::vector<GlowData>& glows)
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// To half
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, irr_driver->getFBO(FBO_TMP1_WITH_DS));
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getFBO(FBO_HALF1));
|
||||
glBlitFramebuffer(0, 0, UserConfigParams::m_width, UserConfigParams::m_height, 0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
FrameBuffer::Blit(irr_driver->getFBO(FBO_TMP1_WITH_DS), irr_driver->getFBO(FBO_HALF1), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
// To quarter
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, irr_driver->getFBO(FBO_HALF1));
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getFBO(FBO_QUARTER1));
|
||||
glBlitFramebuffer(0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2, 0, 0, UserConfigParams::m_width / 4, UserConfigParams::m_height / 4, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
FrameBuffer::Blit(irr_driver->getFBO(FBO_HALF1), irr_driver->getFBO(FBO_QUARTER1), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glStencilFunc(GL_EQUAL, 0, ~0);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_COLORS));
|
||||
m_rtts->getFBO(FBO_COLORS).Bind();
|
||||
m_post_processing->renderGlow(m_rtts->getRenderTarget(RTT_QUARTER1));
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
@ -804,16 +794,13 @@ void IrrDriver::renderLights(scene::ICameraSceneNode * const camnode, float dt)
|
||||
|
||||
for (unsigned i = 0; i < sun_ortho_matrix.size(); i++)
|
||||
sun_ortho_matrix[i] *= getInvViewMatrix();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2));
|
||||
irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver();
|
||||
GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||
gl_driver->extGlDrawBuffers(2, bufs);
|
||||
m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2).Bind();
|
||||
if (!UserConfigParams::m_dynamic_lights)
|
||||
glClearColor(.5, .5, .5, .5);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
if (!UserConfigParams::m_dynamic_lights)
|
||||
{
|
||||
gl_driver->extGlDrawBuffers(1, bufs);
|
||||
//gl_driver->extGlDrawBuffers(1, bufs);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -891,20 +878,17 @@ void IrrDriver::renderLights(scene::ICameraSceneNode * const camnode, float dt)
|
||||
renderPointLights(MIN2(lightnum, MAXLIGHT));
|
||||
if (SkyboxCubeMap)
|
||||
m_post_processing->renderDiffuseEnvMap(blueSHCoeff, greenSHCoeff, redSHCoeff);
|
||||
gl_driver->extGlDrawBuffers(1, bufs);
|
||||
// gl_driver->extGlDrawBuffers(1, bufs);
|
||||
}
|
||||
|
||||
void IrrDriver::renderSSAO()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_SSAO));
|
||||
m_rtts->getFBO(FBO_SSAO).Bind();
|
||||
glClearColor(1., 1., 1., 1.);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
m_post_processing->renderSSAO();
|
||||
// Blur it to reduce noise.
|
||||
m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_SSAO), irr_driver->getRenderTargetTexture(RTT_SSAO),
|
||||
irr_driver->getFBO(FBO_TMP4), irr_driver->getRenderTargetTexture(RTT_TMP4), UserConfigParams::m_width, UserConfigParams::m_height );
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_SSAO), irr_driver->getFBO(FBO_TMP4));
|
||||
}
|
||||
|
||||
static void getXYZ(GLenum face, float i, float j, float &x, float &y, float &z)
|
||||
@ -1396,9 +1380,9 @@ void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
|
||||
|
||||
void IrrDriver::renderDisplacement()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_TMP4));
|
||||
irr_driver->getFBO(FBO_TMP4).Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_DISPLACE));
|
||||
irr_driver->getFBO(FBO_DISPLACE).Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE);
|
||||
@ -1421,7 +1405,7 @@ void IrrDriver::renderDisplacement()
|
||||
m_displacing[i]->render();
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_COLORS));
|
||||
irr_driver->getFBO(FBO_COLORS).Bind();
|
||||
glStencilFunc(GL_EQUAL, 1, 0xFF);
|
||||
m_post_processing->renderPassThrough(m_rtts->getRenderTarget(RTT_DISPLACE));
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
|
@ -107,37 +107,35 @@ RTT::RTT()
|
||||
RenderTargetTextures[RTT_TMP_128] = generateRTT(shadowsize3, GL_RGBA16F, GL_BGR, GL_FLOAT);
|
||||
RenderTargetTextures[RTT_LOG_LUMINANCE] = generateRTT(shadowsize0, GL_R16F, GL_RED, GL_FLOAT);
|
||||
|
||||
FrameBuffers[FBO_SSAO] = generateFBO(RenderTargetTextures[RTT_SSAO]);
|
||||
FrameBuffers.reserve(FBO_COUNT);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_SSAO]}, res.Width, res.Height);
|
||||
// Clear this FBO to 1s so that if no SSAO is computed we can still use it.
|
||||
glClearColor(1., 1., 1., 1.);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
FrameBuffers[FBO_NORMAL_AND_DEPTHS] = generateFBO(RenderTargetTextures[RTT_NORMAL_AND_DEPTH], DepthStencilTexture);
|
||||
FrameBuffers[FBO_COLORS] = generateFBO(RenderTargetTextures[RTT_COLOR], DepthStencilTexture);
|
||||
FrameBuffers[FBO_MLAA_COLORS] = generateFBO(RenderTargetTextures[RTT_MLAA_COLORS], DepthStencilTexture);
|
||||
FrameBuffers[FBO_LOG_LUMINANCE] = generateFBO(RenderTargetTextures[RTT_LOG_LUMINANCE]);
|
||||
FrameBuffers[FBO_TMP1_WITH_DS] = generateFBO(RenderTargetTextures[RTT_TMP1], DepthStencilTexture);
|
||||
FrameBuffers[FBO_TMP2_WITH_DS] = generateFBO(RenderTargetTextures[RTT_TMP2], DepthStencilTexture);
|
||||
FrameBuffers[FBO_TMP4] = generateFBO(RenderTargetTextures[RTT_TMP4], DepthStencilTexture);
|
||||
FrameBuffers[FBO_LINEAR_DEPTH] = generateFBO(RenderTargetTextures[RTT_LINEAR_DEPTH]);
|
||||
FrameBuffers[FBO_DISPLACE] = generateFBO(RenderTargetTextures[RTT_DISPLACE], DepthStencilTexture);
|
||||
FrameBuffers[FBO_HALF1] = generateFBO(RenderTargetTextures[RTT_HALF1]);
|
||||
FrameBuffers[FBO_HALF2] = generateFBO(RenderTargetTextures[RTT_HALF2]);
|
||||
FrameBuffers[FBO_QUARTER1] = generateFBO(RenderTargetTextures[RTT_QUARTER1]);
|
||||
FrameBuffers[FBO_QUARTER2] = generateFBO(RenderTargetTextures[RTT_QUARTER2]);
|
||||
FrameBuffers[FBO_EIGHTH1] = generateFBO(RenderTargetTextures[RTT_EIGHTH1]);
|
||||
FrameBuffers[FBO_EIGHTH2] = generateFBO(RenderTargetTextures[RTT_EIGHTH2]);
|
||||
|
||||
FrameBuffers[FBO_BLOOM_1024] = generateFBO(RenderTargetTextures[RTT_BLOOM_1024]);
|
||||
FrameBuffers[FBO_BLOOM_512] = generateFBO(RenderTargetTextures[RTT_BLOOM_512]);
|
||||
FrameBuffers[FBO_TMP_512] = generateFBO(RenderTargetTextures[RTT_TMP_512]);
|
||||
FrameBuffers[FBO_BLOOM_256] = generateFBO(RenderTargetTextures[RTT_BLOOM_256]);
|
||||
FrameBuffers[FBO_TMP_256] = generateFBO(RenderTargetTextures[RTT_TMP_256]);
|
||||
FrameBuffers[FBO_BLOOM_128] = generateFBO(RenderTargetTextures[RTT_BLOOM_128]);
|
||||
FrameBuffers[FBO_TMP_128] = generateFBO(RenderTargetTextures[RTT_TMP_128]);
|
||||
|
||||
FrameBuffers[FBO_COMBINED_TMP1_TMP2] = generateFBO(RenderTargetTextures[RTT_TMP1], DepthStencilTexture);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, RenderTargetTextures[RTT_TMP2], 0);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_NORMAL_AND_DEPTH]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP1], RenderTargetTextures[RTT_TMP2]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_COLOR]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_LOG_LUMINANCE]}, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_MLAA_COLORS]}, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP1]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP2]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP4]}, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_LINEAR_DEPTH]}, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_HALF1]}, half.Width, half.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_HALF2]}, half.Width, half.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_QUARTER1]}, quarter.Width, quarter.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_QUARTER2]}, quarter.Width, quarter.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_EIGHTH1]}, eighth.Width, eighth.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_EIGHTH2]}, eighth.Width, eighth.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_DISPLACE]}, DepthStencilTexture, res.Width, res.Height);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_1024]}, 1024, 1024);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_512]}, 512, 512);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_512]}, 512, 512);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_256]}, 256, 256);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_256]}, 256, 256);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_128]}, 128, 128);
|
||||
FrameBuffers.emplace_back(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_128]}, 128, 128);
|
||||
|
||||
if (irr_driver->getGLSLVersion() >= 150)
|
||||
{
|
||||
@ -159,7 +157,6 @@ RTT::RTT()
|
||||
|
||||
RTT::~RTT()
|
||||
{
|
||||
glDeleteFramebuffers(FBO_COUNT, FrameBuffers);
|
||||
glDeleteTextures(RTT_COUNT, RenderTargetTextures);
|
||||
glDeleteTextures(1, &DepthStencilTexture);
|
||||
if (irr_driver->getGLSLVersion() >= 150)
|
||||
|
@ -17,6 +17,8 @@
|
||||
#ifndef HEADER_RTTS_HPP
|
||||
#define HEADER_RTTS_HPP
|
||||
|
||||
#include "graphics/glwrap.hpp"
|
||||
|
||||
namespace irr {
|
||||
namespace video {
|
||||
class ITexture;
|
||||
@ -117,9 +119,10 @@ public:
|
||||
|
||||
unsigned getDepthStencilTexture() const { return DepthStencilTexture; }
|
||||
unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; }
|
||||
unsigned getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; }
|
||||
FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; }
|
||||
private:
|
||||
unsigned RenderTargetTextures[RTT_COUNT], FrameBuffers[FBO_COUNT];
|
||||
unsigned RenderTargetTextures[RTT_COUNT];
|
||||
std::vector<FrameBuffer> FrameBuffers;
|
||||
unsigned DepthStencilTexture;
|
||||
|
||||
unsigned shadowFBO, shadowColorTex, shadowDepthTex;
|
||||
|
@ -147,7 +147,7 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh)
|
||||
|
||||
// Generate displace mask
|
||||
// Use RTT_TMP4 as displace mask
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_TMP4));
|
||||
irr_driver->getFBO(FBO_TMP4).Bind();
|
||||
|
||||
glUseProgram(MeshShader::DisplaceMaskShader::Program);
|
||||
MeshShader::DisplaceMaskShader::setUniforms(ModelViewProjectionMatrix);
|
||||
@ -159,7 +159,7 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh)
|
||||
// Render the effect
|
||||
if (!displaceTex)
|
||||
displaceTex = irr_driver->getTexture(FileManager::TEXTURE, "displace.png");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_DISPLACE));
|
||||
irr_driver->getFBO(FBO_DISPLACE).Bind();
|
||||
setTexture(0, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true);
|
||||
setTexture(1, irr_driver->getRenderTargetTexture(RTT_TMP4), GL_LINEAR, GL_LINEAR, true);
|
||||
setTexture(2, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true);
|
||||
|
Loading…
Reference in New Issue
Block a user