Introduction to Computer Graphics Toshiya Hachisuka Last Time - - PowerPoint PPT Presentation

introduction to computer graphics
SMART_READER_LITE
LIVE PREVIEW

Introduction to Computer Graphics Toshiya Hachisuka Last Time - - PowerPoint PPT Presentation

Introduction to Computer Graphics Toshiya Hachisuka Last Time Introduction to ray tracing Intersection algorithms with a ray Sphere Implicit surface Triangle GLSL Sandbox Last Time for all pixels { ray =


slide-1
SLIDE 1

Introduction to Computer Graphics


 Toshiya Hachisuka

slide-2
SLIDE 2
  • Introduction to ray tracing
  • Intersection algorithms with a ray
  • Sphere
  • Implicit surface
  • Triangle
  • GLSL Sandbox

Last Time

slide-3
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
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
SLIDE 5
  • Shading models
  • BRDF
  • Lambertian
  • Specular
  • Simple lighting calculation
  • Tone mapping

Today

slide-6
SLIDE 6

Basic Shading

Normal Light Source How much light illuminate this point?

slide-7
SLIDE 7

Basic Shading

Light Source

E = Φ ⇣ ~ n ·~ l ⌘ 4⇡r2 r ~ l ~ n

Irradiance

slide-8
SLIDE 8

Basic Shading

E = Φ ⇣ ~ n ·~ l ⌘ 4⇡r2

Irradiance

slide-9
SLIDE 9

Surface Appearance

  • How is light reflected by
  • Mirror
  • Paper
  • Rough metallic surface
slide-10
SLIDE 10

Types of Reflections

  • Diffuse: matte paint, paper
  • Glossy: plastic, rough metallic surface
  • Specular: mirror
  • Retro-reflective: the moon
slide-11
SLIDE 11

BRDF

  • Bidirectional Reflectance Distribution Function
  • How light is reflected off a surface
  • Capture appearance of surface
slide-12
SLIDE 12

BRDF

  • Bidirectional Reflectance Distribution Function
  • How light is reflected off a surface
  • Capture appearance of surface
slide-13
SLIDE 13

BRDF

~ n θ ~ !i ~ !o

slide-14
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
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
SLIDE 16

BSDF

  • Bidirectional Scattering Distribution Function
  • Generalization of BRDF to transparency
  • Defined over all the directions
slide-17
SLIDE 17

Defining BRDF

  • Two approaches
  • Measurement
  • Analytical models
  • We learn simple analytical models
slide-18
SLIDE 18

Lambertian

  • Uniformly reflects light over all directions
  • “Matte” surfaces

f(~ !o, ~ !i) = Kd ⇡

slide-19
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
SLIDE 20

Lambertian - Example

slide-21
SLIDE 21

Specular Reflection

  • Mirror reflection

~ n θ θ f(~ !o, ~ !i) = Ks(~ !o, ~ !r) cos ✓

slide-22
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
SLIDE 23

Specular Reflection - Example

slide-24
SLIDE 24

Specular Refraction

  • Glass etc.

~ n θi θo ηi ηo f(~ !o, ~ !i) = Kt(~ !o, ~ !t) cos ✓i

slide-25
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
SLIDE 26

Snell’s Law

~ n θi θo ηi ηo ηi sin θi = ηo sin θo

slide-27
SLIDE 27

Index of Refraction

  • Some values of η

Vacuum Air Ice Water Crown glass Diamond 1.0 1.00029 1.31 1.33 1.52 - 1.65 2.417

slide-28
SLIDE 28

Refracted Direction

⇧ ⇥t = −1 2 (⇧ ⇥−(⇧ ⇥·⇧ n)⇧ n)− ⇤ ⇧ ⌥ 1 − 1 2 ⇥2 (1 − (⇧ ⇥ · ⇧ n)2) ⌅ ⌃⇧ n

~ n η1 η2 ~ ! ~ !t

slide-29
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 30
slide-31
SLIDE 31

Fresnel Reflection

  • Both reflection and refraction occur at interface
slide-32
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

  • ρ2

s + ρ2 t

slide-33
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 34
slide-35
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
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
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
SLIDE 38

Other BRDFs

[Ashikmin & Shirley]

slide-39
SLIDE 39

Other BRDFs

MERL BRDF Database

  • Measured BRDFs
slide-40
SLIDE 40

Shadows

  • Return irradiance only if the light is visible

Illuminated Occluded

slide-41
SLIDE 41

Shadows

  • Avoid self-intersection due to numerical error
  • Ignoring intersections that are too close etc.

Occluded?

slide-42
SLIDE 42

With Shadows

slide-43
SLIDE 43

Without Shadows

slide-44
SLIDE 44

Multiple Light Sources

  • Simply add up all the contributions
  • Linearity of illumination

One light source Two light source

slide-45
SLIDE 45

Image Based Lighting

  • Use of pixels in the image as light sources

Input illumination Renderings

slide-46
SLIDE 46

Image Based Lighting

  • If ray hits nothing, return a value from image

Image

slide-47
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
SLIDE 48

Lo(x, ~ !o) = Z

f(x, ~ !o, ~ !i)Li(x, ~ !i) cos ✓id!i Le

Area Light Sources

slide-49
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
SLIDE 50

Color in Computer Graphics

  • Store only three values (Red, Green, Blue)

Energy R G B Frequency

slide-51
SLIDE 51

Why RGB?

  • Because we see with RGB
  • Rods: Intensity sensors
  • Cones: Color sensors (typically three types)
slide-52
SLIDE 52

Full Spectrum Rendering

  • Simulation at many wavelength ⇒ RGB
slide-53
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
SLIDE 54

RGB to Spectrum

  • Ill-conditioned problem
  • Spectrum has much more info than RGB
  • “An RGB to Spectrum Conversion for Reflectances”
slide-55
SLIDE 55

Human Eye vs Monitor

  • Human eye
  • 214:1 brightness difference
  • 14 bits

  • Monitor
  • 255:1 brightness difference
  • 8 bits
slide-56
SLIDE 56

Tone Mapping

  • Convert an HDR value into 0-1 (0-255)
slide-57
SLIDE 57

Linear Scaling

  • Scale and clamp

l(x, y) = min(cL(x, y), 1.0)

slide-58
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
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
SLIDE 60

Photographic Tone Reproduction

  • Inspired by photography [Reinhard]
  • Often works well
  • Desired brightness Lwhite
slide-61
SLIDE 61

Comparisons

http://cadik.posvete.cz/tmo/

slide-62
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
SLIDE 63

Gamma Correction

Corrected No correction

slide-64
SLIDE 64

Missing Piece

slide-65
SLIDE 65

Missing Piece