• No results found

TNM046: Datorgrafik Shading

N/A
N/A
Protected

Academic year: 2021

Share "TNM046: Datorgrafik Shading"

Copied!
11
0
0

Loading.... (view fulltext now)

Full text

(1)

TNM046: Datorgrafik Shading

Sasan Gooran VT 2013

2

Light sources

Reflecting surface

The simplest model for a light emitter is a point source. A reasonable approximation for a source whose dimensions are small compared to the size of objects in the scene.

Sources, such as the sun, that are sufficiently far from the scene can be accurately modeled as point sources.

3

Light sources

When light is incident on an opaque surface, part is reflected and part is absorbed. Shiny materials reflect more.

A nearby source is more accurately modeled as a distributed light source.

(2)

4

Ambient light

A surface that is not exposed directly to a light source still will be visible if nearby objects are illuminated.

In the basic illumination model we can set a general brightness for a scene (uniform illumination), called ambient light (background light)

This is denoted by Ia

Each surface is illuminated with this constant value.

5

If only ambient light:

Iamb,diff= kaIa This happens very seldom, at least

one light source is included in a scene (often as a point source)

Basic Illumination Models

Ambient light

Images from: Computer Graphics, D. Hearn and M.P. Baker

6

Reflection

Surfaces that are rough tend to scatter the reflected light in all directions (Diffuse reflection)

A very rough matte surface produces primarily diffuse reflections (surface appears equally bright from all viewing directions)

What we call the color of an object is the color of the diffuse reflection of the incident light.

A blue object illuminated by a white light source, for example, reflects the blue component and totally absorbs all other components. Blue object under “red light” appears black.

Light sources also create highlights (bright spots) called specular reflection (more on shiny surfaces).

(3)

7

Diffuse reflection

Diffuse reflections are constant over each surface in a scene, independent of the viewing direction.

The fractional amount of the incident light that is diffusely reflected can be set for each surface with parameter kd, the diffuse reflection coefficient or diffuse reflectivity. kd is constant and between 0 and 1.

For a highly reflective surface: kd≈ 1

For a surface that absorbs most of the incident light: kd≈ 0

8

Assumption: The diffuse reflections from the surface are scattered with equal intensity in all directions (ideal diffuse reflectors, or lambertian reflectors)

Lambert’s cosine Law:

φN

N (normal)

Radiant (energy direction) Light intensity à radiant energy per projected area perpendicular to direction = dA cosφΝ

Basic Illumination Models

Diffuse reflection

9

Even though there is equal light scattering in all directions, the brightness of the surface depends on the orientation of the surface relative to the light source.

A surface that is oriented perpendicular to the direction of the incident light appears brighter than if the surface were tilted.

Il N

θ A

A cosθ

I

l,diff

= k

d

I

l

cosθ

Notice: A surface is illuminated by a point source only if the angle of incident is between 0 and 90 degrees. When cosθ is negative the light source is “behind” the surface.

Basic Illumination Models

Diffuse reflection

(4)

10

N ˆ

L ˆ N is unit normal vector for the surface ˆ L is unit normal vector from a position ˆ on the surface to the point light source

I

l,diff

= k

d

⋅ I

l

⋅ ( ˆ N • ˆ L)

Notice: if ˆN • ˆL 0, then Il,diff= 0

Diffuse reflection

Observe that Il is the light intensity that hits the object which is dependent on the intensity of the light source and its distance to the object (r).

Il=1

rs⋅ Ilight _ source The factor s is often set to 1.

11

I

diff

= k

a

I

a

+ k

d

⋅ I

l

⋅ ( ˆ N • ˆ L)

Notice: if ˆN • ˆL < 0, then the second term should be set to zero Combine the ambient and point-source intensities:

Both ka and kd depend on surface material properties and are assigned a value between 0 and 1.

Basic Illumination Models

Ambient + Diffuse

Only ambient Ambient + Diffuse (single source) Images from: Computer Graphics, D. Hearn and M.P. Baker

12

Basic Illumination Models

Ambient + Diffuse I

diff

= k

a

I

a

+ k

d

⋅ I

l

⋅ ( ˆ N • ˆ L)

N1 L1

N0 L0

Assume two surfaces, 0 and 1

Only Diffuse: Surface 0 is completely black without ambient light because:

Nˆ0• ˆL0< 0

N1 L1

N0 L0

Ambient + Diffuse: Surface 0 is not completely black because of the ambient light.

(5)

13

When we look at an illuminated shiny surface (polished metal, an apple, a person’s forehead) we see a highlight (bright spot) at certain viewing directions (called specular reflection)

Specular reflection and Phong model

N ˆ L ˆ

R ˆ

Vˆ θ θ φ

R : Specular directionˆ

V: unit vector pointing to the viewerˆ

φ: angle between ˆV and ˆR

For an ideal reflector (perfect mirror) incident light is reflected only in the specular-reflection direction. In this case, we would only see reflected light when V and R coincide (i.e. φ=0)

14

Objects other than ideal reflectors, exhibit reflection over a finite range of viewing positions around R.

Shiny: narrow specular reflection range Dull: wider specular reflection range

Basic Illumination Models

Specular reflection and Phong model

Phong model: sets the intensity of specular reflection proportional to cosnsφ.

0°≤φ ≤ 90° → 0 ≤ cosφ ≤ 1

Specular reflection parameter ns is determined by the type of surface.

15

A very shiny surface à a large value of ns (over 100) Smaller values down to 1 for dull surfaces!

For perfect reflector ns is infinite.

Basic Illumination Models

Specular reflection and Phong model

N ˆ L ˆ R ˆ

Large ns Shiny surface

N ˆ L ˆ R ˆ

Small ns Dull surface

(6)

16

Specular reflection and Phong model

φ cosnsφ

N ˆ L ˆ

R ˆ V ˆ

φ The intensity of specular reflection depends on the material properties of the surface (ns) and … (next page)

Notice that: cosφ = ˆV • ˆR, (why?)

17

… and specular reflection coefficient W(θ) for each surface:

Basic Illumination Models

Specular reflection and Phong model

Phong model:

I

spec

= W (θ )I

l

cos

ns

φ N ˆ

L ˆ

R ˆ V ˆ

θ

The intensity of specular reflection depends on the material properties of the surface (ns) and the angle of incidence (θ)

18

Basic Illumination Models

Specular reflection and Phong model

Phong model:

I

spec

= W (θ )I

l

cos

ns

φ

For many opaque materials, we can reasonably model W(θ) with a constant ks.

I

spec

= k

s

I

l

( ˆ V • ˆ R)

ns

W (θ )

θ

silver

gold glass

Image from: Computer Graphics, D. Hearn and M.P. Baker

In general, W(θ) tends to increase as θ increases, at θ=90o, W(θ)=1 (all of the incident light is reflected)

(7)

19

Specular reflection and Phong model

I

spec

= k

s

I

l

( ˆ V • ˆ R)

ns

N ˆ

L ˆ R ˆ

S = ( ˆL • ˆN ) ˆN

S

T 

T =S − ˆL R = ˆˆ L + 2

T = ˆL + 2(S − ˆL) = 2

S − ˆL R = 2( ˆˆ L • ˆN ) ˆN − ˆL

θ θ

20

Basic Illumination Models

Combined Diffuse and Specular Reflections

I = Idiff+ Ispec= kaIa+ kdIl( ˆN • ˆL) + ksIl( ˆV • ˆR)ns Question: what happens if ˆN • ˆL 0? what happens if ˆV• ˆR  0?

With multiple (m) light sources:

I = Idiff+ Ispec= kaIa+ Ili!kd( ˆN • ˆLi) + ks( ˆV • ˆRi)ns

" #

$

i=1 m

Observe that the diffuse part is independent of the viewing direction, why?

21

Basic Illumination Models

Combined Diffuse and Specular Reflections

Image from: Computer Graphics, D. Hearn and M.P. Baker

Only ambient

Ambient + Diffuse Ambient + Diffuse + Specular

(8)

22

Flat shading Flat shading (constant-intensity shading)

A single intensity is calculated for each triangle. All points over the surface of the triangle are then displayed with the same intensity value. Uses one normal per triangle.

+ Quick displaying - Discontinuities

23

Shading

Gouraud shading

Linear interpolating intensity values across the surface Intensity values for each triangle are matched with the values of adjacent triangles along the common edges. (no intensity discontinuities that can occur in Flat shading)

Procedure:

•  Determine the average unit normal vector at each triangle vertex (how to do that? See next page)

•  Apply an illumination model to each vertex to calculate the vertex intensity (Ambient light or/and diffuse light or/and specular reflection)

•  Linearly interpolate vertex intensities over the surface of the triangle

24

Shading

Gouraud shading (vertex normal)

Nj

Nj+1

Nj+2 Definition: The normal of the vertex i is the average of the unit normals of all the triangles j, which share the vertex i.

Ni

Nˆi=Nˆj+ ˆNj+1+ ˆNj+2 Nˆj+ ˆNj+1+ ˆNj+2

General: Nˆi= Nˆk

k=1 n

Nˆk

k=1 n

(9)

25

Gouraud shading (interpolation)

I1

I3

I2 x y

We can now determine the intensity at the vertices from a light model, here assume that I1, I2, I3 (intensities at this triangles’ three vertices) are calculated.

I4=y4− y2

y1− y2

I1+y1− y4

y1− y2

I2 I5=y5− y2

y3− y2

I3+y3− y5

y3− y2

I2

"

#

$$

%

$

$

4 5

P

IP=x5− xP

x5− x4

I4+xP− x4

x5− x4

I5

26

Shading

Gouraud shading

+ Quite fast. Effective for shading surfaces which reflect diffusely.

Specular highlights are dependent on the relative positions of the underlying triangles.

- Not good for “large” triangles (nearby light source)

According to this figure, there won’t be any specular reflection included in I1 and I2. Since in Gouraud model we interpolate I1 and I2 to get the intensity at point 3, there won’t be any specular reflection at point 3 either, which is wrong because the figure clearly shows that there must be strong specular reflection included at point 3.

I1 3 I2

27

Shading

Gouraud shading

Large triangle and the light source close to the center.

The light intensity at each vertex will be quite low (far from the light). The triangle will be rendered quite dark, which is wrong.

(10)

28

Phong shading

Phong shading (Please don’t confuse this with Phong model)

A more accurate model is to interpolate normal vectors and then apply the illumination model.

•  Determine the average unit normal vector at each triangle vertex

•  Linearly interpolate the vertex normals over the surface of the triangle

•  Apply any illumination model along each scan line to calculate pixel intensities for the surface points

29

Shading

Phong shading (interpolation)

We can first determine the normals at each vertex N1, N2, N3 (see page 24). Then the linear interpolation:

N4*=y4− y2 y1− y2

Nˆ1+y1− y4 y1− y2

Nˆ2 N5*=y5− y2

y3− y2

Nˆ3+y3− y5

y3− y2

Nˆ2

"

#

$$

%

$

$

N1

N3

N2 x y

N*4 P N*5 NP

Notice that N*4 and N*5 might not be normalized, therefore:

Nˆ4= N4*

N4* and ˆN5= N5* N5*

30

Shading

Phong shading (interpolation)

N1

N3

N2

x y

N4 P N5

NP

Np*=x5− xP x5− x4

Nˆ4+xP− x4 x5− x4

Nˆ5

Nˆp= Np* Np*

Now when we have the normals, the intensity for the surface points can be calculated by any illumination model.

And

(11)

31

Flat, Gouraud and Phong shading

Images from: Mark Dieckmann’s lecture notes

Flat Gouraud Phong

Flat shading: shows artificial triangle edges on the curved objects.

Phong shading: gives a better highlight on the bowling ball and makes the tip of the tower look better.

32

Color assignment

Images from: Mark Dieckmann’s lecture notes

We have now discussed how to calculate the intensity using ambient, diffusely reflected and specularly reflected light.

In order to calculate the color, a color vector C=(Ir, Ig, Ib) is defined. Ir, Ig and Ib are the intensities of red, green and blue respectively.

Assume that Co=(ro, go, bo) is the color vector of an object and CL=(rL, gL, bL) the color vector representing a light source. The simplest possible combination is element-wise multiplication.

Co⋅ CL= (ro⋅ rL, go⋅ gL, bo⋅ bL)

33

N ˆ

L ˆ N is unit normal vector for the surface ˆ

L is unit normal vector from a positionˆ on the surface to the point light source

rdiff

gdiff bdiff

!

"

#

##

#

$

%

&

&

&

&

= kdro⋅ rL

go⋅ gL bo⋅ bL

!

"

#

#

##

$

%

&

&

&&⋅ ( ˆN • ˆL) Notice : if ˆN • ˆL 0, then the result has to be set to a zero vector (zero)

Color Combination

References

Related documents

Pick the first point, then the sense of your fingers gives you the other two points in the

•  Apply an illumination model to each vertex to calculate the vertex intensity (Ambient light or/and diffuse light or/and specular reflection). •  Linearly interpolate

Source: Teaching Texture Mapping Visually, Rosalee Wolfe, DePaul

Source: Teaching Texture Mapping Visually, Rosalee Wolfe, DePaul University The color remains constant when

In OpenGL, together with the vertex coordinate you also specify the normal vector and the texture coordinates (for texture mapping). Texture mapping will be

In order to perform different transformations (e.g. scaling, translation, rotation etc.) on an object you transform the object’s vertices.. This is done by multiplying the

Rotation about an axis parallel to one of the coordinate planes Step 1: Translate the object so that the rotation axis passes through the coordinate origin. This vector is now on

The purpose of this paper is to examine one venture capital firm with the aim to give a conclusive understanding of the practice within the venture capital industry, focusing on the