CT4201/EC4215: Computer Graphics Projections · 2020. 4. 27. · Sequence of Spaces and...
Transcript of CT4201/EC4215: Computer Graphics Projections · 2020. 4. 27. · Sequence of Spaces and...
CT4201/EC4215: Computer Graphics
ProjectionsBOCHANG MOON
Graphics Pipeline
Modeling Transformation
Illumination
Viewing Transformation
Clipping
Projection
Rasterization
Display
Sequence of Spaces and Transformations
Object space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
Sequence of Spaces and Transformations
Object space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
ProjectionTransformation
Canonical view volume (normalized device coordinates)
ViewportTransformation
Screen space
Canonical View Volume
(-1,-1,-1)
(1,1,1)
x
yz
Viewport Transformation
• Primitives (or line segments) within the canonical view volume will be mapped to the image
(-1,-1,-1)
(1,1,1)
x
yz
Image (or window on the screen)
𝑛𝑥 pixels
𝑛𝑦 pixels
Viewport Transformation
• Ignore the z-coordinates of points for now◦ In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
(-1,-1,-1)
(1,1,1)
x
yz
Image (or window on the screen)
𝑛𝑥 pixels
𝑛𝑦 pixels
Raster Image (again)
• Ignore the z-coordinates of points for now◦ In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
• Where do we need to locate pixels in 2D space?
4x4 imagey
x(0,0)
x=-0.5 x=3.5y=-0.5
y=3.5
Raster Image (again)
• Ignore the z-coordinates of points for now◦ In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
• Where do we need to locate pixels in 2D space?
• The rectangular domain of a 𝑛𝑥 × 𝑛𝑦 image
◦ 𝑅 = −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
Viewport Transformation
• Ignore the z-coordinates of points for now◦ In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
• Q. How do we transform a rectangle to another rectangle?
Example: Windowing Transform
• Problem specification: move a 2D rectangle into a new position
y
x
(𝑥𝑙 , 𝑦𝑙)
(𝑥ℎ, 𝑦ℎ) y
x
(𝑥𝑙′, 𝑦𝑙
′)
(𝑥ℎ′ , 𝑦ℎ
′ )
Example: Windowing Transform
• Problem specification: move a 2D rectangle into a new position◦ Step1. translate: move the point 𝑥𝑙 , 𝑦𝑙 to the origin
y
x
(𝑥𝑙 , 𝑦𝑙)
(𝑥ℎ, 𝑦ℎ) y
x
(𝑥ℎ − 𝑥𝑙 , 𝑦ℎ − 𝑦𝑙)
Example: Windowing Transform
• Problem specification: move a 2D rectangle into a new position◦ Step2. scale: resize the rectangle to be the same size of the target.
y
x
y
x
(𝑥ℎ − 𝑥𝑙 , 𝑦ℎ − 𝑦𝑙)
(𝑥ℎ′ − 𝑥𝑙
′, 𝑦ℎ′ − 𝑦𝑙
′)
Example: Windowing Transform
• Problem specification: move a 2D rectangle into a new position◦ Step3. translate: move the origin to point (𝑥𝑙
′, 𝑦𝑙′)
y
x
y
x
(𝑥ℎ′ − 𝑥𝑙
′, 𝑦ℎ′ − 𝑦𝑙
′)
(𝑥𝑙′, 𝑦𝑙
′)
(𝑥ℎ′ , 𝑦ℎ
′ )
Example: Windowing Transform
• Problem specification: move a 2D rectangle into a new position
◦ Target = translate(𝑥𝑙′, 𝑦𝑙
′) 𝑠𝑐𝑎𝑙𝑒𝑥ℎ′−𝑥𝑙
′
𝑥ℎ−𝑥𝑙,𝑦ℎ′−𝑦𝑙
′
𝑦ℎ−𝑦𝑙𝑡𝑟𝑎𝑛𝑠𝑙𝑎𝑡𝑒(−𝑥𝑙 , −𝑦𝑙)
◦ =1 0 𝑥𝑙
′
0 1 𝑦𝑙′
0 0 1
𝑥ℎ′−𝑥𝑙
′
𝑥ℎ−𝑥𝑙0 0
0𝑦ℎ′−𝑦𝑙
′
𝑦ℎ−𝑦𝑙0
0 0 1
1 0 −𝑥𝑙0 1 −𝑦𝑙0 0 1
◦ =
𝑥ℎ′−𝑥𝑙
′
𝑥ℎ−𝑥𝑙0
𝑥𝑙′𝑥ℎ−𝑥ℎ
′ 𝑥𝑙
𝑥ℎ−𝑥𝑙
0𝑦ℎ′−𝑦𝑙
′
𝑦ℎ−𝑦𝑙
𝑦𝑙′𝑦ℎ−𝑦ℎ
′𝑦𝑙
𝑦ℎ−𝑦𝑙
0 0 1
Viewport Transformation
• Ignore the z-coordinates of points for now◦ In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5, 𝑛𝑥 − 0.5 × [−0.5, 𝑛𝑦 − 0.5]
•
𝑥𝑠𝑐𝑟𝑒𝑒𝑛𝑦𝑠𝑐𝑟𝑒𝑒𝑛
1=
𝑛𝑥
20
𝑛𝑥−1
2
0𝑛𝑦
2
𝑛𝑦−1
2
0 0 1
𝑥𝑐𝑎𝑛𝑜𝑛𝑖𝑐𝑎𝑙𝑦𝑐𝑎𝑛𝑜𝑛𝑖𝑐𝑎𝑙
1
• For the case with z-coordinates,
◦ 𝑀𝑣𝑖𝑒𝑤𝑝𝑜𝑟𝑡 =
𝑛𝑥
20
0𝑛𝑦
2
0𝑛𝑥−1
2
0𝑛𝑦−1
2
0 00 0
1 00 1
Sequence of Spaces and Transformations
Object space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
ProjectionTransformation
Canonical view volume (normalized device coordinates)
ViewportTransformation
Screen space
Projections
• Transform 3D points in eye space to 2D points in image space
• Two types of projections◦ Orthographic projection
◦ Perspective projection
Modeling Transformation
Illumination
Viewing Transformation
Clipping
Projection
Rasterization
Display
x
y
z
Orthographic Projection
• Assumption◦ A viewer is looking along the minus z-axis with his head pointing in the y-direction
◦ Implies n > f
x
y
z(l,b,n)
(r,t,f)
Orthographic Projection
• The view volume (orthographic view volume) is an axis-aligned box ◦ [l, r] x [b, t] x [f, n]
• Notations◦ 𝑥 = 𝑙 ≡ 𝑙𝑒𝑓𝑡 𝑝𝑙𝑎𝑛𝑒, 𝑥 = 𝑟 ≡ 𝑟𝑖𝑔ℎ𝑡 𝑝𝑙𝑎𝑛𝑒
◦ 𝑦 = 𝑏 ≡ 𝑏𝑜𝑡𝑡𝑜𝑚 𝑝𝑙𝑎𝑛𝑒, 𝑦 = 𝑡 ≡ 𝑡𝑜𝑝 𝑝𝑙𝑎𝑛𝑒
◦ 𝑧 = 𝑛 ≡ 𝑛𝑒𝑎𝑟 𝑝𝑙𝑎𝑛𝑒, 𝑧 = 𝑓 ≡ 𝑓𝑎𝑟 𝑝𝑙𝑎𝑛𝑒
x
y
z(l,b,n)
(r,t,f)
Orthographic Projection
• Transform points in orthographic view volume to the canonical view volume◦ Also windowing transform (3D)
(l,b,n)
(r,t,f)
(-1,-1,-1)
(1,1,1)
Projectiontransformation
Orthographic Projection
• Transform points in orthographic view volume to the canonical view volume◦ Also windowing transform (3D)
◦ Map a box 𝑥𝑙 , 𝑥ℎ × 𝑦𝑙 , 𝑦ℎ × 𝑧𝑙 , 𝑧ℎ to another box 𝑥𝑙′, 𝑥ℎ
′ × 𝑦𝑙′, 𝑦ℎ
′ × [𝑧𝑙′, 𝑧ℎ
′ ]
◦
𝑥ℎ′−𝑥𝑙
′
𝑥ℎ−𝑥𝑙0
0𝑦ℎ′−𝑦𝑙
′
𝑦ℎ−𝑦𝑙
0𝑥𝑙′𝑥ℎ−𝑥ℎ
′ 𝑥𝑙
𝑥ℎ−𝑥𝑙
0𝑦𝑙′𝑦ℎ−𝑦ℎ
′𝑦𝑙
𝑦ℎ−𝑦𝑙
0 00 0
𝑧ℎ′−𝑧𝑙′
𝑧ℎ−𝑧𝑙
𝑧𝑙′𝑧ℎ−𝑧ℎ
′ 𝑧𝑙
𝑧ℎ−𝑧𝑙
0 1
Orthographic Projection
• Transform points in orthographic view volume to the canonical view volume◦ Also windowing transform (3D)
• 𝑀𝑜𝑟𝑡ℎ𝑜 =
2
𝑟−𝑙0
02
𝑡−𝑏
0 −𝑟+𝑙
𝑟−𝑙
0 −𝑡+𝑏
𝑡−𝑏
0 00 0
2
𝑛−𝑓−
𝑛+𝑓
𝑛−𝑓
0 1
Composite Transformation
• The matrix that transforms points in world space to screen coordinate:
• 𝑀 = 𝑀𝑣𝑖𝑒𝑤𝑝𝑜𝑟𝑡𝑀𝑜𝑟𝑡ℎ𝑜𝑀𝑣𝑖𝑒𝑤𝑖𝑛𝑔
Orthographic Projection
• Transform points in orthographic view volume to the canonical view volume◦ Also windowing transform (3D)
• Tend to ignore relative distances between objects and eye◦ Unrealistic
• In practice, ◦ We usually do not use this projection.
◦ It can be useful in applications where relative lengths should be judged.
Orthographic Projection in OpenGL
• void glOrtho(GLdouble left, GLdouble right,
• GLdouble bottom, GLdouble top,
• GLdouble nearVal, GLdouble farVal);
(l,b,n)
(r,t,f)
Perspective Projection
• Objects in an image become smaller as their distance from the eye increases.
• History of perspective:◦ Artists from the Renaissance period employed the perspective property.
Images from wikipedia
Perspective Projection
• Objects in an image become smaller as their distance from the eye increases.
• History of perspective:◦ Artists from the Renaissance period employed the perspective property.
• In everyday life?
Perspective Projection
• 𝑦𝑠 =𝑑
𝑧𝑦
◦ 𝑦𝑠: y-axis coordinate in view plane
◦ y: distance of the point along the y-axis
d
view
pla
ne
e g
z
𝑦
𝑦𝑠
Homogeneous Coordinate
• Represent a point 𝑥, 𝑦, 𝑧 with an extra coordinate w◦ 𝑥, 𝑦, 𝑧, 𝑤
◦ In the previous lecture, 𝑤 = 1
• Let’s define 𝑤 to be the denominator of the x-, y-, z-coordinates
◦ (𝑥, 𝑦, 𝑧, 𝑤) represent the 3D point (𝑥
𝑤,𝑦
𝑤,𝑧
𝑤)
◦ A special case, 𝑤 = 1, is still valid.
◦ 𝑤 can be any values
Projective Transform
• Let’s define 𝑤 to be the denominator of the x-, y-, z-coordinates
◦ (𝑥, 𝑦, 𝑧, 𝑤) represent the 3D point (𝑥
𝑤,𝑦
𝑤,𝑧
𝑤)
◦ A special case, 𝑤 = 1, is still valid.
◦ 𝑤 can be any values
• Projective transformation
◦
𝑥𝑦ǁ𝑧𝑤
=
𝑎1 𝑏1𝑎2 𝑏2
𝑐1 𝑑1𝑐2 𝑑2
𝑎3 𝑏3𝑒 𝑓
𝑐3 𝑑3𝑔 ℎ
𝑥𝑦𝑧1
◦ 𝑥′, 𝑦′, 𝑧′ = (𝑥
𝑤,𝑦
𝑤,𝑧
𝑤)
Perspective Projection
• Example with 2D homogeneous vector 𝑦 𝑧 1 𝑇
◦𝑦𝑠1
=𝑑 0 00 1 0
𝑦𝑧1
◦ This is corresponding to the perspective equation, 𝑦𝑠 =𝑑
𝑧𝑦.
Perspective Projection
• Some info. for perspective matrix◦ Define our project plane as the near plane
◦ Distance to the near plane: −𝑛
◦ Distance to the far plane: −𝑓
• Perspective equation: 𝑦𝑠 =𝑛
𝑧𝑦
• Perspective matrix
◦ 𝑃 =
𝑛 00 𝑛
0 00 0
0 00 0
𝑛 + 𝑓 −𝑓𝑛1 0
Perspective Projection
• Perspective matrix
◦ 𝑃 =
𝑛 00 𝑛
0 00 0
0 00 0
𝑛 + 𝑓 −𝑓𝑛1 0
• A mapping with the perspective matrix:
◦ 𝑃
𝑥𝑦𝑧1
=
𝑛𝑥𝑛𝑦
𝑛 + 𝑓 𝑧 − 𝑓𝑛𝑧
=
𝑛𝑥
𝑧𝑛𝑦
𝑧
𝑛 + 𝑓 −𝑓𝑛
𝑧
1
Perspective Projection
• A mapping with the perspective matrix:
◦ 𝑃
𝑥𝑦𝑧1
=
𝑛𝑥𝑛𝑦
𝑛 + 𝑓 𝑧 − 𝑓𝑛𝑧
=
𝑛𝑥
𝑧𝑛𝑦
𝑧
𝑛 + 𝑓 −𝑓𝑛
𝑧
1
• Properties◦ The first, second, and fourth rows are for the perspective equation.
◦ The third row is for keeping z coordinate at least approximately.◦ E.g., when z = n, transformed z coordinate is still n.
◦ E.g., when 𝑧 > 𝑛, we cannot preserve the z coordinate exactly, but relative orders between points will be preserved.
Perspective Projection
• Perspective matrix◦ Map the perspective view volume to the orthographic view volume.
Composite Transformation
• The matrix that transforms points in world space to screen coordinate:
• 𝑀 = 𝑀𝑣𝑖𝑒𝑤𝑝𝑜𝑟𝑡𝑀𝑜𝑟𝑡ℎ𝑜𝑃𝑀𝑣𝑖𝑒𝑤𝑖𝑛𝑔 = 𝑀𝑣𝑖𝑒𝑤𝑝𝑜𝑟𝑡𝑀𝑝𝑒𝑟𝑀𝑣𝑖𝑒𝑤𝑖𝑛𝑔
• 𝑀𝑝𝑒𝑟 = 𝑀𝑜𝑟𝑡ℎ𝑜𝑃 (perspective projection matrix)
◦ 𝑀𝑝𝑒𝑟 =
2𝑛
𝑟−𝑙0
02𝑛
𝑡−𝑏
𝑙+𝑟
𝑙−𝑟0
𝑏+𝑡
𝑏−𝑡0
0 00 0
𝑓+𝑛
𝑛−𝑓
2𝑓𝑛
𝑓−𝑛
1 0
Perspective Projection in OpenGL
• void glFrustum(GLdouble left, GLdouble right,
• GLdouble bottom, GLdouble top,
• GLdouble nearVal, GLdouble farVal);
Perspective Projection in OpenGL
• void gluPerspective(GLdouble fovy, GLdouble aspect,
• GLdouble zNear, GLdouble zFar);
• Parameters ◦ fovy: field of view (in degrees) in the y direction
◦ aspect: aspect ratio is the ratio of x (width) to y (height)
• Symmetric constraints are implicitly applied.◦ l = -r, b = -t
• A constraint to prevent image distortion
◦𝑛𝑥
𝑛𝑦=
𝑟
𝑡 x
y
z
𝜃
2
Further Reading
• In our textbook, Fundamentals of Computer Graphics (4th edition)◦ Chapter 7