presentation source

Download Report

Transcript presentation source

CS 551 / 645:
Introductory Computer Graphics
Color Continued
Clipping in 3D
David Luebke
4/9/2016
Administrivia



Hand back assignment 1 (finally…)
Hand out assignment 3
Graphics Lunch (Glunch)…Fridays at noon,
typically in Olsson 236D (this week in 228E)
– Announcements on uva.cs.graphics or at
http://www.cs.virginia.edu/glunch
– This week:


David Luebke
Antialiasing on LCD screens
Graphical interface stuff in Windows2000
4/9/2016
Recap: Basics of Color

Physics:
– Illumination

Electromagnetic spectra
– Reflection



Material properties (i.e., conductance)
Surface geometry and microgeometry (i.e., polished
versus matte versus brushed)
Perception
– Physiology and neurophysiology
– Perceptual psychology
David Luebke
4/9/2016
Recap: Physiology of Vision

The retina
– Rods
– Cones
David Luebke
4/9/2016
Recap: Cones

Three types of cones:
– L or R, most sensitive to red light (610 nm)
– M or G, most sensitive to blue light (560 nm)
– S or B, most sensitive to blue light (430 nm)
– Color blindness results from missing cone type(s)
David Luebke
4/9/2016
Recap: Metamers


A given perceptual sensation of color derives
from the stimulus of all three cone types
Identical perceptions of color can thus be
caused by very different spectra
David Luebke
4/9/2016
Recap: Perceptual Gotchas

Color perception is also difficult because:
– It varies from person to person (thus std observers)
– It is affected by adaptation (transparency demo)
– It is affected by surrounding color:
David Luebke
4/9/2016
Color Spaces


Three types of cones suggests color is a 3D
quantity. How to define 3D color space?
Idea: shine given wavelength () on a
screen, and mix three other wavelengths
(R,G,B) on same screen. Have user adjust
intensity of RGB until colors are identical:


David Luebke
How closely does this
correspond to a color CRT?
Problem: sometimes need
to “subtract” R to match 
4/9/2016
CIE Color Space

The CIE (Commission Internationale
d’Eclairage) came up with three hypothetical
lights X, Y, and Z with these spectra:

Note that:
X~R+B
Y ~ G + everything
Z~B

Idea: any wavelength  can be matched
perceptually by positive combinations of X,Y,Z
David Luebke
4/9/2016
CIE Color Space

The gamut of all colors perceivable is thus a
three-dimensional shape in X,Y,Z:

For simplicity, we
often project to the
2D plane X+Y+Z=1
X = X / (X+Y+Z)
Y = Y / (X+Y+Z)
Z=1-X-Y
David Luebke
4/9/2016
CIE Chromaticity Diagram (1931)
David Luebke
4/9/2016
Device Color Gamuts


Since X, Y, and Z are hypothetical light
sources, no real device can produce the
entire gamut of perceivable color
Example: CRT monitor
David Luebke
4/9/2016
Device Color Gamuts

The RGB color cube sits within CIE color
space something like this:
David Luebke
4/9/2016
Device Color Gamuts


We can use the CIE chromaticity diagram to
compare the gamuts of various devices:
Note, for example,
that a color printer
cannot reproduce
all shades available
on a color monitor
David Luebke
4/9/2016
Converting Color Spaces

Simple matrix operation:
 R'  XR
G '   YR
  
 B'  ZR

XG
YG
ZG
XB   R 
YB  G 
ZB   B 
The transformation C2 = M-12 M1 C1 yields
RGB on monitor 2 that is equivalent to a
given RGB on monitor 1
David Luebke
4/9/2016
Converting Color Spaces

Converting between color models can also
be expressed as such a matrix transform:
0.11   R 
Y  0.30 0.59
 I   0.60  0.28  0.32 G 
  
 
Q  0.21  0.52 0.31   B 

YIQ is the color model used for color TV in
America. Y is luminance, I & Q are color
– Note: Y is the same as CIE’s Y
– Result: backwards compatibility with B/W TV!
David Luebke
4/9/2016
Gamma Correction


We generally assume colors are linear
But most display devices are inherently
nonlinear
– I.e., brightness(voltage) != 2*brightness(voltage/2)

Common solution: gamma correction
– Post-transformation on RGB values to map them
to linear range on display device:
1

– Can have separate  for R, G, B
yx
David Luebke
4/9/2016
Next Topic: 3-D Clipping
David Luebke
4/9/2016
3-D Clipping

Before actually drawing on the screen, we
have to clip (Why?)
– Safety: avoid writing pixels that aren’t there
– Efficiency: save computation cost of rasterizing
primitives outside the field of view

Can we transform to screen coordinates first,
then clip in 2-D?
– Correctness: shouldn’t draw objects behind viewer
(what will an object with negative z coordinates do
in our perspective matrix?) (draw it…)
David Luebke
4/9/2016
Perspective Projection

Recall the matrix:
 x  1
 y  0


 z  0

 
 z d  0

0
1
0
0
0
1
0 1d
0  x 



0  y 
0  z 
 
0  1 
Or, in 3-D coordinates:
 x

,
z d
David Luebke

y
, d 
zd

4/9/2016
Clipping Under Perspective


Problem: after multiplying by a perspective
matrix and performing the homogeneous
divide, a point at (-8, -2, -10) looks the same
as a point at (8, 2, 10).
Solution A: clip before multiplying the point
by the projection matrix
– I.e., clip in camera coordinates

Solution B: clip before the homogeneous
divide
– I.e., clip in homogeneous coordinates
David Luebke
4/9/2016
Clipping Under Perspective

We will talk first about solution A:
Clipped
world
coordinates
Clip against
view volume
3-D world
coordinate
primitives
David Luebke
Canonical
screen
coordinates
Apply projection
matrix and
homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
4/9/2016
Recap: Perspective Projection

The typical view volume is a frustum or
truncated pyramid
x or–y In viewing coordinates:
z
David Luebke
4/9/2016
Perspective Projection


The viewing frustum consists of six planes
The Sutherland-Cohen algorithm (clipping
polygons to a region one plane at a time)
generalizes to 3-D
– Clip polygons against six planes of view frustum
– So what’s the problem?
David Luebke
4/9/2016
Perspective Projection


The viewing frustum consists of six planes
The Sutherland-Cohen algorithm (clipping
polygons to a region one plane at a time)
generalizes to 3-D
– Clip polygons against six planes of view frustum
– So what’s the problem?

The problem: clipping a line segment to an
arbitrary plane is relatively expensive
– Dot products and such
David Luebke
4/9/2016
Perspective Projection

In fact, for simplicity we prefer to use the
canonical view frustum:
x or y
1
Front or
hither plane
Back or yon plane
-1
z
Why is this going to be
simpler?
-1
David Luebke
4/9/2016
Perspective Projection

In fact, for simplicity we prefer to use the
canonical view frustum:
x or y
1
Front or
hither plane
Back or yon plane
-1
z
Why is the yon plane
at z = -1, not z = 1?
-1
David Luebke
4/9/2016
Clipping Under Perspective

So we have to refine our pipeline model:
Apply
normalizing
transformation
3-D world
coordinate
primitives
Clip against
canonical
view
volume
projection
matrix;
homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
– Note that this model forces us to separate
projection from modeling & viewing transforms
David Luebke
4/9/2016
Clipping Homogeneous Coords

Another option is to clip the homogeneous
coordinates directly.
– This allows us to clip after perspective projection:
– What are the advantages?
Apply
projection
matrix
3-D world
coordinate
primitives
David Luebke
Clip
against
view
volume
Homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
4/9/2016
Clipping Homogeneous Coords

Other advantages:
– Can transform the canonical view volume for
perspective projections to the canonical view
volume for parallel projections


Clip in the latter (only works in homogeneous coords)
Allows an optimized (hardware) implementation
– Some primitives will have w  1


David Luebke
For example, polygons that result from tesselating splines
Without clipping in homogeneous coords, must perform
divide twice on such primitives
4/9/2016
Clipping: The Real World

In the Real World, a common shortcut is:
Clip against
hither and
yon planes
David Luebke
Projection
matrix;
homogeneous
divide
Transform into
screen
coordinates
Clip in 2-D
screen
coordinates
4/9/2016