void Renderer::renderDeferredShading() { if (!m_shaderDSLighting || !m_shaderDSCompositing) init(m_windowWidth, m_windowHeight); if (!m_dsLightColor || !m_dsLightRootNode) throw std::string("Error in renderDeferredShading - Light Color or Light Root Node was not set"); FBO *a = new FBO(m_windowWidth,m_windowHeight,3,false,false); a->bind(); glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderDSLighting->bind(); m_shaderDSLighting->sendMat4("viewMatrix", m_currentViewMatrix); m_shaderDSLighting->sendMat4("projectionMatrix", m_currentProjectionMatrix); m_shaderDSLighting->sendSampler2D("positionMap", m_gBuffer->getColorTexture(0), 0); m_shaderDSLighting->sendSampler2D("normalMap", m_gBuffer->getColorTexture(1), 1); m_shaderDSLighting->sendInt("windowWidth", m_windowWidth); m_shaderDSLighting->sendInt("windowHeight", m_windowHeight); m_shaderDSLighting->sendVec3("lightColor", *m_dsLightColor); m_dsLightRootNode->render(*m_shaderDSLighting); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glClearColor(1.0, 1.0, 1.0, 0.0); m_shaderDSLighting->unbind(); a->unbind(); //COMPOSITING TEIL =============================== bindFBO(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderDSCompositing->bind(); m_shaderDSCompositing->sendSampler2D("colorMap", getLastFBO()->getColorTexture(2), 0); m_shaderDSCompositing->sendSampler2D("lightMap", a->getColorTexture(2), 1); m_sfq.renderGeometry(); m_shaderDSCompositing->unbind(); unbindFBO(); delete a; }
void Renderer::renderSSAO() { if (!m_shaderSSAOcalc || !m_shaderSSAOblur || !m_shaderSSAOfinal) init(m_windowWidth, m_windowHeight); FBO *a = new FBO(m_windowWidth, m_windowHeight, 3, false, false); FBO *b = new FBO(m_windowWidth, m_windowHeight, 3, false, false); a->bind(); glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderSSAOcalc->bind(); m_shaderSSAOcalc->sendSampler2D("positionMap", m_gBuffer->getColorTexture(0), 0); m_shaderSSAOcalc->sendSampler2D("normalMap", m_gBuffer->getColorTexture(1), 1); m_shaderSSAOcalc->sendMat4("sceneProjectionMatrix", m_currentProjectionMatrix); m_shaderSSAOcalc->sendFloat("radius", *m_ssaoRadius); m_shaderSSAOcalc->sendFloat("quality", *m_ssaoQuality); m_sfq.renderGeometry(); m_shaderSSAOcalc->unbind(); a->unbind(); //Blur #1 SSAO calculation b->bind(); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderSSAOblur->bind(); m_shaderSSAOblur->sendSampler2D("colortexture", a->getColorTexture(2), 0); m_shaderSSAOblur->sendInt("secondPass", 0); m_sfq.renderGeometry(); m_shaderSSAOblur->unbind(); b->unbind(); //Blur #2 SSAO calculation a->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderSSAOblur->bind(); m_shaderSSAOblur->sendSampler2D("colortexture", b->getColorTexture(2), 0); m_shaderSSAOblur->sendFloat("secondPass", 1); m_sfq.renderGeometry(); m_shaderSSAOblur->unbind(); a->unbind(); glClearColor(0, 0, 0, 0); //COLOR COMPOSITING bindFBO(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shaderSSAOfinal->bind(); m_shaderSSAOfinal->sendSampler2D("colorMap", getLastFBO()->getColorTexture(2), 0); m_shaderSSAOfinal->sendSampler2D("ssaoMap", a->getColorTexture(2), 1); m_sfq.renderGeometry(); m_shaderSSAOfinal->unbind(); unbindFBO(); delete a; delete b; }