Sie sind auf Seite 1von 7

Interactive Computer Graphics The Need for shading

In the last lecture we added realism to graphics scenes


by drawing them as solids.
Lecture 7: Shading
Object faces were either filled with a plain colour or
with a mapped texture.

In real scenes, the reflected light intensity is also


important.

Graphics Lecture 7: Slide 1 Graphics Lecture 7: Slide 2

The Physics of shading Object Properties

If we look at a point on an object we perceive a colour Looking at a point on an object we see the reflection
and a shading intensity that depends on the various of the light that falls on it. This reflection is governed
characteristics of the object and the light sources that by:
illuminate it.
1. The position of the object relative to the light sources
For the time being we will consider only the 2. The surface normal vector
brightness at each point. We will extend the treatment 3. The albedo of the surface (ability to adsorb light energy)
to colour in the next lecture. 4. The reflectivity of the surface

Graphics Lecture 7: Slide 3 Graphics Lecture 7: Slide 4

Light Source Properties Surface Characteristics

The important properties of the light source are Surfaces can have reflective characteristics ranging
from:
1. Intensity of the emitted light
2. The distance to the point on the surface 1. Dull, (matt) surfaces
2. Shiny (specular) surfaces
(When considering colour the first is an intensity 3. Reflective (mirror) surfaces.
distribution as we shall see later)
We will consider matt surfaces first.

Graphics Lecture 7: Slide 5 Graphics Lecture 7: Slide 6

1
Matt surfaces Lambert’s Cosine Law

Ireflected = Ii kd Cos(θ)

Incident where
Light Ii is the intensity of the incident light
Kd is a constant (surface albedo)
and θ is the angle between the surface normal and the
Perfectly Matt surface direction of the light source
The reflected intensity is the same in all directions

Graphics Lecture 7: Slide 7 Graphics Lecture 7: Slide 8

Lambert’s Cosine Law Colour

Light Source Strictly speaking the surface properties will vary with
the wavelength of the light (λ) so we should write:

s Ireflected(λ) = Ii(λ) kd(λ) Cos(θ)


n
Viewpoint However we will consider just the intensity
θ
component for the moment.
Lambertian
Surface

Graphics Lecture 7: Slide 9 Graphics Lecture 7: Slide 10

Vector Notation Ambient Light

If we specify our graphics scene in 3D space it is Pure diffuse shading is impossible to achieve in a
convenient to use vectors for the light source direction scene of several objects, since light that is reflected is
and the surface normal. itself a light source.

since n.s = |n||s|Cos(θ) Thus in addition to the direct light from the light
we can write Cos(θ) = n.s / |n||s| sources there is also a background ‘ambient’ light.

and so Lambert’s law is


Ireflected = Ii kd n.s / |n||s|

Graphics Lecture 7: Slide 11 Graphics Lecture 7: Slide 12

2
Radiosity Reflectance equation with ambient light

To model the ambient light accurately is very


difficult, attempts at doing so are called ‘radiosity’ Ireflected = Ia ka + Ii kd n.s / |n||s|
modelling
and since in general we know nothing about the
As a first approximation we can treat the ambient intensity of the ambient light we can simply write
light as a constant for the whole scene
Ireflected = ka + Ii kd n.s / |n||s|

and treat ka as an heuristic constant

Graphics Lecture 7: Slide 13 Graphics Lecture 7: Slide 14

Specularity Surface Characteristics

In practice no surface is purely matt. Reflected


Incident Direction Incident
Light Light

There is usually more energy emitted in the reflected Slightly specular (shiny) surface
Perfectly Matt surface
direction than any other. The reflected intensity is the same in all directions Slightly higher intensity in the reflected direction

This effect is termed specular reflection Reflected Reflected


Incident
Direction Incident Direction
Light Light

Highly specular (shiny) surface Perfect Mirror


High intensity in the reflected direction All light re-admitted in the reflected direction

Graphics Lecture 7: Slide 15 Graphics Lecture 7: Slide 16

Modelling specular reflection

In practice we can model this effect by adding a


specular component to the diffuse component.
Specular Component

The specular component will depend on the angle n


between the reflected direction and the viewpoint.
r
s
Diffuse
θ θ
v α Component

Graphics Lecture 7: Slide 17 Graphics Lecture 7: Slide 18

3
Bui-Tuong Phong formula Simplifications and Complications

This empirical formula has gained universal Usually f(θ) is taken to be a constant giving a
acceptance. complete reflectance equation as:

Ireflected = Ii f(θ) cost(α) Ireflected = ka + Ii kd Cos(θ) + Ii Ks cost(α)

where Ii is the incident light intensity, Some systems specify separate intensities for each
f(θ) is a function that depends on the angle between component from each light source.
the incident light ray and the surface normal
t is the shininess Ireflected = Ia ka + Ii kd Cos(θ) + Ii Ks cost(α)

Graphics Lecture 7: Slide 19 Graphics Lecture 7: Slide 20

Vector formulation Inverse Square Law

Ireflected = ka + Ii kd n.s / |n||s| + Ii Ks (r.v / |r||v|)t It is well known that light falls off according to an
inverse square law. Thus, if we have light sources
In practice we can make life easier by normalising all close to our polygons we should model this effect.
the vectors so that they are specified as unit vectors.
I = Ii/d2
n=n/|n| s=s/|s| r=r/|r| v=v/|v|
where
I is the incident light intensity at a point on an object
Ireflected = ka + Ii kd n.s + Ii Ks (r.v)t Ii is the light intensity at the source and
d is the distance from the light source to the object

Graphics Lecture 7: Slide 21 Graphics Lecture 7: Slide 22

Heuristic Law Distance to the viewpoint

Although physically correct the inverse square law One might be tempted to think that light intensity falls
does not produce the best results. off with the distance to the viewpoint, but it doesn’t!

Instead packages tend to use: Why not?

I = Ii/(d + k)

where k is an heuristic constant

Graphics Lecture 7: Slide 23 Graphics Lecture 7: Slide 24

4
Using Shading Flat Shading

There are three levels at which shading can be applied Each polygon is shaded uniformly over its surface.
in polygon based systems:
The shade is computed by taking a point in the centre
Flat Shading and the surface normal vector. (Equivalent to a light
Gouraud Shading source at infinity)
Phong Shading
Usually only diffuse and ambient components are
They provide increasing realism at higher used.
computational cost

Graphics Lecture 7: Slide 25 Graphics Lecture 7: Slide 26

Shading from different light sources Interpolation Shading

Local Light Source Flat Shading A more accurate way to render a shaded polygon is to
compute an independent shade value at each point.

This is done quickly by interpolation.

1. Compute a shade value at each vertex


2. Interpolate to find the shade value at the boundary
3. Interpolate to find the shade values in the middle

Graphics Lecture 7: Slide 27 Graphics Lecture 7: Slide 28

Calculating the shades at the edges Calculating the internal shades


I1
I1
Ic = (d1If + d2Is)/(d1+d2)
d1
Ie = (d1I3 + d2I1)/(d1+d2)
Is If
Scan Line
d1 d2
I2 I2
d2
Stage 1: Stage 2:
Calculating the edge pixels Calculating the centre pixels
I3
I3

Graphics Lecture 7: Slide 29 Graphics Lecture 7: Slide 30

5
Interpolating over polygons: Gouraud Shading Computing an average normal vector at a vertex

In addition to interpolating shades over polygons, we nave =(n1 + n2 + n3 + n4)/4


can interpolate them over groups of polygons to
create the impression of a smooth surface. n1
n4

The idea is to create at each vertex an averaged nave


intensity from all the polygons that meet at that
vertex.

n2 Gouraud Shading
n3 (Object Space)

Graphics Lecture 7: Slide 31 Graphics Lecture 7: Slide 32

Gouraud Shading Phong Shading

The averaged normal is used to compute a shade One limitation of Gouraud shading is that we cannot
value for the vertex. determine specular components accurately, since we
do not have the normal vector at each point on a
This is then interpolated as before. polygon.

The boundaries of the polygons are thus smoothed A solution is to interpolate the normal vector, not the
out. shade value.

Graphics Lecture 7: Slide 33 Graphics Lecture 7: Slide 34

Interpolation of the 3D normals 2D or 3D

We may express any point for this facet in parametric The interpolation calculations may be done in either
form: 2D or 3D
P = V1 + µ1(V2 - V1) + µ2(V3-V1)
The average normal vector at the same point may be For specular reflections the calculation of the
calculated as the vector a: reflected vector and viewpoint vector must be done in
a = n1 + µ1(n2 - n1) + µ2(n3-n1) 3D.
and then
naverage = a / | a |

Graphics Lecture 7: Slide 35 Graphics Lecture 7: Slide 36

6
Bump Mapping Bump Mapping

Technique developed by Blinn 1978 to enable a surface to


appear rough (eg.wrinkled or dimpled) without the need to Original
model this in three dimensions. Surface
Achieved by peturbating the surface normals of a smooth
surface to ‘trick’ the eye into thinking this surface is rough Bump
textured. Map
Large efficiency gain since model can be much simplified
Main limitation is that profiles and silhouettes of an object Bump Mapped
will not display the expected 3D surface characteristics
Surface
Graphics Lecture 7: Slide 37 Graphics Lecture 7: Slide 38

Bump Mapping Bump Mapping

Graphics Lecture 7: Slide 39 Graphics Lecture 7: Slide 40

Bump Mapping

Graphics Lecture 7: Slide 41

Das könnte Ihnen auch gefallen