- By
**oren** - Follow User

- 145 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'CS430 Computer Graphics' - oren

Download Now**An Image/Link below is provided (as is) to download presentation**

Download Now

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Topics

- Rasterization in the Graphics Pipeline
- Rasterization of Line Primitives
- Rasterization of Circle Primitives
- Rasterization of Filled Area
- Filling Polygons
- Antialiasing Techniques

Rasterization in the Graphics Pipeline

- Life after Window to Viewport Transformation?
- Backend of graphics pipeline
- Scan conversion (rasterization)
- Convert specification of a primitive into pixels in the frame buffer
- Process of taking high-level information such as the positions and colors of vertices and determining the colors of many pixels in a region of the frame buffer

Rasterization in the Graphics Pipeline

- Per fragment operation
- Rasterization produces fragments, not just pixels
- Fragment: color, depth, and texture coordinate
- Steps and tests are performed on a fragment before it is written into the frame buffer as a simple pixel value
- Backend of graphics pipeline

Per Fragment Operations

Pixels on display

Viewport Transformation

Scan Conversion

Rasterization in the Graphics Pipeline

- Rasterization of primitives
- Line
- Circle
- Polyline
- Polygon
- Filled area
- Text

Line Primitive

- Pixel provides a basis for all the raster graphics techniques
- Q: How is a line segment defined?
- A: By the two endpoints
- Q: How is a line displayed
- A: By scan converting two endpoints into pixels on the line from one endpoint to the other
- We are going to study three algorithms to perform scan conversion for a line

Line Primitive

- Basic line equation
- y = mx + b,

where m = slope, b = intercept on y axis

- Given two points (ax, ay) and (bx, by)

m = (by - ay)/(bx - ax)

b = ay – max

- Example: a = (1, 1), b = (5, 3)

Basic Increment Algorithm

- Algorithm (Brute Force)
- Given two points (ax, ay) and (bx, by), ax < bx

m = (by - ay)/(bx - ax)

b = ay – max

for (x = ax; x<= bx; x++)

y = mx + b

setPixel(x, round(y))

// round(y) = floor(y + 0.5)

Basic Increment Algorithm

- Problems
- One multiplication for each y
- Calculation of round()
- When abs(m) > 1, there are many missing pixels, since incrementing x by 1 increments y by > 1
- When ax = bx, m = infinity

Expensive

Operations

Can be solved easily by programming

DDA Algorithm

- Relies on the fact that for any 2 pts on line, xi+1 - xi = 1 (pixels)
- yi+1 = mxi+1 + b

= m (xi + x) + b

= (mxi + b) + mx

= yi + mx

yi+1= yi + m, if x = 1

DDA Algorithm

- Algorithm
- Given two points (ax, ay) and (bx, by), ax < bx

m = (by - ay)/(bx - ax)

for (x = ax; x<= bx; x++; y += m)

setPixel(x, round(y))

- Problems
- No multiplication, but round() is still there
- ax = bx
- Missing pixels when abs(m) > 1

Bresenham's Midpoint Algorithm

- Use the midpoint between two y values of a line to make a decision about which direction the next pixel should go
- Using a decision variable d to decide whether the line passes over or under M (the Midpoint)
- If d > 0 then go NE (North East) pixel
- If d <=0 then go E (East)
- Details will be given in the lecture

Bresenham's Midpoint Algorithm

- Example
- E or NE?

Bresenham's Midpoint Algorithm

- Example
- From (5, 8) to (9, 11)

Bresenham's Midpoint Algorithm

- Algorithm
- Given two points (ax, ay) and (bx, by), ax < bx

y = ay H = by - ay W = bx - ax

E = 2H NE = 2(H - W) F = 2H - W

for (x = ax; x<= bx; x++)

setPixel(x, y)

if (F < 0)

F += E

else

y++

F += NE

Bresenham's Midpoint Algorithm

- No multiplication, no rounding
- BUT, the algorithm given in the notes only works when
- ax < bx and
- 0 m 1
- Polyline and polygon can then be constructed using lines

Circle Primitive

- Circle equation (radius = R)
- Centered at the origin: x2 + y2 = R2
- Centered at (a, b): (x - a)2 + (y - b)2 = R2
- Basic increment algorithm won’t work
- y =

Using Polar Coordinates

- Better than basic increment

, where

(xc, yc) is the centre

r is the radius

is the angle in radians

- Problems
- floating point operations
- cos() and sin()

Using Regular Polygon

- Regular polygon
- A polygon is regularif it is simple, if all its sides have equal lengths, and if adjacent sides meet at equal interior angles
- n-gon
- Regular polygon having n sides
- Large n approximates a circle

Using Regular Polygon

- Code shown in the textbook
- Fig 3.43
- Fig 3.55
- Your lab and project
- Problems
- Do we get rid of floating point operations, cos(), and sin()?

Symmetry of Circle

- Circle is symmetric

for each point calculated, we can plot 7 others

only calculations for 1/8 of the circle is required

Symmetry of Circle

- Algorithm
- CirclePoints(x, y) // for circle centered at (0, 0)

{ setPixel(x, y)

setPixel(x, -y)

setPixel(-x, y)

setPixel(-x, -y)

setPixel(y, x)

setPixel(y, -x)

setPixel(-y, x)

setPixel(-y, -x)

}

Bresenham's Midpoint Algorithm

- Is there an algorithm to draw circles without floating point operations?
- The same person did it …
- Similar to his line drawing algorithm
- Eightfold symmetry of circles

computation performed only on the second octant of the circle

(x,y) from (0,R) to (R/sqrt(2), R/sqrt(2))

Bresenham's Midpoint Algorithm

- A decision variable d is used to decide to go two directions E or SE based upon how close the line is to the midpoint M
- If d < 0 then chooses E
- If d 0 then chooses SE
- Details will be given in the lecture
- No floating point operations!!

Bresenham's Midpoint Algorithm

The second octant

Bresenham's Midpoint Algorithm

- Algorithm
- Given radius R and center (0, 0)

x = 0 y = Rd = 1 - R

CirclePoints(x, y)

while (y > x)

if (d < 0)

d += 2x + 3

else

d += 2(x - y) + 5

y--

x++

CirclePoint(x, y)

Bresenham's Midpoint Algorithm

Before and after …

Filled Area

- Filling pixel-defined region
- Fill the region R of the set of all pixels having color C that are “connected” to a given pixel S.
- Example: pour ink in a region in MS-Paint
- Filling polygons
- Given a list of vertices of a polygon, fill the region of the polygon

Flood-Fill

- Change every interior 4-connected pixel of color intColor to a new color newColor
- Algorithm
- floodFill(x, y, intColor, newColor)

if (getPixel(x, y) == intColor)

setPixel(x, y, newColor)

floodFill(x-1, y, intColor)

floodFill(x+1, y, intColor)

floodFill(x, y+1, intColor)

floodFill(x, y-1, intColor)

Flood-Fill

- Flood-fill is a recursive algorithm
- Problem
- Neighbors are test blindly
- Might cause a stack overflow even for a small region
- Example:

seed=(4,2)

the calls are on

(3,2), (2,2), (1,2), (3,2),

(2,3), (2,1), (4,2), (3,3),…

totally 21 calls!!

5

4

3

2

1

0

0

1

2

3

4

5

Run-Fill

- Solution to flood-fill
- Exploit region coherence :likelihood that a pixel adjacent to an interior pixel is also an interior pixel
- Run
- Group of pixels lying on the same scan line
- Run-fill
- Identified and filled a whole run at once

Run-Fill

- Algorithm
- while (stack not empty)

push address of seed pixel on the stack

seed = pop(stack)

fill in the run defined by seed

find interior runs reachable from this run in the row above

push addresses of right most pixels of each run

find interior runs reachable from this run in the row below

push addresses of right most pixels of each run

Filling Polygons

- Progress through the frame buffer scan line by scan line, and use inside-outside test to fill portions of each line
- Algorithm (brute force)

for each scan line L

find intersections of L with all edges of polygon

sort intersections by increasing x-value

fill pixel runs between all pairs of intersections

out

in

out

in

out

Filling Polygons

- What is the time complexity of the brute force algorithm?
- Use edge coherence to improve performance
- Tendency for many of the edges intersected by scan line y to be intersected as well by scan line (y + 1)
- Property that the x-value of the intersection migrates in uniform increments from scan line to scan line
- Maintain an active-edge list (AEL) to locate intersections quickly

Filling Polygons

- Each edge in AEL contains
- xint: x-value of intersection of current scan line and the edge
- 1/m: reciprocal of the edge’s slope m
- yhigh: y-value of upper endpoint of the edge
- Why storing 1/m?
- xint + 1/m is the x-value of intersection of the edge and the next scan line above
- Edge coherence

Filling Polygons

- When move up to next scan line y
- If yhigh of an edge < y then delete the edge
- New edge(s) might be added to AEL
- For nonsimple polygons, the intersections might have to be sorted
- How do we find edges that should be added quickly?
- Edge table

Filling Polygons

- Edge table
- Array of lists, one list for each scan line
- The list edgetable[y]
- Contains information about any edge with lower endpoint at scan line y
- xint: x-value of lower endpoint
- 1/m: reciprocal of the edge’s slope m
- yhigh: y-value of upper endpoint of the edge
- Horizontal edges are not in the edge table
- It’s ok, though … why?

30 1 90

110 -1 90

:

:

40 -.5 80

40 .666 70

40

:

:

20

70 0 70

90 .33 80

Filling Polygons- Example

80

40

20

10

30

50

70

90

110

Filling Polygons

- Algorithm
- AEL = NULL

for (y = 0; y <= maxRow; y++)

add all edges in edgetable[y] to AEL

if (AEL != NULL)

sort AEL by xint

fill pixels values along y

delete any edge with yhigh ==y

xint = xint + 1/m for each edge in AEL

Antialiasing Techniques

- Aliasing
- Distortion of information due to undersampling
- Appearance of “jaggies” because of discrete nature of pixels
- Antialiasing techniques: reduce aliasing
- Prefiltering
- Supersampling
- Postfiltering

Prefiltering

- Pixel color computed based on the fraction of pixel area covered by object
- But it’s time consuming to calculate the coverage of pixels
- Example:

Prefiltering

- Pitteway and Watkinson’s algorithm
- Efficient algorithm calculating the coverage
- Based on Bresenham’s algorithm
- For a line with a slope m, where 0 m 1
- Coverage increased by m if go east
- Coverage decreased by 1 – m if go northeast

Supersampling

- Taking more intensity samples of the scene than are displayed
- Each pixel value is then formed as the average of neighbor samples
- Ns : value of oversampling
- Example: Ns = 2 double sampling
- Object sampled two time more densely in both x and y than displayed
- Final pixel value

= average of nine neighbor samples

Supersampling

- Example: Ns = 2 double sampling
- Pixel A = 2/3 of object’s color + 1/3 of background color
- Pixel B = object’s color

A

B

Supersampling

- Works even with no supersampling, i.e., Ns = 1
- Scene sampled at the corner of each display pixel
- Intensity of pixel = average of pixel corners

pixel corner

Postfiltering

- Improved visual effect by giving center sample more weight than neighbors
- Display pixel = weighted average of an appropriate set of neighbors
- Example
- Pixels Mask (Window function)

28 16 4 1/16 1/16 1/16

42 30 17 1/16 1/2 1/16

53 60 62 1/16 1/16 1/16

Intensity of display pixel =

30/2 + (28 + 16 + 4 + 42 + 17 + 53 + 60 + 62)/16 = 32.625 33

Download Presentation

Connecting to Server..