Lighting Shading by John Hable
-
Upload
naughty-dog -
Category
Technology
-
view
5.720 -
download
5
description
Transcript of Lighting Shading by John Hable
![Page 1: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/1.jpg)
Uncharted 2: HDR Lighting
John Hable Naughty Dog
![Page 2: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/2.jpg)
Agenda
1. Gamma/Linear-Space Lighting 2. Filmic Tonemapping 3. SSAO 4. Rendering Architecture/How it all fits
together.
![Page 3: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/3.jpg)
Skeletons in the Closet
• Used 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 2
![Page 4: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/4.jpg)
Part 1: Gamma!
![Page 5: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/5.jpg)
Gamma
• Mostly 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 3
![Page 6: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/6.jpg)
Demo
• What is halfway between white and black
• Suppose we show alternating light/dark lines.
• If we squint, we get half the linear intensity.
![Page 7: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/7.jpg)
Demo
• Test image with 4 rectangles.
• Real image of a computer screen shot from my camera.
![Page 8: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/8.jpg)
Demo
• Alternating lines of black and white (0 and 255).
![Page 9: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/9.jpg)
Demo
• So if the left and right are alternating lines of 0 and 255, then what color is the rectangle with the blue dot?
![Page 10: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/10.jpg)
Demo
• Common wrong answer: 127/128.
• That’stheboxonthetop.
128
![Page 11: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/11.jpg)
Demo
• Correct answer is 187.
• WTF?
128
187
![Page 12: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/12.jpg)
Color Ramp
• You have seen this before.
0 255 127
187
![Page 13: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/13.jpg)
Gamma Lines
• F(x) = pow(x,2.2)
0
187
127
255
![Page 14: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/14.jpg)
What is Gamma
• Gamma of 0.45, 1, 2.2
• Our monitors are the red one
![Page 15: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/15.jpg)
We all love mink...
• F(x) = x
![Page 16: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/16.jpg)
We all love mink...
• F(x) = pow(x,0.45) note: .45 ~= 1/2.2
![Page 17: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/17.jpg)
We all love mink...
• F(x) = pow(x,2.2)
![Page 18: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/18.jpg)
What is Gamma
• Gettoknowthesecurves…
![Page 19: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/19.jpg)
What is Gamma
• Back and forth between curves.
.45
2.2 2.2
.45
![Page 20: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/20.jpg)
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
![Page 21: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/21.jpg)
Let’s build a Camera…
• A linear camera.
1.0 2.2
Actual Light
Hard Drive
Monitor Output
![Page 22: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/22.jpg)
Let’s build a Camera…
• Any consumer camera.
.45 2.2
Actual Light
Hard Drive
Monitor Output
![Page 23: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/23.jpg)
How to fix this?
• Your screen displays a gamma of 2.2
• This is stored on your hard drive. – Youneverseethisimage,butit’sonyourharddrive.
2.2
![Page 24: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/24.jpg)
What is Gamma
• Curves again.
![Page 25: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/25.jpg)
What is Gamma
Q) Why not just store as linear?
A) Our eyes perceive more data in the blacks.
![Page 26: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/26.jpg)
How bad is it?
• Suppose we look at the 0-63 range.
• What if displays were linear?
![Page 27: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/27.jpg)
Gamma
• Gamma of 2.2 gives us more dark colors.
![Page 28: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/28.jpg)
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:
![Page 29: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/29.jpg)
Ramp Again
• See any banding in the whites?
![Page 30: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/30.jpg)
3D Graphics
• If your game is not gamma correct, it looks like the image on the left..
• Note:we’retalkingabout“correct”,not“good”
![Page 31: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/31.jpg)
3D Graphics
• Here's what is going on.
Screen Hard Drive
Lighting
![Page 32: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/32.jpg)
3D Graphics
• Account 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 )
![Page 33: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/33.jpg)
3D Graphics
• Here's what is going on.
Hard Drive
Gamma
Lighting Shader Correct
Monitor Adjust
![Page 34: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/34.jpg)
3D Graphics
• Comparison again...
![Page 35: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/35.jpg)
3D Graphics
• The Wrong Shader? Spec = CalSpec();
Diff = tex2D( Sampler, UV );
Color = Diff * max( 0, dot( N, L ) ) + Spec;
return Color;
![Page 36: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/36.jpg)
3D Graphics
• The 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);
![Page 37: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/37.jpg)
3D Graphics
• But, there is hardware to do this for us. – Hardware does sampling for free
– For Texture read:
• D3DSAMP_SRGBTEXTURE
– For RenderTarget write:
• D3DRS_SRGBWRITEENABLE
![Page 38: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/38.jpg)
3D Graphics
• With those states we can remove the pow functions. Spec = CalSpec();
Diff = tex2D( Sampler, UV );
Color = Diff * max( 0, dot( N, L ) ) + Spec;
return Color;
![Page 39: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/39.jpg)
3D Graphics
• What does the real world look like?
– Notice the harsh line.
![Page 40: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/40.jpg)
3D Graphics
• Another Example
![Page 41: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/41.jpg)
FAQs
Q1) But I like the soft falloff!
A1) Don’tbesosure.
![Page 42: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/42.jpg)
FAQs
• Itlooksliketheoneontopbeforethemonitor’s2.2
![Page 43: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/43.jpg)
Harsh Falloff
• Devastating.
![Page 44: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/44.jpg)
Harsh Falloff
• Devastating.
![Page 45: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/45.jpg)
Harsh Falloff
• Devastating.
![Page 46: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/46.jpg)
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’tusesRGBorpow(2.2) on read
• 128 = 0.5
![Page 47: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/47.jpg)
Which Maps?
• Diffuse Map
• Definitely Gamma
• Normal Map
• Definitely Linear
![Page 48: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/48.jpg)
Which Maps?
• Specular?
• Uncharted 2 had them as Linear
• Artists have trouble tweaking them to look right
• Probably should be in Gamma
![Page 49: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/49.jpg)
Which Maps?
• Ambient Occlusion
• Technically,it’samathematicalvaluelikeanormalmap.
• But artists tweak them a lot and bake extra lighting into them.
• Uncharted 2 had them as Linear
• Probably should be Gamma
![Page 50: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/50.jpg)
Exercise for the Reader
• Gamma 2.2 != sRGB != Xenon PWL
• sRGB: PC and PS3 gamma
• Xenon PWL: Piecewise linear gamma
![Page 51: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/51.jpg)
Xenon Gotchas
• Xbox 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 other
![Page 52: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/52.jpg)
Linear-Space Lighting: Conclusion
“Drake!Youmustbelieve in linear-spacelighting!”
![Page 53: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/53.jpg)
Part 2: Filmic Tonemaping
![Page 54: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/54.jpg)
Filmic Tonemapping
• Let's talk about the magic of the human eye.
![Page 55: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/55.jpg)
Filmic Tonemapping
• Real example from my apartment.
• Full Auto settings.
• Outside blown out.
• Cello case looks empty.
• My eye somehow adjusts...
![Page 56: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/56.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 57: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/57.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 58: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/58.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 59: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/59.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 60: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/60.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 61: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/61.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 62: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/62.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 63: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/63.jpg)
Filmic Tonemapping
• Adaptiveness of human eye.
![Page 64: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/64.jpg)
Filmic Tonemapping
• One more
![Page 65: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/65.jpg)
Filmic Tonemapping
• One more
![Page 66: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/66.jpg)
Gamma
• Let’stakeanHDRimage
• Note: 1 F-Stop is a power of two
• So 4 F-stops is 2^4=16x difference in intensity
![Page 67: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/67.jpg)
Gamma
• Exposure: -4
![Page 68: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/68.jpg)
Gamma
• Exposure: -2
![Page 69: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/69.jpg)
Gamma
• Exposure: 0
![Page 70: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/70.jpg)
Gamma
• Exposure: 2
![Page 71: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/71.jpg)
Gamma
• Exposure: 4
![Page 72: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/72.jpg)
Now what?
• We actually need 8 stops
• Good News: HDR Image
• Bad News: Now what?
• Re-tweaking exposure won't help
![Page 73: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/73.jpg)
Gamma
• This is what Photography people call tonemapping. – Photomatix
– This one is local
– Theonewe’lluseisglobal
![Page 74: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/74.jpg)
Point of Confusion
• Two problems to solve.
• Simulate the Iris
• Dynamic Range in different shots
• Tunnel vs. Daylight
• Simulate the Retina
• Different Range within a shot
• Inside looking outside
![Page 75: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/75.jpg)
Terminology
• Photography/Film
• Within a Shot – HDR Tonemapping
• Different Shots – Choosing the correct exposure?
• Video Games
• Within a Shot – HDR Tonemapping
• Different Shots – HDR Tonemapping?
![Page 76: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/76.jpg)
Terminology
• For this presentation
• Within a Shot – HDR Tonemapping
• Different Shots
• Automatic Exposure Adjustment
• Dynamic Iris
![Page 77: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/77.jpg)
Linear Curve
• Apartment of Habib Zargarpour
• Creative Director, Microsoft Game Studios
• Used to be Art Director on LMNO at EA
![Page 78: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/78.jpg)
Linear Curve
• OutColor = pow(x,1/2.2)
![Page 79: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/79.jpg)
Reinhard
• Most common tonemapping operator is Reinhard
• Simplest version is:
• F(x) = x/(x+1)
• Yes,I’moversimplifiying for time.
![Page 80: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/80.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 81: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/81.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 82: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/82.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 83: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/83.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 84: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/84.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 85: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/85.jpg)
Fade!
• Let's fade from linear to Reinhard.
![Page 86: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/86.jpg)
Why Does this happen
• Start with orange (255,88,21)
![Page 87: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/87.jpg)
Linear Curve
• Linear curve at the low end and high end
![Page 88: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/88.jpg)
Bad Gamma
• Better blacks actually, but wrong color at the bottom and horrible hue-shifting.
![Page 89: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/89.jpg)
Reinhard
• Desaturated blacks, but nice top end.
![Page 90: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/90.jpg)
Color Changes
• Gee...if only we could get:
• The crisper, more saturated blacks of improper gamma.
• The nice soft highlights of Reinhard
• And get the input colors to actually match like pure linear.
![Page 91: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/91.jpg)
Voila!
• Guess what? There is a solution!
![Page 92: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/92.jpg)
Voila!
• Solution by Haarm-Peter Duiker
• CG Supervisor at Digital Domain
• Used to be a CG Supervisor on LMNO at EA
![Page 93: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/93.jpg)
Film
Q) Why do they still use film in movies?
A) The look.
![Page 94: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/94.jpg)
Film
• Kodak film examples.
Shoulder
Toe
![Page 95: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/95.jpg)
Film
• Using a film curve solves tons of problems.
• Film vs. Digital purists.
• Whowould’vethought:Kodakknowshowtomakegoodfilm.
![Page 96: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/96.jpg)
Filmic Curve
• Crisp blacks, saturated dark end, and nice highlights.
![Page 97: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/97.jpg)
Filmic Tonemapping
• This technique works with any color.
Reinhard
Linear
Filmic
![Page 98: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/98.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 99: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/99.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 100: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/100.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 101: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/101.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 102: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/102.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 103: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/103.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 104: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/104.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 105: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/105.jpg)
Filmic Tonemapping
Reinhard
Linear
Filmic
• This technique works with any color.
![Page 106: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/106.jpg)
Filmic Tonemapping
• Intermsof“CrispBlacks”vs.“MilkyBlacks”
• Filmic > Linear > Reinhard
• Intermsof“SoftHighights”vs.“ClampedHighlights”
• Filmic = Reinhard > Linear
![Page 107: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/107.jpg)
Filmic Tonemapping
• Linear.
![Page 108: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/108.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 109: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/109.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 110: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/110.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 111: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/111.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 112: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/112.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 113: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/113.jpg)
Filmic Tonemapping
• Fade from linear to filmic.
![Page 114: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/114.jpg)
Filmic vs Reinhard
• Fade from linear to Reinhard.
![Page 115: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/115.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 116: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/116.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 117: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/117.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 118: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/118.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 119: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/119.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 120: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/120.jpg)
Filmic Tonemapping
• Fade from Reinhard to filmic.
![Page 121: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/121.jpg)
Filmic Tonemapping
• Let's do a comparison.
![Page 122: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/122.jpg)
Filmic Tonemapping
• This is with a linear curve.
![Page 123: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/123.jpg)
Filmic Tonemapping
• And here is filmic.
![Page 124: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/124.jpg)
Filmic Tonemapping
• First, we'll go up.
![Page 125: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/125.jpg)
Filmic Tonemapping
• Exposure 0
![Page 126: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/126.jpg)
Filmic Tonemapping
• Exposure +1
![Page 127: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/127.jpg)
Filmic Tonemapping
• Exposure +2
![Page 128: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/128.jpg)
Filmic Tonemapping
• Exposure +3
![Page 129: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/129.jpg)
Filmic Tonemapping
• Exposure +4
![Page 130: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/130.jpg)
Filmic Tonemapping
• Ok, now that's bad.
• What happens if we go down?
• Notice the crisper blacks in the filmic version.
![Page 131: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/131.jpg)
Filmic Tonemapping
• Exposure: 0
![Page 132: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/132.jpg)
Filmic Tonemapping
• Exposure: -1
![Page 133: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/133.jpg)
Filmic Tonemapping
• Exposure: -2
![Page 134: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/134.jpg)
Filmic Tonemapping
• Exposure: -3
![Page 135: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/135.jpg)
Filmic Tonemapping
• Exposure: -4
![Page 136: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/136.jpg)
Filmic Tonemapping
• Colors get crisper and more saturated at the bottom end.
![Page 137: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/137.jpg)
Filmic Tonemapping
float3 ld = 0.002;
float linReference = 0.18;
float logReference = 444;
float logGamma = 0.45;
outColor.rgb = (log10(0.4*outColor.rgb/linReference)/ld*logGamma + logReference)/1023.f;
outColor.rgb = clamp(outColor.rgb , 0, 1);
float FilmLutWidth = 256;
float Padding = .5/FilmLutWidth;
outColor.r = tex2D(FilmLutSampler, float2( lerp(Padding,1-Padding,outColor.r), .5)).r;
outColor.g = tex2D(FilmLutSampler, float2( lerp(Padding,1-Padding,outColor.g), .5)).r;
outColor.b = tex2D(FilmLutSampler, float2( lerp(Padding,1-Padding,outColor.b), .5)).r;
![Page 138: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/138.jpg)
Filmic Tonemapping
• Variation in white section:
254
240
248
252
224
![Page 139: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/139.jpg)
More Magic
• The catch:
• Three texture lookups
• Jim Hejl to the rescue
Principle Member of Technical Staff
GPU Group, Office of the CTO
AMD Research
• Used to work for EA
![Page 140: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/140.jpg)
More Magic
• Awesome approximation with only ALU ops.
• Replaces the entire Lin/Log and Texture LUT
• Includes the pow(x,1/2.2)
x = max(0, LinearColor-0.004); GammaColor = (x*(6.2*x+0.5))/(x*(6.2*x+1.7)+0.06);
![Page 141: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/141.jpg)
Filmic Tonemapping
• Nice curve
• Toe arguably too strong
• Most monitors are too contrasty, strong toe makes it worse
• May want less shoulder
• The more range, the more shoulder
• If your scene lacks range, you want to tone down the shoulder a bit
![Page 142: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/142.jpg)
Filmic Tonemapping
A = Shoulder Strength
B = Linear Strength
C = Linear Angle
D = Toe Strength
E = Toe Numerator
F = Toe Denominator
Note: E/F = Toe Angle
LinearWhite = Linear White Point Value
F(x) = ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F)) - E/F;
FinalColor = F(LinearColor)/F(LinearWhite)
![Page 143: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/143.jpg)
Filmic Tonemapping
Shoulder Strength = 0.22
Linear Strength = 0.30
Linear Angle = 0.10
Toe Strength = 0.20
Toe Numerator = 0.01
Toe Denominator = 0.30
Linear White Point Value = 11.2
These numbers DO NOT have the pow(x,1/2.2) baked in
![Page 144: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/144.jpg)
Conclusions
• Filmic Tonemapping – IMO: The most important post effect – Changes your life completely
• Once you have it, you can't live without it – If you implement it, you have to redo all your lighting
• You can't just switch it on if your lighting is tweaked for no dynamic range.
![Page 145: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/145.jpg)
Filmic Tonemapping
“AtleastI’mnotgettingchokedingammaspace...”
![Page 146: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/146.jpg)
Part 3: SSAO
![Page 147: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/147.jpg)
SSAO Time
• That was fun.
• Time for stage 3.
• Let’stalkaboutwhyyouneedAO.
![Page 148: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/148.jpg)
Why AO?
• Theshadow“grounds”thecar.
![Page 149: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/149.jpg)
Why AO?
• Unlessyou’realreadyintheshadow!
![Page 150: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/150.jpg)
Why AO?
• Your shadow can't help you now!
![Page 151: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/151.jpg)
Why AO?
• Your shadow can't help you now!
![Page 152: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/152.jpg)
Why AO?
• Your shadow can't help you now!
![Page 153: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/153.jpg)
Why AO?
• Your shadow can't help you now!
![Page 154: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/154.jpg)
How important is it?
• The shadow from the sun grounds object.
• But if you are already in shadow, you need something else...
• It's the AO that grounds the car in those shots.
• So what if we took the AO out?
• Trick taught to me by Habib (the guy with the awesome condo earlier)
![Page 155: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/155.jpg)
Why AO?
• Your shadow can't help you now!
![Page 156: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/156.jpg)
Why AO?
• Your shadow can't help you now!
![Page 157: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/157.jpg)
Why AO?
• Your shadow can't help you now!
![Page 158: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/158.jpg)
Why AO?
• Your shadow can't help you now!
![Page 159: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/159.jpg)
Why AO?
• Your shadow can't help you now!
![Page 160: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/160.jpg)
Why AO?
• Your shadow can't help you now!
![Page 161: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/161.jpg)
Why AO?
• Your shadow can't help you now!
![Page 162: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/162.jpg)
Why AO?
• Your shadow can't help you now!
![Page 163: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/163.jpg)
How to use AO?
• Sun is Directional Light
• Sky is Hemisphere Light (ish)
![Page 164: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/164.jpg)
How to use AO?
• Sun is Yellow (ish)
• Sky is Blue (ish)
![Page 165: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/165.jpg)
How to use AO?
• Sun is Directional
• Approximate Directional Shadow with Shadow Mapping
![Page 166: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/166.jpg)
How to use AO?
• Sky is Hemisphere (sorta)
• Approximate Hemisphere Shadow with AO
![Page 167: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/167.jpg)
How to use AO?
• Sun is yellow, sky is blue.
![Page 168: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/168.jpg)
How to use AO?
![Page 169: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/169.jpg)
How to use AO?
![Page 170: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/170.jpg)
How to use AO?
![Page 171: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/171.jpg)
How to use AO?
![Page 172: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/172.jpg)
How to use AO?
![Page 173: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/173.jpg)
Sunlight
Q) Why not have it affect sunlight?
A) It does the exact opposite of what you want it to do.
![Page 174: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/174.jpg)
SSAO Example
• Off
![Page 175: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/175.jpg)
SSAO Example
• On
![Page 176: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/176.jpg)
SSAO Example
• SSAO Darkens Shadows – Good
• SSAO Darkens Sunlight – BAD
• Reduces perceived contrast
• Makes lighting look flatter
• My Opinion: SSAO should NOT affect Direct Light
![Page 177: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/177.jpg)
The Algorithm
• Only Input is Half-Res Depth
• No normals
• No special filtering (I.e. Bilateral)
• Processed in 64x64 blocks
• Adjacent Depth tiles included as well
![Page 178: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/178.jpg)
The Algorithm
• Calculate Base AO
• Dilate Horizontal
• Dilate Vertical
• Apply Low Pass Filter
![Page 179: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/179.jpg)
SSAO Passes
0) Base Image
![Page 180: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/180.jpg)
SSAO Passes
1) Base SSAO
![Page 181: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/181.jpg)
SSAO Passes
2) Dilate Horizontal
![Page 182: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/182.jpg)
SSAO Passes
3) Dilate Vertical
![Page 183: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/183.jpg)
SSAO Passes
4) Low Pass Filter
(I.e. blur the $&%@ out of it)
![Page 184: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/184.jpg)
SSAO Passes
• Step One: The Base AO
• Uses half-res depth buffer
• Calculate AO based on nearby depth samples
![Page 185: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/185.jpg)
SSAO Passes
• Pink point on a black surface.
![Page 186: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/186.jpg)
SSAO Passes
• Correct way is to look at the hemisphere...
![Page 187: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/187.jpg)
SSAO Passes
• ...and find the area that is visible to the point.
• Our solution is much hackier.
![Page 188: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/188.jpg)
SSAO Passes
• Who needs sphere? A box will do just as well.
![Page 189: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/189.jpg)
SSAO Passes
• Instead of area though, we will approximate volume.
![Page 190: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/190.jpg)
SSAO Passes
• We can estimate volume without knowing the normal.
• Half Volume = Fully Unoccluded
![Page 191: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/191.jpg)
SSAO Passes
• We can estimate volume without knowing the normal.
• Half Volume = Fully Unoccluded
![Page 192: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/192.jpg)
SSAO Passes
• We can estimate volume without knowing the normal.
• Half Volume = Fully Unoccluded
![Page 193: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/193.jpg)
SSAO Passes
• We can estimate volume without knowing the normal.
• Half Volume = Fully Unoccluded
![Page 194: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/194.jpg)
SSAO Passes
• Start with a point
![Page 195: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/195.jpg)
SSAO Passes
• And sample pairs of points.
![Page 196: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/196.jpg)
SSAO Passes
• What if we have an occluder?
![Page 197: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/197.jpg)
SSAO Passes
• What if we have an occluder?
![Page 198: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/198.jpg)
SSAO Passes
• We lose depth info.
![Page 199: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/199.jpg)
SSAO Passes
• We could call it occluded.
![Page 200: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/200.jpg)
SSAO Passes
• But, is that correct? Maybe not.
![Page 201: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/201.jpg)
SSAO Passes
• Let's choose a cutoff, and mark the pair as invalid.
![Page 202: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/202.jpg)
SSAO Passes
• Sample pattern?
![Page 203: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/203.jpg)
SSAO Passes
• Sample pattern. Discard in pairs.
![Page 204: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/204.jpg)
SSAO Passes
• Note the single light outline.
![Page 205: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/205.jpg)
SSAO Passes
• Find discontinuties...
![Page 206: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/206.jpg)
SSAO Passes
• Find discontinuties...
![Page 207: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/207.jpg)
SSAO Passes
• Find discontinuties...
![Page 208: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/208.jpg)
SSAO Passes
• Find discontinuties...
![Page 209: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/209.jpg)
SSAO Passes
• ...and dilate at discontinuties. Here is original.
![Page 210: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/210.jpg)
SSAO Passes
• After X dilate.
![Page 211: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/211.jpg)
SSAO Passes
• After Y dilate. And the light outline is gone.
![Page 212: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/212.jpg)
SSAO Passes
• And do a gaussian blur.
![Page 213: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/213.jpg)
SSAO Passes
• Final
![Page 214: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/214.jpg)
Artifacts
1. White Outline
2. Crossing Pattern
3. Depth Discontinuities
![Page 215: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/215.jpg)
Artifacts
• Blur adds white outline
• Crossing Pattern
![Page 216: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/216.jpg)
Artifacts
• More Crossing patterns
![Page 217: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/217.jpg)
Artifacts
• Depth Discontinuities. Notice a little anti-halo.
![Page 218: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/218.jpg)
Artifacts
• Hard to see in real levels though.
![Page 219: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/219.jpg)
Artifacts
• Artifacts are usually only noticeable to the trained eye
• Benefits outweigh drawbacks
• Have option to turn it off per surface
• Most snow fades at distance
• Some objects apply sqrt() to brighten it
• Some objects just have it off
![Page 220: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/220.jpg)
More Shots
• On
![Page 221: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/221.jpg)
More Shots
• Off
![Page 222: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/222.jpg)
More Shots
• Here's a few more shots.
![Page 223: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/223.jpg)
More Shots
• Here's a few more shots.
![Page 224: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/224.jpg)
More Shots
• Here's a few more shots.
![Page 225: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/225.jpg)
More Shots
• Here's a few more shots.
![Page 226: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/226.jpg)
More Shots
• Here's a few more shots.
![Page 227: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/227.jpg)
More Shots
• Here's a few more shots.
![Page 228: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/228.jpg)
More Shots
• Here's a few more shots.
![Page 229: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/229.jpg)
More Shots
• Here's a few more shots.
![Page 230: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/230.jpg)
More Shots
• Here's a few more shots.
![Page 231: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/231.jpg)
More Shots
• Here's a few more shots.
![Page 232: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/232.jpg)
SSAO Conclusion
• Grounds characters and other objects
• Deepens our Blacks
• Artifacts are not too bad
• Could use better filtering for halos
• RunsonSPUs,anddoesn’tneednormalbuffer
![Page 233: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/233.jpg)
Part 4: Architecture
![Page 234: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/234.jpg)
Architecture
• Time for part 4.
• Here is the base overview.
• Skip some things
![Page 235: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/235.jpg)
Rendering Passes
• Final output
![Page 236: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/236.jpg)
Rendering Passes
• Depth and Normal, 2x MSAA
![Page 237: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/237.jpg)
Rendering Passes
• Shadow depths for cascades
![Page 238: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/238.jpg)
Rendering Passes
• Cascade calculation to screen-space
![Page 239: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/239.jpg)
Rendering Passes
• Meanwhile on the SPUs...
![Page 240: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/240.jpg)
Rendering Passes
• SSAO
![Page 241: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/241.jpg)
Rendering Passes
• Fullscreen lighting. Diffuse and specular.
• Calculate lighting in Tiles
![Page 242: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/242.jpg)
Rendering Passes
• Back on the GPU...
![Page 243: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/243.jpg)
Rendering Passes
• Render to RGBM, 2x MSAA
![Page 244: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/244.jpg)
Rendering Passes
• Resolve RGBM 2x MSAA to FP16 1x
![Page 245: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/245.jpg)
Rendering Passes
• Transparent objects and post.
![Page 246: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/246.jpg)
Full Timeline
• Full Rendering Pipeline
![Page 247: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/247.jpg)
Full Timeline
• Full Render in 3 frames
![Page 248: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/248.jpg)
Frame 1
• Begin Frame 1.
![Page 249: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/249.jpg)
Frame 1
• Timeline
SPUs
GPU
PPU
![Page 250: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/250.jpg)
Frame 1
• Begin Frame 1.
![Page 251: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/251.jpg)
Frame 1
• All PPU stuff.
![Page 252: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/252.jpg)
Frame 1
• PPU kicks off SPU jobs
![Page 253: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/253.jpg)
Frame 2
• Does most of the rendering.
![Page 254: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/254.jpg)
Frame 2
• Vertex processing on SPUs...
![Page 255: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/255.jpg)
Frame 2
• ...kicks of 2x DepthNormal pass.
![Page 256: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/256.jpg)
Frame 2
• Resolve 2x MSAA buffers to 1x and copy.
![Page 257: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/257.jpg)
Frame 2
• Spotlight shadow depth pass.
![Page 258: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/258.jpg)
Frame 2
• Sunlight shadow depth pass.
![Page 259: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/259.jpg)
Frame 2
• Kick Fullscreen Lighting SPU jobs.
![Page 260: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/260.jpg)
Frame 2
• SSAO Jobs.
![Page 261: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/261.jpg)
Frame 2
• Motion Blur
![Page 262: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/262.jpg)
Frame 2
• Resolve shadow to screen. Copy Fullscreen lighting.
![Page 263: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/263.jpg)
Frame 2
• Add Fullscreen shadowed lights.
![Page 264: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/264.jpg)
Frame 2
• Standard Pass Vertex Processing on SPUs.
![Page 265: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/265.jpg)
Frame 2
• Standard pass. Writes to 2x RGBM.
![Page 266: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/266.jpg)
Frame 2
• Resolve 2x RGBM to 1x FP16
![Page 267: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/267.jpg)
Frame 2
• Full-Res Alpha-Blended effects.
![Page 268: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/268.jpg)
Frame 2
• Half-Res Particles and Composite.
![Page 269: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/269.jpg)
Frame 3
• Now for the 3rd frame.
![Page 270: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/270.jpg)
Frame 3
• Start PostFX jobs at end of Frame 2.
![Page 271: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/271.jpg)
Frame 3
• Fill in PostFX jobs in Frame 3 with low priority.
![Page 272: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/272.jpg)
Frame 3
• Read from main memory, do distortion and HUD.
![Page 273: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/273.jpg)
Full Timeline
• All together.
![Page 274: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/274.jpg)
SPU Optimization
• Quick notes on how we optimize SPU code.
![Page 275: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/275.jpg)
Performance
• Yes! You can optimize SPU code by hand!
• This was news to me when I started here.
![Page 276: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/276.jpg)
Performance
• Let’stalkaboutLaundry
• Say you have 5 loads to do
• 1 washer, 1 dryer
![Page 277: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/277.jpg)
In-Order
• Load 1 in Washer
• Load 1 in Dryer
• Load 2 in Washer
• Load 2 in Dryer
• Load 3 in Washer
• Load 3 in Dryer
• Load 4 in Washer
• Load 4 in Dryer
• Load 5 in Washer
• Load 5 in Dryer
![Page 278: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/278.jpg)
Pipelined
• Load 1 in Washer
• Load 2 in Washer, Load 1 in Dryer
• Load 3 in Washer, Load 2 in Dryer
• Load 4 in Washer, Load 3 in Dryer
• Load 5 in Washer, Load 4 in Dryer
• Load 5 in Dryer
![Page 279: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/279.jpg)
Software Pipelining
• We can do this in software
• Called“SoftwarePipelining”
• It’showweoptimizeSPUcodebyhand
• Pal Engstad (our Lead Graphics Programmer) will be putting a doc online explaining the full process.
• Should be online: look for the post on the blog
• Direct links:
• www.naughtydog.com/docs/gdc2010/intro-spu-optimizations-part-1.pdf
• www.naughtydog.com/docs/gdc2010/intro-spu-optimizations-part-2.pdf
![Page 280: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/280.jpg)
SPU C++ Intrinsics
for( int y = 0; y < clampHeight; y++ ) {
int lColorOffset = y * kAoBufferLineWidth;
VF32 currWordAo = pvColor[ lColorOffset / 4 ];
prevWordAo[0] = prevWordAo[1] = prevWordAo[2] = prevWordAo[3] = currWordAo[0];
ao_n4 = prevWordAo;
ao_n3 = (VF32)si_shufb( (qword)prevWordAo, (qword)currWordAo, (qword)s_BCDa );
ao_n2 = (VF32)si_shufb( (qword)prevWordAo, (qword)currWordAo, (qword)s_CDab );
ao_n1 = (VF32)si_shufb( (qword)prevWordAo, (qword)currWordAo, (qword)s_Dabc );
ao_curr = currWordAo;
for (int x = 0; x < kAoBufferLineWidth; x+=4) {
VF32 nextWordAo = pvColor[ (lColorOffset + x + 4)/ 4 ];
VF32 ao_p1 = (VF32)si_shufb( (qword)currWordAo, (qword)nextWordAo, (qword)s_BCDa );
VF32 ao_p2 = (VF32)si_shufb( (qword)currWordAo, (qword)nextWordAo, (qword)s_CDab );
VF32 ao_p3 = (VF32)si_shufb( (qword)currWordAo, (qword)nextWordAo, (qword)s_Dabc );
VF32 ao_p4 = nextWordAo;
VF32 blurAo = ao_n4*w4 + ao_n3*w3 + ao_n2*w2 + ao_n1*w1 + ao_curr*w0;
blurAo += ao_p1*w1 + ao_p2*w2 + ao_p3*w3 + ao_p4*w4;
pvColor[ (lColorOffset + x)/ 4 ] = blurAo;
prevWordAo = currWordAo;
currWordAo = nextWordAo;
ao_n4 = prevWordAo;
ao_n3 = ao_p1;
ao_n2 = ao_p2;
ao_n1 = ao_p3;
ao_curr = currWordAo;
}
}
![Page 281: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/281.jpg)
SPU Assembly 1/2
loop:
{nop} {o6} lqx currAo, pvColor, colorOffset
{nop} {o4} shufb prevAo0, currAo, currAo, s_AAAA
{nop} {o4} shufb ao_n30, prevAo0, currAo, s_BCDa
{nop} {o4} shufb ao_n20, prevAo0, currAo, s_CDab
{nop} {o4} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2} selb ao_n4, ao_n4, prevAo0, endLineMask {lnop}
{e2} selb ao_n3, ao_n3, ao_n30, endLineMask {lnop}
{e2} selb ao_n2, ao_n2, ao_n20, endLineMask {lnop}
{e2} selb ao_n1, ao_n1, ao_n10, endLineMask {lnop}
{nop} {o6} lqx nextAo, pvNextColor, colorOffset
{nop} {o4} shufb ao_p1, currAo, nextAo, s_BCDa
{nop} {o4} shufb ao_p2, currAo, nextAo, s_CDab
{nop} {o4} shufb ao_p3, currAo, nextAo, s_Dabc
{e6} fa ao_n4, ao_n4, nextAo {lnop}
{e6} fa ao_n3, ao_n3, ao_p3 {lnop}
{e6} fa ao_n2, ao_n2, ao_p2 {lnop}
{e6} fa ao_n1, ao_n1, ao_p1 {lnop}
EVEN ODD
![Page 282: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/282.jpg)
SPU Assembly 2/2
{e6} fm blurAo, ao_n4, w4 {lnop}
{e6} fma blurAo, ao_n3, w3, blurAo {lnop}
{e6} fma blurAo, ao_n2, w2, blurAo {lnop}
{e6} fma blurAo, ao_n1, w1, blurAo {lnop}
{e6} fma blurAo, currAo, w0, blurAo {lnop}
{nop} {o6} stqx blurAo, pvColor, colorOffset
{nop} {o4} shlqbii ao_n4, currAo, 0
{nop} {o4} shlqbii ao_n3, ao_p1, 0
{nop} {o4} shlqbii ao_n2, ao_p2, 0
{nop} {o4} shlqbii ao_n1, ao_p3, 0
{e2} ceq endLineMask, colorOffset, endLineOffset {lnop}
{e2} ceq endBlockMask, colorOffset, endOffset {lnop}
{e2} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {lnop}
{e2} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask {lnop}
{e2} a endLineOffset, endLineOffset, endLineOffsetIncr {lnop}
{e2} a colorOffset, colorOffset, colorOffsetIncr {lnop}
{nop} branch: {o?} brz endBlockMask, loop
EVEN ODD
![Page 283: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/283.jpg)
SPU Assembly
{e6} fa ao_n3, ao_n3, ao_p3 {o6} lqx nextAo, pvNextColor, colorOffset
• Here is a sample line of assembly code
• SPUs issue one even and odd instruction per cycle
• One line = One cycle
• e6 = even, 6 cycle latency
• o6 = odd, 6 cycle latency
![Page 284: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/284.jpg)
Iteration 1
loop:
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop lnop
nop branch: {o?:0} brz endBlockMask, loop
![Page 285: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/285.jpg)
Iteration 1
loop:
nop lnop
nop {o6:0} lqx currAo, pvColor, colorOffset
nop {o6:0} lqx nextAo, pvNextColor, colorOffset
nop {o4:0} shlqbii endLineMask_, endLineMask, 0
nop lnop
nop lnop
nop lnop
nop {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
nop {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
nop {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 286: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/286.jpg)
Iteration 1
loop:
nop lnop
nop {o6:0} lqx currAo, pvColor, colorOffset
nop {o6:0} lqx nextAo, pvNextColor, colorOffset
nop {o4:0} shlqbii endLineMask_, endLineMask, 0
nop lnop
nop lnop
nop lnop
nop {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
nop {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
nop {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 287: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/287.jpg)
Problems
• Take this line:
{o6} lqx currAo, pvColor, colorOffset
{o4} shufb prevAo0, currAo, currAo, s_AAAA
• Load a value into currAo
• Next instruction needs currAo
• currAo won’tbereadyyet
• Stall for 5 cycles
![Page 288: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/288.jpg)
Iteration 1
loop:
nop lnop
nop {o6:0} lqx currAo, pvColor, colorOffset
nop {o6:0} lqx nextAo, pvNextColor, colorOffset
nop {o4:0} shlqbii endLineMask_, endLineMask, 0
nop lnop
nop lnop
nop lnop
nop {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
nop {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
nop {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 289: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/289.jpg)
Iteration 1
loop:
nop lnop
nop {o6:0} lqx currAo, pvColor, colorOffset
nop {o6:0} lqx nextAo, pvNextColor, colorOffset
nop {o4:0} shlqbii endLineMask_, endLineMask, 0
nop lnop
nop lnop
nop lnop
nop {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
nop {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
nop {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 290: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/290.jpg)
Iteration 2
loop:
nop lnop
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
nop {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 lnop
{e6:1} fa ao_n2_, ao_n2, ao_p2 lnop
nop lnop
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
nop {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 291: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/291.jpg)
Iteration 3
loop:
nop lnop
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 lnop
{e6:1} fa ao_n2_, ao_n2, ao_p2 lnop
nop lnop
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask lnop
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 292: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/292.jpg)
Iteration 4
loop:
nop lnop
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 lnop
{e6:1} fa ao_n2_, ao_n2, ao_p2 lnop
{e6:3} fma blurAo___, currAo___, w0, blurAo__ lnop
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask {o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ lnop
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ lnop
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 293: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/293.jpg)
Copy Operations
loop:
{e2:x} ai ao_n1__, ao_n1_, 0 {o4:x} shlqbii currAo_, currAo, 0
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 {o4:x} shlqbii ao_p1_, ao_p1, 0
{e6:1} fa ao_n2_, ao_n2, ao_p2 {o4:x} shlqbii ao_p2_, ao_p2, 0
{e6:3} fma blurAo___, currAo___, w0, blurAo__ {o4:x} shlqbii ao_p3_, ao_p3, 0
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask {o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ {o4:x} shlqbii currAo___, currAo__, 0
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ {o4:x} shlqbii currAo__, currAo_, 0
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 294: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/294.jpg)
Optimized
loop:
{e2:x} ai ao_n1__, ao_n1_, 0 {o4:x} shlqbii currAo_, currAo, 0
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 {o4:x} shlqbii ao_p1_, ao_p1, 0
{e6:1} fa ao_n2_, ao_n2, ao_p2 {o4:x} shlqbii ao_p2_, ao_p2, 0
{e6:3} fma blurAo___, currAo___, w0, blurAo__ {o4:x} shlqbii ao_p3_, ao_p3, 0
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask{o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ {o4:x} shlqbii currAo___, currAo__, 0
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ {o4:x} shlqbii currAo__, currAo_, 0
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
![Page 295: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/295.jpg)
Optimized
loop:
{e2:x} ai ao_n1__, ao_n1_, 0 {o4:x} shlqbii currAo_, currAo, 0
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 {o4:x} shlqbii ao_p1_, ao_p1, 0
{e6:1} fa ao_n2_, ao_n2, ao_p2 {o4:x} shlqbii ao_p2_, ao_p2, 0
{e6:3} fma blurAo___, currAo___, w0, blurAo__ {o4:x} shlqbii ao_p3_, ao_p3, 0
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask{o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ {o4:x} shlqbii currAo___, currAo__, 0
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ {o4:x} shlqbii currAo__, currAo_, 0
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
EVEN ODD
![Page 296: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/296.jpg)
Optimized
loop:
{e2:x} ai ao_n1__, ao_n1_, 0 {o4:x} shlqbii currAo_, currAo, 0
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 {o4:x} shlqbii ao_p1_, ao_p1, 0
{e6:1} fa ao_n2_, ao_n2, ao_p2 {o4:x} shlqbii ao_p2_, ao_p2, 0
{e6:3} fma blurAo___, currAo___, w0, blurAo__ {o4:x} shlqbii ao_p3_, ao_p3, 0
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask{o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ {o4:x} shlqbii currAo___, currAo__, 0
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ {o4:x} shlqbii currAo__, currAo_, 0
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
EVEN ODD
![Page 297: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/297.jpg)
Optimized
loop:
{e2:x} ai ao_n1__, ao_n1_, 0 {o4:x} shlqbii currAo_, currAo, 0
{e6:1} fa ao_n4, ao_n4, nextAo {o6:0} lqx currAo, pvColor, colorOffset
{e6:1} fa ao_n3, ao_n3, ao_p3 {o6:0} lqx nextAo, pvNextColor, colorOffset
{e6:2} fma blurAo_, ao_n2_, w2, blurAo {o4:0} shlqbii endLineMask_, endLineMask, 0
{e6:1} fa ao_n1_, ao_n1, ao_p1 {o4:x} shlqbii ao_p1_, ao_p1, 0
{e6:1} fa ao_n2_, ao_n2, ao_p2 {o4:x} shlqbii ao_p2_, ao_p2, 0
{e6:3} fma blurAo___, currAo___, w0, blurAo__ {o4:x} shlqbii ao_p3_, ao_p3, 0
{e6:1} fm blurAo, ao_n4, w4 {o4:0} shufb prevAo0, currAo, currAo, s_AAAA
{e2:0} ceq endLineMask, colorOffset, endLineOffset {o4:0} shufb ao_p1, currAo, nextAo, s_BCDa
{e2:0} ceq endBlockMask, colorOffset_, endOffset {o4:0} shufb ao_p2, currAo, nextAo, s_CDab
{e2:0} selb endLineOffsetIncr, zero, colorLineBytes, endLineMask {o4:0} shufb ao_p3, currAo, nextAo, s_Dabc
{e2:0} selb ao_n4, currAo_, prevAo0, endLineMask_ {o4:0} shufb ao_n30, prevAo0, currAo, s_BCDa
{e6:2} fma blurAo__, ao_n1__, w1, blurAo_ {o4:0} shufb ao_n20, prevAo0, currAo, s_CDab
{e6:1} fma blurAo, ao_n3, w3, blurAo {o4:0} shufb ao_n10, prevAo0, currAo, s_Dabc
{e2:0} selb colorOffsetIncr, defOffsetIncr, endColorOffsetIncr, endLineMask{o6:3} stqx blurAo___, pvColor, colorOffset_
{e2:0} selb ao_n3, ao_p1_, ao_n30, endLineMask_ {o4:0} shufb colorOffset_, colorOffset_, colorOffset, s_BCa0
{e2:0} selb ao_n2, ao_p2_, ao_n20, endLineMask_ {o4:x} shlqbii currAo___, currAo__, 0
{e2:0} selb ao_n1, ao_p3_, ao_n10, endLineMask_ {o4:x} shlqbii currAo__, currAo_, 0
{e2:0} a colorOffset, colorOffset, colorOffsetIncr lnop
{e2:0} a endLineOffset, endLineOffset, endLineOffsetIncr branch: {o?:0} brz endBlockMask, loop
EVEN ODD
![Page 298: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/298.jpg)
Solution
• Gives about a 2x performance boost
• Sometimes more or less
• SSAO went from 2ms on all 6 SPUs to 1ms on all 6 SPUs
• With practice, can do about 1-2 loops per day.
• SSAO has 6 loops, and took a little over a week.
• Same process for:
• PostFX
• Fullscreen Lighting
• Ambient Cubemaps
• Many more
![Page 299: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/299.jpg)
Full Timeline
• Hand-Optimized by ICE Team
![Page 300: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/300.jpg)
Full Timeline
• Hand-Optimized by Uncharted 2 Team
![Page 301: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/301.jpg)
Performance
• Final Render
![Page 302: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/302.jpg)
Performance
• Without Fullscreen Lighting
![Page 303: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/303.jpg)
Performance
• Fullscreen Lighting Results
![Page 304: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/304.jpg)
Performance
• Fullscreen Lighting / SSAO Performance
![Page 305: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/305.jpg)
Performance
Fullscreen Lighting
SSAO
• Fullscreen Lighting / SSAO Performance
![Page 306: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/306.jpg)
Performance
• Fullscreen Lighting / SSAO Performance
![Page 307: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/307.jpg)
Performance
• Fullscreen Lighting / SSAO Performance
![Page 308: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/308.jpg)
Performance
• Fullscreen Lighting / SSAO Performance
![Page 309: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/309.jpg)
Performance
Fullscreen Lighting
SSAO
• Fullscreen Lighting / SSAO Performance
![Page 310: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/310.jpg)
Architecture Conclusions
“So,youaretheschedulerthathasbeennippingatmyheels...”
![Page 311: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/311.jpg)
Final Final Thoughts
• Gamma is super-duper important.
• Filmic Tonemapping changes your life.
• SSAO is cool, and keep it out of your sunlight.
• SPUs are awesome.
• Theydon’toptimizethemselves.
• For a tight for-loop, you can do about 2x better than the compiler.
![Page 312: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/312.jpg)
Btw...
• Naughty Dog is hiring!
• We’realsolookingfor
• Senior Lighting Artist.
• Graphics Programmer
![Page 313: Lighting Shading by John Hable](https://reader034.fdocuments.in/reader034/viewer/2022042521/553b4ad9550346b94f8b46e6/html5/thumbnails/313.jpg)
That’s it!
• Questions…