user1364743
user1364743

Reputation: 5661

Bloom effect using downscaling (downsampling) technique using OpenGL/GLSL

Hello I'm trying to implement Bloom effect in my program. In fact, I've already implemented the effect using a highlight pass and a separate gaussian blur pass.

Here's an example:

Bright pass texture:

enter image description here

Gaussian blur render pass (2 internal passes for this effect):

enter image description here

And finally the final pass (brightPass + BlurPass):

enter image description here

(I want to precise I don't have implemented HDR tone mapping yet).

But I found a very interesting article from intel:

https://software.intel.com/en-us/articles/compute-shader-hdr-and-bloom

It said :

"First the bright pass is performed where values below a specified threshold are filtered out. The bright pass output is then downscaled by half 4 times. Each of the downscaled bright pass outputs are blurred with a separable Gaussian filter and then added to the next higher resolution bright pass output."

I understood how it works but I did not understand how to perform texture downscaling using OpenGL. However I know if I use glGenerateMipmap() function (at the initialization of my FBO) with 4 mipmap levels I think I will have my 4 downscaled texture directly with the desired format (1/16, 1/8, 1/4 and 1/2) like it's written in the article.

But my problem is I can't find the way to do this!

Does it exist a way to bind the other textures generated using mipmaping and use them in the fragment shader? Should I have to render the bright pass 4 times with 4 separates FBOs applying different formats (1/16, ...). I think it's a solution but it's probably not correct about the performance. I think the bright pass should be rendered once using the window max size and then using the downscaled textures (mipmap) already loaded in memory but I don't know how to bind and use them into my shaders! I'm really lost.

Thanks a lot in advance for your help!

Upvotes: 2

Views: 5036

Answers (2)

Pidhorskyi
Pidhorskyi

Reputation: 1582

You may use textureLod, as BDL suggested, but I think that there is no real need for this. Once the required mipmap levels are generated, the right level will be selected automatically depending on the size of the active render buffer. The main idea of the article you have mentioned, is that they perform several blurring steps on differently sized sources. After mipmap levels were generated, you will have 4 mipmap levels that represent 1/16, 1/8, 1/4 and 1/2 scaled textures from bright pass. Each of this buffers you should blur, using the render buffer of the same size (1/16, 1/8, 1/4 and 1/2 correspondingly). If the render buffer, you are rendering to is 1/16 scale of the source texture from the bright pass, than the 4-th mipmap level will be used. So you do not need to specify mipmap level manually.

Upvotes: 1

BDL
BDL

Reputation: 22176

You can access a specific mipmap-level in a shader using the

gvec4 textureLod(gsampler2D sampler, vec2 P, float lod);

method, where lod specifies the mipmap level. (link to documentation).

Upvotes: 1

Related Questions