• No results found

8.1-rendering.ppt

N/A
N/A
Protected

Academic year: 2020

Share "8.1-rendering.ppt"

Copied!
55
0
0

Loading.... (view fulltext now)

Full text

(1)

Rendering

Will cover one aspect:

Real Time 3D Rendering

3D scene

renderin

g

Image

screen

buffer

( 2D array of

N times per

sec

( e.g. N=60

)

(2)

Real Time 3D Rendering

Challenging problem! As an example:

pixel

= 32 bit = 4 bytes

("pixel depth")

screen buffer

= 1024 x 768 pixels

("screen

resolution")

frame rate

= 60 Hrz

("fps")

188 MegaBytes / sec

total

= 4 x 1024 x 768 x 60 byte al sec

(3)

Real Time 3D Rendering

High fill-rates

– note:

...the fill-rate is not always the bottleneck

– note 2:

...this is only a lower bound for the fill-rate.

• We did not consider the

depth-complexity

~

x2.5

(as we

will see...)

• There are more than 32 bit x pixel

(4)

Real Time 3D Rendering

Difficult task

– Luckily, this is highly parallelizable

Basic idea:

(5)

Real Time 3D Rendering

We will focus on:

Real-Time

Hardware-Based

(6)

Spoecialized Hardware for rendering

Pro:

efficency

• Most frequent commands

hard-wired

in the

chipset

• parallelism rendering/main application

– rendering in the graphic card

– CPU and main RAM used by the application

But most importantly:

• Explotation of the

parallelism

implicit in the rendering

– Parallelismo in the pipeline

– parallelism

in each phase

of the pipeline

Cons:

low flexibility

(7)

Rendering paradigms

Raytracing

Rasterization based

Image based (per es. light field)

Radiosity

Point-splatting

(8)

Rasterization-based HW-supported

rendering

Also known as:

Transform and Lighting (

T&L

) paradigm

3D scene

renderin

g

screen

buffer

Few types of primitives:

points

lines

but mostly

triangles

(9)

Rasterization-based HW-supported

rendering

Assumption: the scene is only composed of

triangles (or points and lines)

x

z

v

0

=(

x

0

, y

0

, z

0

)

v

1

=(

x

1

, y

1

, z

1

)

(10)

Rasterization-based HW-supported

rendering

Assumption:

the scene is only composed of triangles (or

points and lines)

(11)

Scene only composed of triangles

one quadrilateral?

"quad"

"diagonal

split"

(12)

Scene only composed of triangles

an n-sides polygon?

Polygon triangolation:

(not

always trivial...)

(13)

Scene only composed of triangles

triangles!

(14)

Transform & Lighting

screen

buffer

3D Points

3D

Segments

3D

Triangles

Graphic card

Transform

&

(15)

Transform & Lighting...

Transform

:

– Trasformations of coordinate systems

– objective: put the scene in front of our (virtual) camera

– Draw the visible triangles on the screen

Lighting

:

– Light effects

(in general )

– objective: compute the resulting color for each

fragment of the scene

• Due to:

(16)

... Rasterization-Based Rendering

More precisely...

3D

vertices

fragment

process

pixels

final

fragments

transform

x

z

v

0

v

1

v

2

rasterizer

y

2D

screen

triangle

v

0

v

1

v

2

(17)

Rasterization-Based HW-Supported

Rendering: triangles

x

y

z

v

0

v

1

v

2

Final

pixels

(filling of the screen-buffer)

fr

a

g

m

e

n

ts

(c

a

n

d

id

a

te

p

ix

e

ls

)

V

e

rt

ic

e

s

(p

o

in

ts

i

n

R

3

)

P

ro

je

ct

e

d

v

e

rt

ic

e

s

(p

o

in

ts

i

n

R

2

)

Z

V

e

rt

e

x

c

o

m

p

u

ta

ti

o

n

s

rasterize

r

Fr

a

g

m

e

n

t

co

m

p

u

ta

ti

o

n

s

set

-up

v

0

v

1

(18)

Final

pixels

(filling of the screen-buffer)

fr

a

g

m

e

n

ts

(c

a

n

d

id

a

te

p

ix

e

ls

)

V

e

rt

ic

e

s

(p

o

in

ts

i

n

R

3

)

P

ro

je

ct

e

d

v

e

rt

ic

e

s

(p

o

in

ts

i

n

R

2

)

Z

V

e

rt

e

x

c

o

m

p

u

ta

ti

o

n

s

rasterize

r

Fr

a

g

m

e

n

t

co

m

p

u

ta

ti

o

n

s

set

-up

Rasterization-Based HW-Supported

Rendering

Physical components of the

HW!

Pipeline

Parallelism

Efficiency

(19)

Short history: PC...

1996

general purpose

HW (with a CPU)

dedicated HW

(with a GPU)

(20)

Short history: PC...

1997

general purpose

HW (con CPU)

dedicated HW

(with a GPU)

(21)

Short history: PC...

1999

general purpose

HW (with a CPU)

dedicated HW

(with a GPU)

(22)

Rasterization-Based HW-Supported

Rendering: triangles

co

m

p

u

ta

zi

o

n

i

p

e

r

fr

a

m

m

e

n

to

x

y

z

v

0

v

1

v

2

v

0

v

1

v

2

(23)

Rasterization-Based HW-Supported

Rendering:

rasterize

r

triangoli

x

y

z

v

0

v

1

v

2

set

-up

v

0

v

1

(24)

Rasterizing!

(25)

Segments Rasterization

• Goal: producing

lines as close as

possible to the

original one

v

0

v

1

Working with integer coordinates.

Rounding first.

(26)

Segments Rasterization

We wanto to identify

the sequence of

fragments that

– Best approximates the

segment

hence

(27)

Segments Rasterization

Slope

m

1

1 fragment per column

dx=9

d

y=

7

(28)

Slope

m

>1

1 fragment per row

dx=3

d

y=

1

0

Let us consider the previous case,

this is similar

(29)

Segments Rasterization:

analytical algorithm

The line equation is:

)

1

m

(

B

m

x

y

dx=9

d

y=

7

(30)

Segments Rasterization:

analytical algorithm

The rasterization

starts from (

x

0

,y

0

) and

goes to (

x

1

,y

1

)

P

0

(31)

Analytical algorithm

For

x

=

x

0

to

x

1

x

++

y

← m

x

+ B

round

y to the nearest

integer

(32)

Analytical algorithm

Select the fragment (pixel) closest to the ideal

(real) line

In order to find it you need:

– 1 addition

(a +1 on integers)

– 1 multiplication

(float)

(33)

First optimization: algorithm DDA

DDA

= Digital Differential Analyzer

Do without the multiplication

Compute incrementally

(34)

First optimization: algorithm DDA

Trivially:

x

y

y

i

1

i

m

B

)

(

m

1

x

x

y

i

i

B

m

1

1

i

i

x

y

m

1

i

i

y

(35)

First optimization: algorithm DDA

For

x

=

x

0

to

x

1

x

++

y

← m

x

+ B

round

y to the nearest

integer

output the fragment (x , y)

y ←

y

0

For

x

=

x

0

to

x

1

• x

++

y

+=m

• round

y

• output the fragment (x ,

y)

analytical

DDA

(36)

Bresenham’s Algorithm

Idea:

use only integers

Given the last chosen

point, which ones can

we selct now?

(assuming 0 < m < 1)

last fragment output

(37)

0≤m<1

Eight

possibilities!

Bresenham’s Algorithm

B

m

x

y

B

m

x

y

B

m

x

y

B

m

y

x

B

m

y

x

B

m

x

(38)

Bresenham’s Algorithm

Only two choices!

– East

– North-East

Choices for

the next one

Last

fragment

P=(x

i

,y

i

)

NE

(39)

Bresenham’s Algorithm

Q is the intersection of

the line with the next

column

Scelte per il

pixel corrente

Ultimo pixel

selezionato

Q

P=(x

p

,y

p

)

NE

(40)

Bresenham’s Algorithm

Q intersection of the

line with next column

M is the middlepoint

of the line E-NE

We need to figure

out on which side of

the line lies M

Scelte per il

pixel corrente

Ultimo pixel

selezionato

Q

M

P=(x

p

,y

p

)

NE

(41)

Bresenham’s Algorithm

We use the implicit form of the line equation:

0

c

b

a

)

,

F(

x

y

x

y

dx

dx;

dy;

b

c

B

(42)

Bresenham’s Algorithm

The function F:

– is 0 for all points on

the line

– is positive below the

line

– is negative above the

line

Q

M

NE

(43)

Bresenham’s Algorithm

In order to choose

among NE and E, we

should check the sign

of

Q

M

NE

E

)

,

1

F(

F(M)

1

2

p

p

y

(44)

Bresenham’s Algorithm

Decision variable

d

d = F(M),

Hence

c

)

(

b

)

1

(

a

d

1

2

p

p

y

x

Q

M

NE

(45)

Bresenham’s Algorithm

If (d

0)

Then M is above the

line

Choose E

Q

M

NE

(46)

Bresenham’s Algorithm

If (d > 0)

Then M is below the

line

Choose NE

Q

M

NE

(47)

Bresenham’s Algorithm

If (d = 0)

Then M is on the line

Choose either one (E

or NE)

Q

M

NE

(48)

Bresenham’s Algorithm

Final improvement!

We can compute d

incrementally!

– (like the y in the DDA)

Choices for the

following one

Choices for

next one

Chosen pixel

M

E

M

NE

M

P=(x

p

,y

p

)

NE

E

?

(49)

Bresenham’s Algorithm

When I choose E

Choices for the

following one

Choices for

the next one

Chosen pixel

M

E

M

NE

Q

M

P=(x

p

,y

p

)

NE

E

)

(

d

)

(

d

new

old

E

M

F

M

F

• result:

a

old

new

d

(50)

Bresenham’s Algorithm

When I choose NE

Choices for the

following one

Choices for

the next one

Chosen pixel

M

E

M

NE

Q

M

P=(x

p

,y

p

)

NE

E

)

(

d

)

(

d

new

old

NE

M

F

M

F

• result:

b

a

old

new

d

(51)

Bresenham’s Algorithm

Ok, d is increased by a constant

• (different in the two cases E or NE)

What is the starting value ?

2

b

a

)

,

(

F

)

,

1

(

F

d

1

2

0

0

0

0

start

x

y

x

y

2

2

b

a

d

start

dy

dx

• (

x

0

,

y

0

) belongs to the line, hence F(

x

0

,

y

0

)

(52)

Bresenham’s Algorithm

MidpointLine(

int

x0,

int

y0,

int

x1,

int

y1)

{

int

dx, dy, incrE, incrNE, d, x, y;

while

(x < x1 ) {

if

( d <= 0 ) {

d = d+incrE;

x++;

}

else

{

d = d+incrNE;

x++;

y++;

}

OutputFragment(x, y);

}

}

Integer variables

Choice of E

Initialization

dy = y1-y0;

dx = x1-x0;

d = 2*dy-dx;

incrE = 2*dy;

incrNE = 2*(dy-dx);

x = x0;

y = y0;

(53)

Segments of Width > 1

(54)

Segments of Width > 1

(55)

Segments of Width > 1

In OpenGL

void glLineWidth( width );

Not always an integer

(allowed when anti-aliasing

References

Related documents

Out of the drawbacks of solid cantilever shear wall structures, coupled shear wall structure with buckling- restrained steel link wall is introduced and it is

I review several core theories in international business expansion and management strategy to assess which elements of these theories may need to be re-specified in light of

For three consecutive days, Victor Val- ley College nursing students in CNSA (California Nursing Student's Associa- tion) promoted continuing education with a little help from

Results suggest that the probability of under-educated employment is higher among low skilled recent migrants and that the over-education risk is higher among high skilled

The main optimization of antichain-based algorithms [1] for checking language inclusion of automata over finite alphabets is that product states that are subsets of already

The present study deals with the parametric study on buckling behavior of woven fiber laminated composite plates subjected to uniform temperature and moisture

Aptness of Candidates in the Pool to Serve as Role Models When presented with the candidate role model profiles, nine out of ten student participants found two or more in the pool

The notion of using community-based health care to provide primary care to rural areas has become very effective in spreading better health care to poor areas around the world, and is