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

What's hot (20)

PPT
String classes and its methods.20
myrajendra
 
PPT
03.Scan Conversion.ppt
RobinAhmedSaikat
 
PPT
2D transformation (Computer Graphics)
Timbal Mayank
 
PPSX
Java Object Oriented Programming
University of Potsdam
 
PDF
Lab manual of Digital image processing using python by khalid Shaikh
khalidsheikh24
 
PPT
Polygon filling
Ankit Garg
 
PPTX
Character generation techniques
Mani Kanth
 
PPTX
Computer graphics - bresenham line drawing algorithm
Ruchi Maurya
 
PPT
Line drawing algo.
Mohd Arif
 
PPTX
Clipping
AMIT VIRAMGAMI
 
PPTX
Animation in Computer Graphics
RinkuNahar
 
PPTX
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
PPT
Virus and Malicious Code Chapter 5
AfiqEfendy Zaen
 
PPTX
Matrix representation- CG.pptx
RubaNagarajan
 
PDF
Notes 2D-Transformation Unit 2 Computer graphics
NANDINI SHARMA
 
PPTX
Interface in java
PhD Research Scholar
 
PDF
Methods in Java
Jussi Pohjolainen
 
PPTX
Output primitives in Computer Graphics
Kamal Acharya
 
PDF
Unit 3
ypnrao
 
DOC
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
String classes and its methods.20
myrajendra
 
03.Scan Conversion.ppt
RobinAhmedSaikat
 
2D transformation (Computer Graphics)
Timbal Mayank
 
Java Object Oriented Programming
University of Potsdam
 
Lab manual of Digital image processing using python by khalid Shaikh
khalidsheikh24
 
Polygon filling
Ankit Garg
 
Character generation techniques
Mani Kanth
 
Computer graphics - bresenham line drawing algorithm
Ruchi Maurya
 
Line drawing algo.
Mohd Arif
 
Clipping
AMIT VIRAMGAMI
 
Animation in Computer Graphics
RinkuNahar
 
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
Virus and Malicious Code Chapter 5
AfiqEfendy Zaen
 
Matrix representation- CG.pptx
RubaNagarajan
 
Notes 2D-Transformation Unit 2 Computer graphics
NANDINI SHARMA
 
Interface in java
PhD Research Scholar
 
Methods in Java
Jussi Pohjolainen
 
Output primitives in Computer Graphics
Kamal Acharya
 
Unit 3
ypnrao
 
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 

Similar to Lec02 03 rasterization (20)

PPTX
L-5 (Line Drawing Algorithms Computer graphics).pptx
JatinSareen6
 
PPTX
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
PPTX
Computer Graphics Unit 1
aravindangc
 
PPT
Lect14 lines+circles
Siddharth Maloo
 
PPT
Unit I-cg.ppt Introduction to Computer Graphics elements
RajeshSukte1
 
PPT
Introduction to Computer Graphics elements
RajeshSukte1
 
PPT
Introduction to Computer Graphics computer
RajeshSukte1
 
PDF
Lec-4_Rendering-1.pdf
RuatiBT20CS014
 
PPTX
Chapter 3 - Part 1 [Autosaved].pptx
Kokebe2
 
PPTX
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
54MahakBansal
 
PPTX
Study on Fundamentals of Raster Scan Graphics
Dr. Chandrakant Divate
 
PDF
Computer Graphics Unit 2
SanthiNivas
 
PDF
scan conversion of point , line and circle
Divy Kumar Gupta
 
PDF
raster algorithm.pdf
Mattupallipardhu
 
PPTX
CG-Lecture3.pptx
lakshitasarika2014
 
PDF
module 1.pdf
KimTaehyung188352
 
PDF
Computer graphics notes 2 tutorials duniya
TutorialsDuniya.com
 
PPT
Line drawing algorithm and antialiasing techniques
Ankit Garg
 
PPTX
Chapter 3 Output Primitives
PrathimaBaliga
 
PPT
1536 graphics &amp; graphical programming
Dr Fereidoun Dejahang
 
L-5 (Line Drawing Algorithms Computer graphics).pptx
JatinSareen6
 
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Computer Graphics Unit 1
aravindangc
 
Lect14 lines+circles
Siddharth Maloo
 
Unit I-cg.ppt Introduction to Computer Graphics elements
RajeshSukte1
 
Introduction to Computer Graphics elements
RajeshSukte1
 
Introduction to Computer Graphics computer
RajeshSukte1
 
Lec-4_Rendering-1.pdf
RuatiBT20CS014
 
Chapter 3 - Part 1 [Autosaved].pptx
Kokebe2
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
54MahakBansal
 
Study on Fundamentals of Raster Scan Graphics
Dr. Chandrakant Divate
 
Computer Graphics Unit 2
SanthiNivas
 
scan conversion of point , line and circle
Divy Kumar Gupta
 
raster algorithm.pdf
Mattupallipardhu
 
CG-Lecture3.pptx
lakshitasarika2014
 
module 1.pdf
KimTaehyung188352
 
Computer graphics notes 2 tutorials duniya
TutorialsDuniya.com
 
Line drawing algorithm and antialiasing techniques
Ankit Garg
 
Chapter 3 Output Primitives
PrathimaBaliga
 
1536 graphics &amp; graphical programming
Dr Fereidoun Dejahang
 
Ad

Recently uploaded (20)

PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
PDF
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Ad

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