Sie sind auf Seite 1von 21

2

Table of Contents

Realistic rendering:
Basic effects

What is Rendering?
Rendering techniques
Elimination of hidden surfaces/faces: Z-buffer
Raytracing and radiosity
Light models
Shading
Textures
T

What is Rendering?

The rendering process

Make synthetic pictures indistinguishable from real photographs


Figure out color and intensity of light hitting each point in image
The full problem is amazingly difficult
/!\ several problems must be solved

Rendering steps in further details

Main steps to render an image:


Projection & Realism

Projection
3D transformations and perspective (already covered): scaling,
rotation,, translation,, p
perspective
p
transformations,, clipping
pp g
Hidden surface removal: back-face culling, z-buffer, painters
algorithm, Warnocks

Project scene from 3D to 2D using virtual camera


Elements closer to camera obscure more distant ones
=> to determine visible and non-visible surfaces
For each point in image, determine color, texture, relative
positions of light sources and, in more complex illumination
models, indirect reflection of light off of other surfaces in scene
Once we know what colors to draw for each point in image, final
step: map these colors onto our display device

Realism
Light and shading: Diffuse and specular reflection, Phong &
Gouraud shading models
Ray tracing: Ray-tracing model,
d l reflective
fl
& transparent objects
b
Color: Gamma correction halftoning & color models

First Problem: hidden lines and surfaces

Hidden surface algorithms


When we render a scene in "real world" often some objects will
be hidden by other objects
Hidden Surface algorithm attempts to identify these surfaces,
and display them logically

In figure a),
a) which cube is in front?
Ambiguous image caused by some line segments which
shouldnt be shown

Many different approaches proposed for determining how to


display polygons in proper depth
depth order
Primary concerns: speed, flexibility, and efficiency

10

Back-face Culling

Pros and Cons of Back-face culling

Main idea: to put away all backfacing polygons, as


not seen by viewer
works for convex bodies
Polygon "backfacing" if its normal N facing away
from viewing direction V, i.e. if (NV) = cos() > 0
For non-perspective projection we can direct V
along e.g. Z axis:
(NV) = (Nez ) = cos() = Nz
value cos() = Nz used also to determine brightness
of face

Main advantage: speed, in case it can be used (convex objects)


Test cheap and we expect at least half polygons discarded
Usually
ll performed
f
d in conjunction with
h more complete
l
hidden
h dd
surface algorithm
Convenient use for seeing inside box or any container:

11

Z-Buffer Algorithm
One of most commonly used routines
Often
Oft implemented
i
l
t d iin h
hardware
d
Idea behind very simple:
assign z-value to each polygon
then display the one (pixel by pixel)
that has the smallest value

12

Z-Buffer Algorithm
Consider these 2 polygons (P1 and P2)
C
Computer
t would
ld start
t t ((arbitrarily)
bit il ) with
ith P
Polygon
l
1
and put it's depth value into buffer. It would do
same for next polygon, P2
It will then check each overlapping pixel and check
to see which one closer to viewer, and display
appropriate color
Basic ideas valid for polygons in any orientation
and permutation

14

Pros and Cons of Z-Buffer algorithm

Z-Buffer Algorithm

Algorithm simple to use and can be implemented easily in


object or image space
quickly even with many polygons
Can be executed quickly,

No ambiguities

However:
- Takes up lot of memory
- Can't do transparent surfaces without additional code

13

15

Painter's algorithm (Z-Sorting)

16

Painter's algorithm (Z-Sorting)


Draw polygons as oil painter might: farthest one first
It sorts polygons in virtual structure and displays them in order
If none of polygons overlap,
overlap algorithm works very well

Camera

17

Painters algorithm (2)

18

Pros and Cons of Painters algorithm

/!\ most graphics rending programs include polygons


arranged in complicated configurations
=>require complex and processor intensive sort

Implementation hard if sorting & splitting needed


Speed fast if objects can be sorted a priori, otherwise
sorting many objects can be costly
Difficult to use for general 3D rendering

=> data structure Binary Space Partitioning Tree


once polygon-order determined
=> view can be generated from ANY POINT
Splitting of intersecting objects & sorting operations needed

19

Warnocks subdivision algorithm


Screen divided in rectangular windows
3 cases considered for each window:

20

Warnocks subdivision algorithm


Foley et al. propose an improvement
=> using polygon vertices!

There is nothing to display on window


Section to display simple enough, no
problem
Section to display isnt simple
enough, then window divided in 4
subsections and algorithm
g
repeated
p
in
a recursive way

21

When is a section simple enough to display?

22

Pros and Cons of Warnocks algorithm

When there is only one polygon inside section, window filled


with appropriate color
When section intersected by only one polygon, window first
f ll d with
filled
h background
b k
d color
l and
d after
f
intersecting section off
polygon filled
When section inside closer polygon to point of view, window
filled with color corresponding to polygon

Makes good use of quad-tree data structure


Could be hard to generalize
g
to non-polygon
p yg
models
C
Recursive subdivisions can often go down to pixel level

window

window

window

a
b

23

Lighting and Shading


This is one of primary elements of generating realistic images
Issues involved with physics of light and color and
physiological
p
y
g
aspects
p
of how humans p
perceive light
g & color
Accurate simulation of light energy and how it emanates
reflects off and passes through objects is amazingly complex
and computationally intractable task
Much of computer graphics involves tricking eye by producing
reasonable approximations

24

Color and the Human Visual System


Light sources emit intensity, which is a function of the
wavelength of light: I()
Humans perceive I() as a color
The
Th normall h
human retina
i has
h three
h
types off color
l receptors
which respond stronger to short, medium or long wavelengths

25

Color Systems

26

The RGB system

RGB (Red, Green, Blue) Additive


CMY (Cyan, Magenta, Yellow) Subtractive (complement of
RGB) often add K (blacK) to get better black
HSL (Hue, Saturation, Lightness) Cone shaped colour space
YIQ (Y == Luminence == CIE Y; IQ encode colour) Backwards
compatible with black-and-white TV (only show Y)

System derived from another system proposed by CIE


(Commission Internationale de l'Eclairage) in 1931
y
defined space
p
based on 3 p
primary
y colors: RED,,
CIE system
GREEN, BLUE. Any visible color result of combination of
these basic colors
RGB system corresponds to mechanism used by TV
monitors, where colors created by means of RED, GREEN
and BLUE phosphorus pixels

27

The RGB cube


The RGB model makes use of a cube whose edges measure 1 unit

28

The HLS system


Each color is specified by three magnitudes:
Hue (color tone), Lightness and Saturation

Hue represented
p
by
y angle
g with origin
g in the circle
The 3 primary colors form regular hexagon

Lightness; gray scale from 0 (black) to 1 (white)


Saturation; percentage of pure color (1: pure color, 0: gray of
corresponding lightness)
Jaune = <1,1,0> Magenta = <1,0,1> Cyan = <0,1,1>
The gray scale goes through the diagonal, from black at the
origin (<0,0,0>) to white at the top (<1,1,1>)

29

The HLS system

30

Transparency

An opaque object in front of another one hides it


In Computer Graphics => Hidden Surface Removal algorithm
g may
yg
go across some materials
However,, light
These materials are called transparent and objects behind
should not be hidden
Objects being transparent objects should be represented
differently
There are simple techniques and more complex taking into
account refraction (Snell-Descartes law)

31

32

Simple transparency

Simple transparency

Example: Imagine a red box seen across a green glass

We can now apply the following formula


I = t*I1 + (1-t)*I2
With
I1: intensity of point P1 located behind point P2, with
intensity I2

g
The color of the box will be a mixture of red and green
Proportions of red and green is dependent on
transmission (transparency) coefficient of the glass
If the glass is completely opaque, the result should be
green (the box is not visible !); if the glass is completely
transparent, the result should be red (like without glass)

t: coefficient of transparency of the polygon to which


belong P2, its value varies
from 0: opaque
to 1 completely transparent

Between both extremes, all mixtures are possible

33

34

35

36

Variation of transparency

Transparency and curved objects

Transparency and curved objects

Simple linear combination : provides acceptable results with


non-curved and ultra-thin objects
For object like sphere, we should take into account curvature
transparency larger in direction of center than in borders
Distance inside transparent
object through ray A is longer
than through ray B
A

Transparency factor dependent on object curvature


For a viewer on axis z:
t = tmin + (tmax - tmin)(1 - (1 - nz))
with:
t: transparency factor for a given position
tmin: minimal transparency factor
tmax: maximal transparency factor
nz: absolute value of z component of unit vector normal to
surface for a given position

37

38

Transparency and curved objects

Synthetic light

Curvature increases => nz decreases and t converges to tmin


Curvature decreases => nz increases and t converges to tmax
To take into account thickness of material:

If we eliminate hidden faces of sphere approximated


by polygons and color all visible polygons with same
red color => red circle!
Feeling of volume through a repartition of intensities
of colors on the surface

t = tmin + (tmax - tmin)(1 - (1 - nz) m)

Each point may have a different intensity and this


intensity is dependent on the current light

Thin glass => large m value


Thick glass => small m value
Refraction => ray tracing

=> to render a 3D scene by a computer with color, we


need
d to synthesize
h i light
li h

39

Types of light sources


1. Ambient light:
Uniform lighting
2. Direction sources:
Light sources are supposed to be very far away (infinite)
with light rays parallel to the given direction
3. Point sources:
Light sources located in a fixed point,
point rays are radial

40

Variation of
position of
point light
source

intensity of
point light
source with
shadow

intensity of
point light
source no
shadow

intensity
y of
ambient light

10

41

42

Spots

Spots: variations of

We can also use a model of spot due to Warn (1983).


Spots are controlled by:

concentration factor

direction

their position
their direction
a concentration factor

43

Spots: examples of advanced model

44

Reflection and Light Source Models


Given a point on a surface visible to the viewer through a
pixel, what color should we assign to the pixel?
We want to smoothly shade objects in scene
In a simple
l llighting
h
model
d l we can make
k the
h ffollowing
ll
assumptions:
Linearity of reaction: outgoing energy proportional to
incoming

Energy conservation: no more outgoing energy than


incoming
Full spectrum of light can be represented by three floats
(Red,Green,Blue)

11

45

Types of reflection

46

Specular Reflection
A large proportion of the incident light is reflected over a
narrow range of angles, making the surface look shiny.

There are two ways in which reflection can occur:


Diffuse Reflection
Light is scattered uniformly, making the surface look
matte.

Combined Reflection
in practice, many materials exhibit both of these effects to
different degrees.

47

More on specular reflection


Specular reflection accounts for shininess or glossiness of
surface
p of surface
Reflection occurs more or less from top
Specular surfaces are not perfect mirrors, so reflection
occurs over range of angles
Visual effects of specular reflection are highlights:
concentrated areas of higher intensity representing
reflected image of light source
Intensity of highlight at particular point on surface usually
f ll quite
falls
i rapidly
idl as viewing
i i
position
ii
changes
h

48

Surface Orientation
The geometry of the reflection process:

Angle of incidence

The normal and light vectors should be normalised.

12

49

Illumination Model 1

50

Problems with illumination model 1


We lose 3D info. Because an object is illuminated
uniformly:

Considers only ambient lighting:


Ambient lighting
Uniform illumination from all directions
Arises from multiple reflections
Ia=intensity of ambient light
L=kala
Ambient reflection coefficient: ka
Measures the reflectivity of surface for diffuse light
(values in the range 0-1)

Therefore, reflection of light from a localised


source must be considered

51

Lamberts Cosine Law


The amount of light received
g source depends
p
from a light
on the surface orientation

52

Diffuse Reflection
The intensity of diffusely reflected light can be calculated
as follows:

13

53

Illumination Model 2

54

Specular Reflection notation:

We consider illumination from ambient and a point light


source
ka

Specular reflections: around R


y is g
greatest along
gR
=>intensity
and falls-off as the angle
increases

I = ambient + diffuse
I = kala + kdlp(NL)

A model of specular reflection


specifies the functional form of
tthis
s fall-off
a o

kd

55

Specular Reflection
Snells law:
Light reaching the object is reflected in the direction having
the same angle:

56

Phong shading model


Can be considered as an imperfect specular reflector:

I = Ip ks (cos)n
Ap
problem
ob e o
of tthis
s model
ode is:
s with
t po
pointt light
g t sou
source,
ce, tthe
e
effect is visible only at one point on the surface
This is useful for indirect illumination (reflection and
shadows)

14

57

More on Phong model

58

Phong Model

This is an empirical model which provides a simple way of


controlling the size of the specular highlight

The cosine term in terms of vectors:


With R and L normalised: cos = RV
Hence
H
Is
I (RV)
(R V)n
The specular reflection also depends on :
Is W() (RV)n
in practice, we set W() = ks (the coefficient of specular
reflection, with values in the range 0-1) This controls
y the surface appears
pp
who shinny

f()=cosn
n depends on surface properties ans controls the spread of
the specular highlight
for a perfect reflector n =
For a very poor reflector n = 1

59

60

Illumination Model 3
Variation of highlight

Variation of reflectance

Reflection from a surface with diffuse and specular


properties:
I = ambient + diffuse + specular

ks

15

61

Light Source Distance

62

Illumination Model 4

We have not mentioned the effect of the position of the


light source.
The intensity of light from a point light source depends on
how far away it is
is.
Phisically, intensity falls off as the square of the distance.
The effective intensity of a light source lp after travelling
a distance d is:

Reflection from a surface when the attenuation of light is included


I = ambient + dist-factor(diffuse + specular)

This represents a linear fall-off of intensity.


d0 is constant, used to prevent infinite intensity when d=0
For multiple light sources, use linear superposition:

However, experiments show that a better formula is:

63

And what about Color?


So far our models make no mention of colour
=> only light intensities
We can choose a color model and apply the illumination model
to each color component, for example, RGB
The surface of the object is defined by kdR, kdG and kdB
This assumes specular highlight is of the same color as the light
source
More sophisticated, spectrally-based color models are available
An example for the Red component:

64

Torrance-Sparrow Model

Phong model has no physical meaning.


Happens to look good, but we dont
don t know why.
How to relate it to physical properties (roughness)?
Cook-Torrance-Sparrow Model
related to physical properties
but complex

16

65

Torrance-Sparrow Model

66

Torrance-Sparrow

The surface is modelled as micro-facets:


Light incoming on the facets is scattered, reflected,
obscured
obscured

Geometrical factor expressing the facets effects


Depends on light and viewpoint direction:
(,, , )
No simple function like (cosn )
Approximates very well physical effects
(shininess, roughness)

Depends
D
d on th
the geometrical
t i l distribution
di t ib ti
off th
the ffacets
t

67

Torrance-Sparrow

68

Polygon Shading
Typically, objects are represented by meshes of polygons
Our illumination model computes the intensity at a single point
on a surface
How can we compute the
h intensity across the
h polygon?
l
?
Compute the shade at the centre and use this to represent the
whole polygon: flat shading
Compute the shade at all points: unnecessary and impractical
Compute the shade at key points and interpolate for the rest:
Gouraud and Phong shading

17

69

Flat shading

70

Flat shading

This method is the simplest and most computationally efficient


Not realistic
Polygon structure is still evident: faceted appeareance
Structure can be refined to reduce the visual effect
It has problems with Mach banding
The human visual system is extremely good at detecting edges,
even when they are not there
Abrupt changes in the shading of two adjacent polygons are
perceived to be even greater
We need to smooth out these changes

Original Model

Optimized

Spot

Gouraud

Phong

71

Intensity Interpolation (Gouraud shading)


Henri Gouraud (1971)
Given a polygon and a scan-line, problem is to determine
y at interior p
point,, such as P
intensity
For this we need the intensity values at the vertices A,B,C

72

Intensity interpolation
First compute intensity values at each polygon vertex
We need the vertex normals
Compute
C
t vertex
t normall approximately
i t l b
by averaging
i
th
the
surface normals of surrounding polygons

18

73

Intensity interpolation

74

Gouraud Vs. Flat shading

Next, compute the intensities at points Q and R where the


scan-line and polygon intersect, using linear interpolation:

Finally, linearly interpolate between IQ and IR to get the


intensity at point P
This method avoids shading discontinuity for adjacent
polygons

75

Gouraud shading

76

Main issue with Gouraud shading?

Original Model

Optimized for Gouraud shading

19

77

78

Normal vector interpolation


Phong shading

Main issue with Gouraud shading


Smooths out real edges
=> compute 2 vertex normals, one for each boundary side
/!\ if the highlight lies inside a single polygon
=> lost in specular reflection
Regular corrugated surfaces
=> appear to be shaded uniformly

Bui-Tuong Phong (1975)


Similar to intensity interpolation, except that we linearly
interpolate the surface normal vector across the polygon
polygon.
For the example situation described before we have

Now apply illumination model with interpolated normal to


find intensity at the required point.

79

Phong shading, pros and cons

80

Phong shading

More realistic shading than intensity interpolation.


Specular highlights are preserved because the
illumination model is applied after the
interpolation.
Mach banding greatly reduced

More computationally expensive.


Each interpolation requires complete shading
calculation.

20

Next session
Realistic rendering:
Advanced effects

21

Das könnte Ihnen auch gefallen