Advertisement Jump to content
Sign in to follow this  
Medo Mex

Is that Bloom effect?

This topic is 1881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

 

Yesterday, I started reading about HDR Bloom effect and today I tried to implement it, now I'm not sure if what I have done is correct and I'm guessing there could be something wrong?

 

Here is what I got so far:

[attachment=18916:01.png]

 

Here is what I did:

1. Render scene to texture with D3DFMT_A16B16G16R16F format to produce HDR scene texture

2. Render the HDR texture to full screen quad to apply gaussian blur vertically

3. Render the HDR texture to full screen quad again to apply gaussian blur horizontally

4. Render the final scene to full screen quad and give the shader the blurred scene texture (bloom texture) to multiply it with the scene

 

If I'm wrong or missing anything, please correct me.

 

Notice: The bloom texture size (width and height) is quarter the size of the scene:

device->CreateTexture(WindowWidth / 4, WindowHeight / 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &bloomTexture, NULL);
Edited by Medo3337

Share this post


Link to post
Share on other sites
Advertisement

Cool picture.

Though they are usually used together, HDR and bloom are 2 different techniques, used for different purposes.

 

Bloom is used to mimic photography light-bleeding effect.

  1. Render scene to texture. Doesn't have to be float texture.
  2. Bright-pass filter - in this pass you create a new texture which contains only the bright areas of the image. For each pixel, you calculate the luminance value, and if this value is larger then a brightness threshold - you output the color, otherwise you output black.
  3. Blur the brightpass map.
  4. Blend the blured bright-map with the original image.

HDR is used for improved dynamic color range control in the image.

  1. Render to float texture. Don't treat the PS output as colors, but rather physical quantities that can (and should) be larger than 1.
  2. Calculate average luminance in frame.
  3. Use tone-map for HDR->LDR conversion.

As you can see, you don't have to use both of them together. HDR will look good alone, while using bloom without HDR can result in color saturating to white.

 

Articles about bloom, HDR and tone-mapping.

Edited by N.I.B.

Share this post


Link to post
Share on other sites


2. Render the HDR texture to full screen quad to apply gaussian blur vertically
3. Render the HDR texture to full screen quad again to apply gaussian blur horizontally

 

Generally, when you're doing something like gaussian blur (or applying any filter kernel that you can separate into horizontal and vertical passes), you want to do something more like:

 

2. Render the HDR texture to full screen quad to apply gaussian blur vertically
3. Render the result of step 2 to a full screen quad to apply gaussian blur horizontally

 

Also, I'm not sure you really want to be multiplying the blur result with your HDR result in the final step. Normally, I'd expect that final shader to be something like:

 

Final Colour = HDR Value * HDR Scaling Factor + Bloom result.

 

The HDR scaling factor is often calculated according to the average brightness of the screen, so a big bright part of the scene makes everything else get darker. The bloom result is often remapped so that low values have no effect at all, so that only bright things will bloom.

Share this post


Link to post
Share on other sites

@N.I.B.:

@C0lumbo:

 

Currently I'm trying to get bloom effect to work correctly

 

Before I apply gaussian blur I rendered the scene to full screen quad in order to achieve (bright pass filter), I have done that as the following:

float4 BrightPassPS ( FQUAD_OUTPUT IN ) : COLOR
{
    float3 color = tex2D(colorSamp, IN.UV) - BRIGHTENS_THRESHOLD;
    return float4(max(color, 0.0f), 1.0f);
}

Now, I'm getting the following results:

 

Final Scene:

[attachment=18919:bloom1.png]

 

Bloom texture:

[attachment=18920:bloom2.png]

 

Final Scene = OriginalScene + BloomTexture;

 

Is that a correct bloom effect? am I doing it correctly?

 

Another thing:

I notice that the scene doesn't look good If I didn't do the following in shader:

float lum = dot( color.rgb, float3( 0.299, 0.587, 0.114 ) );
color *= lum;
return color;

I have seen similar code in HDR demo project, though I don't quite understand the purpose of it.

Edited by Medo3337

Share this post


Link to post
Share on other sites

Your bloom seems to be only blooming horizontally. Presumably that's because you haven't addressed the issue I mentioned in my previous post.

 

You said you're doing:

 

2. Render the HDR texture to full screen quad to apply gaussian blur vertically
3. Render the HDR texture to full screen quad again to apply gaussian blur horizontally

 

You need to be doing:

 

2. Render the HDR texture to full screen quad to apply gaussian blur vertically
3. Render the result of step 2 to another full screen quad to apply gaussian blur horizontally

Share this post


Link to post
Share on other sites

Another thing:
I notice that the scene doesn't look good If I didn't do the following in shader:
float lum = dot( color.rgb, float3( 0.299, 0.587, 0.114 ) );
color *= lum;
return color;
I have seen similar code in HDR demo project, though I don't quite understand the purpose of it.

 

They're trying to get the luminance (Y of YUV) value from RGB in that line. YUV is just a different color space from RGB. It's useful in some ways that RGB isn't, in particular luminance and chrominance are stored separately (Y is luminance, U and V are chrominance). Look here for more info: http://en.wikipedia.org/wiki/YUV The section about conversion from RGB to YUV is particularly relevant, you'll even see the magic constants you have in there smile.png

Edited by Samith

Share this post


Link to post
Share on other sites

@C0lumbo: Yes I'm rendering step 2 to full screen quad, actually this was a typo in the initial post, I meant:

2. Render the HDR texture to full screen quad to apply gaussian blur vertically
3. Render the step 2 to full screen quad again to apply gaussian blur horizontally
 
According to the screenshots, did I implement bloom effect correctly? If yes, what bloom properties should I allow the developer to change in the engine so it can fit the scene?
 
@Samith: What I understand is that luminance is calculated according to the scene and returned as floating point texture, now I'm alittle confused.
 
What is the purpose of multiplying lum with the final pixel color? and why it improve the scene?
Edited by Medo3337

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!