Subodh Kumar IIT Delhi - ERNETsubodh/courses/CSL781/pdfslides/... · 2010. 2. 4. · Subodh Kumar...

Post on 27-Sep-2020

8 views 0 download

Transcript of Subodh Kumar IIT Delhi - ERNETsubodh/courses/CSL781/pdfslides/... · 2010. 2. 4. · Subodh Kumar...

Computer Graphics

Subodh Kumar

Dept of Computer Sc. & Engg.IIT Delhi

Thursday 4 February 2010

Pixel/Screen Coordinates

Thursday 4 February 2010

Pixel/Screen Coordinates

Thursday 4 February 2010

Pixel/Screen Coordinates

Xscreen = 0 1 w-1

Thursday 4 February 2010

Pixel/Screen Coordinates

Xscreen = 0 1 w-1

Caution: In OpenGL this is X = 0, pixel centers are at int + .5

Thursday 4 February 2010

Polygon RasterizationDraw pixels “intersected” by polygon

But one color per pixel..And 2D polygon?

Can iterate over rows (scan lines) Find intersection of scan-lines with edges

All lines and edges?

Thursday 4 February 2010

Polygon RasterizationDraw pixels “intersected” by polygon

But one color per pixel..And 2D polygon?

Can iterate over rows (scan lines) Find intersection of scan-lines with edges

All lines and edges?

Thursday 4 February 2010

Triangle Rasterization Issues

Sliver problem

Thursday 4 February 2010

Animating Slivers

Triangle Rasterization Issues

Thursday 4 February 2010

Triangle Rasterization Issues

Shared Edge Ownership

Thursday 4 February 2010

Polygon Rasterization Rules

Draw pixel, if center inside polygonWhat if it is at an edge?Draw on left edge, Skip on right edgeUnless Horizontal

Then, draw a bottom edge, skip a top edge

Find lo, hi y (scanline)For y=lo to hi: Find left extreme (of span) Find right extreme (of span) For left to right, draw pixel

Thursday 4 February 2010

Triangle Rasterization

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extreme

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)Which two?

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)Which two?

Start with two at the lowest vertex

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)Which two?

Start with two at the lowest vertex What if there are two lowest vertices?

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)Which two?

Start with two at the lowest vertex What if there are two lowest vertices?

When an edge ends (at a vertex), replace edge

Thursday 4 February 2010

Triangle Rasterization

For a scan line: find Left extremeRemember from previous line:

StartX = StartXprevious+ 1/m

Similarly find Right extreme Extrema are on two edges

(sometimes at vertices)Which two?

Start with two at the lowest vertex What if there are two lowest vertices?

When an edge ends (at a vertex), replace edge What if both edges end?

Thursday 4 February 2010

General Polygon Rasterization

Thursday 4 February 2010

General Polygon Rasterization

Multiple spans

Thursday 4 February 2010

General Polygon Rasterization

Multiple spans

B

CD

E

FG

I H

J

AThursday 4 February 2010

General Polygon Rasterization

Multiple spans

B

CD

E

FG

I H

J

AThursday 4 February 2010

General Polygon Rasterization

Multiple spans

B

CD

E

FG

I H

J

AThursday 4 February 2010

General Polygon Rasterization

Multiple spansCount parity

B

CD

E

FG

I H

J

AThursday 4 February 2010

General Polygon Rasterization

Multiple spansCount parity

How do you count vertex intersections?

B

CD

E

FG

I H

J

AThursday 4 February 2010

General Polygon Rasterization

Multiple spansCount parity

How do you count vertex intersections?

Divide into triangles

B

CD

E

FG

I H

J

AThursday 4 February 2010

Triangulation

Draw horizontal line at each vertexAssume no two vertices have the

same YPerturb if assumption not true

Draw diagonals of trapezoids Decomposed into monotone

polygons Triangulate monotone polygon O(n lg* n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Triangulating Monotone Polygons Process vertices from low to high Push first (lowest two) vertices on a stack For each vi

If vi and top are on the same chain: Form diagonal with the top and pop until possible Finally, push vi

Otherwise savetop := top Form diagonal with the top and pop until possible Finally, push savetop and vi

O(n)

Thursday 4 February 2010

Edge Equations

Edge equation (line equation)Defines two half-spaces:

Thursday 4 February 2010

Triangle Evaluation

Triangle = intersection of three positive half-spaces:

A1x + B1y + C1 < 0

A2x + B

2y + C2 < 0

A 3x +

B3y

+ C

3 < 0

A1x + B1y + C1 > 0

A 3x +

B3y

+ C

3 > 0 A

2x + B2y + C

2 > 0

Thursday 4 February 2010

Evaluate Edge Equations

Plug in pixels’ x,y into the equationIf F(x,y) > 0, draw

+++-

--

Thursday 4 February 2010

Triangle Rasterization

Thursday 4 February 2010

Triangle Rasterization Setup:

Find inverse of edge slopesFind bounding box

Thursday 4 February 2010

Triangle Rasterization Setup:

Find inverse of edge slopesFind bounding box

Rasterize: Initialize left, right intersectionFrom Bounding Box bottom to Top:

Update left, right intersectionRound up or downFill span

Thursday 4 February 2010

Triangle Rasterization Setup:

Find inverse of edge slopesFind bounding box

Rasterize: Initialize left, right intersectionFrom Bounding Box bottom to Top:

Update left, right intersectionRound up or downFill span

Interpolate Z, Color?Do in fragment shaderFill span = create fragment

Thursday 4 February 2010

Triangle Rasterization, Really

Multiple rasterizers?Blocked or Strided

Create tiles of fragmentsIn parallel, divide tiles into

sub-tilesEach sub-tile shaded

togetherMask to turn off uncovered

tiles

Thursday 4 February 2010

Triangle Rasterization, Really

Multiple rasterizers?Blocked or Strided

Create tiles of fragmentsIn parallel, divide tiles into

sub-tilesEach sub-tile shaded

togetherMask to turn off uncovered

tiles

Thursday 4 February 2010

Triangle Rasterization, Really

Multiple rasterizers?Blocked or Strided

Create tiles of fragmentsIn parallel, divide tiles into

sub-tilesEach sub-tile shaded

togetherMask to turn off uncovered

tiles

Thursday 4 February 2010

Triangle Rasterization, Really

Multiple rasterizers?Blocked or Strided

Create tiles of fragmentsIn parallel, divide tiles into

sub-tilesEach sub-tile shaded

togetherMask to turn off uncovered

tiles

Partially covered sub-tile

Fully covered sub-tile

Thursday 4 February 2010

Multi-sampling

An attempt to increase resolutionAnti-aliasing: more on this later

Thursday 4 February 2010

Multi-sampling

An attempt to increase resolutionAnti-aliasing: more on this later

Thursday 4 February 2010

Multi-sampling

An attempt to increase resolutionAnti-aliasing: more on this later

Thursday 4 February 2010

Multi-sampling

An attempt to increase resolutionAnti-aliasing: more on this later

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0]

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0]

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0]

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Point Drawing

Draw [X0, Y0] of a certain size

Thursday 4 February 2010

Line Drawing

Draw a lineStart at [X0, Y0]

End at [X1, Y1]

Thursday 4 February 2010

Line Drawing

Draw a lineStart at [X0, Y0]

End at [X1, Y1]

Thursday 4 February 2010

Line Drawing

Draw a lineStart at [X0, Y0]

End at [X1, Y1]

Thursday 4 February 2010

Line Drawing

Draw a lineStart at [X0, Y0]

End at [X1, Y1]

Thursday 4 February 2010