• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ic0de

Best way to filter for a bloom effect

11 posts in this topic

So I have had a bloom effect implemented for some time but I just haven't been able to make it look right. I start my effect by filtering out the really bright parts then I do a two pass Gaussian blur and blend the blurred bright stuff with the original image. I have come to the conclusion that to make it look right I need to tweak how I decide what is bright so far I have two ways neither of which work well. My code is written in GLSL but this really applies to HLSL and cg as well. Anyway the first way goes like this:
[CODE]
if(sample.r > level)
{
sample.r = 1.0;
}
else
{
sample.r = 0.0;
}


if(sample.g > level)
{
sample.g = 1.0;
}
else
{
sample.g = 0.0;
}

if(sample.b > level)
{
sample.b = 1.0;
}
else
{
sample.b = 0.0;
}
[/CODE]
The problem with this method is that It will always glow either red, green or blue. For example a bright purple would glow red.

Method 2:

[CODE]
if((0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b) > level)
{
sample.r = 1.0;
sample.g = 1.0;
sample.b = 1.0;
}
else
{
sample.r = 0.0;
sample.g = 0.0;
sample.b = 0.0;
}
[/CODE]
This method works by determining the overall brightness (luminance?). But it never seems to glow any color but white.

So I developed two methods but neither seem to work right. Does anyone have any methods that they have used successfully? Or any suggestions on how to improve mine? Edited by ic0de
0

Share this post


Link to post
Share on other sites
Why are you multiplying the colour values by 2 in your second approach? That is probably why you're ending up with white glows since after saturation of the values you're likely ending up with white in most cases.
0

Share this post


Link to post
Share on other sites
[quote name='luca-deltodesco' timestamp='1350032211' post='4989397']
Why are you multiplying the colour values by 2 in your second approach? That is probably why you're ending up with white glows since after saturation of the values you're likely ending up with white in most cases.
[/quote]

Sorry that's a typo I was just testing something and accidentally posted the wrong shader. I updated it in my post but obviously it will still set everything to white. How do you suggest I brighten it without making white?
0

Share this post


Link to post
Share on other sites
Don't set them all to 1 for a start.

You could multiply them by a small factor i.e. 1.2 to make them brighter but consider that if you are adding the result to the buffer then you would probably want to de-brighten (great wordage) them first.

I think in the past I have just run a threshold, then blur, then a multiply down, then composite with an add
0

Share this post


Link to post
Share on other sites
I figured it out on my own and I must say It looks beautiful (although the effect seems to be fighting with my ssao). Anyway here is my solution.
[CODE]
if((0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b) > level)
{
float brightenRatio = 1.0 / max(max(sample.r, sample.g), sample.b);
sample.r *= brightenRatio;
sample.g *= brightenRatio;
sample.b *= brightenRatio;
}
else
{
sample.r = 0.0;
sample.g = 0.0;
sample.b = 0.0;
}
[/CODE]

The largest component ends up being 1.0 and the smaller components maintain the same ratio hence obtaining the same colour only brighter. Edited by ic0de
1

Share this post


Link to post
Share on other sites
[CODE](0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b)[/CODE]

Could be.

[CODE]
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
float brightness = dot(lumiance * sample.rgb);
[/CODE]

Your method lose information. Everything over threshold just goes as bright. You allways can brighten up the blurred bloom texture values when you are compositing image. Then you dont lost information and you get much more variety for bloom.

One easy trick is just multiply the color with itself and using treshold or smoothstep.
1

Share this post


Link to post
Share on other sites
[quote name='kalle_h' timestamp='1350078357' post='4989591']
[CODE](0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b)[/CODE]

Could be.

[CODE]
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
float brightness = dot(lumiance * sample.rgb);
[/CODE]

Your method lose information. Everything over threshold just goes as bright. You allways can brighten up the blurred bloom texture values when you are compositing image. Then you dont lost information and you get much more variety for bloom.

One easy trick is just multiply the color with itself and using treshold or smoothstep.
[/quote]

Sorry I don't quite get what you're saying. Do you mean I use something like:
[CODE]
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
float brightness = dot(lumiance * sample.rgb);

if(brightness > level)
{
// do the rest
[/CODE] Edited by ic0de
0

Share this post


Link to post
Share on other sites
[code]
if((0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b) > level)
{
// just do nothing...
}
else
{
discard;
}
[/code]
0

Share this post


Link to post
Share on other sites
The "best way" in my opinion is not to use a threshold at all. A step function is ugly and will cause aliasing. A more natural approach is to just use a lower exposure for your bloom pass, which will naturally subdue to darker areas while allowing brighter areas to remain visible in the end result.
2

Share this post


Link to post
Share on other sites
In the threshold pass on my last project, we used an offset an a multiplier, e.g.
[code]output = max(0, input-threshold)*scale;[/code]Originally I was only had the scale variable, but the artists wanted a bit of extra control as to completely stopping the effect.

As with MJP's suggestion above, this ensures that there's no sudden point where your bloom texture jumps from zero up to some bright value.


BTW you should try an adopt a much more branchless style of programming when writing shaders compared to CPU code.
e.g. your different versions can have their [font=courier new,courier,monospace]if[/font] statements removed by using the [font=courier new,courier,monospace]step[/font] function along with multiplication:
[code]//1
sample.rgb = step(vec3(level), sample.rgb);
//2
sample.rgb = vec3(step(level, dot(sample.rgb, vec3(0.2126, 0.7152, 0.0722))));
//3
float brightenRatio = 1.0 / max(max(sample.r, sample.g), sample.b+0.00000001);
brightenRatio *= step( level, dot(sample.rgb, vec3(0.2126, 0.7152, 0.0722)) );
sample.rgb *= brightenRatio;[/code] Edited by Hodgman
0

Share this post


Link to post
Share on other sites
hy. im using this to in my bloom shader. is simple and it works really well
[CODE]

float4 color = tex2D( srcTex, IN.uv );
color = (-color + (pow(tex2D( srcTex, IN.uv ),Power) * Scale) )/Bias;
return color;
[/CODE]
here's a screenshot using scale = 1.83, power = 4 and bias = 0.27
[URL=http://imgur.com/WXed6][IMG]http://i.imgur.com/WXed6.jpg[/IMG][/URL]
PS: this is HLSL, but i think it should be really similar
1

Share this post


Link to post
Share on other sites
[quote name='pachesantiago' timestamp='1350324376' post='4990455']
hy. im using this to in my bloom shader. is simple and it works really well
[CODE]

float4 color = tex2D( srcTex, IN.uv );
color = (-color + (pow(tex2D( srcTex, IN.uv ),Power) * Scale) )/Bias;
return color;
[/CODE]
here's a screenshot using scale = 1.83, power = 4 and bias = 0.27
[url="http://imgur.com/WXed6"][img]http://i.imgur.com/WXed6.jpg[/img][/url]
PS: this is HLSL, but i think it should be really similar
[/quote]
Sorry, didnt mention that the grayscale is another shader, is not part of the "bright pass"
Using colors:
[URL=http://imgur.com/21Oys][IMG]http://i.imgur.com/21Oys.png[/IMG][/URL]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0