| 374 | |
| 375 | |
| 376 | void RenderManager::postProcess(const unsigned int start){ |
| 377 | if(ImGui::CollapsingHeader("Post-processing")){ |
| 378 | ImGui::SliderInt("Blur", &sceneCamera->blurAmount, 0, 10); |
| 379 | ImGui::SliderFloat("Exposure", &sceneCamera->exposure, 0.1f, 5.0f); |
| 380 | } |
| 381 | |
| 382 | //TODO:: should be a compute shader |
| 383 | pingPongFBO.bind(); |
| 384 | pingPongFBO.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, glm::vec3(0.0f)); |
| 385 | if( sceneCamera->blurAmount > 0){ |
| 386 | //Filtering pixel rgb values > 1.0 |
| 387 | highPassFilterShader.use(); |
| 388 | canvas.draw(simpleFBO.texColorBuffer); |
| 389 | } |
| 390 | |
| 391 | //Applying Gaussian blur in ping pong fashion |
| 392 | //TODO:: ALso make it a compute shader |
| 393 | gaussianBlurShader.use(); |
| 394 | for (int i = 0; i < sceneCamera->blurAmount; ++i){ |
| 395 | //Horizontal pass |
| 396 | glBindFramebuffer(GL_FRAMEBUFFER, simpleFBO.frameBufferID); |
| 397 | glDrawBuffer(GL_COLOR_ATTACHMENT1); |
| 398 | gaussianBlurShader.setBool("horizontal", true); |
| 399 | canvas.draw(pingPongFBO.texColorBuffer); |
| 400 | |
| 401 | //Vertical pass |
| 402 | glBindFramebuffer(GL_FRAMEBUFFER, pingPongFBO.frameBufferID); |
| 403 | gaussianBlurShader.setBool("horizontal", false); |
| 404 | canvas.draw(simpleFBO.blurHighEnd); |
| 405 | } |
| 406 | //Setting back to default framebuffer (screen) and clearing |
| 407 | //No need for depth testing cause we're drawing to a flat quad |
| 408 | screen->bind(); |
| 409 | |
| 410 | //Shader setup for postprocessing |
| 411 | screenSpaceShader.use(); |
| 412 | |
| 413 | screenSpaceShader.setInt("offset", start); |
| 414 | screenSpaceShader.setFloat("exposure", sceneCamera->exposure); |
| 415 | screenSpaceShader.setInt("screenTexture", 0); |
| 416 | screenSpaceShader.setInt("bloomBlur", 1); |
| 417 | screenSpaceShader.setInt("computeTexture", 2); |
| 418 | |
| 419 | //Merging the blurred high pass image with the low pass values |
| 420 | //Also tonemapping and doing other post processing |
| 421 | canvas.draw(simpleFBO.texColorBuffer, pingPongFBO.texColorBuffer); |
| 422 | } |