Hello, me again
This time I’m wondering how I can achieve a blooming result with OpenGL… So far here’s what I did:
[ul][li]Render the whole scene once to a texture (using a FBO) which I’ll call basetexture[]Display that rendered texture using a bright-pass shader and render that into a new texture (let’s call it brightpasstexture)[]Display the brightpass texture to the screen and filter it using a gaussian blur shader, and render it to finalpasstexture[*]Render the whole scene using multitexturing, with basetexture into texunit 0 and finalpasstexture into texunit 1, with GL_ADD[/ul][/li]
Here are the questions:
- Is there a better way to render each step than rendering to texture, then displaying using the next shader and rendering to texture again?
- I know I have to generate several textures from the brightpass one (or whatever texture is going to be used as “bright spots” one) to create the blooming effect. I know that using several gaussian blur shaders with bigger and bigger kernels is too slow, so I read I have to use the same kernel (usually 3x3) BUT each time with a downsampled texture (i.e. first time 256x256 then 128x128 then 64x64…). The question is: how do I generate these downsampled textures? Is there a fast way, or should I resize it at each pass? (I bet this is SLOW)
Here’s the code I’m currently using (note I only use one blur pass at this stage):
// ************************************************************
// *** Render scene *******************************************
// ************************************************************
m_fboBasePass->UseFBO();
glViewport(0,0,width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(pos.x, pos.y, pos.z,
view.x, view.y, view.z,
up.x, up.y, up.z);
m_skybox->Render(pos.x, pos.y, pos.z, engineconfig->farPlane-10.0f, engineconfig->farPlane-10.0f, engineconfig->farPlane-10.0f);
m_mapI->Render();
m_fboBasePass->ReleaseFBO();
////////////////////////////////////////////////////////////////////////
// 2D Drawings /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
glViewport(0,0,width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, width-1.0f, 0.0f, height-1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//// render post processing /////////////////////////////////////////////////////////
glDisable(GL_LIGHTING);
glActiveTextureARB(GL_TEXTURE0_ARB);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBlendFunc(GL_ONE, GL_ZERO);
// bright pass filter
m_fboBrightPass->UseFBO();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
HT_Graphics::SetActiveShaderProgram(HT_Constants::SH_POST_BRIGHTPASS);
glBindTexture(GL_TEXTURE_2D, m_fboBasePass->GetTexture());
int my_sampler_uniform_location = GetVariable("tex0");
glUniform1iARB(my_sampler_uniform_location, 0);
DrawFullScreenQuad(width, height);
m_fboBrightPass->ReleaseFBO();
// blur pass filter
m_fboFinalPass->UseFBO();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
HT_Graphics::SetActiveShaderProgram(HT_Constants::SH_POST_GAUSSIANBLUR);
glBindTexture(GL_TEXTURE_2D, m_fboBrightPass->GetTexture());
my_sampler_uniform_location = GetVariable("tex0");
glUniform1iARB(my_sampler_uniform_location, 0);
my_sampler_uniform_location = GetVariable("width");
glUniform1iARB(my_sampler_uniform_location, width);
my_sampler_uniform_location = GetVariable("height");
glUniform1iARB(my_sampler_uniform_location, height);
DrawFullScreenQuad(width, height);
m_fboFinalPass->ReleaseFBO();
// final pass
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
HT_Graphics::SetActiveShaderProgram(HT_Constants::SH_NONE);
glBlendFunc(GL_ONE, GL_ZERO);
glActiveTexture(GL_TEXTURE0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_fboBasePass->GetTexture());
glActiveTexture(GL_TEXTURE1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_fboBrightPass->GetTexture());
DrawFullScreenQuad(width, height);
Thanks a lot for your feedback!
Cheers
HT