SlideShare a Scribd company logo
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

PPT
Three dimensional concepts - Computer Graphics
PPT
Image Sensing & Acquisition
PPTX
PPTX
Computer graphics basic transformation
PPT
Windows and viewport
PPTX
Psuedo color
PPTX
Color Models Computer Graphics
Three dimensional concepts - Computer Graphics
Image Sensing & Acquisition
Computer graphics basic transformation
Windows and viewport
Psuedo color
Color Models Computer Graphics

What's hot (20)

PPTX
Color models
DOCX
Heart disease prediction system
PPTX
Ray tracing
PPTX
Decision tree
PPTX
Clipping computer graphics
PPT
Image formation
PDF
IoT and m2m
PPTX
Spline representations
PPT
Input and Interaction
PPT
Intro to scan conversion
PPT
image enhancement
PPTX
Image Processing Introduction
PDF
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
PPTX
5. gray level transformation
PPTX
Log Transformation in Image Processing with Example
PPTX
3D Display
PPTX
Clipping
PDF
Machine learning Lecture 1
PPT
Digital Image Processing
Color models
Heart disease prediction system
Ray tracing
Decision tree
Clipping computer graphics
Image formation
IoT and m2m
Spline representations
Input and Interaction
Intro to scan conversion
image enhancement
Image Processing Introduction
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
5. gray level transformation
Log Transformation in Image Processing with Example
3D Display
Clipping
Machine learning Lecture 1
Digital Image Processing
Ad

Similar to Lec02 03 rasterization (20)

PDF
Computer graphics notes 2 tutorials duniya
PPTX
Computer Graphics Unit 1
PPTX
Chapter 3 Output Primitives
PPT
Introduction to Computer Graphics elements
PPT
Unit I-cg.ppt Introduction to Computer Graphics elements
PPT
Introduction to Computer Graphics computer
PPT
Implementation
PDF
Computer Graphics Unit 2
PPT
Line drawing algorithm and antialiasing techniques
DOCX
Unit 2 notes
PPT
1536 graphics &amp; graphical programming
PPT
Angel6E25educationmaterial for reference
PDF
Open GL T0074 56 sm3
PDF
PPTX
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
PDF
Open GL T0074 56 sm1
PPT
Lab lecture 1 line_algo
PDF
Unit 2
PPTX
L-5 (Line Drawing Algorithms Computer graphics).pptx
Computer graphics notes 2 tutorials duniya
Computer Graphics Unit 1
Chapter 3 Output Primitives
Introduction to Computer Graphics elements
Unit I-cg.ppt Introduction to Computer Graphics elements
Introduction to Computer Graphics computer
Implementation
Computer Graphics Unit 2
Line drawing algorithm and antialiasing techniques
Unit 2 notes
1536 graphics &amp; graphical programming
Angel6E25educationmaterial for reference
Open GL T0074 56 sm3
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
Open GL T0074 56 sm1
Lab lecture 1 line_algo
Unit 2
L-5 (Line Drawing Algorithms Computer graphics).pptx
Ad

Recently uploaded (20)

PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
assetexplorer- product-overview - presentation
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
Computer Software and OS of computer science of grade 11.pptx
Download FL Studio Crack Latest version 2025 ?
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
iTop VPN Crack Latest Version Full Key 2025
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Autodesk AutoCAD Crack Free Download 2025
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Reimagine Home Health with the Power of Agentic AI​
Complete Guide to Website Development in Malaysia for SMEs
Monitoring Stack: Grafana, Loki & Promtail
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Designing Intelligence for the Shop Floor.pdf
assetexplorer- product-overview - presentation
Odoo Companies in India – Driving Business Transformation.pdf
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Salesforce Agentforce AI Implementation.pdf
Operating system designcfffgfgggggggvggggggggg
wealthsignaloriginal-com-DS-text-... (1).pdf

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