61
Lighting and Shading

Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Lighting and Shading

Page 2: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Today: Local Illumination

Solving the rendering equation is too expensive

First do local illumination

Then “hack in” reflections and shadows

Page 3: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Local Shading: Notation

light intensity in, light intensity out

vector pointing to: light, normal direction,eye, reflection direction

Page 4: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Ignore camera and light direction completely

Ambient Term

material constant

Page 5: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Ignore camera and light direction completely

Ambient Term

material constant

one eq.per colorchannel

Page 6: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Lambertian surface – constant BRDF

Diffuse Term

Page 7: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Lambertian surface – constant BRDF

Diffuse Term

ignore back faces

Page 8: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Perfect specular surface doesn’t work

Specular Term

Page 9: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Perfect specular surface doesn’t work

Phong model:

Specular Term

specularity coefficient

Page 10: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Perfect specular surface doesn’t work

Phong model:

Looks like “highlight” thatmoves with light & eye

Specular Term

Page 11: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Putting It Together

Page 12: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Putting It Together

typically:

Page 13: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Putting It Together

typically:

three copies of equation, one per color channel

Page 14: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Specularity Coefficientmore specular

hig

her

exp

oo

nent

Page 15: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Light Attenuation

Real light attenuation: inverse square law

Page 16: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Light Attenuation

Real light attenuation: inverse square law

Tends to look bad: too dimor washed out

So, we cheat

Page 17: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

d is light-to-point distance

Can tweak constant & linear term to taste

Light Attenuation

Page 18: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Directional Light

“Light at infinity”

• Sun

All light rays parallel

Obviously, no attenuation

Page 19: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Dealing with Discrete Geometry

Flat shading: use normal per face

Very obvious discontinuitiesat edges

Only used for stylized “chunky” effect

Page 20: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Gouraud Interpolation

First, compute color at vertices

Linearly interpolate color over face

Page 21: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Gouraud Interpolation

First, compute color at vertices

Linearly interpolate color over face

Color now continuous, but still obvious artifacts (nobody uses this anymore)

Page 22: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Phong Interpolation

First, linearly interpolate normals

Next, renormalize normals(important)

Then, compute color per pixel

Page 23: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Phong Interpolation

First, linearly interpolate normals

Next, renormalize normals(important)

Then, compute color per pixel

Because of all of the normalizations, used to be considered decadent;now the standard local shading scheme

Page 24: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Local vs Global Illumination

Local:

• shade each object based only on itself, the eye, and the light sources

Global:

• take all other objects in scene into account also

• BRDFs and the rendering equation

Page 25: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Local vs Global Illumination

Grey Area:

• take other objects into account, without full global illumination

• adds realism without being too slow

Page 26: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Local vs Global Illumination

Grey Area:

• take other objects into account, without full global illumination

• adds realism without being too slow

• common techniques exist for

• shadows

• reflections

• refractions

Page 27: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Shooting Shadow Rays

Page 28: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Shooting Shadow Rays

For each intersection pt:

• for each light:

• shoot ray from point to light

• if it hits an object:

• do nothing (shadow)

• else add shading contribution

Page 29: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Classic Bug

Page 30: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Classic Bug

at what t does the ray hit an object?

Page 31: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Classic Bug

at what t does the ray hit an object?

Page 32: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Classic Bug

at what t does the ray hit an object?

if lucky: {-1.2, 0.0}

Page 33: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Classic Bug

at what t does the ray hit an object?

if lucky: {-1.2, 0.0}

if unlucky: {-1.2, 1e-12}

Page 34: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Ignore t Near Zero?

Page 35: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Ignore t Near Zero?

Page 36: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Ignore t Near Zero?

Fix: move slightly in normal direction (orbackward ray direction) before shooting shadow ray

Page 37: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Hard Shadows

real-world doesn’tlook like this

Page 38: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Hard Shadows

real-world doesn’tlook like this

shadows usuallysoft

why?

Page 39: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Soft Shadows

Page 40: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Other Secondary Rays

Translucent objects

Page 41: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Other Secondary Rays

Reflection & refraction

Page 42: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection

Purely specular (mirrored) surface

Page 43: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection

Purely specular (mirrored) surface:

1. Incoming ray hits surface

Page 44: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection

Purely specular (mirrored) surface:

1. Incoming ray hits surface

2. Shoot secondary reflection ray

Page 45: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection

Purely specular (mirrored) surface:

1. Incoming ray hits surface

2. Shoot secondary reflection ray

3. Set pixel color to color “seen” by

Page 46: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Choosing the Reflection Ray

Angle of reflection = angle of incidence

Page 47: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Choosing the Reflection Ray

Angle of reflection = angle of incidence

I.e. negate component of in normal dir

• leave tangent component untouched

Page 48: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Choosing the Reflection Ray

Angle of reflection = angle of incidence

I.e. negate component of in normal dir

• leave tangent component untouched

Page 49: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Choosing the Reflection Ray

Angle of reflection = angle of incidence

I.e. negate component of in normal dir

• leave tangent component untouched

Page 50: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

The math:

Choosing the Reflection Ray

Page 51: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection in Practice

Objects may not be perfectly mirrored

• blend reflected color with basic shading

Page 52: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection in Practice

Objects may not be perfectly mirrored

• blend reflected color with basic shading

Objects have base color

• multiplies reflected color

Page 53: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflections in Practice

Reflection ray might hit reflective objects

• cast recursive reflection rays…

• stop after somemaximum recursionlimit

Page 54: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Refraction

Page 55: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Refraction

Light bends whenmoving betweendifferent materials

Caused by changein speed of light

We “see” dotted straw

Page 56: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Index of Refraction

Measures speed of light in material

Page 57: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Index of Refraction

Measures speed of light in material

Common values:

• Vacuum: 1.0

• Air: 1.0001

• Water: 1.33

• Glass: 1.5

Page 58: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Snell’s Law

Special cases:

Page 59: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Implementing Snell’s Law

Solve for alpha

Shoot refraction ray

Page 60: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Refractions in Practice

Again, usually multiplied by a base color

Light bends when entering and leaving

• must detect both when ray-tracing

Page 61: Lighting and Shadingfussell/courses/cs384g/... · Lighting and Shading. Today: Local Illumination Solving the rendering equation is too expensive First do local illumination Then

Reflection & Refraction Example