cg t5 - rasterizationmcoimbra/lectures/cg_1213/cg_1213_t5_raster… · interpolation along lines...
TRANSCRIPT
![Page 1: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/1.jpg)
L:CC, MI:ERSI
CG – T5 - Rasterization
Miguel Tavares Coimbra
(course and slides designed by
Verónica Costa Orvalho)
![Page 2: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/2.jpg)
What is rasterization?
CG 12/13 - T5
![Page 3: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/3.jpg)
Basic steps for creating a 2D image
out of a 3D world
CG 12/13 - T5
• Create the 3D world
– Vertexes and triangles in a 3D space
• Project it to a 2D ‘camera’
– Use perspective to transform coordinates into a
2D space
• Paint each pixel of the 2D image
– Rasterization, shading, texturing
– Will break this into smaller things later on
• Enjoy the super cool image you have created
Today
![Page 4: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/4.jpg)
pipeline
. collision detection
. animation global acceleration . physics simulation process on CPU or GPU
. transformation
. projection Computes: . what is to be drawn . how should be drawn . where should be drawn process on GPU
. draws images generated by geometry stage process on GPU CG 12/13 - T5
![Page 5: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/5.jpg)
Rasterization
rasterization:
wireframe
filling with colors
CG 12/13 - T5
![Page 6: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/6.jpg)
CG 12/13 - T5 Slide by Ron Fedkiw, Stanford University
![Page 7: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/7.jpg)
How do we do this?
CG 12/13 - T5
![Page 8: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/8.jpg)
Primitives
• Only three!
– Points
– Line segments
– Triangles
• How do I rasterize them?
– Points are simple
– Lines?
– Triangles?
CG 12/13 - T5
![Page 9: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/9.jpg)
Rasterizing lines
• Lines are defined by
two points
– Projected into my 2D
screen from my 3D
world
• Consider it a
rectangle
– So that it occupies a
non-zero area
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 10: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/10.jpg)
Rasterizing lines
• Lines are defined by
two points
– Projected into my 2D
screen from my 3D
world
• Consider it a
rectangle
– So that it occupies a
non-zero area
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 11: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/11.jpg)
Point sampling
• Draw all the pixels
whose centers fall
within the rectangle
• It may draw undesired
adjacent pixels…
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 12: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/12.jpg)
Point sampling
• Draw all the pixels
whose centers fall
within the rectangle
• It may draw undesired
adjacent pixels…
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 13: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/13.jpg)
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 14: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/14.jpg)
Bresenham lines (midpoint alg.)
• Idea:
– Define line width
parallel to pixel grid
• What does this
mean?
– Turn on the single
nearest pixel in each
column
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 15: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/15.jpg)
Bresenham lines (midpoint alg.)
• Idea:
– Define line width
parallel to pixel grid
• What does this
mean?
– Turn on the single
nearest pixel in each
column
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 16: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/16.jpg)
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 17: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/17.jpg)
Algorithms for drawing lines
• Simple
– Evaluate line equation
per column
• Line equation
– y=b+m.x
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 18: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/18.jpg)
Optimized line drawing
• Multiplying and rounding is slow
• We can add the vertical displacement to our previous vertical coordinate (d) – Initially: d = m(x+1)+b-y
– Then: d+=m
• We call this DDA (digital differential analyzer)
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 19: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/19.jpg)
Interpolation along lines
• We don’t want to simply
know which pixels are
on the line
– Boolean
• Vertexes hold attributes
– Ex: Color
• We want these to vary
smoothly along the line
– Linear interpolation
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 20: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/20.jpg)
Linear interpolation
• Pixels are not exactly
on the line
• Must project pixels on
the line for the correct
percentage
• We can use DDA!
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 21: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/21.jpg)
Linear interpolation
• Pixels are not exactly
on the line
• Must project pixels on
the line for the correct
percentage
• We can use DDA!
CG 12/13 - T5 Adapted from Steve Marschner, Cornell University
![Page 22: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/22.jpg)
What about triangles?
CG 12/13 - T5
![Page 23: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/23.jpg)
Rasterizing triangles
• Pixel belongs to the
triangle if its center is
inside the triangle
• Need two things:
– Which pixels belong to
the triangle?
– How do we interpolate
values from 3
vertexes?
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 24: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/24.jpg)
Using directed lines
• Point is inside the
triangle if it is on the
left of three directed
lines
– They could be on the
right too…
• How do we build a
simple test for this?
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 25: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/25.jpg)
Start by defining a directed line
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 26: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/26.jpg)
Easy to obtain its normal
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 27: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/27.jpg)
Dot product gives us a simple test
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 28: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/28.jpg)
Using our coordinate system
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 29: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/29.jpg)
Line divides the plane in two
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 30: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/30.jpg)
Point inside triangle test
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
![Page 31: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/31.jpg)
Barycentric interpolation
CG 12/13 - T5 Adapted from Ron Fedkiw, Stanford University
Advanced topic!
Check the ref. book
![Page 32: CG T5 - Rasterizationmcoimbra/lectures/CG_1213/CG_1213_T5_Raster… · Interpolation along lines • We don’t want to simply know which pixels are on the line – Boolean • Vertexes](https://reader036.vdocument.in/reader036/viewer/2022071500/611f85136e170452df39e500/html5/thumbnails/32.jpg)
Summary
• Rasterization
– Which pixels belong to the primitive
– How do I interpolate vertex atributes?
• Lines
– Consider them rectangles
– Linear interpolation
• Triangles
– Use three directed lines
– Barycentric interpolation
CG 12/13 - T5