CS 376 Introduction to Computer Graphics 04 / 30 / 2007 Last Lecture :( Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
-
Upload
morris-rodgers -
Category
Documents
-
view
215 -
download
0
Transcript of CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 376Introduction to Computer Graphics
02 / 23 / 2007
Instructor: Michael Eckmann
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Today’s Topics• Questions?
• Comments on altering Bresenham's line algorithm to add antialiasing
capability
• View volumes
• Specifying an arbitrary perspective view
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• This picture only tells part of the story
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• The picture only tells part of the story
• It's clear from the picture that• dlower = Ydesired – Yk• dupper = 1 - dlower
• Even though we're dealing with slopes of less than 1 and > 0,
there are other cases that that picture doesn't display.
• case 1) when dlower < 0
• case 2) when dupper < 0
• case 3) shown on last slide when dlower and dupper both > 0
• case 4) when line goes right through center of a pixel
• Picture on the board.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• Furthermore there's the issue of which two pixels to turn on
• y is the y-coordinate that Bresenham calculates for this step
• The two to turn on is dependent on which case we're in
• case 1) when dlower < 0• the two pixels y coordinates are
• y & y – 1
• case 2) when dupper < 0• the two pixels y coordinates are
• y & y + 1
• case 3) shown on last slide when dlower and dupper both > 0• if Bresenham would've kept y the same then the two pixels y
coordinates are• y & y + 1
• else• y & y – 1
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• case 4) when actual line goes right through the center of a pixel
• that happens when the values of dupper and dlower are 0 and 1 (or really close when dealing with floating points)
• so you can test it by taking the absolute value of the difference between the two and test if this is really close to 1
• Anyway, when this happens we only want to turn on one pixel (the one with the y coordinate that Bresenham calculated) at full intensity
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• The 3rd case depends on which pixel Bresenham (would have) turned
on so you can determine whether to turn on y and y+1 or y and y-1.
• If you try to figure this out after Bresenham actually updates y and p,
then you might want to save the value of p from the previous step so
you can check it to determine if you want to turn on • y and y+1 OR• y and y-1
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• Also, you probably need to keep track of several values that
Bresenham's algorithm doesn't.• e.g.
– slope and yIntercept (how to calculate?) so you have the mathematical equation of the line
– now that you have the mathematical equation of the line, you can compute yDesired (the floating point value of the y-coord of the mathematical line)
– from yDesired and the centers of the two pixels you can compute dUpper and dLower
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Antialiasing Bresenham• As for the intensities of the two pixels– case 1) when dlower < 0
• example: dlower = -.2 and dupper = 1.2• make intens1 = 1+ dlower (e.g. 0.8)• make intens2 = 1 – intens1 (e.g. 0.2)
• case 2) when dupper < 0• example: dlower = 1.1 and dupper = -0.1• make intens1 = 1+ dupper (e.g. 0.9)• make intens2 = 1 – intens1 (e.g. 0.1)
• case 3)• example: dlower = 0.4 and dupper = 0.6 OR• example: dlower = 0.7 and dupper = 0.3• make intens1 = dupper (e.g. 0.6)• make intens2 = 1 – intens1 (e.g. 0.4)
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
other Antialiasing methods• Does anyone recall any of the other antialiasing methods I
discussed for lines?
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
View Volumes• Assuming a rectangular viewport and given the CoP (aka Projection
Reference Point PRP) we have an infinite view volume.• Drawing on board.• So, the view volume contains the portion of the world that may be
displayed in the viewport --- what is not in the volume is clipped out.• To limit the processing (and limit what will be displayed), we typically
reduce the view volume to a finite volume.• We define 2 planes – Front and Back clipping planes (aka hither and
yon).• Now the finite view volume is the volume contained within the pyramid
between the two clipping planes.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
View Volumes• Given a view volume and a projection (e.g. a perspective or parallel
projection matrix), objects can be clipped to the view volume by solving simultaneous equations for intersections with the projectors with the view plane.
• This is computation intensive. A more efficient way is clip against a volume that is easier to clip against. For perspective projections this volume (called the canonical view volume for perspective) is defined by the planes:
x = z, x = -z, y = z, y = -z, z = -zmin
, z = -1
• For parallel projection's the canonical view volume is
x = 1, x = -1, y = 1, y = -1, z = 0, z = -1
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Specifying an arbitrary view• To specify an arbitrary view, we should be able to place the view plane
anywhere in 3d. – we'll need to specify the direction of the plane and where it lives within the
world reference coordinate system (WRC)– we'll also need to know which direction is up (to know what is displayed at
the top of the image when we transform to viewport.
• A common way to specify an arbitrary view is to specify the following:a View Reference Point (VRP) which is a point on the planea View Plane Normal (VPN) which is the normal vector to the planea View Up Vector (VUP) which is a vector from which we determine which
way is up
• See diagram. Is that enough info to specify an arbitrary view in your opinion?
• One note, the VUP vector is allowed to be specified as not perpendicular to
VPN. The up direction (determined by a relation of the directions of VPN and
VUP) though is perpendicular to VPN.
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Specifying an arbitrary view• The VRP, VPN and VUP create another reference coordinate system.
We call this the view reference coordinate system (VRC). We name the principle axes u, v and n.
• Within VRC we – specify a window on the view plane with Center of Window (CW)
and min and max u and v values– a Projection Reference Point (PRP) which is the CoP for perspective
views– Front and Back clipping planes specified as distances F and B, from
VRP along the VPN– see next diagram.
• In the World Reference Coordinate (WRC) system we– define VRP, VPN and VUP
• In the View Reference Coordinate (VRC) system we– define CW, PRP, F and B
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
View Volumes• To be able to clip against the canonical view volume and still allow any
desired arbitrary view volume we'll need to normalize the desired view volume to the canonical view volume.
• So, the procedure to project from 3d to 2d given a finite view volume, will be as follows:
– apply a normalizing transform to get to the canonical view volume– clip against the canonical view volume– project onto the view plane– transform into viewport
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Normalizing to CVV• Now we're ready to develop the normalizing transformation for
perspective projections.• This will transform world coordinate positions so that the view volume is
transformed into the canonical view volume.• After this transform is applied, we would clip against the CVV and then
project onto the view plane (via a perspective projection matrix).
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Normalizing to CVV• The steps to do this are as follows:
– Given the following: VRP, VPN, VUP, PRP, u and v min and max, F and B
1. Translate VRP (view reference point) to origin2. Rotate the VRC (view reference coordinate system) so that
VPN (n-axis) lies on the z-axis, the u-axis lies on the x-axis and the v-axis lies on the y-axis
3. Translate PRP (the Projection Reference Point which is CoP) to the origin
4. Shear so the center line of the view volume lies on the z-axis5. Scale so that the view volume becomes the canonical view volume
Take a look at the pictures
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Translate VRP to origin1. T(-VRP) =
[ 1 0 0 -VRPx ]
[ 0 1 0 -VRPy ]
[ 0 0 1 -VRPz ]
[ 0 0 0 1 ]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Rotate VRC2. Rotate the VRC in the following way:
we want u to go to (1, 0, 0)we want v to go to (0, 1, 0)we want n to go to (0, 0, 1)
make them have the correct directions and magnitude 1
n = VPN / | VPN |
u = (VUP x n) / | VUP x n |
v = n x u
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Rotate VRC2.
we want u to go to (1, 0, 0)we want v to go to (0, 1, 0)we want n to go to (0, 0, 1)
R =
[ ux u
y u
z 0 ]
[ vx v
y v
z 0 ]
[ nx n
y n
z 0 ]
[ 0 0 0 1 ]
example: This matrix transforms the v vector to (0, 1, 0)
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Rotate VRC2. To check, show this matrix transforms the v vector to (0, 1, 0)
[ ux u
y u
z 0 ] [ v
x ] [ u . v ] [ 0 ]
[ vx v
y v
z 0 ] [ v
y ] = [ v . v ] = [ 1 ]
[ nx n
y n
z 0 ] [ v
z ] [ n . v ] [ 0 ]
[ 0 0 0 1 ] [ 1 ] [ 1 ] [ 1 ]
dot product of perpendicular vectors is 0 (cos 90 = 0)and dot product of a vector with itself is its magnitude squared 1*1 = 1
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Translate PRP to origin3. T(-PRP) =
[ 1 0 0 -PRPu ]
[ 0 1 0 -PRPv ]
[ 0 0 1 -PRPn ]
[ 0 0 0 1 ]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Shear4. Now we want to shear so the center line is on z-axis. (To see why we don't
simply want to rotate look at the diagram on the handout to see the cross-
section of the view volume after the first 3 steps are performed.)
Notice the CW is on that line and so is the origin (which PRP got translated
to.)
So, to get that center line on the z-axis, we want the direction of the vector
CW – PRP to be in the (DoP) direction of projection [0,0,z].
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Shear4.
[ ( umin
+ umax
) /2 ] [ PRPu ]
CW = [ ( vmin
+ vmax
) /2 ] PRP = [ PRPv ]
[ 0 ] [ PRPn ]
[ ( umin
+ umax
) /2 – PRPu ]
CW – PRP = [ ( vmin
+ vmax
) /2 – PRPv ]
[ 0 – PRPn ]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Shear4. SH
per =
[ 1 0 SHx 0 ]
[ 0 1 SHy 0 ]
[ 0 0 1 0 ][ 0 0 0 1 ]
[ 1 0 SHx 0 ] [ ( u
min + u
max) /2 – PRP
u ] [ 0 ]
[ 0 1 SHy 0 ] [ ( v
min + v
max) /2 – PRP
v ] = [ 0 ]
[ 0 0 1 0 ] [ 0 – PRPn ] [ DoP
z ]
[ 0 0 0 1 ] [ 1 ] [ 1 ]
So, DoPz = – PRP
n
Solve for SHx and SH
y and get
SHx = ( ( u
min + u
max) /2 – PRP
u ) / PRP
n
SHy = ( ( v
min + v
max) /2 – PRP
v ) / PRP
n
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Scale5. A few notes about the diagram that shows the scaling
There is a mistake where y= (vmax
– vmin
)/2 and y= -(vmax
– vmin
)/2 are
pointing to the top of the back clipping plane. Instead they should be
pointing to the top of the viewing window which is the middle vertical line.
Second, the diagram shows a value vrp'z which is equal to -PRP
n
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Scale5. scaling done in 2 steps
first scale in x and y (to make the sloped planes be unit slopes)second scale uniformly (in x,y,z) so that back clipping plane is at z = -1,
and the unit slopes remain unit slopes
To scale in x and y we have a matrix of the form:[ s
x1 0 0 0 ]
[ 0 sy1
0 0 ][ 0 0 1 0 ][ 0 0 0 1 ]
From the diagram (a) y= -(vmax
– vmin
)/2 is the y value of the bottom of the window.
We want that bottom side of the view volume to lie on the y=z plane which is a unit slope, so we want y= -(v
max – v
min )/2 = z.
z for the viewing window is -PRPn . So, we need to figure out what scale
factor will make -(vmax
– vmin
)/2 equal to -PRPn .
sy1
= 2 PRPn / (v
max – v
min )
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Scale5. (see diagram)
This is similar in the x direction, but the viewing window range in x direction
is (umax
to umin
) so, to scale in x and y so that the 4 sloped planes are unit
slope, we set the scales to be:
sx1
= 2 PRPn / (u
max – u
min )
sy1
= 2 PRPn / (v
max – v
min )
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Scale5. (see diagram)
to then scale so that back clipping plane is at z = -1 (do the scaling uniformly
(in x y and z) so that the 4 sloped planes remain unit slope.) We have a
matrix of the form
[ sx2
0 0 0 ]
[ 0 sy2
0 0 ][ 0 0 s
z2 0 ]
[ 0 0 0 1 ]we want the z = -PRP
n + B plane to be the z = -1 plane . So, we need to
figure out what scale factor will make -PRPn + B be -1.
sx2
= -1 / (-PRPn + B)
sy2
= -1 / (-PRPn + B)
sz2
= -1 / (-PRPn + B)
where B is the distance to the back clipping plane from -PRPn
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Scale5. final scale matrix S
per =
[ sx2
0 0 0 ] [ sx1
0 0 0 ]
[ 0 sy2
0 0 ] [ 0 sy1
0 0 ][ 0 0 s
z2 0 ] [ 0 0 1 0 ]
[ 0 0 0 1 ] [ 0 0 0 1 ]
Michael Eckmann - Skidmore College - CS 376 - Spring 2007
Perspective NormalizationComposit matrix transformation to do Normalization of arbitrary perspective
projection view volume to canonical view volume
Nper
= Sper
SHper
T(-PRP) R T(-VRP)