04 - viewing transformations, rasterization
Post on 05-Dec-2021
8 Views
Preview:
TRANSCRIPT
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
04 - Viewing Transformations, Rasterization
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Viewing transformations
World Coordinates
Screen Space (pixels)
Modeling Camera Projection Viewport
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Coordinate Systems
object coordinates
world coordinates
camera coordinates
screen coordinates
Image Copyright: Mark Pauly
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Viewing Transformationobject space
model camera projection viewport
canonical view volumeworld space
camera space screen space
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Viewport transformation
viewport
canonical view volume
screen space1-1
nx
ny
2
4xscreen
yscreen1
3
5 =
2
4nx/2 0 nx�1
2
0 ny/2 ny�12
0 0 1
3
5
2
4xcanonical
ycanonical1
3
5
How does it look in 3D?
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Orthographic Projection
projection
canonical view volume
camera space
xz
y(l,b,n)
(r,t,f)
Morth =
2
664
2r�l 0 0 � r+l
r�l
0 2t�b 0 � t+b
t�b
0 0 2n�f �n+f
n�f
0 0 0 1
3
775
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Camera Transformation
camera
world space
camera space
1. Construct the camera reference system given: 1. The eye position e2. The gaze direction g3. The view-up vector t
uv w
e
w = � g
||g||
u =t⇥w
||t⇥w||
v = w ⇥ u
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Change of frame
o x
y
euv
p
p = (px, py) = o+ pxx+ pyyp = (pu, pv) = e+ puu+ pvv
2
4pxpy1
3
5 =
2
41 0 ex0 1 ey0 0 1
3
5
2
4ux vx 0uy vy 00 0 1
3
5
2
4pupv1
3
5 =
2
4ux vx exuy vy ey0 0 1
3
5
2
4pupv1
3
5
pxy =
u v e0 0 1
�puv puv =
u v e0 0 1
��1
pxy
Can you write it directly without the inverse?
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Camera Transformation
camera
world space
camera space
1. Construct the camera reference system given: 1. The eye position e2. The gaze direction g3. The view-up vector t
uv w
e
w = � g
||g||
u =t⇥w
||t⇥w||
v = w ⇥ u
2. Construct the unique transformations that converts world coordinates into camera coordinates
Mcam =
u v w e0 0 0 1
��1
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Viewing Transformationobject space
model camera projection viewport
canonical view volumeworld space
camera space screen space
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Algorithm• Construct Viewport Matrix
• Construct Projection Matrix
• Construct Camera Matrix
•
• For each model
• Construct Model Matrix
•
• For every point p in each primitive of the model
•
• Rasterize the model
Morth
Mvp
Mcam
Mmodel
M = MvpMorthMcam
Mfinal = MMmodel
pfinal = Mfinalp
Mvp
Morth
Mcam
Mmodel
Mfinal
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
References
Fundamentals of Computer Graphics, Fourth Edition 4th Edition by Steve Marschner, Peter Shirley
Chapter 7
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Rasterization
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo Image Copyright: Andrea Tagliasacchi
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
2D Canvas
(0, 0)
(width-1, height-1)
pixel gridcanvas(-1.0, -1.0)
(1.0, 1.0)
Image Copyright: Andrea Tagliasacchi
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
2D Canvas
(0, 0)
(width-1, height-1)
pixel gridcanvas(-1.0, -1.0)
(1.0, 1.0)
Image Copyright: Andrea Tagliasacchi
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Implicit Geometry Representation• Define a curve as zero set of 2D implicit function
• F(x,y) = 0 → on curve
• F(x,y) < 0 → inside curve
• F(x,y) > 0 → outside curve
• Example: Circle with center (cx, cy) and radius r
F (x, y) = (x� cx)2 + (y � cy)
2 � r2
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Implicit Geometry Representation• Define a curve as zero set of 2D implicit function
• F(x,y) = 0 → on curve
• F(x,y) < 0 → inside curve
• F(x,y) > 0 → outside curve
By Ag2gaeh - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=45004240
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Implicit Rasterization
for all pixels (i,j)
(x,y) = map_to_canvas (i,j)
if F(x,y) < 0
set_pixel (i,j, color)
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Implicit Geometry Representation
• Example: Triangle
Image Copyright: Andrea Tagliasacchi
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1
ab
c
p
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1
• Unique for non-collinear a,b,c
2
4ax bx cxay by cy1 1 1
3
5 ·
2
4↵��
3
5 =
2
4px
py
1
3
5
ab
c
p
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1
• Unique for non-collinear a,b,c
• Ratio of triangle areas
ab
c
p↵(p) =
area(p,b, c)
area(a,b, c)
�(p) =area(p, c,a)
area(a,b, c)
�(p) =area(p,a,b)
area(a,b, c)
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1 • Unique for non-collinear a,b,c• Ratio of triangle areas • α(p), β(p), γ(p) are linear functions
a
b
c a
b
c a
b
c
1
1
1
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
γ <0
β<0 α<0
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1 • Unique for non-collinear a,b,c• Ratio of triangle areas • α(p), β(p), γ(p) are linear functions • Gives inside/outside information
ab
c
α,β,γ > 0
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Barycentric Interpolation• Barycentric coordinates:
• p = αa + βb + γc with α + β + γ = 1 • Unique for non-collinear a,b,c• Ratio of triangle areas • α(p), β(p), γ(p) are linear functions • Gives inside/outside information • Use barycentric coordinates to interpolate vertex normals (or other data, e.g. colors)
AB
C
P
n(P) = ↵ · n(A) + � · n(B) + � · n(C)
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Color Interpolation
http://www.cgchannel.com/2010/11/cg-science-for-artists-part-2-the-real-time-rendering-pipeline/
AB
C
P
Per-vertex Per-pixel
Evaluate color on vertices, then interpolates it
Interpolates positions and normals, then evaluate color on each pixel
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Triangle Rasterization• Each triangle is represented as three 2D points (x0, y0), (x1, y1), (x2, y2)
• Rasterization using barycentric coordinates
x = α · x0 + β · x1 + γ · x2
y = α · y0 + β · y1 + γ · y2
α + β + γ = 1
γ < 0 β < 0
α < 0(x2, y2)
(x1, y1)
(x0, y0)
(x, y)
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
• Each triangle is represented as three 2D points (x0, y0), (x1, y1), (x2, y2)
• Rasterization using barycentric coordinates
Triangle Rasterization
for all y do for all x do compute (α,β,γ) for (x,y)
if (α ∈ [0,1] and β ∈ [0,1] and γ ∈ [0,1]
set_pixel (x,y)
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Clipping
• Ok if you do it brute force
• Care is required if you are explicitly tracing the boundaries
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Objects Depth Sorting• To handle occlusion, you
can sort all the objects in a scene by depth
• This is not always possible!
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
z-buffering
Image Depth (z)
• You render the image both in the Image and in the depth buffer, where you store only the depth
• When a new fragment comes in, you draw it in the image only if it is closer
• This always work and it is cheap to evaluate! It is the default in all graphics hardware
• You still have to sort for transparency…
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
z-buffer quantization and “z-fighting”• The z-buffer is quantized (the
number of bits is heavily dependent on the hardware platform)
• Two close object might be quantized differently, leading to strange artifacts, usually called “z-fighting”
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
• Render nxn pixels instead of one
• Assign the average to the pixel
Super Sampling Anti-Aliasing
Image Copyright: Fritz Kessler
c1 c2
c3 c4
c1 + c2 + c3 + c44
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
Many different names and variants• SSAA (FSAA)
• MSAA
• CSAA
• EQAA
• FXAA
• TX AA
Copyright: tested.com (http://www.tested.com/tech/pcs/1194-how-to-choose-the-right-anti-aliasing-mode-for-your-gpu/#)
MSAA
CSCI-GA.2270-001 - Computer Graphics - Daniele Panozzo
References
Fundamentals of Computer Graphics, Fourth Edition 4th Edition by Steve Marschner, Peter Shirley
Chapter 8
top related