cs475m - computer graphics › ~paragc › teaching › 2016 › ... · cs475m - computer graphics...
TRANSCRIPT
![Page 1: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/1.jpg)
CS475m - Computer Graphics
Lecture 1 : Rasterization Basics
![Page 2: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/2.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image FormationLight Source
Camera
Image
World
![Page 3: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/3.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image FormationLight Source
Camera
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
![Page 4: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/4.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Point Light Source
Camera
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
Image Formation
![Page 5: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/5.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Formation
Camera
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
● In this model can you reason about:
— Shadows?
— Area light sources?
— Diffraction?
— Energy transfer?
Point Light Source
![Page 6: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/6.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Formation
Camera
Image Model
World
Reflected Ray
Incident Ray
Transmitted Ray
Point Light Source
![Page 7: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/7.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image ModelHow is this image drawn on the computer screen?
![Page 8: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/8.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image ModelAn image is an array of raster elements called pixels.
![Page 9: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/9.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image ModelAn image is an array of raster elements called pixels. Every pixel has at least a colour value.
![Page 10: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/10.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image ModelLet's take a closer look.
![Page 11: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/11.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Model
How is the sphere drawn using the pixels?
![Page 12: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/12.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Model
To draw a geometrical figure...
![Page 13: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/13.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Model
...we assign the correct pixels with the correct colour. This process is rasterization.
![Page 14: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/14.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Image Model
Continue the pixel colouring to get regions filled with colour.
![Page 15: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/15.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Why this image model?
Input
Processor
Framebuffer
Display
The framebuffer is a memory buffer storing the colour value for each pixel displayed.
![Page 16: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/16.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Why this image model?
Input
Processor
Framebuffer
Display
So the image model mimics the memory model from hardware.
![Page 17: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/17.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Why this image model?
Input
Processor
Framebuffer
Display
So the image model mimics the memory model from hardware.
An alternate image model is a vector image model.
![Page 18: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/18.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to colour the correct pixels?
function line(int x0, int x1, int y0, int y1) int deltax = x1 x0 int deltay = y1 y0 float error = 0 float deltaerr = deltay / deltax
// Assume deltax != 0 (line is not vertical), // note that this division needs to be done in a way
that preserves the fractional part int y = y0 for x = x0 to x1 plot(x,y) error = error + deltaerr if error ≥ 0.5 then y = y + 1 error = error 1.0
Bresenham's Line Drawing Algorithm
O(0,0)
(x1,y1)
(x0, y0)
X
Y
![Page 19: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/19.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to colour the correct pixels?
Bresenham's Line Drawing Algorithm
● Extension for all line directions.
● Optimize.
● Demo
● Curves read!
O(0,0)
(x1,y1)
(x0, y0)
X
Yfunction line(int x0, int x1, int y0, int y1) int deltax = x1 x0 int deltay = y1 y0 float error = 0 float deltaerr = deltay / deltax
// Assume deltax != 0 (line is not vertical), // note that this division needs to be done in a way
that preserves the fractional part int y = y0 for x = x0 to x1 plot(x,y) error = error + deltaerr if error ≥ 0.5 then y = y + 1 error = error 1.0
![Page 20: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/20.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to fill pixels?O(0,0) X
Y
![Page 21: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/21.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to fill pixels?O(0,0) X
Y
![Page 22: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/22.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to fill pixels?
![Page 23: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/23.jpg)
CS475m: Lecture 1 Parag Chaudhuri
How to fill pixels?
Scanfill Algorithm
O(0,0) X
Y
![Page 24: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/24.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Edge Ymin
Ymax
X for Y=Y
min
1/m
e2
V3
V2
X3
1/m2
e3
V3
V4
X3
1/m3
e1
V1
V2
X1
1/m1
e5
V1
V5
X1
1/m5
e4
V4
V5
X4
1/m4
How to fill pixels – Scanfill Algorithm
V1
V2
V5
V4
V3e1
e4
e3
e2
e5
O(0,0) X
Y
The Edge List
● Edges in the edge list become active when the ycoordinate of the current scan line matches their Ymin value.
● First intersection point between an active edge and a scan line is always the endpoint corresponding to Ymin.
![Page 25: CS475m - Computer Graphics › ~paragc › teaching › 2016 › ... · CS475m - Computer Graphics Lecture 1 : Rasterization Basics. CS475m: Lecture 1 Parag Chaudhuri Image Formation](https://reader033.vdocuments.site/reader033/viewer/2022060500/5f1aac4d06f7d03e834d98bb/html5/thumbnails/25.jpg)
CS475m: Lecture 1 Parag Chaudhuri
Inside / Outside
Special Cases
How to fill pixels – Scanfill Algorithm
● For monotonically increasing/decreasing edges across a shared vertex count one intersection.
● Else count two.
● Ignore horizontal edges.