Monday, August 31, 2015

sRGB gamma

In my previous post I did some gamma conversions to sRGB and a comment asked if I used the real sRGB gamma.   I did not.   From wikipedia the full formula is:

 


The linear part is only near the beginning (I think to avoid the infinite slope at 0).   I usually just use gamma = 1/2.2 as an approximation, but I thought I better check how much error that introduces.   For the part far from zero, the error is very small:



Nearer zero it's worse but as long as your range isn't in there gamma 1/2.2 is good enough for most things

Wednesday, August 26, 2015

Saturated colors look brighter than greys

Graphics people are pretty used to converting RGB colors to "luminance", and usually things that have higher luminance look brighter.    For sRGB the standard formula is:

Y = 0.2126 R + 0.7152 G + 0.0722 B

The (R,G,B) here is linear.   To get it linear you need a gamma of approximately 2.2 (see the wikipedia page for the exact transform which is linear for low values).

 If we go with a linear Y of 0.0722, these pure saturated colors are all the same luminance:

(0, 0, 1.0)
(0, 0.1, 0)
(0.34, 0, 0)

In 8bit RGB after gamma these would be equal Y RGB:

(77, 77, 77)
(0, 0, 255)
(0, 90, 0)
(156, 0, 0)

This is an image with those colors:


Note the blue and red probably look brighter to you even through they "should" be the same luminance.   The green is about the same brightness as the grey for me on my computer.   There are many places in calibration and cross-computer image viewing that would explain some of why these are not all the same subjective brightness.   But a contributing effect is almost certainly the Helmholtz-Kohlrausch effect, where saturated colors appear brighter than neutral colors.   It's good to be aware of this because it can make you think your math is wrong when in fact your perceptual system is just complicated!





Tuesday, August 18, 2015

SIGGRAPH 2015 proceedings free this week

Via an interesting post from Eric Haines with some cool tidbits.   The whole siggraph 2015 proceedings is free this week

Also Eric notes: Folklore 1: Jim Blinn confirmed that the teapot model was shrunk down because it looked nicer that way, not that the pixels were non-square (incorrectly propagated here and here). Jim & 3D printed teapot.    (I have also spread that false info!   We will know computer graphics has gone mainstream when this is at snopes).

Thursday, August 13, 2015

Lumens and brightness and all that

This post I am really writing mainly for myself.   I can't afford to test my software with a real HDR screen like this 4000 cd/m^2 (luminace) SIM2 display which is around $30k.    Mike Herf suggested I try a projector aimed at a wall to create an image about the size of the SIM2.   Good idea!

I have always found photometry (light for humans) and radiometry (light for physics) confusing.   For rendering you can just use radiance and once you forget its definition it doesn't impact your programming much.   But when my confusion always becomes most deadly to me is when I buy a projector because the constants matter a lot there.   Fortunately, I don't have to do that very often.   First lets start with lumens.    This is a measure of how much light comes from a light source per solid angle.   When you see a projector, it usually says what it cranks out in lumens.   For example, here is a screen shot from amazon today:



So it's "brightness" is 800 lumens.   Ignore the term "brightness"-- that has so many inconsistent formal and informal meanings it's not useful.   But the 800 lumens is objective.   But what is a "lumen"?   It's the "perceivable" amount of power the projector puts out.   So you plug the projector in and it consumes, say, 500 Watts of power.   Some of that is lost to heat and perhaps other waste, and 300 Watts comes out as photons.    If that light is all ultraviolet and you can't see it, that is zero lumens.    Lumens are just a constant "of human usefulness" that is wavelength dependent times the number of Watts.    A very nice figure shows this:
A single Watt of light can produce up to 683 lumens.   Figure from a nice post on green lasers.
The 683 lm/W is an historical constant to ensure backward compatibility with old units when this stuff was all candles.   So our made-up 500W projector could in principle produce 683x500 lumens.   This of course is the peak value of the projector.   For a hypothetical laser-based projector, cranking up the green would be the brightest but for most projectors it just means a white screen.

But we are graphics people.   We want luminance.    So how "bright" (note the almost meaningless term but I don't have a better one!) is it?       For emitting screens like phones and TVs, this can be complicated because the luminance varies with angle as visualized in this image:
Different phones have their brightness fall-off differently with viewing angle. (figure from an article that goes into this in more detail)

This falloff is usually by design so that most of the light can be sent toward the user looking straight at the device.   Not suprisingly this is especially true of mobile devices which rarely have more than one viewer.   Mike Herf tells me that his measurements usually have a falloff roughly modeled by a phong-like cosine function with an exponent around 4 to 5.   So when phones or TVs report their luminance they usually mean straight on viewing.

It makes sense for a projector to talk about lumens and not luminance because the luminance depends on the screen distance.   What's the conversion?   It depends on the screen because the screen will absorb some light, and it will vary with angle like the phone screens in the picture above.

Let's assume a perfect Lambertian screen with albedo 1.0 where all the light hits the screen.   Because it's Lambertian it will be dimmer at normal viewing incidence than many screens.     The measure of luminance is candela per square meter per steradian.    This is sometimes called nits.   If the screen is A square meters this is almost easy because of the candela per square meter part.    But what's up with that steradian?   As a Lambertian surface this screen will vary in how much power it send in each direction, but we know the luminance is constant so something detail-oriented and confusing is at work.   So we could go dig into the first principles (my favorite is Pat Hanrahan's chapter in the Ray Tracing classic book) or we could recall a lovely formula used all the time in radiosity (for radiometry) also applies in photometry (it's all just scaling factors):

Luminance of a diffuse surface = (exiting luminous power) / (PI * area)

So for a lambertian surface, our life is simple.   Take the lumens of the projector, and divide by PI times area.   For a one meter screen that is approximately divide by 3.   I once lived in Indiana, so I will say that is exact.

What is the area of that SIM2 screen I want to be able to emulate?    It's a 47" screen, and that usually means the diagonal.   It's 16x9, so the screen dimensions are approximately 41" by 23"which means it is about 943 square inches which according to a web calculator is about 0.6 square meters.    Since I want to be conservative, I can call that 1.0, but also pretend my screen is perfectly white.   So to get a SIM2 brightness (4000nit) at a SIM2 size I need to 12,000 lumen projector.   If I can paint my wall to 90% albedo and use the real 0.6 area and the real 3.14(etc) PI, I need about an 8500lumen projector.   It's hard to find relatively low-cost projectors (like $1000ish) over 5000 lumens, so this is not a happy number.   But close enough that I should shop.

Wednesday, August 12, 2015

New edition of my graphics text coming this December

At SIGGRAPH my publisher announced the new edition of my graphics text is coming out.  Here is my picture of their discount flyer:

Note a key change is Steve Marschner will now be the lead author.   This is something we have been moving toward starting with the last edition.   In the second edition I added some guest chapters and Steve's on signal processing was fantastic.   I think one of my strengths is explaining things, but Steve is better.   Steve agreed to start improving some of the core material, and we agreed that when the book was more than half his we would switch positions.   He has made a ton of improvements in this edition.   Just so nobody will accuse me of false modesty, I think my chapters on transformations and linear algebra are my best work and I wish I could send them back in time 30 years to my younger, hairier, slimmer, smarter, but more ignorant self.   Steve has put his touch on those too, so I would send the new versions :)

Send complaints to Steve.   But CC me!

New type of plane tiling found

   A new plane tiling has been found! 

Note the roll of computers.  From the link above:


But then the hunt went cold. Until last month, when Casey Mann, Jennifer McLoud and David Von Derau of the University of Washington Bothell announced last week that they had discovered this little beauty:
pentagon
Pinterest
Illustration: Casey Mann
“We discovered the tile using using a computer to exhaustively search through a large but finite set of possibilities,” said Casey. “We were of course very excited and a bit surprised to find the new type of pentagon.

Thursday, August 6, 2015

Fresnel Equations

When I tried to do a slightly more careful Brewster's angle test last week it quickly became apparent my reflectances were wrong.   After a long painful bug hunt, it turns out that I had the polarization components (parallel and perpendicular) reversed the the Fresnel code.    This is probably the most painful bit of code if you are used to using the Schlick approximation (which I am), so it's not surprising it was the culprit.

In the image below there are still lots of not so subtle differences.   I'll do some more physical tests after siggraph because they may mainly be however the iphone is tone mapping combined with my lack of positional/geometric calibration.  

Rendering on left and photo on right.   Note the very dim reflection of the iPad because the camera is near Brewster's angle.