• 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
knarkowicz

Gamma correct gradient

8 posts in this topic

Hi,

I'm wondering why sRGB gradients look "better" than linear space gradients. Fox example the gradient from black(0x000000) to white(0xFFFFFF) clearly lacks some black shades - [url="http://scanline.ca/gradients"]http://scanline.ca/gradients[/url]. I tried to check it on different LCD's, but everywhere the sRGB one looks better. Additionally the CIELAB gradient looks just like the sRGB one. On the other hand examples like this one - [url="http://filmicgames.com/archives/354"]http://filmicgames.com/archives/354[/url] prove that the color in the middle of the gradient should be ~0.73 and not 0.5. So I'm quite lost here.
0

Share this post


Link to post
Share on other sites
It's all about perception. The human eye sees dark shades much better than bright shades, whereas linear RGB doesn't care and gives equal brightness everywhere. We compensate for this by "squashing" the color curve so that we get more black shades, which gives the image a more natural and contrasted look. A raw, uncorrected RGB image will appear bland and dull.
0

Share this post


Link to post
Share on other sites
I still don't see why linear space and gamma correction should be used while resizing images, but not when generating gradients.

For example let's take that black-white gradient from http://scanline.ca/gradients/. First one uses linear color space and gamma correction and the color in the middle is (187/255,187/255,187/255). Second one doesn't and color in it's middle is - (128/255,128/255,128/255). According to http://filmicgames.com/archives/354 the color in the middle should be like in the first gradient, but the second gradient looks much better.
0

Share this post


Link to post
Share on other sites
[quote name='KriScg' timestamp='1349284884' post='4986458']I'm wondering why sRGB gradients look "better" than linear space gradients. Fox example the gradient from black(0x000000) to white(0xFFFFFF) clearly lacks some black shades - [url="http://scanline.ca/gradients"]http://scanline.ca/gradients[/url]. I tried to check it on different LCD's, but everywhere the sRGB one looks better. Additionally the CIELAB gradient looks just like the sRGB one. On the other hand examples like this one - [url="http://filmicgames.com/archives/354"]http://filmicgames.com/archives/354[/url] prove that the color in the middle of the gradient should be ~0.73 and not 0.5. So I'm quite lost here.[/quote]This is a big vague -- are you talking about creating a linear gradient from and displaying it on an sRGB monitor, and then transforming that linear gradient into sRGB space and displaying it on an sRGB monitor?
If so, then this description should make it obvious why one looks worse -- the colour-space of your data and the colour-space of your display don't match in the former test.
[quote name='KriScg' timestamp='1349306658' post='4986584']I still don't see why linear space and gamma correction should be used while resizing images, but not when generating gradients.[/quote]If you're working with mathematical brightness values, then you should always work in linear space, however the default assumption is that the user's monitor is in sRGB space ([i]and most image files are also saved in sRGB space, so when they're displayed, no correction is required[/i]). So if you're creating a gradient of intensity values, you can first create a linear gradient, and then transform it using the sRGB curve for storage/display.
[quote name='KriScg' timestamp='1349306658' post='4986584']
First one uses linear color space and gamma correction and the color in the middle is (187/255,187/255,187/255). Second one doesn't and color in it's middle is - (128/255,128/255,128/255)
[/quote]The second one is a linear gradient (being viewed on an sRGB monitor). The first one is a linear gradient that's been "gamma corrected" into sRGB space (and then viewed on an sRGB monitor). The second one is obviously not going to appear as intended due to the "gamma mismatch" between intended brightness and actual displayed brightness. Edited by Hodgman
2

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1349318501' post='4986637']
This is a big vague -- are you talking about creating a linear gradient from and displaying it on an sRGB monitor, and then transforming that linear gradient into sRGB space and displaying it on an sRGB monitor?
[/quote]

Sorry for confusion.

First gradient is created in linear space and gamma corrected.
[CODE]
vec3 colorA = vec3( 0, 0, 0 );
vec3 colorB = vec3( 1, 1, 1 );
vec3 linearColorA = pow( colorA, 2.2 );
vec3 linearColorB = pow( colorB, 2.2 );
for ( unsigned i = 0; i < 255; ++i )
{
vec3 currColor = lerp( linearColorA, linearColorB, i / 255 );
result[ i ] = pow( currColor, 1.0 / 2.2 );
}
[/CODE]
And it looks like this:
[attachment=11616:gradientA.png]

The second one is created in sRGB space.
[CODE]
vec3 colorA = vec3( 0, 0, 0 );
vec3 colorB = vec3( 1, 1, 1 );
for ( unsigned i = 0; i < 255; ++i )
{
result[ i ] = lerp( colorA, colorB, i / 255 );
}
[/CODE]
And it looks like this:
[attachment=11617:gradientB.png]

Now according to [url="http://filmicgames.com/archives/354"]http://filmicgames.com/archives/354[/url] if you resize a 2 pixel image, where one pixel is white and second is black then the resulting pixel should have color (187,187,187). So the middle color of the gradient should be (187,187,187) - just like in the first gradient. On the other hand second gradient looks better.

This is quite an issue, because in gamma correct UI rendering, when you set up a gradient on a button from black to white it looks bad and graphic artists don't like it [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img].

[quote name='Hodgman' timestamp='1349318501' post='4986637']
So if you're creating a gradient of intensity values, you can first create a linear gradient, and then transform it using the sRGB curve for storage/display.
[/quote]

I'm doing exactly that, but the resulting gradient looks incorrect.
0

Share this post


Link to post
Share on other sites
[quote name='KriScg' timestamp='1349342440' post='4986699']The second one is created in sRGB space.[/quote]That's a linear gradient, as it's just a linear interpolation of two RGB values.
I guess you could say that if the two inputs were sRGB colours, then the output is an sRGB gradient -- but seeing black/white are the same in linear and in sRGB -- it's basically a linear gradient (being displayed on an sRGB device).[quote]First gradient is created in linear space and gamma corrected.[/quote]That's also a linear gradient approximately transformed to sRGB, because the sRGB curve is approximately equal to the "gamma 2.2" curve. This is what I'd call an sRGB gradient ([i]except using the proper curve, instead of the pow2.2 approximation[/i])

N.B. In both sRGB/Gamma2.2, 187 equates to 50% black/white. In linear, 128 corresponds to 50% black/white.
[quote]Now according to [url="http://filmicgames.com/archives/354"]http://filmicgames.com/archives/354[/url] if you resize a 2 pixel image, where one pixel is white and second is black then the resulting pixel should have color (187,187,187). So the middle color of the gradient should be (187,187,187) - just like in the first gradient.[/quote]Theres a reason for this -- if your monitor is correctly calibrated as an sRGB device, then when standing back from a black/white checkerboard image and squinting, it will appear exactly the same as an image filled with 187 grey. An image filled with 128 grey will appear [i]much[/i] darker than the (averaged due to distance/squinting) black/white checkerboard.
[quote]On the other hand second gradient looks better.[/quote]this isn't a fair visual comparison because you're skipping over a huge number of values in your first gradient. After 0/255, your second value is 21/255 ([i][font=courier new,courier,monospace]pow(1/255,1/2.2)*255[/font][/i]), so you've skipped 19 shades in there! Your first gradient would have to be almost 200000 pixels wide for you to see all the unique 256 shades of grey in the 8-bit gamma 2.2 gradient.
The second one might look better because it's made up of 256 unique shades, whereas your first is only made up of 183 shades.

Even though, as above there is a mathematical reason for 187 being "middle grey", if you're using this gradient for an artistic purpose, then the "best" gradient is going to be subjectively defined, not mathematically defined.
[quote]when you set up a gradient on a button from black to white it looks bad and graphic artists don't like it[/quote]If this is the root problem, can you describe it a bit more -- e.g. what this gradient is for?

Also there's something weird with your gradient images; the labelled shades are to the left of their markers by a bit. Edited by Hodgman
1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1349344409' post='4986704']
The second one might look better because it's made up of 256 unique shades, whereas your first is only made up of 183 shades.

Even though, as above there is a mathematical reason for 187 being "middle grey", if you're using this gradient for an artistic purpose, then the "best" gradient is going to be subjectively defined, not mathematically defined.[/quote]

"Best" as the one with linear perceptual brightness change.

[quote name='Hodgman' timestamp='1349344409' post='4986704']
If this is the root problem, can you describe it a bit more -- e.g. what this gradient is for?
[/quote]

For example there is a button, which is represented by rectangle consisting of 4 vertices. You can set a color for every vertex of that rectangle. When you use a fully white texture, set one edge to black and second one to white then you get gradient just like the first one in my previous post (UI rendering is gamma correct). This gradient doesn't look as if it would have linear perceptual brightness change - it clearly has too much of white shades.
0

Share this post


Link to post
Share on other sites
You've mentioned that you correct your final image by using [font=courier new,courier,monospace]pow(x, 1/2.2)[/font], but are you sure that your monitor is actually an sRGB or "gamma 2.2" display?

On an sRGB display 186/187 should be perceptually half way between 0 and 255 (50%) and 136 should be perceptually half way between 0 and 187 (25%) -- but if your display is not calibrated to sRGB, then this obviously won't be the case.

You can experimentally discover these values for your specific monitor by creating a black/white checkerboard image next to a filled area of a certain shade (e.g. 187), standing back and squinting at the image, and seeing if the blurred checkerboard matches the filled shade.

Or, load up [url="http://www.lagom.nl/lcd-test/gamma_calibration.php"]this calibration image[/url], stand a few metres back from the screen and squint, and see where the bars fade together. On my cheap office LCD, that image actually blends together around the 1.8 mark, instead of the 2.2 mark as it's supposed to. So to display "gamma correct" images on this monitor, I'd have to use a [font=courier new,courier,monospace]pow(x, 1/1.8)[/font] correction curve.
1

Share this post


Link to post
Share on other sites
[quote name='KriScg' timestamp='1349367518' post='4986802']
"Best" as the one with linear perceptual brightness change.
[/quote]

There is your answer, RGB space is not perceptually linear, sRGB on the other hand is. So if it's a linear gradient you're looking for then you should skip the gamma compression stage at the end and simply work directly in the sRGB space which is linear.
-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