• Tidak ada hasil yang ditemukan

Computer Graphics

N/A
N/A
Protected

Academic year: 2024

Membagikan "Computer Graphics"

Copied!
30
0
0

Teks penuh

(1)

Computer Graphics Computer Graphics Computer Graphics Computer Graphics Computer Graphics Computer Graphics Computer Graphics Computer Graphics

Subodh

Subodh KumarKumar Dept of Computer Sc. &

Dept of Computer Sc. & EnggEngg.. IIT Delhi

IIT Delhi

(2)

Pixel/Screen Coordinates Pixel/Screen CoordinatesPixel/Screen Coordinates Pixel/Screen Coordinates Pixel/Screen Coordinates Pixel/Screen CoordinatesPixel/Screen Coordinates Pixel/Screen Coordinates

Xscreen = 0 1 w-1

Caution:

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

(3)

Drawing Drawing Drawing Drawing Drawing DrawingDrawing Drawing

Draw a lineDraw a line

Start at [XStart at [X00, Y, Y00]]

End at [XEnd at [X11, Y, Y11]]

(4)

Drawing Drawing Drawing Drawing Drawing DrawingDrawing Drawing

Draw a lineDraw a line

Start at [XStart at [X00, Y, Y00]]

End at [XEnd at [X11, Y, Y11]]

(5)

Drawing Drawing Drawing Drawing Drawing DrawingDrawing Drawing

Draw line: [XDraw line: [X00, Y, Y00] TO [X] TO [X11, Y, Y11]]

mitered

bevelled

rounded

Endcap?

(6)

Drawing Drawing Drawing Drawing Drawing DrawingDrawing Drawing

Draw line [1, 1] TO [8, 1]Draw line [1, 1] TO [8, 1]

7 pixels long7 pixels long

(7)

Line Drawing Line DrawingLine Drawing Line Drawing Line Drawing Line Drawing Line Drawing Line Drawing

Which pixels to drawWhich pixels to draw

How thick is the lineHow thick is the line

How long is the lineHow long is the line

How are the ends drawnHow are the ends drawn

Do you allow overdrawDo you allow overdraw

Which direction is the line drawn inWhich direction is the line drawn in

What color should they beWhat color should they be

Similar issues exist for drawing other Similar issues exist for drawing other shapes

shapes

(8)

Line Drawing Simplified Line Drawing Simplified Line Drawing Simplified Line Drawing Simplified Line Drawing Simplified Line Drawing SimplifiedLine Drawing Simplified Line Drawing Simplified

Draw pixel ifDraw pixel if

Line is close to itLine is close to it

ieie, lies in the circle, lies in the circle

Or, the diamondOr, the diamond

Draw pixel if:Draw pixel if:

Line exits diamondLine exits diamond

What if line does not exit What if line does not exit the diamond?

the diamond?

What if line straddles or What if line straddles or ends at a diamond edge ends at a diamond edge

(9)

Perturb/Snap End Perturb/Snap End Perturb/Snap End Perturb/Snap End Perturb/Snap End Perturb/Snap End Perturb/Snap End

Perturb/Snap End---pointspointspointspointspointspointspointspoints

(10)

Efficient Line Drawing Efficient Line DrawingEfficient Line Drawing Efficient Line Drawing Efficient Line Drawing Efficient Line DrawingEfficient Line Drawing Efficient Line Drawing

Proceed in the direction of smaller slopeProceed in the direction of smaller slope

DDA: Digital Difference AnalyzerDDA: Digital Difference Analyzer

Y = Y = mmXX + i+ i

mm(x+1) + i, (x+1) + i, mm(x+2) + i (x+2) + i

Successively add Successively add mm to y and round itto y and round it

Bresenham’Bresenhamss midpoint algorithmmidpoint algorithm

Which next pixels are the closest to the lineWhich next pixels are the closest to the line

aXaX + + bYbY + c = 0+ c = 0

Useful for curves as wellUseful for curves as well

(11)

Bresenham Bresenham Bresenham Bresenham Bresenham Bresenham Bresenham

Bresenham’’’’’’’’ssssssss AlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithm

If slope in [If slope in [--1:1]1:1]

3 possibilities3 possibilities

(12)

Bresenham Bresenham Bresenham Bresenham Bresenham Bresenham Bresenham

Bresenham’’’’’’’’ssssssss AlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithmAlgorithm

If slope in [If slope in [--1:1]1:1]

3 possibilities3 possibilities

If slope in [0:1]?If slope in [0:1]?

On which side of On which side of the next mid

the next mid--point point does the line lie?

does the line lie?

(13)

Locate Mid Locate Mid Locate Mid Locate Mid Locate Mid Locate MidLocate Mid

Locate Mid---pointpointpointpointpointpointpointpoint

Y = Y = mmXX + i+ i

yy = = m m (x+1) + i(x+1) + i

> y+.5?> y+.5?

Consider:Consider:

F(x,y) = 0F(x,y) = 0

ieie aX+bY+caX+bY+c = 0= 0

F(F(pp) = 0 => Curve intersects ) = 0 => Curve intersects pp

F(F(pp) < 0 => Curve passes below ) < 0 => Curve passes below pp

F(F(pp) > 0 => Curve passes above ) > 0 => Curve passes above pp

x,y

x+1,y+.5

If a > 0 If a > 0

(14)

Locate Mid Locate Mid Locate Mid Locate Mid Locate Mid Locate MidLocate Mid

Locate Mid---pointpointpointpointpointpointpointpoint

d = a(x+1) + b(y+.5) + cd = a(x+1) + b(y+.5) + c

ddprevprev = =

ax + b(y+.5) + cax + b(y+.5) + c

Or, ax + b(yOr, ax + b(y--.5) + c.5) + c

ieie,,

d d aa

Or, d Or, d a a bb

How do you initialize d?How do you initialize d?

x,y

x+1,y+.5

(15)

Initialize d Initialize d Initialize d Initialize d Initialize d Initialize d Initialize d Initialize d

What if initial vertex coordinates are at What if initial vertex coordinates are at pixel centers?

pixel centers?

ddinitialinitial = a(x= a(x00 + 1) + b(y+ 1) + b(y00+.5) + c+.5) + c

= ax= ax00 + by+ by00 + c + a + b/2+ c + a + b/2

= a + b/2= a + b/2

Can we avoid that division?Can we avoid that division?

Otherwise, can we snap?Otherwise, can we snap?

(x(x00, y, y00))

(16)

Polygon Polygon Polygon Polygon Polygon Polygon Polygon

Polygon RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization RulesRulesRulesRulesRulesRulesRulesRules

Draw pixel, if center inside polygonDraw pixel, if center inside polygon

Find intersection of scanFind intersection of scan--lines with edgeslines with edges

All edges?All edges?

(17)

Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues

Sliver Sliver problem problem

(18)

Animating Animating Slivers

Slivers

Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues

(19)

Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues Triangle Rasterization Issues

Shared Edge OwnershipShared Edge Ownership

(20)

Polygon Polygon Polygon Polygon Polygon Polygon Polygon

Polygon RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization RulesRulesRulesRulesRulesRulesRulesRules

Draw pixel, if center inside polygonDraw pixel, if center inside polygon

What if it is at an edge?What if it is at an edge?

Draw on left edge, Skip on right edgeDraw on left edge, Skip on right edge

Unless HorizontalUnless Horizontal

Then, draw a bottom edge, skip a top edgeThen, 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

(21)

Triangle Triangle Triangle Triangle Triangle Triangle Triangle

Triangle RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization IIIIIIII

Find Left extreme:Find Left extreme:

= = rasterizerasterize left lineleft line

= remember left line= remember left line

StartXStartX = = StartXStartXpreviousprevious+ 1/+ 1/mm

Similarly find Right extremeSimilarly find Right extreme

ExtremaExtrema are edges (sometimes at vertices)are edges (sometimes at vertices)

Which two?Which two?

Start with two at the lowest vertexStart with two at the lowest vertex

What is there are two lowest verticesWhat is there are two lowest vertices

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

(22)

General Polygon General Polygon General Polygon General Polygon General Polygon General Polygon General Polygon

General Polygon RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization

Multiple spansMultiple spans

Count parityCount parity

How do you count How do you count

vertex intersections?

vertex intersections?

Divide into trianglesDivide into triangles

B C

D

E F

G

I H

J

A

(23)

Triangulation TriangulationTriangulation Triangulation Triangulation Triangulation Triangulation Triangulation

Draw horizontal line at each Draw horizontal line at each vertex

vertex

Assume no two vertices have Assume no two vertices have the same Y

the same Y

Perturb if assumption not truePerturb if assumption not true

Draw diagonals of trapezoidsDraw diagonals of trapezoids

Decomposed into monotone Decomposed into monotone polygons

polygons

Triangulate monotone Triangulate monotone polygon

polygon

O(nO(n lglg n)n)

(24)

Triangulating Monotone Triangulating Monotone Triangulating Monotone Triangulating Monotone Triangulating Monotone Triangulating Monotone Triangulating Monotone Triangulating Monotone

Polygons Polygons Polygons Polygons Polygons PolygonsPolygons Polygons

Form diagonalsForm diagonals

If vertex visibleIf vertex visible

Otherwise, proceed to next Otherwise, proceed to next vertex

vertex

O(O(nn))

(25)

Edge Equations Edge Equations Edge Equations Edge Equations Edge Equations Edge EquationsEdge Equations Edge Equations

Edge equation (line equation)Edge equation (line equation)

Defines two Defines two halfhalf--spacesspaces::

(26)

Triangle Evaluation Triangle Evaluation Triangle Evaluation Triangle Evaluation Triangle Evaluation Triangle EvaluationTriangle Evaluation Triangle Evaluation

Triangle = intersection of three Triangle = intersection of three positive half

positive half--spaces:spaces:

A1x + B1y + C1< 0 A2x + B

2y + C

2 < 0

Ax3 + B 3 y + C 3

< 0

A1x + B1y + C1> 0 A 3

x + B 3 y + C 3

> 0 A

2x + B

2y + C

2 > 0

(27)

Evaulate Evaulate Evaulate Evaulate Evaulate Evaulate Evaulate

Evaulate Edge EquationsEdge EquationsEdge EquationsEdge EquationsEdge EquationsEdge EquationsEdge EquationsEdge Equations

Plug in pixelsPlug in pixels x,yx,y into the equationinto the equation

If If F(x,yF(x,y) > 0, draw) > 0, draw

+ +

+ - -

-

(28)

Triangle Triangle Triangle Triangle Triangle Triangle Triangle

Triangle RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization

Setup:Setup:

Find edge slopesFind edge slopes

Find bounding boxFind bounding box

RasterizeRasterize::

Initialize left, right intersectionInitialize left, right intersection

From Bounding Box bottom to Top:From Bounding Box bottom to Top:

Update left, right intersectionUpdate left, right intersection

Round up or downRound up or down

Fill spanFill span

Interpolate Z, Color?Interpolate Z, Color?

Do in fragment Do in fragment shadershader

Fill span = create fragmentFill span = create fragment

(29)

Update Intersection Update Intersection Update Intersection Update Intersection Update Intersection Update Intersection Update Intersection Update Intersection

If y > swapIf y > swap--vertexvertex--yy

Replace one slopeReplace one slope

Replace one xReplace one xyy-1-1

xxyy = x= xy-y-11+ 1/m = x+ 1/m = xyy--11 + N/D + N/D

If y = swapIf y = swap--vertexvertex--yy

Replace one slopeReplace one slope

Replace one xReplace one xyy-1-1

(30)

Triangle Triangle Triangle Triangle Triangle Triangle Triangle

Triangle RasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterizationRasterization, Really, Really, Really, Really, Really, Really, Really, Really

Multiple Multiple rasterizersrasterizers??

Blocked or Blocked or StridedStrided

Create tiles of fragmentsCreate tiles of fragments

In parallel, divide tiles into In parallel, divide tiles into subsub--tilestiles

Each sub-Each sub-tile shaded tile shaded together

together

Mask to turn off uncovered Mask to turn off uncovered tiles

tiles

Partially covered sub-tile

Fully covered sub-tile

Referensi

Dokumen terkait

In R 3 , try to draw pictures to convince yourself that any non-zero vector spans a subspace which is a line through the origin; any two non-zero vectors that are not on the same

Start at a green number and draw a line to any red number that is less than the green number.. Draw a line that connects one number to one other number

Arrow points to the line or lines on drawing which clearly identify the proposed joint or weld area. The tail of the welding symbol is used to indicate the welding or cutting

Two drawing games used in this research Learn to Draw and Scratch: Learn to Draw TABLE 1 MAPING AMONG THE TASKS,COMPETENCIES AND FEATURES IN THE DRAWING GAMES Task Competencies

The shape of the turtle is there to help you see the turtle’s current position and heading, but you need to issue other commands, such asfd, to create a drawing.. If you have created a

While a sense of competition can be good, it can be hard to know where to draw the line, which is why Gargi encourages its students to build their own internal motivation and work

• If the object is moved to a new position, it can be regarded as a new object Obj’ , all of whose coordinate point P’ can be obtained from the original points P by the

 Due to the different absorption curves of the cones, colors are seen as variable combinations of the so-called primary colors: red, green, and blue  Their wavelengths were