Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


how to do a brightpass properly


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 31 December 2012 - 04:15 PM

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, 10 January 2013 - 11:07 PM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31131

Like
0Likes
Like

Posted 31 December 2012 - 08:33 PM

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, 31 December 2012 - 09:30 PM.


#3 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 02 January 2013 - 04:50 PM

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



#4 Tasche   Members   -  Reputation: 222

Like
1Likes
Like

Posted 09 January 2013 - 09:37 AM

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, 10 January 2013 - 07:29 PM.


#5 RobMaddison   Members   -  Reputation: 736

Like
0Likes
Like

Posted 09 January 2013 - 09:44 AM

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)

#6 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 09 January 2013 - 10:20 AM

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



#7 RobMaddison   Members   -  Reputation: 736

Like
0Likes
Like

Posted 09 January 2013 - 11:12 AM

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?

#8 RobMaddison   Members   -  Reputation: 736

Like
0Likes
Like

Posted 09 January 2013 - 11:16 AM

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

#9 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 10 January 2013 - 07:38 PM

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



#10 mhagain   Crossbones+   -  Reputation: 8142

Like
2Likes
Like

Posted 10 January 2013 - 07:42 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#11 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 10 January 2013 - 08:31 PM

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?



#12 Tasche   Members   -  Reputation: 222

Like
0Likes
Like

Posted 10 January 2013 - 11:20 PM

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



#13 Ashaman73   Crossbones+   -  Reputation: 7851

Like
0Likes
Like

Posted 11 January 2013 - 01:20 AM

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! smile.png

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?

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.



#14 RobMaddison   Members   -  Reputation: 736

Like
0Likes
Like

Posted 11 January 2013 - 06:31 AM

Can we see some screenshots of before and after? ;)

#15 mhagain   Crossbones+   -  Reputation: 8142

Like
1Likes
Like

Posted 11 January 2013 - 07:28 AM

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! smile.png

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS