SlideShare a Scribd company logo
1 of 15
RASTERIZATION
Scan Converting a Line
Lecture 02-03
Graphics Pipeline
• The graphics pipeline or rendering pipeline refers to the sequence of steps
used to create a 2D raster representation of a 3D scene.
• Stages of the graphics pipeline:
• Modeling individual Objects using 3D geometric primitives: Traditionally done
using triangles, making a wire frame for an object.
• Modeling and transformation into world coordinates: Transform from the local
coordinate system to the 3d world coordinate system.
• Camera transformation: Transform the 3d world coordinate system into the 3d
camera coordinate system, with the camera as the origin.
• Lighting: Illuminate according to lighting and reflectance.
• Projection transformation: Transform the 3d world coordinates into the 2d view of
the camera.
• Clipping: Geometric primitives that now fall completely outside of the viewing
frustum will not be visible and are discarded at this stage.
• Scan conversion or rasterization: The process by which the 2D image space
representation of the scene is converted into raster format and the correct resulting
pixel values are determined. From now on, operations will be carried out on each
single pixel.
• Texturing, fragment shading: At this stage of the pipeline individual fragments are
assigned a color based on values interpolated from the vertices during rasterization,
from a texture in memory, or from a shader program.
Points
• How to draw points in processing?
• Coordinates of the screen
• top left corner is assigned as origin, going right increases in x to width-1
coordinate, and going down increases in y to the height-1
• The setup() function
• Creating a window using size(width, height)
• Drawing a point using point(x,y)
• Setting point size using strokeWeight(no. of pixels)
• Setting color using stroke(colorR, colorG, colorB)
• single color value for working with greyscale images, each argument has a
value from 0-255
• Changing background color using background()
• Once stroke or stroke weight is changed, it affects the primitives
used/written after this line of code and not to any of the previously
drawn.
• How to rasterize a line between two given points?
Scan Conversion
• ‘Scan conversion’/rasterization is the process of taking
geometric shapes and converting them into an array of
pixels stored in the framebuffer to be displayed
• Or converting from ‘random scan’/vector specification to a raster
scan where we specify which pixels are ‘ON’ based on a stored
array of pixels
• Takes place after clipping occurs
• All graphics packages do this at end of the rendering
pipeline
How does computer draw line?
• Screen made of pixels
• High-level language specifies line
• System must color pixels
• There should be
• No gaps in adjacent pixels
• Pixels close to ideal line
• Consistent choices; same pixels in same
situations
• Smooth looking
• Even brightness in all orientations
• Same line for as for P0, P1 and P1, P0
• Which pixels to choose?
Scan Convert a Line
• Finding the next pixel
Special cases:
• Horizontal Line:
• Draw pixel P and increment x coordinate value by 1 to get next pixel.
• Vertical Line:
• Draw pixel P and increment y coordinate value by 1 to get next pixel.
• Diagonal Line:
• Draw pixel P and increment both x and y coordinate by 1 to get next
pixel. Here |slope|=1
• What should we do in the general case?
• For |slope| < 1 (gentle slope), increment x coordinate by 1 and
choose pixel on or closest to line. For |slope| > 1 (steep slope),
increment y coordinate by 1 and choose pixel on or closest to line.
• But how do we measure “closest”?
Steep Slope vs. Gentle Slope
• So, choose which coordinate to increment and the point to
start from wisely
Strategy 1: Explicit Line Equation
• Slope-intercept form: y=mx+c, where
• Find out m and c for once
• For |m| <=1 find out no. of pixels to be shaded, for every x
find out the value for y
00 mxyb 
x
y
xx
yy
m
end
end






0
0
Strategy 2: Parametric Form
• P(t)=(1-t)P0+tP1
where P(0)=P0 and P(1)=P1
• Putting t=0 gives the first point and putting t=1 gives the
second point, so, t varies from 0 to 1 i.e. 0<=t<=1
• The value of t represents the step size to be used.
• It is one unit of movement in the given direction
• Smaller t means smaller step.
• Smaller step means more steps are required to complete
the line
• More steps, i.e. smaller steps, is better resolution
• 1/t = number of “subdivisions” of the line
void DrawLine(Point p1, Point p2)
{
for(float t = 0.0; t <= 1.0; t += 0.005)
{
float newX = p1.X * (1.0-t) + p2.X * t;
float newY = p1.Y * (1.0-t) + p2.Y * t;
point(newX, newY);
}
}
Using t implies any resolution of the line is normalized between 0 and 1
Implementing Parametric Form
The previous two strategies
• Every value of (x,y) pair is independent of the calculations
performed for the previous pair
• Interpolate instead, do incremental calculations
• Expensive to implement since it uses floating point
multiplication for finding each value of y
• Get rid of expensive operations
Strategy 3: Incremental Algorithms
DDA – Digital Differential Analyzer Algorithm
(works for lines of both steep and gentle slopes)
1. Start with starting and ending coordinates of the line:
• (x0, y0) and (x1, y1)
2. Color first pixel (round to nearest integer)
3. Suppose x1-x0 > y1-y0 (gentle slope)
• numsteps=x1-x0 steps (# pixels to be colored)
• else there will be y1-y0 steps i.e. numsteps=y1-y0
4. Set x=x0, y=y0
5. Set stepX= (x1-x0)/numsteps; stepY= (y1-y0)/numsteps
6. At each step,
• increment x by stepX, and
• increment y by stepY
7. For each step, round off x and y to nearest integer, and color
pixel
DDA Example
• Suppose we want to
draw a line starting at
pixel (2,3) and ending
at pixel (12,8).
• What are the values of
the variables x and y at
each timestep?
• What are the pixels
colored, according to
the DDA algorithm?
numsteps = 12 – 2 = 10
xinc = 10/10 = 1.0
yinc = 5/10 = 0.5
t x y R(x) R(y)
0 2 3 2 3
1 3 3.5 3 4
2 4 4 4 4
3 5 4.5 5 5
4 6 5 6 5
5 7 5.5 7 6
6 8 6 8 6
7 9 6.5 9 7
8 10 7 10 7
9 11 7.5 11 8
10 12 8 12 8
DDAAlgorithm (continued)
• Advantage
• Does not calculate coordinates based on the complete equation
• Disadvantage
• Round-off errors are accumulated, thus line diverges more and
more from actual line
• Round-off operations take time and still uses floating point
additions, both of which are expensive
References
• Computer Graphics with OpenGL, Hearn and Baker,
2010, 4th edition (text book)
• http://www.ltcconline.net/greenl/courses/107/polarparam/p
arameq.htm
• http://cs.brown.edu/courses/
• https://courses.engr.illinois.edu/ece390/lecture/lockwood/
bresenham.gif

More Related Content

What's hot

DDA (digital differential analyzer)
DDA (digital differential analyzer)DDA (digital differential analyzer)
DDA (digital differential analyzer)Inamul Hossain Imran
 
Visible surface determination
Visible  surface determinationVisible  surface determination
Visible surface determinationPatel Punit
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmJyotiraman De
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICSJagan Raja
 
1536 graphics &amp; graphical programming
1536 graphics &amp; graphical  programming1536 graphics &amp; graphical  programming
1536 graphics &amp; graphical programmingDr Fereidoun Dejahang
 
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Aparna Joshi
 
Basics of Linear Hough Transform
Basics of Linear Hough TransformBasics of Linear Hough Transform
Basics of Linear Hough TransformRaj Rana
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2SIMONTHOMAS S
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsJoseph Charles
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Intensity Transformation Functions of image with Matlab
Intensity Transformation Functions of image with Matlab Intensity Transformation Functions of image with Matlab
Intensity Transformation Functions of image with Matlab Shafi Sourov
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithmKKARUNKARTHIK
 
Basics of CT- Lecture 9.ppt
Basics of CT- Lecture 9.pptBasics of CT- Lecture 9.ppt
Basics of CT- Lecture 9.pptMagde Gad
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalAnkit Garg
 

What's hot (20)

DDA (digital differential analyzer)
DDA (digital differential analyzer)DDA (digital differential analyzer)
DDA (digital differential analyzer)
 
Visible surface determination
Visible  surface determinationVisible  surface determination
Visible surface determination
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
 
1536 graphics &amp; graphical programming
1536 graphics &amp; graphical  programming1536 graphics &amp; graphical  programming
1536 graphics &amp; graphical programming
 
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 
visible surface detection
visible surface detectionvisible surface detection
visible surface detection
 
Basics of Linear Hough Transform
Basics of Linear Hough TransformBasics of Linear Hough Transform
Basics of Linear Hough Transform
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Intensity Transformation Functions of image with Matlab
Intensity Transformation Functions of image with Matlab Intensity Transformation Functions of image with Matlab
Intensity Transformation Functions of image with Matlab
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
 
Hidden Surfaces
Hidden SurfacesHidden Surfaces
Hidden Surfaces
 
Basics of CT- Lecture 9.ppt
Basics of CT- Lecture 9.pptBasics of CT- Lecture 9.ppt
Basics of CT- Lecture 9.ppt
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
3 d
3 d3 d
3 d
 

Similar to Lec02 03 rasterization

Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi54MahakBansal
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniyaTutorialsDuniya.com
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014rolly purnomo
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 

Similar to Lec02 03 rasterization (20)

Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Lect14 lines+circles
Lect14 lines+circlesLect14 lines+circles
Lect14 lines+circles
 
Lec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdfLec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdf
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
module 1.pdf
module 1.pdfmodule 1.pdf
module 1.pdf
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniya
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
testpang
testpangtestpang
testpang
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Module 2
Module 2Module 2
Module 2
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 

Lec02 03 rasterization

  • 1. RASTERIZATION Scan Converting a Line Lecture 02-03
  • 2. Graphics Pipeline • The graphics pipeline or rendering pipeline refers to the sequence of steps used to create a 2D raster representation of a 3D scene. • Stages of the graphics pipeline: • Modeling individual Objects using 3D geometric primitives: Traditionally done using triangles, making a wire frame for an object. • Modeling and transformation into world coordinates: Transform from the local coordinate system to the 3d world coordinate system. • Camera transformation: Transform the 3d world coordinate system into the 3d camera coordinate system, with the camera as the origin. • Lighting: Illuminate according to lighting and reflectance. • Projection transformation: Transform the 3d world coordinates into the 2d view of the camera. • Clipping: Geometric primitives that now fall completely outside of the viewing frustum will not be visible and are discarded at this stage. • Scan conversion or rasterization: The process by which the 2D image space representation of the scene is converted into raster format and the correct resulting pixel values are determined. From now on, operations will be carried out on each single pixel. • Texturing, fragment shading: At this stage of the pipeline individual fragments are assigned a color based on values interpolated from the vertices during rasterization, from a texture in memory, or from a shader program.
  • 3. Points • How to draw points in processing? • Coordinates of the screen • top left corner is assigned as origin, going right increases in x to width-1 coordinate, and going down increases in y to the height-1 • The setup() function • Creating a window using size(width, height) • Drawing a point using point(x,y) • Setting point size using strokeWeight(no. of pixels) • Setting color using stroke(colorR, colorG, colorB) • single color value for working with greyscale images, each argument has a value from 0-255 • Changing background color using background() • Once stroke or stroke weight is changed, it affects the primitives used/written after this line of code and not to any of the previously drawn. • How to rasterize a line between two given points?
  • 4. Scan Conversion • ‘Scan conversion’/rasterization is the process of taking geometric shapes and converting them into an array of pixels stored in the framebuffer to be displayed • Or converting from ‘random scan’/vector specification to a raster scan where we specify which pixels are ‘ON’ based on a stored array of pixels • Takes place after clipping occurs • All graphics packages do this at end of the rendering pipeline
  • 5. How does computer draw line? • Screen made of pixels • High-level language specifies line • System must color pixels • There should be • No gaps in adjacent pixels • Pixels close to ideal line • Consistent choices; same pixels in same situations • Smooth looking • Even brightness in all orientations • Same line for as for P0, P1 and P1, P0 • Which pixels to choose?
  • 6. Scan Convert a Line • Finding the next pixel Special cases: • Horizontal Line: • Draw pixel P and increment x coordinate value by 1 to get next pixel. • Vertical Line: • Draw pixel P and increment y coordinate value by 1 to get next pixel. • Diagonal Line: • Draw pixel P and increment both x and y coordinate by 1 to get next pixel. Here |slope|=1 • What should we do in the general case? • For |slope| < 1 (gentle slope), increment x coordinate by 1 and choose pixel on or closest to line. For |slope| > 1 (steep slope), increment y coordinate by 1 and choose pixel on or closest to line. • But how do we measure “closest”?
  • 7. Steep Slope vs. Gentle Slope • So, choose which coordinate to increment and the point to start from wisely
  • 8. Strategy 1: Explicit Line Equation • Slope-intercept form: y=mx+c, where • Find out m and c for once • For |m| <=1 find out no. of pixels to be shaded, for every x find out the value for y 00 mxyb  x y xx yy m end end       0 0
  • 9. Strategy 2: Parametric Form • P(t)=(1-t)P0+tP1 where P(0)=P0 and P(1)=P1 • Putting t=0 gives the first point and putting t=1 gives the second point, so, t varies from 0 to 1 i.e. 0<=t<=1 • The value of t represents the step size to be used. • It is one unit of movement in the given direction • Smaller t means smaller step. • Smaller step means more steps are required to complete the line • More steps, i.e. smaller steps, is better resolution • 1/t = number of “subdivisions” of the line
  • 10. void DrawLine(Point p1, Point p2) { for(float t = 0.0; t <= 1.0; t += 0.005) { float newX = p1.X * (1.0-t) + p2.X * t; float newY = p1.Y * (1.0-t) + p2.Y * t; point(newX, newY); } } Using t implies any resolution of the line is normalized between 0 and 1 Implementing Parametric Form
  • 11. The previous two strategies • Every value of (x,y) pair is independent of the calculations performed for the previous pair • Interpolate instead, do incremental calculations • Expensive to implement since it uses floating point multiplication for finding each value of y • Get rid of expensive operations
  • 12. Strategy 3: Incremental Algorithms DDA – Digital Differential Analyzer Algorithm (works for lines of both steep and gentle slopes) 1. Start with starting and ending coordinates of the line: • (x0, y0) and (x1, y1) 2. Color first pixel (round to nearest integer) 3. Suppose x1-x0 > y1-y0 (gentle slope) • numsteps=x1-x0 steps (# pixels to be colored) • else there will be y1-y0 steps i.e. numsteps=y1-y0 4. Set x=x0, y=y0 5. Set stepX= (x1-x0)/numsteps; stepY= (y1-y0)/numsteps 6. At each step, • increment x by stepX, and • increment y by stepY 7. For each step, round off x and y to nearest integer, and color pixel
  • 13. DDA Example • Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). • What are the values of the variables x and y at each timestep? • What are the pixels colored, according to the DDA algorithm? numsteps = 12 – 2 = 10 xinc = 10/10 = 1.0 yinc = 5/10 = 0.5 t x y R(x) R(y) 0 2 3 2 3 1 3 3.5 3 4 2 4 4 4 4 3 5 4.5 5 5 4 6 5 6 5 5 7 5.5 7 6 6 8 6 8 6 7 9 6.5 9 7 8 10 7 10 7 9 11 7.5 11 8 10 12 8 12 8
  • 14. DDAAlgorithm (continued) • Advantage • Does not calculate coordinates based on the complete equation • Disadvantage • Round-off errors are accumulated, thus line diverges more and more from actual line • Round-off operations take time and still uses floating point additions, both of which are expensive
  • 15. References • Computer Graphics with OpenGL, Hearn and Baker, 2010, 4th edition (text book) • http://www.ltcconline.net/greenl/courses/107/polarparam/p arameq.htm • http://cs.brown.edu/courses/ • https://courses.engr.illinois.edu/ece390/lecture/lockwood/ bresenham.gif