Rasterization CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain http://iloveshaders.blogspot.com/2011/05/how-rasterization-process-works.html
Render [ren-der]: The process of generating an image from a description of a scene by means of a computer program https://en.wikipedia.org/wiki/Rendering_(computer_graphics) 2 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Two Ways to Render an Image 3 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Two Ways to Render an Image Projection: 3D description to 2D description 4 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Two Ways to Render an Image Rasterization http://iloveshaders.blogspot.com/2011/05/how-rasterization-process-works.html 5 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Two Ways to Render an Image Raytracing http://upload.wikimedia.org/wikipedia/commons/8/83/Ray_trace_diagram.svg 6 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Rasterization 7 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Rasterize [rastərʌɪz]: Rasterize [rastərʌɪz] : To convert vector data to raster – pixel or dot – format. To convert vector data to raster format. 8 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Rasterization Process “A triangle is here, a circle “This pixel is yellow…” is there, …” 9 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Scan Conversion Figuring out which pixels to shade. 10 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
The Basics: Framebuffer 11 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
The Basics: Framebuffer Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel Pixel 12 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Framebuffer Coordinates + y Pixel Center (2,1) (1,1) (0,0) + x 13 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Problem + y + x 14 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
The Basics: Scan Conversion + y + x 15 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
The Basics: Scan Conversion + y + x 16 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Convention + y Must intersect diamond + x 17 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Convention + y Must intersect diamond + x 18 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Desirable Properties • Fast • Simple • Integer arithmetic 19 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm • Introduced in 1967 • Best-fit approximation under some conditions 20 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm • Introduced in 1967 Variation by Pitteway (1967) “Midpoint Algorithm” • Best-fit approximation under some conditions 21 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm • Equation of a line 22 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm • Equation of a line Assumption: 23 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm • Equation of a line Assumption: Easy fix via rotation/reflection 24 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Stategy Every step: increment x • Keep track of “error” ϵ • At every step accumulate • 𝜗 ← 𝜗 + 𝑛 • ' If 𝜗 ≥ • ( Increment y • Reset 𝜗 ← 𝜗 + 𝑛 − 1 • Start with 𝜗 = 𝑛 𝜗 • 1 25 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝜗 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 + 𝒏 − 𝟐 else 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 1 26 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝜗 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 + 𝒏 − 𝟐 else 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 1 27 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝜗 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 1 28 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝜗 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 (𝑦0,𝑧0) 𝒚 ← 𝒚 + 𝟐 𝑦,𝑧 29 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝑦,𝑧 𝜗 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 (𝑦0,𝑧0) 𝒚 ← 𝒚 + 𝟐 30 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝑦,𝑧 𝜗 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 (𝑦0,𝑧0) 𝒚 ← 𝒚 + 𝟐 31 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm 𝜗 Algorithm line( 𝒚𝟏, 𝒛𝟏,𝒚𝟐, 𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝑦,𝑧 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) if 𝝑 > 𝟐 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 (𝑦0,𝑧0) 𝒚 ← 𝒚 + 𝟐 32 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm line( 𝒚𝟏, 𝒛𝟏, 𝒚𝟐,𝒛𝟐 ) 𝒚 ← 𝒚𝟏 𝐳 ← 𝒛𝟏 𝝑 = 𝒏 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) 𝟐 if 𝝑 > 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 33 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm line( 𝒚𝟏, 𝒛𝟏, 𝒚𝟐,𝒛𝟐 ) => 𝜗 = 𝑛 = 𝒚 ← 𝒚𝟏 =? ⇒ Δ𝑦 𝜗 = Δ𝑧 𝐳 ← 𝒛𝟏 ⇒ 2Δ𝑦 𝜗 = 2Δ𝑧 𝝑 = 𝒏 Use 𝑒 = 2Δ𝑦 𝜗 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) 𝟐 if 𝝑 > 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 34 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm line( 𝒚𝟏, 𝒛𝟏, 𝒚𝟐,𝒛𝟐 ) => 𝜗 = 𝑛 = 𝒚 ← 𝒚𝟏 =? ⇒ Δ𝑦 𝜗 = Δ𝑧 𝐳 ← 𝒛𝟏 ⇒ 2Δ𝑦 𝜗 = 2Δ𝑧 𝒆 = 𝟑𝚬𝐳 Use 𝑒 = 2Δ𝑦 𝜗 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) 𝟐 if 𝝑 > 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 35 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Bresenham’s Algorithm line( 𝒚𝟏, 𝒛𝟏, 𝒚𝟐,𝒛𝟐 ) ' 𝜗 > 𝒚 ← 𝒚𝟏 ( ⇒ 2Δ𝑦 𝜗 > Δx 𝐳 ← 𝒛𝟏 ⇒ 𝑒 > Δ𝑦 𝒆 = 𝟑𝚬𝐳 while 𝒚 < 𝒚𝟐 pixel( 𝒚, 𝒛 ) 𝟐 if 𝝑 > 𝟑 𝒛 ← 𝒛 + 𝟐 𝝑 ← 𝝑 − 𝟐 𝝑 ← 𝝑 + 𝒏 𝒚 ← 𝒚 + 𝟐 36 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Recommend
More recommend