![Page 1: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/1.jpg)
MIT EECS 6.837, Teller and Durand 1
Line Rasterization
MIT EECS 6.837Frédo Durand and Seth Teller
![Page 2: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/2.jpg)
MIT EECS 6.837, Teller and Durand 2
Administrative• Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2
– Due Friday 27 at 5pm– Model a scene using iv files from assignt 1– Lighting: at least one spot and one other light– You are welcome to add new geometry– Pay attention to the requirements!– Shadows are challenging! (and no required)
![Page 3: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/3.jpg)
MIT EECS 6.837, Teller and Durand 3
Review of previous lecture?• What did we learn?• Where was the “magic”? What were the insights?
![Page 4: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/4.jpg)
MIT EECS 6.837, Teller and Durand 4
Review of previous lecture?• What did we learn?• Where was the “magic”? What were the insights?
– Graphics is a lot about interpolation/extrapolation– Convexity is important– Planes as homogeneous coordinates & dot product– Outcodes– Orienting edges of polygons
• Questions?
![Page 5: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/5.jpg)
MIT EECS 6.837, Teller and Durand 5
Overview of graphics pipeline?
TraverseGeometric
ModelTransform toWorld space
Apply lightingEquation at
vertices
Transform toEye space
Perspective transformto NDC
Clip
Transform to 3D
Screen spaceRasterize Resolve
visibility
3D SceneDatabase
Camera+Viewport Parameters
2D Framebuffer Values
![Page 6: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/6.jpg)
MIT EECS 6.837, Teller and Durand 6
Today’s lecture: line rasterization• Overview of rasterization
• Naïve line rasterization
• Bresenham DDA
• Scanline and active edge list
(x1, y1)
(x2, y2)
E
NE
M
y
![Page 7: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/7.jpg)
MIT EECS 6.837, Teller and Durand 7
Framebuffer Model• Raster Display: 2D array of picture elements
(pixels)• Pixels individually set/cleared (greyscale, color)• Window coordinates: pixels centered at integers
(x1,y1)
(x2,y2)
![Page 8: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/8.jpg)
MIT EECS 6.837, Teller and Durand 8
2D Scan Conversion• Geometric primitive
– 2D: point, line, polygon, circle...– 3D: point, line, polyhedron, sphere...
• Primitives are continuous; screen is discrete
![Page 9: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/9.jpg)
MIT EECS 6.837, Teller and Durand 9
2D Scan Conversion• Solution: compute discrete approximation• Scan Conversion:
algorithms for efficient generation of the samples comprising this approximation
![Page 10: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/10.jpg)
MIT EECS 6.837, Teller and Durand 10
Brute force solution for triangles• ?
![Page 11: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/11.jpg)
MIT EECS 6.837, Teller and Durand 11
Brute force solution for triangles• For each pixel
– Compute line equations at pixel center– “clip” against the triangle
Problem?
![Page 12: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/12.jpg)
MIT EECS 6.837, Teller and Durand 12
Brute force solution for triangles• For each pixel
– Compute line equations at pixel center– “clip” against the triangle
Problem?If the triangle is small, a lot of useless computation
![Page 13: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/13.jpg)
MIT EECS 6.837, Teller and Durand 13
Brute force solution for triangles• Improvement:
– Compute only for the screen bounding box of the triangle
– How do we get such a bounding box?
![Page 14: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/14.jpg)
MIT EECS 6.837, Teller and Durand 14
Brute force solution for triangles• Improvement:
– Compute only for the screen bounding box of the triangle
– Xmin, Xmax, Ymin, Ymax of the triangle vertices
![Page 15: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/15.jpg)
MIT EECS 6.837, Teller and Durand 15
Can we do better? Yes!• Plus, how do we rasterize lines using this
approach?• Efficient rasterization is the topic of the
following two lectures
![Page 16: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/16.jpg)
MIT EECS 6.837, Teller and Durand 16
Rasterization• Line rasterization
– This lecture
Shirley page 55
![Page 17: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/17.jpg)
MIT EECS 6.837, Teller and Durand 17
Rasterization• Line rasterization
– This lecture• Polygon filling, interpolation, visibility
– Tuesday
Shirley page 55
![Page 18: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/18.jpg)
MIT EECS 6.837, Teller and Durand 18
Rasterization• There are subtle differences between rasterizing
a segment, and rasterizing the boundary of a polygon
• Important for assignment 3 & 4
![Page 19: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/19.jpg)
MIT EECS 6.837, Teller and Durand 19
Today’s lecture: line rasterization• Overview of rasterization
• Naïve line rasterization
• Bresenham DDA
• Scanline and active edge list
(x1, y1)
(x2, y2)
E
NE
M
y
![Page 20: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/20.jpg)
MIT EECS 6.837, Teller and Durand 20
Scan Converting 2D Line Segments• Given:
– Segment endpoints (integers x1, y1; x2, y2)• Identify:
– Set of pixels x; y to “light up” for segment
(x1, y1)
(x2, y2)
![Page 21: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/21.jpg)
MIT EECS 6.837, Teller and Durand 21
Algorithm Design Choices• For m = dy/dx• Assume: 0 < m < 1 • Why?
(x1, y1)
(x2, y2)
![Page 22: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/22.jpg)
MIT EECS 6.837, Teller and Durand 22
Algorithm Design Choices• Exactly one pixel per column
– Why?
(x1, y1)
(x2, y2)
![Page 23: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/23.jpg)
MIT EECS 6.837, Teller and Durand 23
Algorithm Design Choices• Exactly one pixel per column
– fewer => disconnected– more =>too thick– “connectedness" with just 1 pixel per column
(x1, y1)
(x2, y2)
![Page 24: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/24.jpg)
MIT EECS 6.837, Teller and Durand 24
Algorithm Design Choices• Note: brightness can vary with slope
– What is the maximum variation?
![Page 25: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/25.jpg)
MIT EECS 6.837, Teller and Durand 25
Algorithm Design Choices• Note: brightness can vary with slope
– What is the maximum variation? • How could we compensate for this?
– Answer: antialiasing (wait until November…)
2
![Page 26: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/26.jpg)
MIT EECS 6.837, Teller and Durand 26
Naive algorithm, 1st attempt • Simply compute y as a function of x
– Conceptually: move vertical scan line from x1 to x2– What is the expression of y as function of x ?
x
y
(x1, y1)
(x2, y2)
![Page 27: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/27.jpg)
MIT EECS 6.837, Teller and Durand 27
Naive algorithm, 1st attempt • Simply compute y as a function of x
– Conceptually: move vertical scan line from x1 to x2– What is the expression of y as function of x ?
x
y
(x1, y1)
(x2, y2))1(1 xxmy −+=
)12(12
11 yyxx
xxyy −−−
+=
dxdym =
![Page 28: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/28.jpg)
MIT EECS 6.837, Teller and Durand 28
Naive algorithm, 1st attempt• Simply compute y as a function of x• Round y (Why?)• Set pixel (x, rnd(y(x)))
x
y
(x1, y1)
(x2, y2))1(1 xxmy −+=
)12(12
11 yyxx
xxyy −−−
+=
dxdym =
![Page 29: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/29.jpg)
MIT EECS 6.837, Teller and Durand 29
Efficiency• Computing y values is expensive• Observe: y += m at each x step (m = dy/dx)• First example of spatial coherence
)1(1 xxmyy −+=
y(x+1)
y(x)x x+1
m
x
y(x)
(x1, y1)
(x2, y2)
y(x+1)
x+1
![Page 30: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/30.jpg)
MIT EECS 6.837, Teller and Durand 30
Incremental algorithm• Start at (x1; y1)• Thereafter, increment y value by slope m• Note: x integer, but y floating point
y(x+1)
y(x)x x+1
m
x
y(x)
(x1, y1)
(x2, y2)
y(x+1)
x+1
![Page 31: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/31.jpg)
MIT EECS 6.837, Teller and Durand 31
Questions?
![Page 32: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/32.jpg)
MIT EECS 6.837, Teller and Durand 32
Today’s lecture: line rasterization• Overview of rasterization
• Naïve line rasterization
• Bresenham DDA
• Scanline and active edge list
(x1, y1)
(x2, y2)
E
NE
M
y
![Page 33: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/33.jpg)
MIT EECS 6.837, Teller and Durand 33
Bresenham's algorithm• Select pixel vertically closest to segment• Justification: intuitive, efficient• Also: pixel center always within 0.5 vertically
•Is selection criterion well-defined ?
•What other rules could we have used?
![Page 34: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/34.jpg)
MIT EECS 6.837, Teller and Durand 34
Bresenham DDA• DDA = Digital Differential Analyzer• Another scan algorithm• Same output as naive & incremental algorithms
![Page 35: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/35.jpg)
MIT EECS 6.837, Teller and Durand 35
Bresenham DDA• Observation: after pixel P at (xp , yp)
next pixel must be either E or NE– Why?
ENE
![Page 36: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/36.jpg)
MIT EECS 6.837, Teller and Durand 36
Bresenham Step• Which pixel to choose: E or NE?
– Choose E if segment passes below or through middle point M
– Choose NE if segment passes above M
E
NE
ME
NE
M
![Page 37: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/37.jpg)
MIT EECS 6.837, Teller and Durand 37
Bresenham Step• Use implicit equation F for underlying line L:
– F(x; y) = 0; where F(x; y) = y-mx-b (Why?) – F positive above L, zero on L, negative below L
• What is the meaning of the value of F(p) ?
MF<0
F>0F=0
p
![Page 38: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/38.jpg)
MIT EECS 6.837, Teller and Durand 38
Bresenham Step• Use implicit equation F for underlying line L• Define an error term e as e = -F(x,y)
– Choose NE if ?????
Me
![Page 39: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/39.jpg)
MIT EECS 6.837, Teller and Durand 39
Bresenham Step• Use implicit equation F for underlying line L• Define an error term e as e = -F(x,y)
– Choose NE if e > 0.5 otherwise choose E
Me
![Page 40: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/40.jpg)
MIT EECS 6.837, Teller and Durand 40
Using the Error Term• Compute e’ under (unconditional) x increment
e’=e+m (remember why?)• Under what condition should we choose E?• Under what condition should we choose NE?
– In this case, how should e’ be computed?
e
e’
![Page 41: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/41.jpg)
MIT EECS 6.837, Teller and Durand 41
Using the Error Term• Compute e’ under x increment e’=e+m• If e’<0.5
– Choose E• Otherwise
– Choose NE?– Then decrement e’ by 1
e
e’
![Page 42: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/42.jpg)
MIT EECS 6.837, Teller and Durand 42
Summary of Bresenham• Initialize x, y, e• Loop over x1::x2
– Plot– Update e– If e>0.5
• Increment y • Decrement 1 from e
ENE
![Page 43: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/43.jpg)
MIT EECS 6.837, Teller and Durand 43
Bresenham Implementation• We've sketched case in which x1 < x2, m <= 1• Handle all eight octants (using symmetry)• Endpoints not necessarily integer coordinates
ENE
![Page 44: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/44.jpg)
MIT EECS 6.837, Teller and Durand 44
Using only integer arithmetic• Multiply everything by dx=(x2-x1)• Initialize dx e=0
– dx e’ = dx e + m dx– dx e’ = dx e +dy– Choose NE if dx e > [ (dx+1) / 2 ]
e
e’
![Page 45: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/45.jpg)
MIT EECS 6.837, Teller and Durand 45
Circle Scan Conversion• Need generate pixels for 2nd octant only• Slope progresses from 0 to –1• Analog of Bresenham Segment Algorithm
![Page 46: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/46.jpg)
MIT EECS 6.837, Teller and Durand 46
Questions?
![Page 47: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/47.jpg)
MIT EECS 6.837, Teller and Durand 47
Discussion: Why learn Bresenham?• You might think: “All modern API do it for me,
why do I need to learn Bresenham?”• Well, somebody has to code it!• Useful extensions
– E.g. ray marching for ray tracing– Remember the key insights– Bresenham is a “paradigm”
![Page 48: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/48.jpg)
MIT EECS 6.837, Teller and Durand 48
Discussion: Why learn Bresenham?• Understand what the hardware does
– E.g. use the hardware for other calculations• E.g. Piano mover problem [Hoff et al. SIGGRAPH 99]
![Page 49: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/49.jpg)
MIT EECS 6.837, Teller and Durand 49
Today’s lecture: line rasterization• Overview of rasterization
• Naïve line rasterization
• Bresenham DDA
• Scanline and active edge list
(x1, y1)
(x2, y2)
E
NE
M
y
![Page 50: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/50.jpg)
MIT EECS 6.837, Teller and Durand 50
Scan Line rasterization• So far, we have drawn one segment at a time• Now, we are going to handle all the segments
together pixel row by pixel row
y
![Page 51: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/51.jpg)
MIT EECS 6.837, Teller and Durand 51
Why Scanline?• Not enough memory
– First framebuer (512) cost $80,000 (late '60s)!• Access to one row at a time (some printers)• Will simplify our treatment of polygons
y
![Page 52: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/52.jpg)
MIT EECS 6.837, Teller and Durand 52
For assignment 3• Access through class Raster
– Constructor (int width, *environment) – Init () provides a clear new scanline– setPixel(x, color) modifies current scaline– write(y) write entire scanline
y
![Page 53: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/53.jpg)
MIT EECS 6.837, Teller and Durand 53
Why learn scanline?• Basic principle of sweep algorithm.
– Spatial coherence:Computation at previous scanline is reused
– E.g. efficient segment intersection– E.g. sweep construction of 4.5D visibility structure
y
![Page 54: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/54.jpg)
MIT EECS 6.837, Teller and Durand 54
Scan Line and Active Edge lists• Assume polygons are convex
– Exactly 0 or 2 edges at each scanline. Why?
y
![Page 55: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/55.jpg)
MIT EECS 6.837, Teller and Durand 55
Scan Line : Principle• Proceed row by row• Maintain Active Edge List (AEL) (EdgeRecList)
• Edge Table (ET) for new edges at y (EdgeRecTable)
y
![Page 56: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/56.jpg)
MIT EECS 6.837, Teller and Durand 56
Scan Line : Principle• Proceed row by row• Maintain Active Edge List (AEL) (EdgeRecList)
• Edge Table (ET) for new edges at y (EdgeRecTable)
Will prove importantfor span fillingy
![Page 57: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/57.jpg)
MIT EECS 6.837, Teller and Durand 57
Precompute: Edge Table (EdgeRecTable)
– One entry per scan line (where edge begins)– Each entry is a linked list of EdgeRecs, sorted by x
• yend: y of top edge endpoint• xcurr, x: current x intersection, delta wrt y• Next or null pointer Edge table
![Page 58: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/58.jpg)
MIT EECS 6.837, Teller and Durand 58
Initialization: events• Edge Table
– List of EdgeRecs, sorted by x
• yend• xcurr, delta wrt y
• Active edge list (AEL)– Will be maintained – Store all active edges
intersecting scanline– Ordered by x
Edge table
![Page 59: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/59.jpg)
MIT EECS 6.837, Teller and Durand 59
When Does AEL Change State?• When a vertex is encountered
– When an edge begins • All such events pre-stored in Edge Table
– When and edge ends• Can be deduced from current Active Edge List
![Page 60: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/60.jpg)
MIT EECS 6.837, Teller and Durand 60
When Does AEL Change State?• When a vertex is encountered• When two edges change order along a scanline
– I.e., when edges cross each other!– How to detect this efficiently?
![Page 61: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/61.jpg)
MIT EECS 6.837, Teller and Durand 61
Processing a Scanline• Add any edges which start in [y; y + 1[
– Using Edge Table (EdgeRecTable)
– How can x, y pre-sorting be exploited ?
y
![Page 62: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/62.jpg)
MIT EECS 6.837, Teller and Durand 62
Processing a Scanline• Add any edges which start in [y; y + 1[• For each edge in AEL (EdgeRecList):
– If edge ends in (y ,y-1) delete it from AEL– Otherwise, for next y: update x
y
![Page 63: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/63.jpg)
MIT EECS 6.837, Teller and Durand 63
Processing a Scanline• Add any edges which start in [y; y + 1[• For each edge in AEL:
– If edge ends in (y ,y-1) delete it from AEL– Otherwise, for next y: update x
y
Write pixels ]x(y), x(y+1)[As you update xUsing Raster.setPixel(x’)Be careful with boundary conditions
![Page 64: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/64.jpg)
MIT EECS 6.837, Teller and Durand 64
Processing a ScanlineWrite pixels ]x(y), x(y+1)[As you update xBe careful with boundary conditionsAdvice: use setPixel(x(y))Then loop on x(y)+1::x(y+1)-1
![Page 65: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/65.jpg)
MIT EECS 6.837, Teller and Durand 65
Processing a Scanline (continued)• Once after each scanline is processed:
– Sort AEL by x (mostly sorted, so...)– Increment scanline variable y– Raster.Write()
![Page 66: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/66.jpg)
MIT EECS 6.837, Teller and Durand 66
Scanline algorithm summary• Initialize Raster, Polygons, Edge Table, AEL• For each scanline y
– Update AEL (insert edges from EdgeTable[y])– Assign raster of pixels from AEL– Update AEL (delete, increment, resort)
y
![Page 67: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/67.jpg)
MIT EECS 6.837, Teller and Durand 67
Scanline algorithm summary• Initialize Raster(width), Polygons, Edge Table, AEL• For each scanline y
– Raster.init()– Update AEL (insert edges from EdgeTable[y])– For each edge
• Update x• Assign raster of pixels from AEL
– Using setPixel(x), on segment– Pay attention to boundary
• If ends, delete
– Resort AEL– Raster.write()
![Page 68: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/68.jpg)
MIT EECS 6.837, Teller and Durand 68
Questions?
![Page 69: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/69.jpg)
MIT EECS 6.837, Teller and Durand 69
Next week: polygon rasterization• Span filling• Value interpolation• Visibility
![Page 70: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/70.jpg)
MIT EECS 6.837, Teller and Durand 70
Assignment 3• Due Friday October 4 at 5pm• Line rasterization• C++ only!• Linux and SGI only!• Scanline wireframe rendering
– Will be used for assignment 4
![Page 71: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/71.jpg)
MIT EECS 6.837, Teller and Durand 71
Playtime: Sunset• We have seen why the sunset is red
![Page 72: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/72.jpg)
MIT EECS 6.837, Teller and Durand 72
Playtime: Green flash• The last ray of the Sun is green
• Any idea why?• Also, novel by Jules Verne
(19th century)– Movie by Rohmer, Summer
![Page 73: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/73.jpg)
MIT EECS 6.837, Teller and Durand 73
Green Flash• http://mintaka.sdsu.edu/GF/• http://www.mtwilson.edu/Tour/Lot/Green_Flash/• http://www.intersoft.it/galaxlux/GreenFlashGallery.htm• http://www.isc.tamu.edu/~astro/research/sandiego.html• http://www.meteores.net/rv.html• http://flzhgn.home.mindspring.com/grnray.htm
![Page 74: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/74.jpg)
MIT EECS 6.837, Teller and Durand 74
Green flash
![Page 75: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/75.jpg)
MIT EECS 6.837, Teller and Durand 75
Green flash• Mirage• Refraction
– temperature gradient
• Ω shape• Depends
on wavelength
![Page 76: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/76.jpg)
MIT EECS 6.837, Teller and Durand 76
![Page 77: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/77.jpg)
MIT EECS 6.837, Teller and Durand 77
Green flash
![Page 78: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/78.jpg)
MIT EECS 6.837, Teller and Durand 78
Green flash• Simulation
![Page 79: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/79.jpg)
MIT EECS 6.837, Teller and Durand 79
Green flash
![Page 80: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/80.jpg)
MIT EECS 6.837, Teller and Durand 80
Green flash• Why don’t you see green flash at sunrise?
![Page 81: Line Rasterization - MIT CSAILMIT EECS 6.837, Teller and Durand 2 Administrative • Prof. Teller office hours today: 5-6 in 4-035 • Assignment 2 – Due Friday 27 at 5pm – Model](https://reader036.vdocument.in/reader036/viewer/2022071215/604628aea93912620c2e390d/html5/thumbnails/81.jpg)
MIT EECS 6.837, Teller and Durand 81
Events• Event list of buckets, 1 per scan line
– Start/finish of an edge (vertex)– Occurs within interval [y; y + 1)– In each bucket, events sorted by x coordinate
Event list