SLIDE 1 Introduction to Computer Graphics
Toshiya Hachisuka
SLIDE 2
- Introduction to ray tracing
- Intersection algorithms with a ray
- Sphere
- Implicit surface
- Triangle
- GLSL Sandbox
Last Time
SLIDE 3 Last Time
for all pixels { ray = generate_camera_ray( pixel ) for all objects { hit = intersect( ray, object ) if “hit” is closer than “first_hit” {first_hit = hit} } pixel = shade( first_hit ) }
SLIDE 4 Today
for all pixels { ray = generate_camera_ray( pixel ) for all objects { hit = intersect( ray, object ) if “hit” is closer than “first_hit” {first_hit = hit} } pixel = shade( first_hit ) }
SLIDE 5
- Shading models
- BRDF
- Lambertian
- Specular
- Simple lighting calculation
- Tone mapping
Today
SLIDE 6
Basic Shading
Normal Light Source How much light illuminate this point?
SLIDE 7
Basic Shading
Light Source
E = Φ ⇣ ~ n ·~ l ⌘ 4⇡r2 r ~ l ~ n
Irradiance
SLIDE 8
Basic Shading
E = Φ ⇣ ~ n ·~ l ⌘ 4⇡r2
Irradiance
SLIDE 9 Surface Appearance
- How is light reflected by
- Mirror
- Paper
- Rough metallic surface
SLIDE 10 Types of Reflections
- Diffuse: matte paint, paper
- Glossy: plastic, rough metallic surface
- Specular: mirror
- Retro-reflective: the moon
SLIDE 11 BRDF
- Bidirectional Reflectance Distribution Function
- How light is reflected off a surface
- Capture appearance of surface
SLIDE 12 BRDF
- Bidirectional Reflectance Distribution Function
- How light is reflected off a surface
- Capture appearance of surface
SLIDE 13
BRDF
~ n θ ~ !i ~ !o
SLIDE 14
BRDF
~ n θ ~ !i ~ !o dE(x, ~ !i) = L(x, ~ !i) cos ✓d!i f(x, ~ !o, ~ !i) = dL(x, ~ !o) dE(x, ~ !i)
SLIDE 15 Reflected Radiance
- Sum of contributions from all directions
Lo(x, ~ !o) = Z
Ω
dLo(x, ~ !o) = Z
Ω
f(x, ~ !o, ~ !i)dEi(x, ~ !i) = Z
Ω
f(x, ~ !o, ~ !i)Li(x, ~ !i) cos ✓d!i
SLIDE 16 BSDF
- Bidirectional Scattering Distribution Function
- Generalization of BRDF to transparency
- Defined over all the directions
SLIDE 17 Defining BRDF
- Two approaches
- Measurement
- Analytical models
- We learn simple analytical models
SLIDE 18 Lambertian
- Uniformly reflects light over all directions
- “Matte” surfaces
f(~ !o, ~ !i) = Kd ⇡
SLIDE 19 Lambertian
- Irradiance times BRDF = Lambertain shading
color shade (hit) { return (Kd / PI) * get_irradiance(hit) }
Lo(x, ~ !o) = Z
Ω
dLo(x, ~ !o) = Z
Ω
f(x, ~ !o, ~ !i)dEi(x, ~ !i) = Kd ⇡ Z
Ω
dEi(x, ~ !i) = Kd ⇡ Ei
SLIDE 20
Lambertian - Example
SLIDE 21 Specular Reflection
~ n θ θ f(~ !o, ~ !i) = Ks(~ !o, ~ !r) cos ✓
SLIDE 22 Specular Reflection
- Recursive tracing toward the reflected dir.
color shade (hit) { case hit.material diffuse: return (Kd / PI) * get_irradiance(hit) mirror: return Ks * shade(trace(reflected_ray)) }
~ !r = −2(~ !i · ~ n)~ n + ~ !i
SLIDE 23
Specular Reflection - Example
SLIDE 24 Specular Refraction
~ n θi θo ηi ηo f(~ !o, ~ !i) = Kt(~ !o, ~ !t) cos ✓i
SLIDE 25 Specular Refraction
- Same as reflection: recursive tracing
color shade (hit) { case hit.material diffuse: return (Kd / PI) * get_irradiance(hit) mirror: return Ks * shade(trace(reflected_ray)) glass: return Kt * shade(trace(refracted_ray)) }
SLIDE 26
Snell’s Law
~ n θi θo ηi ηo ηi sin θi = ηo sin θo
SLIDE 27 Index of Refraction
Vacuum Air Ice Water Crown glass Diamond 1.0 1.00029 1.31 1.33 1.52 - 1.65 2.417
SLIDE 28 Refracted Direction
⇧ ⇥t = −1 2 (⇧ ⇥−(⇧ ⇥·⇧ n)⇧ n)− ⇤ ⇧ ⌥ 1 − 1 2 ⇥2 (1 − (⇧ ⇥ · ⇧ n)2) ⌅ ⌃⇧ n
~ n η1 η2 ~ ! ~ !t
SLIDE 29 Refracted Direction
Be aware of what object ray is entering and existing!
http://graphics.cs.ucdavis.edu/~bcbudge/deep/research/nested_dielectrics.pdf
Stack-based solution
SLIDE 30
SLIDE 31 Fresnel Reflection
- Both reflection and refraction occur at interface
SLIDE 32 Fresnel Reflection
- Based on Fresnel equations
ρs = η1 cos θi − η2 cos θo η1 cos θi + η2 cos θo ρt = η1 cos θo − η2 cos θi η1 cos θo + η2 cos θi F(θo, θi) = 1 2
s + ρ2 t
SLIDE 33 Fresnel Reflection
- Recursive call with branch
glass: R = Fresnel(hit, ray); return R * shade(trace(reflected_ray))
+ (1 - R) * shade(trace(refracted_ray));
SLIDE 34
SLIDE 35 Total Internal Reflection
⌥ 1 − 1 2 ⇥2 (1 − (⇧ ⇥ · ⇧ n)2) ⌅ ⌃
~ n η1 η2 ~ !
Trace only reflected ray with K_s = 1 if
< 0
(inside of the sqrt)
~ !r
SLIDE 36 Complete Glass
- Also known as dielectric materials
- Be careful about ray and normal directions
glass: if (TotalInternal) return shade(trace(reflected_ray)) R = Fresnel(hit, ray); return R * shade(trace(reflected_ray))
+ (1 - R) * shade(trace(refracted_ray));
SLIDE 37 Other BRDFs
- Mircofacets model
- Lots of tiny mirrors at random orientations
- Distribution of orientations of microfacets
decides the sharpness of reflection
- e.g., Cook-Torrance model
Specular Glossy
SLIDE 38 Other BRDFs
[Ashikmin & Shirley]
SLIDE 39 Other BRDFs
MERL BRDF Database
SLIDE 40 Shadows
- Return irradiance only if the light is visible
Illuminated Occluded
SLIDE 41 Shadows
- Avoid self-intersection due to numerical error
- Ignoring intersections that are too close etc.
Occluded?
SLIDE 42
With Shadows
SLIDE 43
Without Shadows
SLIDE 44 Multiple Light Sources
- Simply add up all the contributions
- Linearity of illumination
One light source Two light source
SLIDE 45 Image Based Lighting
- Use of pixels in the image as light sources
Input illumination Renderings
SLIDE 46 Image Based Lighting
- If ray hits nothing, return a value from image
Image
SLIDE 47 Image Based Lighting
- Trace random ray above the hemisphere
color get_irradiance (hit) { Ep = ... // irradiance from point light sources for (i = 1...N) { ray = gen_random_dir(hit.n) if (trace(ray) = no_hit) Ei = Ei + IBL(ray, image) } return Ep + (Ei / N) }
SLIDE 48 Lo(x, ~ !o) = Z
Ω
f(x, ~ !o, ~ !i)Li(x, ~ !i) cos ✓id!i Le
Area Light Sources
SLIDE 49 Some Details
- Generating random rays
- http://people.cs.kuleuven.be/~philip.dutre/GI/
- See Eqn. (34)
- Fetching pixels by rays
- Depends on parameterization
- http://www.pauldebevec.com/Probes/
SLIDE 50 Color in Computer Graphics
- Store only three values (Red, Green, Blue)
Energy R G B Frequency
SLIDE 51 Why RGB?
- Because we see with RGB
- Rods: Intensity sensors
- Cones: Color sensors (typically three types)
SLIDE 52 Full Spectrum Rendering
- Simulation at many wavelength ⇒ RGB
SLIDE 53 Spectrum to RGB
- Two steps
- Compute responses to spectrum as XYZ
- Convert XYZ to RGB
x = Z 700
400
L(λ)¯ x(λ)dλ r = c0x + c1y + c2z
Similar for y & z
SLIDE 54 RGB to Spectrum
- Ill-conditioned problem
- Spectrum has much more info than RGB
- “An RGB to Spectrum Conversion for Reflectances”
SLIDE 55 Human Eye vs Monitor
- Human eye
- 214:1 brightness difference
- 14 bits
- Monitor
- 255:1 brightness difference
- 8 bits
SLIDE 56 Tone Mapping
- Convert an HDR value into 0-1 (0-255)
SLIDE 57 Linear Scaling
l(x, y) = min(cL(x, y), 1.0)
SLIDE 58 Non-linear Scaling
- Use a function to “compress” HDR into 0-1
l(x, y) = f(L(x, y))
Input value (HDR) Output value Linear scaling Non-linear scaling 1.0
SLIDE 59 Film Response
- Inspired by the response curve of a film
- Simple and works well often
l(x, y) = 1.0 − e−cL(x,y)
http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm
SLIDE 60 Photographic Tone Reproduction
- Inspired by photography [Reinhard]
- Often works well
- Desired brightness Lwhite
SLIDE 61 Comparisons
http://cadik.posvete.cz/tmo/
SLIDE 62 Gamma Correction
- 0.5 is not necessary displayed as “0.5”
- Nonlinear mapping on a monitor
- Correction to input tone-mapped value
- g is typically 1.7-2.2
p(x, y) = l(x, y)
1 g
SLIDE 63
Gamma Correction
Corrected No correction
SLIDE 64
Missing Piece
SLIDE 65
Missing Piece