SlideShare a Scribd company logo
Implementation III
Objectives
• Survey Line Drawing Algorithms
• DDA
• Bresenham
2
Rasterization
• Rasterization (scan conversion)
• Determine which pixels that are inside primitive specified by a set of vertices
• Produces a set of fragments
• Fragments have a location (pixel location) and other attributes such color
and texture coordinates that are determined by interpolating values at
vertices
• Pixel colors determined later using color, texture, and other vertex
properties
3
Scan Conversion of Line Segments
• Start with line segment in window coordinates with integer values
for endpoints
• Assume implementation has a write_pixel function
4
y = mx + h
x
y
m
∆
∆
=
DDA Algorithm
•Digital Differential Analyzer
• DDA was a mechanical device for numerical solution of differential equations
• Line y=mx+ h satisfies differential equation
dy/dx = m = ∆y/∆x = y2-y1/x2-x1
•Along scan line ∆x = 1
5
For(x=x1; x<=x2,ix++) {
y+=m;
write_pixel(x, round(y), line_color)
}
Problem
• DDA = for each x plot pixel at closest y
• Problems for steep lines
6
Using Symmetry
• Use for 1 ≥ m ≥ 0
• For m > 1, swap role of x and y
• For each y, plot closest x
7
Bresenham’s Algorithm
•DDA requires one floating point addition per step
•We can eliminate all fp through Bresenham’s
algorithm
•Consider only 1 ≥ m ≥ 0
• Other cases by symmetry
•Assume pixel centers are at half integers
•If we start at a pixel that has been written, there are
only two candidates for the next pixel to be written
into the frame buffer
8
Candidate Pixels
9
1 ≥ m ≥ 0
last pixel
candidates
Note that line could have
passed through any
part of this pixel
Decision Variable
-
10
d = ∆x(b-a)
d is an integer
d > 0 use upper pixel
d < 0 use lower pixel
Incremental Form
• More efficient if we look at dk, the value of the decision variable at x
= k
11
dk+1= dk –2∆y, if dk <0
dk+1= dk –2(∆y- ∆x), otherwise
•For each x, we need do only an integer
addition and a test
•Single instruction on graphics chips
Polygon Scan Conversion
• Scan Conversion = Fill
• How to tell inside from outside
• Convex easy
• Nonsimple difficult
• Odd even test
• Count edge crossings
•Winding number
12
odd-even fill
Winding Number
• Count clockwise encirclements of point
• Alternate definition of inside: inside if winding number ≠ 0
13
winding number = 2
winding number = 1
Filling in the Frame Buffer
• Fill at end of pipeline
• Convex Polygons only
• Nonconvex polygons assumed to have been tessellated
• Shades (colors) have been computed for vertices (Gouraud shading)
• Combine with z-buffer algorithm
• March across scan lines interpolating shades
• Incremental work small
14
Using Interpolation
C1 C2 C3specified by glColor or by vertex shading
C4 determined by interpolating between C1 and C2
C5 determined by interpolating between C2 and C3
interpolate between C4 and C5 along span
15
span
C1
C3
C2
C5
C4
scan line
Flood Fill
•Fill can be done recursively if we know a seed point
located inside (WHITE)
•Scan convert edges into buffer in edge/inside color
(BLACK)
16
flood_fill(int x, int y) {
if(read_pixel(x,y)= = WHITE) {
write_pixel(x,y,BLACK);
flood_fill(x-1, y);
flood_fill(x+1, y);
flood_fill(x, y+1);
flood_fill(x, y-1);
} }
Scan Line Fill
•Can also fill by maintaining a data structure of all
intersections of polygons with scan lines
• Sort by scan line
• Fill each span
17
vertex order generated
by vertex list desired order
Data Structure
18
Aliasing
• Ideal rasterized line should be 1 pixel wide
• Choosing best y for each x (or visa versa) produces aliased raster lines
19
Antialiasing by Area Averaging
•Color multiple pixels for each x depending on
coverage by ideal line
20
original antialiased
magnified
Polygon Aliasing
• Aliasing problems can be serious for polygons
• Jaggedness of edges
• Small polygons neglected
• Need compositing so color
of one polygon does not
totally determine color of
pixel
21
All three polygons should contribute to color

More Related Content

PDF
Specialized indexing for NoSQL Databases like Accumulo and HBase
PPT
PDF
Doc 20180130-wa0004
PPT
Matlab Nn Intro
PDF
Doc 20180130-wa0006
PPTX
Csci101 lect01 first_program
PPTX
Boolean Algebra by SUKHDEEP SINGH
Specialized indexing for NoSQL Databases like Accumulo and HBase
Doc 20180130-wa0004
Matlab Nn Intro
Doc 20180130-wa0006
Csci101 lect01 first_program
Boolean Algebra by SUKHDEEP SINGH

What's hot (19)

PPTX
Md2k 0219 shang
PPTX
IOEfficientParalleMatrixMultiplication_present
PPT
Arrays
DOC
hospital management
PDF
[Question Paper] Fundamentals of Digital Computing (Revised Course) [January ...
PPT
Sparse Matrix and Polynomial
PDF
Fast coputation of Phi(x) inverse
PPTX
Generating code from dags
PPTX
Variables in matlab
PPT
Seed filling algorithm
PPTX
Example of iterative deepening search &amp; bidirectional search
PDF
"Moving CNNs from Academic Theory to Embedded Reality," a Presentation from S...
PPTX
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak Haque
PDF
SIGNATE 国立国会図書館の画像データレイアウト認識 1st place solution
PPSX
Software Metrics
PDF
Deep single view 3 d object reconstruction with visual hull
PPT
Radial Basis Function and Splines.
DOCX
Assignment premier academic writing agency with industry
Md2k 0219 shang
IOEfficientParalleMatrixMultiplication_present
Arrays
hospital management
[Question Paper] Fundamentals of Digital Computing (Revised Course) [January ...
Sparse Matrix and Polynomial
Fast coputation of Phi(x) inverse
Generating code from dags
Variables in matlab
Seed filling algorithm
Example of iterative deepening search &amp; bidirectional search
"Moving CNNs from Academic Theory to Embedded Reality," a Presentation from S...
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak Haque
SIGNATE 国立国会図書館の画像データレイアウト認識 1st place solution
Software Metrics
Deep single view 3 d object reconstruction with visual hull
Radial Basis Function and Splines.
Assignment premier academic writing agency with industry
Ad

Similar to Implementation (20)

PPT
Angel6E25educationmaterial for reference
PDF
Open GL T0074 56 sm3
PPTX
Computer Graphics Unit 1
PPT
Polygon Fill
PPT
1536 graphics &amp; graphical programming
DOCX
Computer graphics question for exam solved
PPTX
Chapter 3 Output Primitives
PPTX
Lec02 03 rasterization
PPTX
Lec02 03 rasterization
PPT
october9.ppt
PPT
Lect14 lines+circles
PPT
03raster 1
PPT
Line drawing algorithm and antialiasing techniques
PDF
Open GL T0074 56 sm1
PDF
Open GL 09 scan conversion
PDF
Computer graphics notes 2 tutorials duniya
PPT
Introduction to Computer Graphics elements
PPT
Unit I-cg.ppt Introduction to Computer Graphics elements
PPT
Introduction to Computer Graphics computer
Angel6E25educationmaterial for reference
Open GL T0074 56 sm3
Computer Graphics Unit 1
Polygon Fill
1536 graphics &amp; graphical programming
Computer graphics question for exam solved
Chapter 3 Output Primitives
Lec02 03 rasterization
Lec02 03 rasterization
october9.ppt
Lect14 lines+circles
03raster 1
Line drawing algorithm and antialiasing techniques
Open GL T0074 56 sm1
Open GL 09 scan conversion
Computer graphics notes 2 tutorials duniya
Introduction to Computer Graphics elements
Unit I-cg.ppt Introduction to Computer Graphics elements
Introduction to Computer Graphics computer
Ad

More from Syed Zaid Irshad (20)

PDF
Data Structures & Algorithms - Spring 2025.pdf
PDF
Operating System.pdf
PDF
DBMS_Lab_Manual_&_Solution
PPTX
Data Structure and Algorithms.pptx
PPTX
Design and Analysis of Algorithms.pptx
PPTX
Professional Issues in Computing
PDF
Reduce course notes class xi
PDF
Reduce course notes class xii
PDF
Introduction to Database
PDF
C Language
PDF
Flowchart
PDF
Algorithm Pseudo
PDF
Computer Programming
PDF
ICS 2nd Year Book Introduction
PDF
Security, Copyright and the Law
PDF
Computer Architecture
PDF
Data Communication
PDF
Information Networks
PDF
Basic Concept of Information Technology
PDF
Introduction to ICS 1st Year Book
Data Structures & Algorithms - Spring 2025.pdf
Operating System.pdf
DBMS_Lab_Manual_&_Solution
Data Structure and Algorithms.pptx
Design and Analysis of Algorithms.pptx
Professional Issues in Computing
Reduce course notes class xi
Reduce course notes class xii
Introduction to Database
C Language
Flowchart
Algorithm Pseudo
Computer Programming
ICS 2nd Year Book Introduction
Security, Copyright and the Law
Computer Architecture
Data Communication
Information Networks
Basic Concept of Information Technology
Introduction to ICS 1st Year Book

Recently uploaded (20)

PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPT
introduction to datamining and warehousing
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPT
Total quality management ppt for engineering students
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Artificial Intelligence
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Abrasive, erosive and cavitation wear.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Visual Aids for Exploratory Data Analysis.pdf
Current and future trends in Computer Vision.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
introduction to datamining and warehousing
Categorization of Factors Affecting Classification Algorithms Selection
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Soil Improvement Techniques Note - Rabbi
Automation-in-Manufacturing-Chapter-Introduction.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Total quality management ppt for engineering students
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Artificial Intelligence
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Information Storage and Retrieval Techniques Unit III
Abrasive, erosive and cavitation wear.pdf

Implementation

  • 2. Objectives • Survey Line Drawing Algorithms • DDA • Bresenham 2
  • 3. Rasterization • Rasterization (scan conversion) • Determine which pixels that are inside primitive specified by a set of vertices • Produces a set of fragments • Fragments have a location (pixel location) and other attributes such color and texture coordinates that are determined by interpolating values at vertices • Pixel colors determined later using color, texture, and other vertex properties 3
  • 4. Scan Conversion of Line Segments • Start with line segment in window coordinates with integer values for endpoints • Assume implementation has a write_pixel function 4 y = mx + h x y m ∆ ∆ =
  • 5. DDA Algorithm •Digital Differential Analyzer • DDA was a mechanical device for numerical solution of differential equations • Line y=mx+ h satisfies differential equation dy/dx = m = ∆y/∆x = y2-y1/x2-x1 •Along scan line ∆x = 1 5 For(x=x1; x<=x2,ix++) { y+=m; write_pixel(x, round(y), line_color) }
  • 6. Problem • DDA = for each x plot pixel at closest y • Problems for steep lines 6
  • 7. Using Symmetry • Use for 1 ≥ m ≥ 0 • For m > 1, swap role of x and y • For each y, plot closest x 7
  • 8. Bresenham’s Algorithm •DDA requires one floating point addition per step •We can eliminate all fp through Bresenham’s algorithm •Consider only 1 ≥ m ≥ 0 • Other cases by symmetry •Assume pixel centers are at half integers •If we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer 8
  • 9. Candidate Pixels 9 1 ≥ m ≥ 0 last pixel candidates Note that line could have passed through any part of this pixel
  • 10. Decision Variable - 10 d = ∆x(b-a) d is an integer d > 0 use upper pixel d < 0 use lower pixel
  • 11. Incremental Form • More efficient if we look at dk, the value of the decision variable at x = k 11 dk+1= dk –2∆y, if dk <0 dk+1= dk –2(∆y- ∆x), otherwise •For each x, we need do only an integer addition and a test •Single instruction on graphics chips
  • 12. Polygon Scan Conversion • Scan Conversion = Fill • How to tell inside from outside • Convex easy • Nonsimple difficult • Odd even test • Count edge crossings •Winding number 12 odd-even fill
  • 13. Winding Number • Count clockwise encirclements of point • Alternate definition of inside: inside if winding number ≠ 0 13 winding number = 2 winding number = 1
  • 14. Filling in the Frame Buffer • Fill at end of pipeline • Convex Polygons only • Nonconvex polygons assumed to have been tessellated • Shades (colors) have been computed for vertices (Gouraud shading) • Combine with z-buffer algorithm • March across scan lines interpolating shades • Incremental work small 14
  • 15. Using Interpolation C1 C2 C3specified by glColor or by vertex shading C4 determined by interpolating between C1 and C2 C5 determined by interpolating between C2 and C3 interpolate between C4 and C5 along span 15 span C1 C3 C2 C5 C4 scan line
  • 16. Flood Fill •Fill can be done recursively if we know a seed point located inside (WHITE) •Scan convert edges into buffer in edge/inside color (BLACK) 16 flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }
  • 17. Scan Line Fill •Can also fill by maintaining a data structure of all intersections of polygons with scan lines • Sort by scan line • Fill each span 17 vertex order generated by vertex list desired order
  • 19. Aliasing • Ideal rasterized line should be 1 pixel wide • Choosing best y for each x (or visa versa) produces aliased raster lines 19
  • 20. Antialiasing by Area Averaging •Color multiple pixels for each x depending on coverage by ideal line 20 original antialiased magnified
  • 21. Polygon Aliasing • Aliasing problems can be serious for polygons • Jaggedness of edges • Small polygons neglected • Need compositing so color of one polygon does not totally determine color of pixel 21 All three polygons should contribute to color