Skip to main content
Uncharted 2: HDR LightingJohn HableNaughty Dog
AgendaGamma/Linear-Space LightingFilmic TonemappingSSAORendering Architecture/How it all fits together.
Skeletons in the ClosetUsed to work for EA Black Box (Vancouver)‏
Ucap Project
I.e. Tiger Woods's Face
Also used to work for EA Los Angeles
LMNO (Spielberg Project)‏
Not PQRS (Boom Blox)‏
Now at Naughty Dog
Uncharted 2Part 1: Gamma!
GammaMostly solved in Film Industry after lots of kicking and screaming
Never heard about it in college
George Borshukov taught it to me back at EA
Matrix Sequels
Issue is getting more traction now
Eugene d’Eon’s chapter in GPU Gems 3DemoWhat is halfway between white and black
Suppose we show alternating light/dark lines.
If we squint, we get half the linear intensity.DemoTest image with 4 rectangles.
Real image of a computer screen shot from my camera.DemoAlternating lines of black and white (0 and 255).DemoSo if the left and right are alternating lines of 0 and 255, then what color is the rectangle with the blue dot?DemoCommon wrong answer: 127/128.
That’s the box on the top.128
DemoCorrect answer is 187.
WTF?128187
Color RampYou have seen this before.0127255187
Gamma Lines255F(x) = pow(x,2.2)‏1871270
What is GammaGamma of 0.45, 1, 2.2
Our monitors are the red oneWe all love mink...F(x) = xWe all love mink...F(x) = pow(x,0.45)        note: .45 ~= 1/2.2‏We all love mink...F(x) = pow(x,2.2)‏What is GammaGet to know these curves…What is GammaBack and forth between curves.2.22.2.45.45
How bad is it?Your monitor has a gamma of about 2.2
So if you output the left image to the framebuffer, it will actually look like the one right.2.2
Let’s build a Camera…A linear camera.ActualLightMonitorOutput1.02.2HardDrive
Let’s build a Camera…Any consumer camera.ActualLightMonitorOutput.452.2HardDrive
How to fix this?Your screen displays a gamma of 2.2
This is stored on your hard drive.
You never see this image, but it’s on your hard drive.2.2
What is GammaCurves again.What is GammaQ) Why not just store as linear?A) Our eyes perceive more data in the blacks.
How bad is it?Suppose we look at the 0-63 range.
What if displays were linear?GammaGamma of 2.2 gives us more dark colors.How bad is it?If displays were linear:
On a scale from 0-255
0 would equal 0
1 would equal our current value of 20
2 would equal our current value of 28
3 would equal our current value of 33
Darkest Values:Ramp AgainSee any banding in the whites? 3D GraphicsIf your game is not gamma correct, it looks like the image on the left..
Note: we’re talking about “correct”, not “good”3D GraphicsHere's what is going on.ScreenHardDriveLighting
3D GraphicsAccount for gamma when reading textures
color = pow( tex2D( Sampler, Uv ), 2.2 )‏
Do your lighting calculations
Account for gamma on color output
finalcolor = pow( color, 1/2.2 )‏3D GraphicsHere's what is going on.MonitorAdjustHardDriveLightingShaderCorrectGamma
3D GraphicsComparison again...3D GraphicsThe Wrong Shader?Spec = CalSpec();Diff = tex2D( Sampler, UV );Color = Diff * max( 0, dot( N, L ) ) + Spec;return Color;
3D GraphicsThe Right Shader?Spec = CalSpec();Diff = pow( tex2D( Sampler, UV ), 2.2 );Color = Diff * max( 0, dot( N, L ) ) + Spec;return pow( Color, 1/2.2);
3D GraphicsBut, there is hardware to do this for us.
Hardware does sampling for free
For Texture read:
D3DSAMP_SRGBTEXTURE
For RenderTarget write:
D3DRS_SRGBWRITEENABLE3D GraphicsWith those states we can remove the pow functions.Spec = CalSpec();Diff = tex2D( Sampler, UV );Color = Diff * max( 0, dot( N, L ) ) + Spec;return Color;
3D GraphicsWhat does the real world look like?
Notice the harsh line.3D GraphicsAnother ExampleFAQsQ1) But I like the soft falloff!A1) Don’t be so sure.
FAQsIt looks like the one on top before the monitor’s 2.2Harsh FalloffDevastating.Harsh FalloffDevastating.Harsh FalloffDevastating.Which Maps?Which maps should be Linear-Space vs Gamma-Space?
Gamma-Space
Use sRGB hardware or pow(2.2) on read
128 ~= 0.2
Linear-Space
Don’t use sRGB or pow(2.2) on read
128 = 0.5Which Maps?Diffuse Map
Definitely Gamma
Normal Map
Definitely LinearWhich Maps?Specular?
Uncharted 2 had them as Linear
Artists have trouble tweaking them to look right
Probably should be in GammaWhich Maps?Ambient Occlusion
Technically, it’s a mathematical value like a normal map.
But artists tweak them a lot and bake extra lighting into them.
Uncharted 2 had them as Linear
Probably should be GammaExercise for the ReaderGamma 2.2 != sRGB != Xenon PWL
sRGB: PC and PS3 gamma
Xenon PWL: Piecewise linear gammaXenon GotchasXbox 360 Gamma Curve is wonky
Way too bright at the low end.
HDR the Bungie Way, Chris Tchou
Post Processing in The Orange Box, Alex Vlachos
Output curve is extra contrasty
Henry LaBounta was going to talk about it.
Try hooking up your Xenon to a waveform monitor and display a test pattern.  Prepare to be mortified.
Both factors counteract each otherLinear-Space Lighting: Conclusion“Drake!  You must believe in linear-space lighting!”
Part 2: Filmic Tonemaping
Filmic TonemappingLet's talk about the magic of the human eye.Filmic TonemappingReal example from my apartment.
Full Auto settings.
Outside blown out.
Cello case looks empty.
My eye somehow adjusts...Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingAdaptiveness of human eye.Filmic TonemappingOne moreFilmic TonemappingOne moreGammaLet’s take an HDR image
Note: 1 F-Stop is a power of two
So 4 F-stops is 2^4=16x difference in intensityGammaExposure: -4GammaExposure: -2GammaExposure: 0GammaExposure: 2GammaExposure: 4Now what?We actually need 8 stops
Good News: HDR Image
Bad News: Now what?
Re-tweaking exposure won't helpGammaThis is what Photography people call tonemapping.
Photomatix
This one is local
The one we’ll use is globalPoint of ConfusionTwo problems to solve.
Simulate the Iris
Dynamic Range in different shots