Download presentation source

Download Report

Transcript Download presentation source

CS 551 / 645:
Introductory Computer Graphics
David Luebke
[email protected]
http://www.cs.virginia.edu/~cs551
David Luebke
7/27/2016
Administrivia


Assignment 4 results on web page
Re-assign new and improved Assignment 6
David Luebke
7/27/2016
Assignment 6 Specifics

The main new challenges will be:
– Clipping in 3-D


Lots of places you can do it (see lecture 18)
How can you get maximum re-use of Assignment 4?
– Perspective projection


David Luebke
Lots of ways you can do it; depends a bit on what
clipping strategy you follow
I’ll describe one way to do it today
7/27/2016
Assignment 6: Perspective
For each vertex in a triangle:
1) world coordinates to viewing coordinates
what matrix does this transform?
2) viewing coords to canonical perspective coords
what does this matrix look like?
3) convert to canonical orthographic coords
matrix from lecture 21
4) divide by w and drop z
5) scale & translate to get pixel coordinates
6) draw lines connecting vertices into framebuffer
Where do we clip? In 2-D or 3-D?
David Luebke
7/27/2016
Assignment 6: Perspective
One possibility (possibly simplest):
1) world coordinates to viewing coordinates
Clip here in 3-D
2) viewing coords to canonical perspective coords
3) convert to canonical orthographic coords
4) divide by w and drop z
5) scale & translate to get pixel coordinates
6) draw lines connecting vertices into framebuffer
David Luebke
7/27/2016
Assignment 6: Perspective
Another possibility (possibly fastest):
1) world coordinates to viewing coordinates
2) viewing coords to canonical perspective coords
3) convert to canonical orthographic coords
Clip here in homogeneous coordinates
4) divide by w and drop z
5) scale & translate to get pixel coordinates
6) draw lines connecting vertices into framebuffer
David Luebke
7/27/2016
Assignment 6: Perspective
Yet another possibility (possibly simplest):
1) world coordinates to viewing coordinates
2) viewing coords to canonical perspective coords
Clip here in 3-D against near & far planes
3) convert to canonical orthographic coords
4) divide by w and drop z
5) scale & translate to get pixel coordinates
Clip here in 2-D against viewport (assn 4!)
6) draw lines connecting vertices into framebuffer
David Luebke
7/27/2016
Lighting



Given a 3-D triangle and a 3-D viewpoint, we
can now figure out which pixels to light on the
screen to represent that triangle
But what color should those pixels be?
If we’re attempting to create a realistic image,
we need to simulate the b of the surfaces in
the scene
– Fundamentally simulation of physics and optics
– As you’ll see, we use a lot of approximations
(a.k.a hacks) to do this simulation fast enough
David Luebke
7/27/2016
Recap: Definitions

Illumination: the transport of energy (in
particular, the luminous flux of visible light)
from light sources to surfaces & points
– Note: includes direct and indirect illumination


Lighting: the process of computing the
luminous intensity (i.e., outgoing light) at a
particular 3-D point, usually on a surface
Shading: the process of assigning colors to
pixels
David Luebke
7/27/2016
Recap: Definitions

Illumination models fall into two categories:
– Empirical: simple formulations that approximate
observed phenomenon

The usual for interactive graphics
– Physically-based: models based on the actual
physics of light interacting with matter

David Luebke
Increasingly, the usual for realistic graphics (Bunny…)
7/27/2016
Recap: Light Sources





Ambient light source: illuminates all surface
points equally
Directional light source: all rays from the light
source are parallel (i.e., light source at )
Point light source: emits light rays in all
directions from a single point
Spotlight: Point light source with (possibly
drastic) directional attenuation
Area light source: emissive disc or polygon
David Luebke
7/27/2016
Recap: Ambient Light Source

A scene lit only with an ambient light source:
David Luebke
7/27/2016
Directional Light Sources

The same scene lit with a directional and an
ambient light source (animated gif)
David Luebke
7/27/2016
Point Light Sources

Using an ambient and a point light source:
David Luebke
7/27/2016
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
David Luebke
7/27/2016
Recap: Lambert’s Law
David Luebke
7/27/2016
Recap:
Computing Diffuse Reflection

The angle between the surface normal and
the incoming light is the angle of incidence:
l
n


Idiffuse = kd Ilight cos 
In practice we use vector arithmetic:
Idiffuse = kd Ilight (n • l)
David Luebke
7/27/2016
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
David Luebke
7/27/2016
The Physics of Reflection



At the microscopic level a specular reflecting
surface is very smooth
Thus rays of light are likely to bounce off the
microgeometry in a mirror-like fashion
The smoother the surface, the closer it
becomes to a perfect mirror
– Polishing metal example (draw it)
David Luebke
7/27/2016
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
David Luebke
7/27/2016
Non-Ideal Specular Reflectance




Snell’s law applies to perfect mirror-like
surfaces, but aside from mirrors (and chrome)
few surfaces exhibit perfect specularity
How can we capture the “softer” reflections of
surface that are glossy rather than mirror-like?
One option: model the microgeometry of the
surface and explicitly bounce rays off of it
Or…
David Luebke
7/27/2016
Non-Ideal Specular Reflectance:
An Empirical Approximation



In general, we expect most reflected light to
travel in direction predicted by Snell’s Law
But because of microscopic surface
variations, some light may be reflected in a
direction slightly off the ideal reflected ray
As the angle from the ideal reflected ray
increases, we expect less light to be reflected
David Luebke
7/27/2016
Non-Ideal Specular Reflectance:
An Empirical Approximation

An illustration of this angular falloff:

How might we model this falloff?
David Luebke
7/27/2016
Phong Lighting

The most common lighting model in
computer graphics was suggested by Phong:
Ispecular  ksIlightcos 
nshiny


The nshiny term is a purely
empirical constant that
varies the rate of falloff
Though this model has no
physical basis, it works
(sort of) in practice
David Luebke
7/27/2016
Phong Lighting: The nshiny Term

This diagram shows how the Phong
reflectance term drops off with divergence of
the viewing angle from the ideal reflected ray:

What does this term control, visually?
David Luebke
7/27/2016
Calculating Phong Lighting

The cos term of Phong lighting can be
computed using vector arithmetic:

Ispecular  ksIlight Vˆ  Rˆ

nshiny
– 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


Rˆ  2 Nˆ  Lˆ Nˆ  Lˆ
David Luebke
7/27/2016
Calculating The R Vector


Rˆ  2 Nˆ  Lˆ Nˆ  Lˆ

This is illustrated below:


Rˆ  Lˆ  2 Nˆ  Lˆ Nˆ
David Luebke
7/27/2016
Blinn & Torrance Variation

Blinn introduced a variation of the Phong
model:
nshiny

Ispecular  ksIlight Nˆ  Hˆ


Here H is a vector bisecting the incoming
light direction and viewing direction:
ˆ  Vˆ
L
Hˆ 
Lˆ  Vˆ
David Luebke
7/27/2016
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?
ˆ  Vˆ
L
Hˆ 
Lˆ  Vˆ
David Luebke
7/27/2016
Phong Examples

These spheres illustrate the Phong model as
L and nshiny are varied:
David Luebke
7/27/2016
The Phong Lighting Model

Our final empirically-motivated model for the
illumination at a surface includes ambient,
difuse, and specular components:
I total  ka I ambient 

#lights

i 1

 
I i  kd Nˆ  Lˆ  k s Vˆ  Rˆ


nshiny


Commonly called Phong lighting
– Note: once per light
– Note: once per color component
– Do ka, kd, and ks vary with color component?
David Luebke
7/27/2016
Phong Lighting: Intensity Plots
David Luebke
7/27/2016
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
David Luebke
7/27/2016
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
David Luebke
7/27/2016
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
David Luebke
7/27/2016
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 surfaces
we introduce vertex normals at each
vertex
– 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)
David Luebke
7/27/2016
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
David Luebke
7/27/2016
Gouraud Shading

This is the most common approach
– Perform Phong lighting at the vertices
– Linearly interpolate the resulting colors over faces
– This is what OpenGL does

Demo at
http://www.cs.virginia.edu/~cs551/vrml/tpot.wrl

Does this eliminate the facets?
David Luebke
7/27/2016
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



David Luebke
Same input as Gouraud shading
Usually very smooth-looking results:
But, considerably more expensive
7/27/2016
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:
David Luebke
7/27/2016
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
David Luebke
7/27/2016