Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects...

36
Lezione 4: Grafica 3D*(II) Informatica Multimediale Docente: Umberto Castellani *I lucidi sono tratti da una lezione di Maura Melotti ([email protected])

Transcript of Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects...

Page 1: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Lezione 4: Grafica 3D*(II)

Informatica Multimediale

Docente:

Umberto Castellani

*I lucidi sono tratti da una lezione di Maura

Melotti ([email protected])

Page 2: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

RENDERING

Page 3: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Rendering

What is rendering?

Rendering methods.

What color is the object

at that pixel?

Alpha Buffering

Texture mapping.

Page 4: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Cos’è il rendering

Il rendering è il processo di conversione degli elementi descrittivi della scena in una immagine 2D

• Objects

• Camera

• Light Sources

Final image

Scene description

Page 5: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Metodi di rendering

– Wire-frame

– Painter’s algorithm

– Z-Buffer

– Ray Tracing

– Radiosity

Page 6: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Wire frame

Only the edges of objects are drawn.

Faster and useful for quick previews.

Some mechanical drawings are clearer when

only the edges of objects are drawn.

Page 7: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Algoritmo del pittore

• Problem: how to form an image from a scene such that object mask one other correctly?

Page 8: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Algoritmo del pittore

This technique is similar to the way a painter creates a painting:

start painting the most distant elements, such as the sky, and over-paint these with objects that are closer.

1. sort objects by distance from eye

2. render objects farthest from the eye first

3. continue rendering all objects from back to front

Page 9: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Algoritmo del pittore

Painter’s algorithm fails if object intersect!

An object that intersects the grid looks like this:

But it should look

like this!

Solution: Z-Buffer alghoritm

Page 10: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Z-Buffer

At each pixel is associated a Z-value that is the distance from the eye to the point on the object represented by the pixel.

A Z-buffer is used to record the Z-value of pixels.

Before any polygons are drawn all the Z-value in the Z-Buffer are set to indicate the farthest distance from the eyes.

Before a new value is written in the Z buffer the pixel’s Z-value, stored in the Z-buffer, is compared to the new Z-value.

If the new Z-value represents a closer distance to the eyes the new value is written in the Z Buffer.

Page 11: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Z-Buffer

Important properties:

• Z-buffer is order indipendent.

• Z-buffer rendering can be done incrementally.

Fig.l Fig.2

Page 12: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Z-buffer

Z-values are usually stored in l6 bits, which results in

more than 65000 different depth values.

It is the most common solid surface rendering

technique today.

It is simple enough to be implemented directly in

inexpensive hardware .

But …. it doesn’t address how light really interacts

between object (shadows, refraction, ….) .

Page 13: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing

• Rays that reach the camera (the eye point) are few in comparison with the total rays calculated (too much computational cost!!!).

Forward Propagation:

Back Propagation

• A ray of light is thrown from each light sources.

• If the ray hits an object, refraction and reflection effects must be calculated.

• This can happen many times, depending on the number of objects in the scene.

Page 14: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing

• Unless the object is a light source more rays are shot in each direction where light might be come from.

• A ray is shot from the eye point in the view direction in order to calculate the color of a pixel.

• This process doesn’t stop when the first object is encountered.

Back Propagation:

Page 15: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing

Fig.l: Z-Buffer rendering

Fig.2: Ray Tracing rendering

Page 16: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing

Fig.l: Z-Buffer rendering

Fig.2: Ray Tracing rendering

Page 17: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing vs. Z-buffer

Ray tracing is slow, no real-time:

• the algorithm is very complex, generally

computed at software level

• it works per pixel insted of per object.

Z-Buffer algorithm is faster, real-time:

• visit each polygon once, generally the hardware

does the per pixel operations

• for most of today’s scenes, pixel greatly outnumber

objects.

Page 18: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Ray-tracing

Page 19: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Radiosity

With ray tracing shadows have sharp edges because the test ray to the light source either gets there or it doesn’t.

Radiosity can model the diffuse reflection (secondary scatter).

In real life we can see lots of soft shadows because ligth is reflected by many objects (secondary light).

Page 20: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Radiosity

The radiosity algorithm computes what

portion of the light from each polygon

reaches each of the others.

The light from the bright polygons causes

other polygons to be lit.

These polygons, in turn, shine on other

polygons, which then shine on more

polygons…

This process of lighting up polygons

continues until things are settle down.

Page 21: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Radiosity

Page 22: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Radiosity

Page 23: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Esempi di rendering

Ray tracing

Page 24: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Esempi di rendering

Ray tracing + ombre sfumate

Page 25: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Esempi di rendering

+ caustiche

Page 26: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Esempi di rendering

+ global illumination

Page 27: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

What color is the object at that pixel?

– Flat Shading

– Linear (Gourand) Shading

The process of eventually coming up with pixel color values is

called shading.

Page 28: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

What color is the object at that pixel?

Flat Shading

The color values from the polygon vertices are averaged, and all the polygon’s pixels are set to this fixed (flat) color value.

Each pixel is exactly the

same color throughout

the polygon.

Page 29: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

What color is the object at that pixel?

Linear (Gourand) Shading

The color values from the polygon vertices are linear

interpolated , and the rate of change of the color value is held

constant for all the polygon’s pixels.

Page 30: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Alpha Buffering

- The alpha value (transparency value) is an opacity fraction that indicates how opaque (or transparent) the pixel is.

- The alpha value is commonly

stored in 8 bits: 0 means fully

transparent, 255 means fully opaque.

In alpha buffering an alpha value is kept per pixel (in addition to color value – rgb and Z-value ).

Page 31: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Alpha Buffering

Page 32: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Alpha Buffering

+ =

Page 33: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Texture Mapping

The process of mapping (wrap) an image over an object.

+

=

Page 34: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Texture Mapping

During the modeling step the user defines texture coordinates across the object.

The texture coordinate are interpoleted across each polygon instead of the final color values.

Page 35: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Texture Mapping

Texture mapping adds significant visual detail to the image without the need for modeling more complex geometry.

Page 36: Lezione 4: Grafica 3D*(II)profs.sci.univr.it/~castella/InfoProgMM2012-2013/... · 2. render objects farthest from the eye first 3. continue rendering all objects from back to front.

Rendering review

3D scene description Image

Shading: figuring out pixel color

Texture Mapping

Antialiasing