Computer Graphics (fall 2009)

43
Computer Graphics (fall 2009) School of Computer Science University of Seoul

description

Computer Graphics (fall 2009). School of Computer Science University of Seoul. Chap 6: Shading. Light and Matter Light Sources The Phong Reflection Model Computation of Vectors Polygonal Shading Approximation of a Sphere by Recursive Subdivision Light Sources in OpenGL - PowerPoint PPT Presentation

Transcript of Computer Graphics (fall 2009)

Page 1: Computer Graphics (fall 2009)

Computer Graphics(fall 2009)

School of Computer ScienceUniversity of Seoul

Page 2: Computer Graphics (fall 2009)

Chap 6: Shading

1. Light and Matter2. Light Sources3. The Phong Reflection Model4. Computation of Vectors5. Polygonal Shading6. Approximation of a Sphere by Recursive Subdivision7. Light Sources in OpenGL8. Specification of Materials in OpenGL9. Shading of the Sphere Model10. Global Illumination

Page 3: Computer Graphics (fall 2009)

6.1 Light and Matter

Page 4: Computer Graphics (fall 2009)

Rendering Methods

Rendering equation [Kaj86] Integral eq. resulted by recursive scattering Physics-based, slow to compute

Radiosity, raytracing (Ch.12) and photon mapping Approximation of rendering equation for particular

surfaces Still slow

Phong reflection model Fast!

Page 5: Computer Graphics (fall 2009)

Rendering Equation

Proposed in “The rendering equation” (by James Kajiya, 1986)

Based on “conservation of energy”

Page 6: Computer Graphics (fall 2009)

Radiosity

FEM (Finite Element Method) applied to solve the rendering equation

For scenes with diffuse surfaces

Page 7: Computer Graphics (fall 2009)

Radiosity (cont’d)

Supported by 3D Max, EIAS, etc.

(image courtesy of JCM animation, EIAS)

(image courtesy of David Stoddard, EIAS)

Page 8: Computer Graphics (fall 2009)

Raytracing

Rendering by tracing rays for each pixel from the viewer (camera)

Suitable for reflective surfaces

(image courtesy of Wikipedia)

Page 9: Computer Graphics (fall 2009)

Raytracing (cont’d)

Supported by POV-Ray, YafaRay, etc.

(“Glasses” by Gilles Tran, POV-Ray) (“Nikon” by Bert Buchholz, YafaRay)

Page 10: Computer Graphics (fall 2009)

Photon Mapping

Rays from the light source & camera are traced independently

Image courtesy of Wikipedia)

Page 11: Computer Graphics (fall 2009)

Light-Surface Interaction

Reflected, absorbed and transmitted Depends on

opaqueness wavelength- “Why does an object look red?” roughness - “Why does an object look shiny?” Orientation etc.

Page 12: Computer Graphics (fall 2009)

Surface Types

Specular surfaces Diffuse surfaces Translucent surfaces

Page 13: Computer Graphics (fall 2009)

6.2 Light Sources

Page 14: Computer Graphics (fall 2009)

General Light Source Model

Can be modeled by an illumination function I(x,y,z,,,)

Each frequency consideredindependently

Total contribution can becomputed by integration

Directional properties canvary with frequency

Too complicated to compute

Page 15: Computer Graphics (fall 2009)

Simplified Light Sources

Four types: ambient lighting, point sources, spotlights, and distant lights

Light sources with three components, RGB- based on “three-color theory”

Each component calculated independently Intensity or luminance:

b

g

r

III

I

Page 16: Computer Graphics (fall 2009)

Type #1: Ambient Light

Models uniform illumination Simplified as an intensity that is identical at

every point in the scene:

ab

ag

ar

a

III

I

Page 17: Computer Graphics (fall 2009)

Type #2: Point Sources

Located at p0:

Intensity received at p: High contrast than surface light Can be made soft by

the distance term:

0

0

0

0

ppp

pI

b

g

r

III

00

0 pIpp

ppi 2

1,

12 cdbda

Page 18: Computer Graphics (fall 2009)

Type #3: Spotlights

Cone-shaped directional range Distribution of the light within the cone

usually defined by ecos

Page 19: Computer Graphics (fall 2009)

Type #4: Distant Light Sources

Rays can be assumed parallel Direction instead of location:

1zyx

0p

0zyx

0p

Page 20: Computer Graphics (fall 2009)

6.3 The Phong Reflection Model

Page 21: Computer Graphics (fall 2009)

Phong Reflection Model

Introduced by Phong Four vectors used Three types of material-light interactions –

ambient, diffuse, and specular Local model

(image courtesy of Wikipedia)

Page 22: Computer Graphics (fall 2009)

Phong Reflection Model (cont’d)

i-the light source:

Reflection terms for a material:

Contribution of each light color (e.g., red):

Contribution of all sources (e.g., red):

ibsigbirs

ibdigdird

ibaigaira

LLLLLLLLL

is

id

ia

i

LLL

L

ibsigbirs

ibdigdird

ibaigaira

RRRRRRRRR

is

id

ia

i

RRR

R

irsirdirairsirsirdirdirairair IIILRLRLRI

i

arirsirdirar IIIII

Page 23: Computer Graphics (fall 2009)

#1: Ambient Reflection

Intensity same at every point on the surface Depends on

Material property Independent of

Location of the light source Location of the viewer

aaa LkI

Page 24: Computer Graphics (fall 2009)

#2: Diffuse Reflection

Characterized by rough surfaces Assumed to be “perfectly diffuse” Depends on

Material property Location of the light source

Independent of Location of the viewer

Page 25: Computer Graphics (fall 2009)

#2: Diffuse Reflection (cont’d)

Lambert’s law (for perfectly diffuse surface): cosdR

0,max2 nl

dd

d Lcdbda

kI

Page 26: Computer Graphics (fall 2009)

#3: Specular Reflection

Characterized by smooth surfaces Depends on

Material property Location of the light source Location of the viewer

“shininess coefficient” ()

0,max2vr

s

ss L

cdbdakI

Page 27: Computer Graphics (fall 2009)

Phong Reflection Model

aassddsda LkLkLkcdbda

IIII

0,max0,max12

vrnl

Page 28: Computer Graphics (fall 2009)

Modified Phong Reflection Model

Modified by Blinn a.k.a. “Blinn-Phong Shading Model”

Simplified by halfway angle (h) for faster calcu-lation rv replaced by n h

Faster calculation when the lightand the viewer are at infinity (WHY?) GL_LIGHT_MODEL_LOCAL_VIEWER

Default model in OpenGL

vlvlh

Page 29: Computer Graphics (fall 2009)

6.4 Computation of Vectors

Page 30: Computer Graphics (fall 2009)

Computation of Vectors

How to compute the normal vector of a triangle? a (smooth) surface?

How to compute reflection vector? lnnlr 2

Page 31: Computer Graphics (fall 2009)

6.5 Polygonal Shading

Page 32: Computer Graphics (fall 2009)

Flat & Gouraud Shading

Flat shading The normal of the first vertex used

Gouraud shading Lighting calculation at vertices Linearly interpolated at each fragment Artifacts for coarse polygon

Page 33: Computer Graphics (fall 2009)

Phong Shading

Lighting computation at each fragment Not directly supported by OpenGL Can be implemented using GLSL (OpenGL

Shading Language)

Page 34: Computer Graphics (fall 2009)

6.6 Approximation of a Sphere by Recursive Subdivision

Page 35: Computer Graphics (fall 2009)

6.7 Light Sources in OpenGL

Page 36: Computer Graphics (fall 2009)

Setting Lights

Enable/disable: glEnable(GL_LIGHTING); glEnable(GL_LIGHT#);

At least 8 lights

Positional or directional light: glLight*(GL_LIGHT#, GL_POSITION, position);

Ambient, diffuse, specular components: glLight*(GL_LIGHT#, GL_*, value);

GL_AMBIENTGL_DIFFUSEGL_SPECULAR

Page 37: Computer Graphics (fall 2009)

Setting Lights (cont’d)

Global ambient: glLightModel*(GL_LIGHT_MODEL_AMBIENT, value);

Distance-attenuation model: glLight*(GL_LIGHT#, GL_*, value);

GL_CONSTANT_ATTENUATION (a) GL_LINEAR_ATTENUATION (b) GL_QUADRATIC_ATTENUATION (c)

Spotlight: glLight*(GL_LIGHT#, GL_*, value);

GL_SPOT_DIRECTION GL_SPOT_EXPONENT GL_SPOT_CUTOFF ([0,90] or 180)

2

1cdbda

Page 38: Computer Graphics (fall 2009)

Setting Lights (cont’d)

Infinite/local viewer: glLightModel*(GL_LIGHT_MODEL_LOCAL_VIEW

ER, value); One/two-sided lighting:

glLightModel*(GL_LIGHT_MODEL_TWO_SIDED, value);

Light sources are transformed by mod-elview matrices!

Page 39: Computer Graphics (fall 2009)

6.8 Specification of Materials in OpenGL

Page 40: Computer Graphics (fall 2009)

Setting Materials Material properties are OpenGL states! Ambient, diffuse, specular, emissive:

glMaterial*v(face, GL_*, value); GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,

GL_DIFFUSE_AND_SPECULAR Emissive property

Does not affect any other surface (it’s not a light!) Simply adds color

Shininess: glMaterial*(face, GL_SHININESS, value);

Front/back/front&back: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

glColorMaterial Various materials: refer to teapots.c!

Page 41: Computer Graphics (fall 2009)

Nate Robin’s Tutor

Try yourself!!!

Page 42: Computer Graphics (fall 2009)

6.9 Shading of the Sphere Model

Page 43: Computer Graphics (fall 2009)

6.10 Global Illumination