60
March 1, 2009 Dr. Muhammed Al-Mulhem 1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem Dr. Muhammed Al-Mulhem March 1, 2009 March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

Embed Size (px)

Citation preview

Page 1: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 1

ICS 415Computer Graphics

Rendering Geometric Primitives

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem

March 1, 2009March 1, 2009

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem

March 1, 2009March 1, 2009

Page 2: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 2

Rendering geometric primitivesDescribe objects with points, lines, and surfaces Describe objects with points, lines, and surfaces

• Compact mathematical notationCompact mathematical notation

• Operators to apply to those representationsOperators to apply to those representations

Render the objectsRender the objects

• The rendering pipelineThe rendering pipeline

Reading:Reading:

• Appendix A1-A5Appendix A1-A5

Describe objects with points, lines, and surfaces Describe objects with points, lines, and surfaces

• Compact mathematical notationCompact mathematical notation

• Operators to apply to those representationsOperators to apply to those representations

Render the objectsRender the objects

• The rendering pipelineThe rendering pipeline

Reading:Reading:

• Appendix A1-A5Appendix A1-A5

Page 3: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 3

Rendering

Generate an image from geometric primitivesGenerate an image from geometric primitivesGenerate an image from geometric primitivesGenerate an image from geometric primitives

Rendering

Geometric Primitives

Raster Image

Page 4: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 4

3D Rendering Example

What issues must be addressed by a 3D rendering system?

Page 5: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 5

Overview

3D scene representation3D scene representation

3D viewer representation3D viewer representation

Visible surface determinationVisible surface determination

Lighting simulationLighting simulation

3D scene representation3D scene representation

3D viewer representation3D viewer representation

Visible surface determinationVisible surface determination

Lighting simulationLighting simulation

Page 6: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 6

Overview

3D scene representation3D scene representation

3D viewer representation3D viewer representation

Visible surface determinationVisible surface determination

Lighting simulationLighting simulation

3D scene representation3D scene representation

3D viewer representation3D viewer representation

Visible surface determinationVisible surface determination

Lighting simulationLighting simulation

How is the 3D scenedescribed in a computer?

How is the 3D scenedescribed in a computer?

Page 7: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 7

3D Scene Representation

Scene is usually approximated by 3D primitivesScene is usually approximated by 3D primitives

• PointPoint

• Line segmentLine segment

• PolygonPolygon

• PolyhedronPolyhedron

• Curved surfaceCurved surface

• Solid object Solid object

• etc.etc.

Scene is usually approximated by 3D primitivesScene is usually approximated by 3D primitives

• PointPoint

• Line segmentLine segment

• PolygonPolygon

• PolyhedronPolyhedron

• Curved surfaceCurved surface

• Solid object Solid object

• etc.etc.

Page 8: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 8

3D Point

Specifies a locationSpecifies a locationSpecifies a locationSpecifies a location

Page 9: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 9

3D Point

Specifies a locationSpecifies a location

• Represented by three coordinatesRepresented by three coordinates

Specifies a locationSpecifies a location

• Represented by three coordinatesRepresented by three coordinates

(x,y,z)

Page 10: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 10

3D Vector

Specifies a direction and a magnitudeSpecifies a direction and a magnitudeSpecifies a direction and a magnitudeSpecifies a direction and a magnitude

Page 11: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 11

3D Vector

Specifies a direction and a magnitudeSpecifies a direction and a magnitude

• Represented as the difference between two point positions Represented as the difference between two point positions by three coordinates (Vby three coordinates (Vxx, V, Vyy, V, Vzz).).

• Magnitude |V| = sqrt( VMagnitude |V| = sqrt( Vxx22 + V + Vyy

22 + V + Vzz22))

• Has no locationHas no location

Specifies a direction and a magnitudeSpecifies a direction and a magnitude

• Represented as the difference between two point positions Represented as the difference between two point positions by three coordinates (Vby three coordinates (Vxx, V, Vyy, V, Vzz).).

• Magnitude |V| = sqrt( VMagnitude |V| = sqrt( Vxx22 + V + Vyy

22 + V + Vzz22))

• Has no locationHas no location(Vx, Vy, Vz).(Vx, Vy, Vz).

Page 12: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 12

Vector Addition/Subtraction

Operation u + v, with:Operation u + v, with:

• Identity Identity 00 : : vv + + 00 = = v v

• Inverse Inverse -- : : vv + (- + (-vv) = ) = 00

Addition uses the “parallelogram rule”:Addition uses the “parallelogram rule”:

Operation u + v, with:Operation u + v, with:

• Identity Identity 00 : : vv + + 00 = = v v

• Inverse Inverse -- : : vv + (- + (-vv) = ) = 00

Addition uses the “parallelogram rule”:Addition uses the “parallelogram rule”:

u+v

u

vu-v

uv

-v

-v

Page 13: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 13

Vector Space

Vectors define a vector spaceVectors define a vector space

• They support vector additionThey support vector addition

– Commutative and associativeCommutative and associative

– Possess identity and inversePossess identity and inverse

• They support scalar multiplicationThey support scalar multiplication

– Associative, distributiveAssociative, distributive

– Possess identityPossess identity

Vectors define a vector spaceVectors define a vector space

• They support vector additionThey support vector addition

– Commutative and associativeCommutative and associative

– Possess identity and inversePossess identity and inverse

• They support scalar multiplicationThey support scalar multiplication

– Associative, distributiveAssociative, distributive

– Possess identityPossess identity

Page 14: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 14

Affine Spaces

• Vector spaces lack position and distanceVector spaces lack position and distance

– They have magnitude and direction but no locationThey have magnitude and direction but no location

• Combine the point and vector primitivesCombine the point and vector primitives

– Permits describing vectors relative to a common locationPermits describing vectors relative to a common location

• A point and three vectors define a 3-D coordinate system A point and three vectors define a 3-D coordinate system

• Point-point subtraction yields a vectorPoint-point subtraction yields a vector

• Vector spaces lack position and distanceVector spaces lack position and distance

– They have magnitude and direction but no locationThey have magnitude and direction but no location

• Combine the point and vector primitivesCombine the point and vector primitives

– Permits describing vectors relative to a common locationPermits describing vectors relative to a common location

• A point and three vectors define a 3-D coordinate system A point and three vectors define a 3-D coordinate system

• Point-point subtraction yields a vectorPoint-point subtraction yields a vector

Page 15: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 15

Coordinate Systems

Y

X

Z

Right-handedcoordinate

systemZ

X

Y

Left-handedcoordinate

system

Grasp z-axis with hand

Thumb points in direction of z-axis

Roll fingers from positive x-axis towards positive y-axis

Page 16: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 16

Points + Vectors

Points support these operationsPoints support these operations

• Point-point subtraction: Point-point subtraction: QQ - - PP = = vv

– Result is a vector pointing fromResult is a vector pointing from PP toto QQ

• Vector-point addition: Vector-point addition: PP + + vv = = QQ

– Result is a new pointResult is a new point

• Note that the addition of two points is not definedNote that the addition of two points is not defined

Points support these operationsPoints support these operations

• Point-point subtraction: Point-point subtraction: QQ - - PP = = vv

– Result is a vector pointing fromResult is a vector pointing from PP toto QQ

• Vector-point addition: Vector-point addition: PP + + vv = = QQ

– Result is a new pointResult is a new point

• Note that the addition of two points is not definedNote that the addition of two points is not defined

P

Q

v

Page 17: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 17

3D Line Segment

Linear path between two pointsLinear path between two pointsLinear path between two pointsLinear path between two points

Page 18: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 18

3D Line Segment

Use a linear combination of two pointsUse a linear combination of two points

• Parametric representation:Parametric representation:

– P = PP = P11 + t (P + t (P22 - P - P11), (0 ), (0 t t 1) 1)

Use a linear combination of two pointsUse a linear combination of two points

• Parametric representation:Parametric representation:

– P = PP = P11 + t (P + t (P22 - P - P11), (0 ), (0 t t 1) 1)

P1

P2

Page 19: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 19

3D Ray

Line segment with one endpoint at infinityLine segment with one endpoint at infinity

• Parametric representation: Parametric representation:

– P = PP = P11 + t V, (0 <= t < + t V, (0 <= t < ))

Line segment with one endpoint at infinityLine segment with one endpoint at infinity

• Parametric representation: Parametric representation:

– P = PP = P11 + t V, (0 <= t < + t V, (0 <= t < ))

P1

V

Page 20: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 20

3D Line

Line segment with both endpoints at infinityLine segment with both endpoints at infinity

• Parametric representation: Parametric representation:

– P = PP = P11 + t V, (- + t V, (- < t < < t < ))

Line segment with both endpoints at infinityLine segment with both endpoints at infinity

• Parametric representation: Parametric representation:

– P = PP = P11 + t V, (- + t V, (- < t < < t < ))

P1

V

Page 21: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 21

3D Line – Slope Intercept

Slope Slope =m =m

= rise / run= rise / run

Slope Slope = (y - y1) / (x - x1) = (y - y1) / (x - x1) = (y2 - y1) / (x2 - x1)= (y2 - y1) / (x2 - x1)

Solve for y:Solve for y:

y = [(y2 - y1)/(x2 - x1)]x + [-(y2-y1)/(x2 - x1)]x1 + y1y = [(y2 - y1)/(x2 - x1)]x + [-(y2-y1)/(x2 - x1)]x1 + y1

or: y = mx + bor: y = mx + b

Slope Slope =m =m

= rise / run= rise / run

Slope Slope = (y - y1) / (x - x1) = (y - y1) / (x - x1) = (y2 - y1) / (x2 - x1)= (y2 - y1) / (x2 - x1)

Solve for y:Solve for y:

y = [(y2 - y1)/(x2 - x1)]x + [-(y2-y1)/(x2 - x1)]x1 + y1y = [(y2 - y1)/(x2 - x1)]x + [-(y2-y1)/(x2 - x1)]x1 + y1

or: y = mx + bor: y = mx + b

x

y

P2 = (x2, y2)

P1 = (x1, y1)

P = (x, y)

Page 22: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 22

Euclidean Spaces

Q: What is the distance function between points and Q: What is the distance function between points and vectors in affine space?vectors in affine space?

A: Dot productA: Dot product

• Euclidean affine space = affine space plus dot productEuclidean affine space = affine space plus dot product

• Permits the computation of distance and anglesPermits the computation of distance and angles

Q: What is the distance function between points and Q: What is the distance function between points and vectors in affine space?vectors in affine space?

A: Dot productA: Dot product

• Euclidean affine space = affine space plus dot productEuclidean affine space = affine space plus dot product

• Permits the computation of distance and anglesPermits the computation of distance and angles

Page 23: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 23

Dot Product

• TheThe dot productdot product or, more generallyor, more generally, , inner productinner product of two of two vectors is a scalar:vectors is a scalar:

vv11 • • vv22 = = xx11xx22 + + yy11yy22 + + zz11zz2 2 (in 3D)(in 3D)

• TheThe dot productdot product or, more generallyor, more generally, , inner productinner product of two of two vectors is a scalar:vectors is a scalar:

vv11 • • vv22 = = xx11xx22 + + yy11yy22 + + zz11zz2 2 (in 3D)(in 3D)

u θ

v

Page 24: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 24

Dot Product

Useful for many purposesUseful for many purposes• Computing the length (Euclidean Norm) of a vector: Computing the length (Euclidean Norm) of a vector:

– lengthlength((vv) = ||) = ||vv|| = sqrt(|| = sqrt(v • v)v • v)

• NormalizingNormalizing a vector, making it unit-length: a vector, making it unit-length: v = v / ||v||v = v / ||v||

• Computing the angle between two vectors:Computing the angle between two vectors:

– u • v u • v = |= |uu| || |vv| cos(θ)| cos(θ)

• Checking two vectors for orthogonalityChecking two vectors for orthogonality

– u • v = 0.0u • v = 0.0

Useful for many purposesUseful for many purposes• Computing the length (Euclidean Norm) of a vector: Computing the length (Euclidean Norm) of a vector:

– lengthlength((vv) = ||) = ||vv|| = sqrt(|| = sqrt(v • v)v • v)

• NormalizingNormalizing a vector, making it unit-length: a vector, making it unit-length: v = v / ||v||v = v / ||v||

• Computing the angle between two vectors:Computing the angle between two vectors:

– u • v u • v = |= |uu| || |vv| cos(θ)| cos(θ)

• Checking two vectors for orthogonalityChecking two vectors for orthogonality

– u • v = 0.0u • v = 0.0 u θ

v

Page 25: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 25

ProjectingProjecting one vector onto another one vector onto another

• If If vv is a unit vector and we have another vector, is a unit vector and we have another vector, ww

• We can project We can project ww perpendicularly onto perpendicularly onto vv

• And the result,And the result, u u, has length , has length w w • • vv

ProjectingProjecting one vector onto another one vector onto another

• If If vv is a unit vector and we have another vector, is a unit vector and we have another vector, ww

• We can project We can project ww perpendicularly onto perpendicularly onto vv

• And the result,And the result, u u, has length , has length w w • • vv

Dot Product

u

w

v

wv

wv

wvw

wu

)cos(

Page 26: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 26

Dot Product

Is commutativeIs commutative

• u • v = v • uu • v = v • u

Is distributive with respect to additionIs distributive with respect to addition

• u • (v + w) = u • v + u • wu • (v + w) = u • v + u • w

Is commutativeIs commutative

• u • v = v • uu • v = v • u

Is distributive with respect to additionIs distributive with respect to addition

• u • (v + w) = u • v + u • wu • (v + w) = u • v + u • w

Page 27: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 27

Cross Product

The The cross productcross product or or vector productvector product of two vectors is a of two vectors is a vector:vector:

The cross product of two vectors is orthogonal to bothThe cross product of two vectors is orthogonal to both

Right-hand rule dictates direction of cross productRight-hand rule dictates direction of cross product

The The cross productcross product or or vector productvector product of two vectors is a of two vectors is a vector:vector:

The cross product of two vectors is orthogonal to bothThe cross product of two vectors is orthogonal to both

Right-hand rule dictates direction of cross productRight-hand rule dictates direction of cross product

1221

1221

1221

tdeterminan222

11121 )(

y x y x

z x z x

z y z y

zyx

zyx

uuu zyx

vv

Page 28: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 28

Cross Product Right Hand Rule• See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

• Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

• Twist your hand about the A-axis such that B extends perpendicularly from your palm

• As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 29: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 29

Cross Product Right Hand Rule

• See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

• Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

• Twist your hand about the A-axis such that B extends perpendicularly from your palm

• As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 30: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 30

Cross Product Right Hand Rule

• See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

• Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

• Twist your hand about the A-axis such that B extends perpendicularly from your palm

• As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 31: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 31

Cross Product Right Hand Rule

• See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

• Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

• Twist your hand about the A-axis such that B extends perpendicularly from your palm

• As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 32: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 32

Cross Product Right Hand Rule

• See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

• Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

• Twist your hand about the A-axis such that B extends perpendicularly from your palm

• As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 33: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 33

Other helpful formulas

Length = sqrt (x2 - x1)Length = sqrt (x2 - x1)22 + (y2 - y1) + (y2 - y1)22

Midpoint, p2, between p1 and p3Midpoint, p2, between p1 and p3

• p2 = ((x1 + x3) / 2, (y1 + y3) / 2))p2 = ((x1 + x3) / 2, (y1 + y3) / 2))

Two lines are perpendicular if:Two lines are perpendicular if:

• M1 = -1/M2M1 = -1/M2

• cosine of the angle between them is 0cosine of the angle between them is 0

• Dot product = 0Dot product = 0

Length = sqrt (x2 - x1)Length = sqrt (x2 - x1)22 + (y2 - y1) + (y2 - y1)22

Midpoint, p2, between p1 and p3Midpoint, p2, between p1 and p3

• p2 = ((x1 + x3) / 2, (y1 + y3) / 2))p2 = ((x1 + x3) / 2, (y1 + y3) / 2))

Two lines are perpendicular if:Two lines are perpendicular if:

• M1 = -1/M2M1 = -1/M2

• cosine of the angle between them is 0cosine of the angle between them is 0

• Dot product = 0Dot product = 0

Page 34: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 34

3D Plane

A linear combination of three pointsA linear combination of three pointsA linear combination of three pointsA linear combination of three points

P1

P3P2

Page 35: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 35

Origin

3D Plane

A linear combination of three pointsA linear combination of three points

• Implicit representation: Implicit representation:

– ax + by + cz + d = 0, or ax + by + cz + d = 0, or

– P·N + d = 0P·N + d = 0

• N is the plane “normal”N is the plane “normal”

– Unit-length vectorUnit-length vector

– Perpendicular to planePerpendicular to plane

A linear combination of three pointsA linear combination of three points

• Implicit representation: Implicit representation:

– ax + by + cz + d = 0, or ax + by + cz + d = 0, or

– P·N + d = 0P·N + d = 0

• N is the plane “normal”N is the plane “normal”

– Unit-length vectorUnit-length vector

– Perpendicular to planePerpendicular to plane

P1

N = (a,b,c)

d

P3P2

Page 36: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 36

3D Sphere

All points at distance “r” from point “(cAll points at distance “r” from point “(cxx, c, cyy, c, czz)”)”

• Implicit representation:Implicit representation:

– (x - c(x - cxx))22 + (y - c + (y - cyy))22 + (z - c + (z - czz))22 = r = r 22

• Parametric representation:Parametric representation:

– x = r cos(x = r cos() cos() cos() + c) + cxx

– y = r cos(y = r cos() sin() sin() + c) + cyy

– z = r sin(z = r sin() + c) + czz

All points at distance “r” from point “(cAll points at distance “r” from point “(cxx, c, cyy, c, czz)”)”

• Implicit representation:Implicit representation:

– (x - c(x - cxx))22 + (y - c + (y - cyy))22 + (z - c + (z - czz))22 = r = r 22

• Parametric representation:Parametric representation:

– x = r cos(x = r cos() cos() cos() + c) + cxx

– y = r cos(y = r cos() sin() sin() + c) + cyy

– z = r sin(z = r sin() + c) + czz

r

Page 37: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 37

3D Geometric Primitives

More detail on 3D modeling later in course More detail on 3D modeling later in course

• PointPoint

• Line segmentLine segment

• PolygonPolygon

• PolyhedronPolyhedron

• Curved surfaceCurved surface

• Solid object Solid object

• etc.etc.

More detail on 3D modeling later in course More detail on 3D modeling later in course

• PointPoint

• Line segmentLine segment

• PolygonPolygon

• PolyhedronPolyhedron

• Curved surfaceCurved surface

• Solid object Solid object

• etc.etc.

H&B Figure 10.46

Page 38: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 38

Take a breath

We’re done with the primitivesWe’re done with the primitives

Now we’re moving on to study how graphics uses Now we’re moving on to study how graphics uses these primitives to make pretty picturesthese primitives to make pretty pictures

We’re done with the primitivesWe’re done with the primitives

Now we’re moving on to study how graphics uses Now we’re moving on to study how graphics uses these primitives to make pretty picturesthese primitives to make pretty pictures

Page 39: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 39

Rendering 3D ScenesTransform

Illuminate

Transform

Clip

Project

Rasterize

Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay

Page 40: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 40

Camera Models

The most common model The most common model is pin-hole camerais pin-hole camera • All captured light rays arrive along All captured light rays arrive along

paths toward focal point without paths toward focal point without lens distortion lens distortion (everything is in focus)(everything is in focus)

• Sensor response Sensor response proportional to radianceproportional to radiance

• Other models consider ...Depth of field, Motion blur, Lens distortion

The most common model The most common model is pin-hole camerais pin-hole camera • All captured light rays arrive along All captured light rays arrive along

paths toward focal point without paths toward focal point without lens distortion lens distortion (everything is in focus)(everything is in focus)

• Sensor response Sensor response proportional to radianceproportional to radiance

• Other models consider ...Depth of field, Motion blur, Lens distortion

View plane

Eye position(focal point)

Page 41: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 41

Camera Parameters

What are the parameters of a camera?What are the parameters of a camera?What are the parameters of a camera?What are the parameters of a camera?

Page 42: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 42

Camera ParametersPositionPosition

• Eye position (px, py, pz)Eye position (px, py, pz)

OrientationOrientation

• View direction (dx, dy, dz)View direction (dx, dy, dz)

• Up direction (ux, uy, uz)Up direction (ux, uy, uz)

ApertureAperture

• Field of view (xfov, yfov)Field of view (xfov, yfov)

Film planeFilm plane

• ““Look at” pointLook at” point

• View plane normalView plane normal

PositionPosition

• Eye position (px, py, pz)Eye position (px, py, pz)

OrientationOrientation

• View direction (dx, dy, dz)View direction (dx, dy, dz)

• Up direction (ux, uy, uz)Up direction (ux, uy, uz)

ApertureAperture

• Field of view (xfov, yfov)Field of view (xfov, yfov)

Film planeFilm plane

• ““Look at” pointLook at” point

• View plane normalView plane normal

right

back

Up direction

Eye Position

Viewdirection

ViewPlane

“Look at”Point

Page 43: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 43

Moving the camera

View Frustum

Right

BackTowards

Up

Page 44: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 44

The Rendering Pipeline

Transform

Illuminate

Transform

Clip

Project

Rasterize

Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay

Page 45: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 45

Rendering: Transformations

We’ve learned about transformationsWe’ve learned about transformations

But they are used in three ways:But they are used in three ways:

• Modeling transformsModeling transforms

• Viewing transforms (Move the camera)Viewing transforms (Move the camera)

• Projection transforms (Change the type of camera)Projection transforms (Change the type of camera)

We’ve learned about transformationsWe’ve learned about transformations

But they are used in three ways:But they are used in three ways:

• Modeling transformsModeling transforms

• Viewing transforms (Move the camera)Viewing transforms (Move the camera)

• Projection transforms (Change the type of camera)Projection transforms (Change the type of camera)

Page 46: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 46

The Rendering Pipeline: 3-D

Result:Result:

• All vertices of scene in shared 3-D “world” coordinate systemAll vertices of scene in shared 3-D “world” coordinate system

• Vertices shaded according to lighting modelVertices shaded according to lighting model

• Scene vertices in 3-D “view” or “camera” coordinate systemScene vertices in 3-D “view” or “camera” coordinate system

• Exactly those vertices & portions of polygons in view frustumExactly those vertices & portions of polygons in view frustum

• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped vertices

Scene graphObject geometry

LightingCalculations

Clipping

ModelingTransforms

ViewingTransform

ProjectionTransform

Page 47: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 47

The Rendering Pipeline: 3-D

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

• All vertices of scene in shared 3-D “world” coordinate systemAll vertices of scene in shared 3-D “world” coordinate system

Page 48: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 48

Rendering: Transformations

Modeling transformsModeling transforms

• Size, place, scale, and rotate objects and parts of the Size, place, scale, and rotate objects and parts of the model w.r.t. each othermodel w.r.t. each other

• Object coordinates -> world coordinatesObject coordinates -> world coordinates

Modeling transformsModeling transforms

• Size, place, scale, and rotate objects and parts of the Size, place, scale, and rotate objects and parts of the model w.r.t. each othermodel w.r.t. each other

• Object coordinates -> world coordinatesObject coordinates -> world coordinates

Z

X

Y

X

Z

Y

Page 49: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 49

The Rendering Pipeline: 3-D

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

•All geometric primitives are illuminatedAll geometric primitives are illuminated

Page 50: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 50

Lighting Simulation

Lighting parametersLighting parameters

• Light source emissionLight source emission

• Surface reflectanceSurface reflectance

• Atmospheric attenuationAtmospheric attenuation

• Camera responseCamera response

Lighting parametersLighting parameters

• Light source emissionLight source emission

• Surface reflectanceSurface reflectance

• Atmospheric attenuationAtmospheric attenuation

• Camera responseCamera responseN

N

Camera

Surface

LightSource

Page 51: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 51

Lighting Simulation

Direct illuminationDirect illumination

• Ray castingRay casting

• Polygon shadingPolygon shading

Global illuminationGlobal illumination

• Ray tracingRay tracing

• Monte Carlo methodsMonte Carlo methods

• Radiosity methodsRadiosity methods

Direct illuminationDirect illumination

• Ray castingRay casting

• Polygon shadingPolygon shading

Global illuminationGlobal illumination

• Ray tracingRay tracing

• Monte Carlo methodsMonte Carlo methods

• Radiosity methodsRadiosity methods

NN

Camera

Surface

LightSource

N

Page 52: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 52

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

• Scene vertices in 3-D “view” or “camera” coordinate systemScene vertices in 3-D “view” or “camera” coordinate system

The Rendering Pipeline: 3-D

Page 53: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 53

Rendering: Transformations

Viewing transformViewing transform

• Rotate & translate the world to lie directly in front of Rotate & translate the world to lie directly in front of the camerathe camera

– Typically place camera at originTypically place camera at origin

– Typically looking down -Z axisTypically looking down -Z axis

• World coordinatesWorld coordinates View coordinatesView coordinates

Viewing transformViewing transform

• Rotate & translate the world to lie directly in front of Rotate & translate the world to lie directly in front of the camerathe camera

– Typically place camera at originTypically place camera at origin

– Typically looking down -Z axisTypically looking down -Z axis

• World coordinatesWorld coordinates View coordinatesView coordinates

Y

X

Z

Right-handedcoordinate

system

Page 54: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 54

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

• Remove geometry that is out of viewRemove geometry that is out of view

The Rendering Pipeline: 3-D

Page 55: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 55

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped vertices

The Rendering Pipeline: 3-D

Page 56: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 56

Rendering: Transformations

Projection transformProjection transform

• Apply perspective foreshorteningApply perspective foreshortening

– Distant = small: the Distant = small: the pinhole camerapinhole camera model model

• View coordinates View coordinates Screen coordinates Screen coordinates

Projection transformProjection transform

• Apply perspective foreshorteningApply perspective foreshortening

– Distant = small: the Distant = small: the pinhole camerapinhole camera model model

• View coordinates View coordinates Screen coordinates Screen coordinates

Page 57: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 57

Perspective CameraPerspective Camera

Orthographic CameraOrthographic Camera

Perspective CameraPerspective Camera

Orthographic CameraOrthographic Camera

Rendering: Transformations

Page 58: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 58

Rendering 3D Scenes

Transform

Illuminate

Transform

Clip

Project

Rasterize

Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay

Page 59: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 59

Rasterize

Convert screen coordinates to pixel colorsConvert screen coordinates to pixel colorsConvert screen coordinates to pixel colorsConvert screen coordinates to pixel colors

Page 60: March 1, 2009 Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Rendering Geometric Primitives Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

March 1, 2009 Dr. Muhammed Al-Mulhem 60

Summary

Geometric primitivesGeometric primitives

• Points, vectorsPoints, vectors

Operators on these primitivesOperators on these primitives

• Dot product, cross product, normDot product, cross product, norm

The rendering pipelineThe rendering pipeline

• Move models, illuminate, move camera, clip, project to Move models, illuminate, move camera, clip, project to display, rasterizedisplay, rasterize

Geometric primitivesGeometric primitives

• Points, vectorsPoints, vectors

Operators on these primitivesOperators on these primitives

• Dot product, cross product, normDot product, cross product, norm

The rendering pipelineThe rendering pipeline

• Move models, illuminate, move camera, clip, project to Move models, illuminate, move camera, clip, project to display, rasterizedisplay, rasterize