how to do a brightpass properly

This topic is 1831 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

ello, been off the forums (and off my hobby) for a while, now back at it :)

so im trying to write a bloom/glow/whateveryouwantocallit shader for my app along the lines of this page:

http://kalogirou.net/2006/05/20/how-to-do-good-bloom-for-hdr-rendering/

okeys... got stuff working now, still looks kinda crappy :D

parameters used:
-gauss blur sigma: 0.84
-gauss blur domain: -3*sigma to 3*sigma; codomain normalized to sum = 1
-gauss kernel samples: 15 (on all targets)
-highpass filter funtion: inputColor-(0.5,0.5,0.5)
-target sizes: B0:512x256, B1: 256x128, B2: 128:64
-scene texture size: 1280x720
-combine blur targets function: blurAccum = B0+B1+B2
-combine bloomtexture with scene: finalColor = blurAccum*0.5+scene*0.5

EDIT: ha i actually found my old thread:
http://www.gamedev.net/topic/612541-understanding-theory-of-bloom-effect/

that one wasn't quite answered completely so feel free to comment on that too :)

EDITEDIT: updated the original post to reflect the progress Edited by Tasche

Share this post

Share on other sites

Physically, all you need is "input * fraction", but on my last project we used "(input - threshold) * fraction".
If you're working with HDR data, then you should avoid saturate too.

There's a lot of other details that will contribute to how 'sucky' the final effect looks -- e.g.
• are you using HDR inputs? Are the blur passes done with HDR data? Which texture formats are used?
• whether you're compositing the result before or after tone-mapping(if using HDR)
• which compositing function is used.
• how the blurring passes work.

Also, it's quite likely that the 'brightpass' texture will look quite ugly, even if the final effect looks good. You need to evaluate it as a whole.

Edited by Hodgman

Share this post

Share on other sites

ok very nice, thanks alot Hodgman, this is very helpful.

ill post some feedback as soon as i get this done down to the last pass, maybe some screenshots...

as for testing purposes im not using HDR calculations.

actually, all those question in your bullets, thats stuff ive been asking myself too :), except for the blurring used; ill go with the one discribed in the link, maybe use different size kernels.

but il cross those bridges when i get there :P

to add anything to this topic i really need to get the whole effect going first i guess, so ill be posting back on friday probably

again, thx for the input.

cheers,

tasche

Share this post

Share on other sites
okeys... got stuff working now, still looks kinda crappy :D

parameters used:
-gauss blur sigma: 0.84
-gauss blur domain: -3*sigma to 3*sigma; codomain normalized to sum = 1
-gauss kernel samples: 15 (on all targets)
-highpass filter funtion: inputColor-(0.5,0.5,0.5)
-target sizes: B0:512x256, B1: 256x128, B2: 128:64
-scene texture size: 1280x720
-combine blur targets function: blurAccum = B0+B1+B2
-combine bloomtexture with scene: finalColor = blurAccum*0.5+scene*0.5

i played with the values, but not too much (only thing that can be changed in runtime is sigma and domain range, rest is hardcoded atm)
esp. the combining of the blurs and the final add to the scene are probably really lame, but its just preliminary testing
if anyone knows any good values, or how to come up with those other than trial and error, or has anything else to add, feel free to post

EDIT: removed screenshots Edited by Tasche

Share this post

Share on other sites
Don't you need some light areas in your sample image to bring out the bright pass? Also, your last image didn't work (for me)

Share this post

Share on other sites
Don't you need some light areas in your sample image to bring out the bright pass? Also, your last image didn't work (for me)

hm im not sure i understand you correctly, but i have a light source, the sun. effectively, its just a color_of_the_terrain * lightmap_value, nothing too fancy. however if you notice my brightpass calculation, any color with at least one component above 0.5 will write to the highpass texture. i was just too lazy to post a SS, but the highpass has content. but true, its probably not the best scene to do bloom effect testing on :D

Share this post

Share on other sites
There's no sun in your sample screenshot though, it's a fairly mid-dark landscape. If you looked at that in real life, you wouldn't expect any bloom because there are no light areas for the light to bleed through. The whole idea of bloom is give the illusion that light is effectively bleeding out over objects that are occluding the light source.

Think of standing in a room with a window and looking at the sun, the light from the sun will appear to bloom over the edges of the window. The idea is that you bright pass your scene to mask out areas darker than your brightness threshold, apply a blur to that bright pass and then modulate it with the original scene. Is that what you're trying to achieve?

Share this post

Share on other sites
Sorry, my post sounds like I'm assuming you don't know what you're doing, that's not the case...

Share this post

Share on other sites

okeys, i removed the screenshots because ppl kinda got hung up on those, they were actually just meant for ppl who are bored :)

what i actually wanted to hear are some comments on the used parameters and functions, if anyone cares to comment.

especially interested in comments from people who have tried doing bloom in their project, since they must have faced the same questions (more or less)

i am still aware that in the end, its a matter of taste, i'm just interested in seeing how other people decided on those things.

also, maybe the mod (Hodgman) maybe wants to give me some good links on where (and if) to use HDR (like some pros and cons, or generally how much it actually affects visual quality, stuff i found so far just goes about explaning the technique, not the intended results)

the bold text is for tl;dr :)

thanks in advance

Share this post

Share on other sites

I've tried a few different approaches before, but right now my preferred one is this: don't do a brightpass at all.  Instead, raise the original colour to some power, greyscale the result, then multiply the original colour by that result.  I find that it gives a nice smooth transition between boomed parts of the scene and non-bloomed parts, and preserves the original colour balance perfectly.

Share this post

Share on other sites
I've tried a few different approaches before, but right now my preferred one is this: don't do a brightpass at all.  Instead, raise the original colour to some power, greyscale the result, then multiply the original colour by that result.  I find that it gives a nice smooth transition between boomed parts of the scene and non-bloomed parts, and preserves the original colour balance perfectly.

okeys, this is interesting. so what you suggest is something like this (pixelshader ...pre blur pass pseudo code)?

powColor.r=inColor.r * inColor.r     //i thought of using x^n with n=2 because pow() seems expensive? pls comment on this! :)

powColor.r=inColor.g * inColor.g

powColor.r=inColor.b * inColor.b

greyscale = (powColor.r +.powColor.b +powColor.g)/3    //calculate the arithmetic mean value (i think graphics guys refer to this as luminance, right?)

inColor *= greyscale          //rescale the original color

this results in texture data which can be fed to the rest of the effect pipeline (the blurs and combining) just like the brightpass.

is this what you had in mind? or did i get something wrong?

Share this post

Share on other sites

okeys, even if you didnt mean it the way i interpreted it, it looks *ways* better than my original brightpass, at almost no fps cost at all, even when using pow()

and preserves the original colour balance perfectly.

word

probably the best gain to this method

Share this post

Share on other sites

[quote name='Tasche' timestamp='1357871509' post='5020113']
okeys, this is interesting. so what you suggest is something like this (pixelshader ...pre blur pass pseudo code)?

powColor.r=inColor.r * inColor.r //i thought of using x^n with n=2 because pow() seems expensive? pls comment on this!

powColor.r=inColor.g * inColor.g

powColor.r=inColor.b * inColor.b

greyscale = (powColor.r +.powColor.b +powColor.g)/3 //calculate the arithmetic mean value (i think graphics guys refer to this as luminance, right?)

inColor *= greyscale //rescale the original color

this results in texture data which can be fed to the rest of the effect pipeline (the blurs and combining) just like the brightpass.

is this what you had in mind? or did i get something wrong?
[/quote]

Some notes, this is more like a contrast function than a brightpass, but will work. Luminance is often a weighted sum of RGB like Y = 0.2126 R + 0.7152 G + 0.0722 B, And eventually I believe, that most compilers will optimize the pow function, therefor pow(x,2) will most likely compile to x*x if the compile mean that this one is faster.

Share this post

Share on other sites
Can we see some screenshots of before and after? ;)

Share this post

Share on other sites
I've tried a few different approaches before, but right now my preferred one is this: don't do a brightpass at all.  Instead, raise the original colour to some power, greyscale the result, then multiply the original colour by that result.  I find that it gives a nice smooth transition between boomed parts of the scene and non-bloomed parts, and preserves the original colour balance perfectly.

okeys, this is interesting. so what you suggest is something like this (pixelshader ...pre blur pass pseudo code)?

powColor.r=inColor.r * inColor.r     //i thought of using x^n with n=2 because pow() seems expensive? pls comment on this!

powColor.r=inColor.g * inColor.g

powColor.r=inColor.b * inColor.b

greyscale = (powColor.r +.powColor.b +powColor.g)/3    //calculate the arithmetic mean value (i think graphics guys refer to this as luminance, right?)

inColor *= greyscale          //rescale the original color

this results in texture data which can be fed to the rest of the effect pipeline (the blurs and combining) just like the brightpass.

is this what you had in mind? or did i get something wrong?

You're pretty much correct here, although obviously your code is going to be different to mine; here's my calculation:

return float4 (ColorIn.rgb * pow (abs (max (ColorIn.r, max (ColorIn.g, ColorIn.b))), powerFactor), 1.0f);

If you're concerned about performance of the power function an option is to encode it as a 256x1 floating point texture then do a look up.  In practice I don't find that really necessary.