Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar...

59
Lighting and Shading Slides: Tamar Shinar,Victor Zordon

Transcript of Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar...

Page 1: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Lighting and Shading

Slides: Tamar Shinar, Victor Zordon

Page 2: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

2

Why we need shading

•Suppose we build a model of a sphere using many polygons and color each the same color. We get something like

•But we want

Page 3: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

3

Shading

•Why does the image of a real sphere look like

•Light-material interactions cause each point to have a different color or shade

•Need to consider Light sources Material properties Location of viewer Surface orientation (normal)

Page 4: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

General rendering

• The most general approach is based on physics - using principles such as conservation of energy

• a surface either emits light (e.g., light bulb) or reflects light from other illumination sources, or both

• light interaction with materials is recursive

• the rendering equation is an integral equation describing the limit of this recursive process

[Angel and Shreiner]

Page 5: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Fast local shading models

• the rendering equation can’t be solved analytically

• numerical methods aren’t fast enough for real-time

• for our fast graphics rendering pipeline, we’ll use a local model where shade at a point is independent of other surfaces

• use Phong reflection model

• shading based on local light-material interactions

Page 6: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Local shading model

directlight

reflectedlight

[Angel and Shreiner]

Page 7: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

7

Global Effects

translucent surface

shadow

multiple reflection

[Angel and Shreiner]

Page 8: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Light-material interactionsat a surface, light is absorbed, reflected, or transmitted

specular diffuse translucent

[Angel and Shreiner]

Page 9: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

General light sourceIllumination function:

integrate contributions from all sources to shade the point

[Angel and Shreiner]

Page 10: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Idealized light sources

• Ambient light

• Point light

• Spotlight

• distant (directional) light

luminance:

[Angel and Shreiner]

Page 11: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Ambient light source

• achieve a uniform light level

• no black shadows

• ambient light intensity at each point in the scene

Page 12: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

illumination intensity at p:

Point light source[A

ngel and Shreiner]

Page 13: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Point light sourcePoint light sources alone aren’t too realistic - add ambient light to mitigate high contrast

Most real-world scenes have large light sources

[Angel and Shreiner]

umbrapenumbra

Page 14: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Point light source

Point light sources alone aren’t too realistic - drop off intensity more slowly

Most real-world scenes have large light sources

[Angel and Shreiner]

Page 15: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Spotlights[A

ngel and Shreiner]

Page 16: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Spotlights[A

ngel and Shreiner]

Page 17: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Distant light sourcecharacterized by

direction

[Angel and Shreiner]

Page 18: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Lambertian Reflection Modelhttp://w

ww

.andreafisherpottery.com/cgi-bin/artistlnk.cgi?Jody_Folw

ell

Page 19: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

direct: maximum light intensity

indirect: reduced light intensity

Lambert’s cosine law

Lambertian Reflection Model

color intensity

Page 20: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

direct: maximum light intensity

indirect: reduced light intensity

Lambert’s cosine law

Lambertian Reflection Model

color intensity

Page 21: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

direct: maximum light intensity

indirect: reduced light intensity

Lambert’s cosine law

Lambertian Reflection Model

reflectancecolor intensity

Page 22: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

direct: maximum light intensity

indirect: reduced light intensity

Lambert’s cosine law

Lambertian Reflection Model

illumination

reflectancecolor intensity

Page 23: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Lambertian Reflection Model

Page 24: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

two-sided lighting

Lambertian Reflection Model

Page 25: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Ambient Reflection

Surfaces facing away from the light will be

totally black

Page 26: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Ambient Reflection

All surfaces get same amount of ambient light

Page 27: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Phong Reflection Modelhttp://w

ww

.andreafisherpottery.com/cgi-bin/artistlnk.cgi?Jody_Folw

ell

Page 28: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Phong Reflection Model

•efficient, reasonably realistic•3 components•4 vectors

[Brad Smith, W

ikimedia C

omm

ons]

Page 29: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Phong Reflection Model

illuminationreflectancecolor intensity

[Brad Smith, W

ikimedia C

omm

ons]

Page 30: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Ambient reflection

ambient reflection coefficient

different ambient coefficients for different colors

Page 31: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Diffuse reflection

Page 32: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Diffuse reflection

diffuse reflection coefficient

direct: maximum light intensity

indirect: reduced light intensity

Lambert’s cosine law

Page 33: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Specular reflection

Ideal reflector

angle of incidence

angle ofreflection

r is the mirror reflection direction

Page 34: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Specular reflection

Specular surface

specular reflection is strongest in mirror reflection direction

specular highlight

Page 35: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Specular reflection

specular reflection drops off with increasing angle

specular reflection coefficient

Phong exponent

Page 36: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Specular reflection

metalplastic

Phong exponent

Page 37: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Phong Reflection Model[Brad Sm

ith, Wikim

edia Com

mons]

Ambient Diffuse Specular

Page 38: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Alternative: Blinn-Phong Model

h

halfway vector

Ambient Diffuse Specular

[Brad Smith, W

ikimedia C

omm

ons]

Page 39: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Shading Polygonal Geometry

Page 40: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Smooth surfaces are often approximated by polygons

Shading approaches:

1. Flat2. Smooth (Gouraud)3. Phong

Page 41: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Flat Shading

valid for light at inf and viewer at inf

and faceted surfaces

do the shading calculation once per polygon

Page 42: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Mach Band Effect

Page 43: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Smooth Shading

do the shading calculation once

per vertex

Page 44: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

44

Interpolating Normals

• Must renormalize

Page 45: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

45

Interpolating Normals

• Must renormalize

Page 46: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

46

Interpolating Normals

• Must renormalize

Page 47: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

We can interpolate attributes using barycentric coordinates

http://jtibble.dyndns.org/graphics/eecs487/eecs487.html

Gouraud shading (Gouraud, 1971)

Page 48: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Phong Shading

do the shading calculation once per fragment

Page 49: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Comparison

Flat Gouraud Phong

Page 50: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Problems with Interpolated Shading

• Polygonal silhouette

• Perspective distortion

• Orientation dependence

• Unrepresentative surface normals

[Fol

ey, v

an D

am, F

eine

r, H

ughe

s]

Page 51: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Programmable Shading

Page 52: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Fixed-Function Pipeline

CPU GPU

User Program

GeometryProcessing

PixelProcessing

primitives2D screencoordinates

Control pipeline through GL state variables

Page 53: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Programmable Pipeline

CPU GPU

User Program

GeometryProcessing

PixelProcessing

primitives2D screencoordinates

vertex shaderpixel shader

Supply shader programs to be executed on GPU as part of pipeline

Page 54: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

[Shirley and Marschner]

Phong reflectance in vertex and pixel shaders using GLSL

Vertex Shader (Gouraud interpolation)

Pixel Shader (Phong interpolation)

Page 55: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Dawn, NVIDIARusty car shader, NVIDIA

Call of Juarez DX10 Benchmark, ATI

Page 56: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Computing Normal Vectors

Page 57: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Plane Normals

Page 58: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Implicit function normals

sphere

plane

Page 59: Lighting and Shading - UCR Computer Science and Engineering · Lighting and Shading Slides: Tamar Shinar, Victor Zordon. 2 Why we need shading •Suppose we build a model of a sphere

Parametric form

tangent vectors

normal