Docsity

Lecture Slides on Rasterization - Interactive Computer Graphics | CS 418, Study notes of Computer Graphics

Toggle sidebar
bg1
Rasterization
Converts
• lines and triangles
• with floating point vertices
• in viewport (screen) coordinates
into
•pixels
• with integer coordinates
• in viewport (screen) coordinates
pixels centered
at grid
vertices,
not grid cells
pixels centered
at grid
vertices,
not grid cells
Line Rasterization
• Need to rasterize lines
between any two clipped
screen points, from (x0,y0)
to (x1,y1)
• Only rasterize lines from
the origin to a point in the
first octant
• Translate start vertex to
origin
• Reflect end vertex into first
octant
(x0,y0)
(x1,y1)
(x1-x0,y1-y0)
(x0-x1,
y0-y1)
Line Rasterization
• How to rasterize a line
from (0,0) to (4,3)
• Pixel (0,0) and (4,3) easy
• One pixel for each integer
x-coordinate
• Pixel’s y-coordinate
closest to line
• If line equal distance
between two pixels, pick
on arbitrarily but
consistently
01234
0
1
2
3
4
?
?
Midpoint Algorithm
• Which pixel should be
plotted next?
–East?
– Northeast?
NE
E
pf3
pf4
pf5

Partial preview of the text

Download Lecture Slides on Rasterization - Interactive Computer Graphics | CS 418 and more Study notes Computer Graphics in PDF only on Docsity!

Rasterization Converts•^

lines and triangles

-^

with floating point vertices

-^

in viewport (screen) coordinates into•^

pixels

-^

with integer coordinates

-^

in viewport (screen) coordinates

pixels centered

at gridvertices, pixels centerednot grid cells

at gridvertices, not grid cells

Line Rasterization •^

Need to rasterize linesbetween any two clippedscreen points, from (

x^0

, y

to (

x^1

, y

•^

Only rasterize lines fromthe origin to a point in thefirst octant

-^

Translate start vertex toorigin

-^

Reflect end vertex into firstoctant

( x

, y 0

) 0

( x^1

, y 1

) ( x

-x 1

,^0 y^1

-y^0

)

( x

-x 0

, 1 y-y^0

) 1

Line Rasterization •^

How to rasterize a linefrom (0,0) to (4,3)

-^

Pixel (0,0) and (4,3) easy

-^

One pixel for each integerx-coordinate

-^

Pixel’s y-coordinateclosest to line

-^

If line equal distancebetween two pixels, pickon arbitrarily butconsistently

0

1

2

3

4

4 3 2 1 0

Midpoint Algorithm •^

Which pixel should beplotted next?– East?– Northeast?

NE E

Midpoint Algorithm •^

Which pixel should beplotted next?– East?– Northeast?

-^

Line equation

y^

mx

b

m

y^1

y

x^1

x

b^

y

0

–^

mx

0

f (

x ,

y ) =

mx

b

y

NE M E

f^ < 0

f^

Midpoint Algorithm •^

Which pixel should beplotted next?– East?– Northeast?

-^

Line equation

y^

mx

b

m

y^1

y

x^1

x

b^

=^

y^0

mx

0

f (

x ,

y ) =

mx

b

y

•^

f (

M

Æ

NE

•^

f (

M

)^

Æ

E

NE M E

Pixel Increments f (

x ,

y )

mx

b

y

M

= P

f (

M

)^

f (

x +1,

y +½)

m

( x

b

y +½)

mx

m

b

y

mx

b

y + m

f (

P

m

f (

E

)^

f (

x +1,

y )

f (

P

m

f (

NE

)^

f (

x +1,

y +1)

f (

P

m

f (0,0)

b

NE M E

P

Midpoint Increments f (

M

)^

f (

P

m

f (

M

) E

f (

x +2,

y +½)

m

( x

b

y +½)

f (

P

m

f (

M

m

f (

M

NE

f (

x +2,

y +1½)

m

( x

b

y +1½)

f (

P

m

f (

M

m

f (1, ½) =

m

b

NE M E

P

NE ENE EE

(^2) M

E M

NE

PolygonRasterization •^

Ignore horizontal lines

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

PolygonRasterization •^

Ignore horizontal lines

-^

Sort edges by smallery coordinate

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

For each scanline…

-^

Add edges wherey = ymin

-^

Sorted by x

-^

Then by dx/dy

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization Plotting rules for when

segments lie on pixels

  1. Plot lefts2. Don’t plot rights3. Plot bottoms4. Don’t plot tops

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

y = 1

-^

Delete y = ymax edges

-^

Update x

-^

Add y = ymin edges

-^

For each pair x

,x 0

, plot 1

from ceil(x

to ceil(x

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

y = 2

-^

Delete y = ymax edges

-^

Update x

-^

Add y = ymin edges

-^

For each pair x

,x 0

, plot 1

from ceil(x

to ceil(x

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

y = 3

-^

Delete y = ymax edges

-^

Update x

-^

Add y = ymin edges

-^

For each pair x

,x 0

, plot 1

from ceil(x

to ceil(x

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

y = 4

-^

Delete y = ymax edges

-^

Update x

-^

Add y = ymin edges

-^

For each pair x

,x 0

, plot 1

from ceil(x

to ceil(x

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

E

F

G

PolygonRasterization •^

y = 9

-^

Delete y = ymax edges

-^

Update x

-^

Add y = ymin edges

-^

For each pair x

,x 0

, plot 1

from ceil(x

to ceil(x

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

F

G

E

Gouraud Interpolation •^

Flat shading– Per face normals– Color jumps across edge– Human visual perception

accentuates edges

•^

Smooth shading– Per vertex normals– Colors similar across edge– Edges become harder to

discern

Perception

Gouraud Interpolation •^

Keep track of R, G, B atedge endpoints

-^

Compute dR/dy, dG/dyand dB/dy per edge

-^

Compute dR/dx, dG/dxand dB/dx at eachscanline

-^

Color each pixelR += dR/dxG += dG/dxB += dB/dx

0

1

2

3

4

5

6

7

8

9

9 8 7 6 5 4 3 2 1 0

A

B

C

D

F

G

E