News for hackers. Stuff that matters.
Re:What every coder should know about gamma by crazygringo on Wednesday September 21, 2016 @08:50PM (#12553494)
This is one of the most fascinating articles I've come across on HN, and so well explained, so thank you.

But I wonder about what the "right" way to blend gradients really is -- the article shows how linear blending of bright hues results in an arguably more natural transition.

Yet a linear blending from black to white would actually, perceptually, feel too light -- exactly what Fig. 1 looks like -- the whole point is that a black-to-white gradient looks more even if calculated in sRGB, and not linearly.

So for gradients intended to look good to human eyes, or more specifically that change at a perceptually constant rate, what is the right algorithm when color is taken into account?

I wonder if relying just on gamma (which maps only brightness) is not enough, but whether there are equivalent curves for hue and saturation? For example, looking at any circular HSV color picker, we've very sensitive to changes around blue, and much less so around green -- is there an equivalent perceptual "gamma" for hue? Should we take that into an account for even better gradients, and calculate gradients as linear transitions in HSV rather than RGB?

Re:What every coder should know about gamma by johnnovak on Wednesday September 21, 2016 @09:28PM (#12553662)
I'm glad you enjoyed reading the article. I completely agree on not really having a "right" way to blend gradients. For that reason I almost ended up omitting the gradient example from the article because doing it "correctly" in linear space does not always yield the most pleasant looking results. Generating perceptually fine looking gradients is another huge (and very interesting!) topic in itself, so maybe I'll discuss that in another post in the future.

Until then, have a look at this online gradient generator tools that can use five different algorithms (there's some explanation provided as well for each method):

http://davidjohnstone.net/pages/lch-lab-colour-gradient-pick...

I also recommend reading the superb 'Subtleties of Color' NASA article series on the matter:

http://earthobservatory.nasa.gov/blogs/elegantfigures/2013/0...

PS: I'm slightly confused about your comment on the black to white gradient though. Are you saying the gradient on Figure 1 looks more even to you than on Figure 2? In that case, I think your monitor is miscalibrated, so try gamma-calibrating it first then have another look. Your opinion might change :)

Re:What every coder should know about gamma by mark-r on Friday September 23, 2016 @01:17AM (#12562486)
It took me a while, but I finally figured out why your color gradients were different in nature to the grayscale gradient.

All of your color gradients use a constant light output. You transition from one fully saturated primary to another, or two fully saturated primaries to two others. For that to look natural, the interpolated values should also produce a constant light output.

The grayscale ramp is not a constant light output, and the light intensity needs to follow a perceptual curve to look natural.

Re:What every coder should know about gamma by nshepperd on Thursday September 22, 2016 @01:11AM (#12554529)
On the greyscale gradient- the other way around: Figure 2 looks more even, being a perceptually linear gradient, ie. calculated "gamma incorrectly". Which is to say it's not what a real light would look like (if a light had linear falloff in illumination of this surface?).
Re:What every coder should know about gamma by ars on Thursday September 22, 2016 @01:33AM (#12554606)
I think you are supposed to add the colors then divide by two to keep the brightness constant.

This is not how light behaves (it doesn't divide by two on a wall), but it's what you need to make a gradient.

Re:What every coder should know about gamma by johnnovak on Thursday September 22, 2016 @06:06PM (#12560730)
Not divide by two; you have to use the gamma transfer curve.
Re:What every coder should know about gamma by tangent128 on Wednesday September 21, 2016 @09:08PM (#12553575)
As I read it, for "physical correctness" gamma is the most important consideration.

When selecting your initial color palette, though, it is true hue and saturation do have nonlinear perception.

There are (somewhat complicated) color spaces designed to deal with that: https://en.wikipedia.org/wiki/Lab_color_space

http://www.husl-colors.org/ lets you play with a compromise color space.

Re:What every coder should know about gamma by nitrogen on Wednesday September 21, 2016 @09:03PM (#12553552)
Maybe gradients should be computed in a more perceptually oriented colorspace like LAB, YCbCr, YIQ, XYZ, etc.
Re:What every coder should know about gamma by jjgreen on Thursday September 22, 2016 @05:07AM (#12555537)