#include "client/engine/shader/SSAOBlurShader.h" #include "client/engine/Wrapper.h" SSAOBlurShader::SSAOBlurShader() { } SSAOBlurShader::~SSAOBlurShader() { glDeleteFramebuffers(1, &framebuffer); glDeleteTextures(1, &texture); } bool SSAOBlurShader::init() { program.compile("resources/shader/ssaoBlurVertex.vs", "resources/shader/ssaoBlurFragment.fs"); if(!program.isValid()) { return false; } // generate framebuffer glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); // color texture glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // attache color texture to framebuffer glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); // check if framebuffer is okay if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { cout << "ssao blur frame buffer is not complete!" << endl; return false; } // unbind framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); return true; } void SSAOBlurShader::resize() { glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL); } void SSAOBlurShader::preRender() { // bind ssao blur shader program glUseProgram(program.getProgram()); // bind ssao blur framebuffer glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); //glBindFramebuffer(GL_FRAMEBUFFER, 0); // clear color buffer glClear(GL_COLOR_BUFFER_BIT); // depth testing is not needed glDisable(GL_DEPTH_TEST); } void SSAOBlurShader::bindTexture(unsigned int textureUnit) { glActiveTexture(GL_TEXTURE0 + textureUnit); glBindTexture(GL_TEXTURE_2D, texture); }