cs 551 / 645: introductory computer graphics

25
David Luebke 06/27/22 CS 551 / 645: Introductory Computer Graphics David Luebke [email protected] http://www.cs.virginia.edu/~cs551

Upload: brooke-simon

Post on 02-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

CS 551 / 645: Introductory Computer Graphics. David Luebke [email protected] http://www.cs.virginia.edu/~cs551. Administrivia. Assignment 6: line.c, gfx.c, lookat() description. Recap: Lambert’s Cosine Law. Ideal diffuse surfaces reflect according to Lambert’s cosine law : - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

CS 551 / 645: Introductory Computer Graphics

David Luebke

[email protected]

http://www.cs.virginia.edu/~cs551

Page 2: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Administrivia

Assignment 6: line.c, gfx.c, lookat() description

Page 3: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Lambert’s Cosine Law

Ideal diffuse surfaces reflect according to Lambert’s cosine law:

The energy reflected by a small portion of a surface from a light source in a given direction is proportional to the cosine of the angle between that direction and the surface normal

These are often called Lambertian surfaces Note that the reflected intensity is:

– Independent of the viewing direction– Dependent on the surface orientation with regard

to the light source

Page 4: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Lambert’s Law

Page 5: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Computing Diffuse Reflection The angle between the surface normal and the

incoming light is the angle of incidence:

Idiffuse = kd Ilight cos In practice we use vector arithmetic:

Idiffuse = kd Ilight (n • l)

nl

Page 6: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Specular Reflection

Shiny surfaces exhibit specular reflection– Polished metal– Glossy car finish

A light shining on a specular surface causes a bright spot known as a specular highlight

Where these highlights appear is a function of the viewer’s position, so specular reflectance is view-dependent

Page 7: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: The Optics of Reflection

Reflection follows Snell’s Laws:– The incoming ray and reflected ray lie in a plane

with the surface normal– The angle that the reflected ray forms with the

surface normal equals the angle formed by the incoming ray and the surface normal:

l = r

Page 8: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Non-Ideal Specular Reflectance An illustration of this angular falloff:

How might we model this falloff?

Page 9: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Recap: Phong Lighting

The most common lighting model in computer graphics was suggested by Phong:

shinynlightsspecular IkI cos

The nshiny term is a purelyempirical constant that varies the rate of falloff

Though this model has no physical basis, it works (sort of) in practice

Page 10: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Calculating Phong Lighting

The cos term of Phong lighting can be computed using vector arithmetic:

– V is the unit vector towards the viewer Common simplification: V is constant (implying what?)

– R is the ideal reflectance direction

An aside: we can efficiently calculate R

shinynlightsspecular RVIkI ˆˆ

LNLNR ˆˆˆˆ2ˆ

Page 11: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Calculating The R Vector

This is illustrated below:

LNLNR ˆˆˆˆ2ˆ

NLNLR ˆˆˆ2ˆˆ

Page 12: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Blinn & Torrance Variation

Blinn introduced a variation of the Phong model:

Here H is a vector bisecting the incoming light direction and viewing direction:

shinynlightsspecular HNIkI ˆˆ

VL

VLH

ˆˆ

ˆˆˆ

Page 13: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Blinn & Torrance Variation

What does H represent? (Hint: think of H as the normal of a plane)

A: the orientation of a plane which will maximally reflect light from L towards V

Why bother with this variation?

VL

VLH

ˆˆ

ˆˆˆ

Page 14: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Phong Examples

These spheres illustrate the Phong model as L and nshiny are varied:

Page 15: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

The Phong Lighting Model

Our final empirically-motivated model for the illumination at a surface includes ambient, difuse, and specular components:

Commonly called Phong lighting– Note: once per light– Note: once per color component

– Do ka, kd, and ks vary with color component?

lights

i

n

sdiambientatotal

shiny

RVkLNkIIkI#

1

ˆˆˆˆ

Page 16: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Phong Lighting: Intensity Plots

Page 17: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Applying Illumination

We now have an illumination model for a point on a surface

Assuming that our surface is defined as a mesh of polygonal facets, which points should we use?

Keep in mind:– It’s a fairly expensive calculation– Several possible answers, each with different

implications for the visual quality of the result

Page 18: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Applying Illumination

With polygonal/triangular models:– Each facet has a constant surface normal– If the light is directional, the diffuse reflectance is

constant across the facet– If the eyepoint is infinitely far away (constant V),

the specular reflectance of a directional light is constant across the facet

Page 19: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Flat Shading

The simplest approach, flat shading, calculates illumination at a single point for each polygon:

If an object really is faceted, is this accurate? No:

– For point sources, the direction to light varies across the facet– For specular reflectance, direction to eye varies across the

facet

Page 20: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Flat Shading

We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted:

To get smoother-looking surfaceswe introduce vertex normals at eachvertex– Usually different from facet normal– Used only for shading (as opposed to what?)– Think of as a better approximation of the real

surface that the polygons approximate (draw it)

Page 21: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Vertex Normals

Vertex normals may be – Provided with the model– Computed from first principles – Approximated by averaging the normals of the

facets that share the vertex

Page 23: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Phong Shading

Phong shading is not the same as Phong lighting, though they are sometimes mixed up– Phong lighting: the empirical model we’ve been

discussing to calculate illumination at a point on a surface

– Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel

Same input as Gouraud shading Usually very smooth-looking results: But, considerably more expensive

Page 24: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

An Aside: Transforming Normals

Irritatingly, the matrix for transforming a normal vector is not the same as the matrix for the corresponding transformation on points– In other words, don’t just treat normals as points:

Page 25: CS 551 / 645:  Introductory Computer Graphics

David Luebke 04/20/23

Transforming Normals

Some not-too-complicated affine analysis shows :– If A is a matrix for transforming points,

then (AT)-1 is the matrix for transforming normals When is this the same matrix? What is homogeneous representation of a

vector (as opposed to a point?) Can use this to simplify the problem: only

upper 3x3 matrix matters, so use only it More detail in F&vD Appendix A.5