• No results found

8.2-rendering.ppt

N/A
N/A
Protected

Academic year: 2020

Share "8.2-rendering.ppt"

Copied!
44
0
0

Loading.... (view fulltext now)

Full text

(1)

Triangles Rasterization

Final pixels

(2)

Triangles Rasterization

Computer Graphics

Scan-line Algorithm

Basic Idea:

1. Sort edges on y

2. For every row

from ymin to ymax

1. Find the first fragment A inside

2. Find the first fragment B outside

3. Output all fragments from A included to B

(3)

Triangles Rasterization

Scan-line Algorithm

Basic Idea:

1. Sort edges on y

2. For every row

from ymin to ymax

1. Find the first fragment A inside

2. Find the first fragment B outside

(4)

Bresenham

• For every row:

– Finding hte first fragment inside and the first one outside is similar to Bresenham, but:

• Only one case (iterate on rows)

• Rounding to the smallest integer larger

(5)

Terminology in triangle rasterization

• "Scan-Conversion" = Rasterization

• "to scan-convert" = to Rasterize

• "Span" = interval from the first-in to the first-out

• "Line-scan" = processed line

• "Active edges" = edges taken into consideration

• "Edge tables" = edges (precomputed)

3

2

In the case of triangles!

(6)

Problems with the scan-line algorithm

• Fragments are produced one at the time

• Not suited for a parallel implementation

(7)

Solution

• Produce the fragments in groups

– E.g., groups of 2x2 or 4x4 or 4x1 or 8x1...

• Not all members of a group of fragments will belong to the triangle

• Test each fragment:

(8)

Inclusion test for a triangle

• Inclusion test for an half plane:

YES

NO

p n x

k

n

x

n

p

x

)

0

(

n

p

k

where TEST:

Line defined by a point p

(9)

Inclusion test for a triangle

• The halfplane is defined by:

NO

v0=(x0, y0 )

n

v1=(x1, y1 )

q

The

so-called

EDGE

FUNCTIO

N

n = ( - ( y1 -y0 ) , x1 -x0)

p = (y0 , x0)

f(q) = n‧q - n‧p

(10)

Inclusion test for a triangle

• Triangle=intersection of 3 half-planes

(11)

Inclusion test for a triangle

• Triangle=intersection of 3 half-planes

NO

v0 YES

NO YES YES YES NO v1 v2 YES YES YES YES NO NO YES NO NO NO YES NO YES

(12)

Inclusion test for a triangle

Swap

v

1 and

v

2

v2

v1

v0

Back-facing triangles (counterclockwise)

(13)

Inclusion test for a triangle

Three Edge Functions: (one per edge)

• All YES:

– Fragment inside a front-facing triangle

• All NO:

– Fragment inside a back-facing triangle

• Mixed results:

(14)

Example, using a bounding box

1. Compute the bounding box of the triangle

How to compute the bounding box

(15)

Example, using a bounding box

(16)

Example, using a bounding box

1. Compute the bounding box of the triangle

2. Process each block (e.g. 2x2) 1. Test each fragment in the

block

(17)

Triangles Rasterization

SETUP: compute the bounding box

test a group of fragments (in parallel)

Final pixels

(18)

Clipping

• Clipping!

Outside: CULLED !

 no prob.

Screen

Inside: Rasterize (simple case)

Partly

overlappin g

(19)

Clipping: old approach

• Clipping!

Screen

1. Compute intersections 2. Connect the intersections

A

B

3. Split the polygon into triangles 4. Rasterize each triangle

(20)

Clipping: old approach

• Clipping!

Screen

1. Compute intersections 2. Connect the intersections

3. Split the polygon into triangles 4. Rasterize each triangle

B

(21)

Clipping: old approach

• Clipping!

Screen

B

C

A

D

Worst case, very complex

Very bad for HW implementations

We cannot ignore this case

1. Compute intersections 2. Connect the intersections

(22)

Clipping: modern implementation

• Clipping!

Screen

1. Compute the bounding box 2. Intersect the bounding box

with the screen

3. Rasterize wrt the bounding box, as usual

(23)

Watch out!

• What about clipping against the far and near planes?

bottom plane right plane

left plane

near plane

view frustum

top plane

(24)

Triangles Rasterization

• The method based on computing the bounding box and the inclusion test (edge functions):

– Pros

• easily parallelizable

– (groups 4x4)

• clipping is easy

– For the planes UP, DOWN, LEFT e RIGHT

– Cons

• Large Overheads

(25)

A terrible situation

Screen

Triangles:

• Long and thin

• Along the diagonal

Very unpleasant situation in computer graphics:

(not just for rasterization)

Long and thin= bad

Many algorithms perform poorly

(26)
(27)

Samples

most things in the real world are

continuous

everything in a computer is

discrete

the process of mapping a continuous function to a

discrete one is called

sampling

the process of mapping a discrete function to a

continuous one is called

reconstruction

the process of mapping a continuous variable to a

discrete one is called

quantization

rendering an image requires sampling and

quantization

(28)

Jaggy Line Segments

• we tried to sample a line segment so it would map to a 2D raster display

• we quantized the pixel values to 0 or 1

(29)

Less Jaggy Line Segments

• better if quantize to many shades

– image is less visibly jaggy

• find color for area, not just single point at center of pixel

(30)

30

Supersample and Average

• supersample: create image at higher resolution

– e.g. 768x768 instead of 256x256

– shade pixels wrt area covered by thick line/rectangle

• average across many pixels

– e.g. 3x3 small pixel block to find value for 1 big pixel

– rough approximation divides each pixel into a finer grid of pixels

6/9 9/9

5/9 9/9

(31)

31

Supersample and Average

supersample: jaggies less obvious, but still there

– small pixel center check still misses information – unweighted area sampling

• equal areas cause equal intensity, regardless of distance from pixel center to area

• aka box filter

6/9 9/9

5/9 9/9

0/9 4/9

x Intensity

(32)

Supersampling Example: Image

no supersampling 3x3 supersampling with

(33)

Weighted Area Sampling

intuitively, pixel cut through the center should be

more heavily weighted than one cut along corner

weighting function, W(x,y)

– specifies the contribution of primitive passing

through the point (x, y) from pixel center

– Gaussian filter (or approximation) commonly used

x Intensity

(34)

some objects missed entirely, others poorly sampled

– could try unweighted or weighted area sampling

– but how can we be sure we show everything?

need to think about entire class of solutions!

– brief taste of signal processing

(35)

Image As Signal

• image as spatial signal

2D raster image

– discrete sampling of 2D spatial signal

• 1D slice of raster image

– discrete sampling of 1D spatial signal

Examples from Foley, van Dam, Feiner, and Hughes

Pixel position across scanline

In

te

ns

(36)

Sampling Frequency

• if don’t sample often enough, resulting signal misinterpreted as lower-frequency one

– we call this aliasing

(37)

Sampling Theorem

continuous signal can be completely recovered from its samples

iff

sampling rate greater than twice maximum frequency present in signal

(38)

Nyquist Rate

• lower bound on sampling rate

(39)

Aliasing

• incorrect appearance of high frequencies as low frequencies

• to avoid: antialiasing

– supersample

• sample at higher frequency

– low pass filtering

(40)

Low-Pass Filtering

(41)

Low-Pass Filtering

(42)

Filtering

• low pass

– blur

• high pass

(43)

Texture Antialiasing

(44)

Temporal Antialiasing

• subtle point: collision detection about algorithms for finding collisions in time as much as space

• temporal sampling

– aliasing: can miss collision completely with point samples!

• temporal antialiasing

References

Related documents

When Theatre mode is set to on, the optimum sound quality (if the TV is connected with an audio system using an HDMI cable) and picture quality for film-based contents

The essence of IS algorithms is based on successive determination of the maximal independent sets in a graph and assignment of different colors to vertices of particular IS..

Some qualifying countries have also experienced strong growth in foreign direct investment aimed at taking advantage of AGOA with positive spin-offs for increased employment

The purpose of the present study was to characterize the physico- chemical properties of surfaces of a selection of nu- merically important drinking water isolates and to

To ensure accurate reproduction of an analog signal, the sampling rate must be at least 2*(highest signal freq.). _freq max_signal 2 T 1 rate sampling = =

Symptoms of allergic reactions caused by food NIAID I GUIDELINES FOR ThE DIAGNOSIS AND MANAGEMENT OF FOOD ALLERGY IN ThE UNITED STATES?. Affected part of the body

Shelter caves proximal to the spring appear to have formed through a different process and instead likely represent paleo discharge features when the Edwards Aquifer water table was

Figure 5.12: Packet loss ratio verses datagram for different parallel connections at 64 Kbps. Figure 5.13: Jitter verses datagram for different parallel connections at