28
Lighting & Shading

Lighting & Shading - WordPress.com€¦ · Light Source in shading Point source (A): ... (2/3) The real life ... Flat shading is a lighting technique used in 3D computer

  • Upload
    vodan

  • View
    223

  • Download
    0

Embed Size (px)

Citation preview

Lighting & Shading

Interactive

Computer Graphics

Overview

Local and global illumination

Phong reflectance model (local illumination)

Flat, Gouraud, and Phong

Shading on a polygonal mesh

Surface subdivisions

Shading in OpenGL

Introduction

From a physical perspective, a surface can either emit light by

self-emission, as a light bulb does, or reflect light from other

surfaces that illuminate it.

Some surfaces may both reflect light and emit light from

internal physical processes.

When we look at a point on an object, the color that we see is

determined by multiple interactions among light sources and

reflective surfaces.

These interactions can be viewed as a recursive process.

Light and matter

Some light from the source that reaches surface A is scattered.

Some of this reflected light reaches surface B, and some of it

is then scattered back to A, where some of it is again reflected

back to B, and so on.

This recursive scattering of light between surfaces accounts

for subtle shading effects, such as the bleeding of colors

between adjacent surfaces.

Need for shading

How do you make something look 3D?

Shading is basically variation of colors on the Object.

Shading that is appropriate for the lighting is the primary cue

to 3D appearance

It is a process used in drawing for depicting levels of darkness

on paper by applying media more densely or with a darker

shade for darker areas, and less densely or with a lighter shade

for lighter areas.

Shading Models in Computer Graphics

Local Model

Local illumination refers to direct interaction between one light source

and one object surface.

Shading Models in Computer Graphics

Global Model

Global illumination refers to the interaction of light between

all surfaces in a scene.

Responsible for shading

Reflection between surfaces

Refraction of surfaces

Light Source in shading

Point source (A): All light originates at a point (Case A in below Figure)

• Rays hit planar surface at different incidence angles

Parallel source (B): All light rays are parallel (Case B in below Figure)

Rays hit a planar surface at identical incidence angles

May be modeled as point source at infinity

Also called directional source

Area source (C): Light originates at finite area in space (Case C in below

Figure)

In between the point and parallel sources

Also called distributed source

Local Illumination Models

In computer graphics, single object-light interaction is

approximated through local illumination models.

Basic model used is the Phong model which breaks local

illumination into 3 components:

Ambient reflection

Diffuse reflection

Specular reflection

For every point, or small surface area, of an object, we want to

calculate the light due to these three components.

Simple shading models

Basic light sources

Light intensity can be

independent or dependent of the

distance between object and the

light source`

Ambient Reflection(1/2)

Accounts for the general brightness in a scene from light scattering in all directions from all surfaces.

A light ambient color Ia

represents light “in the scene” i.e. the “ambiance”

light coming from sky dome

of sun light which is directional (cast shadows)

light reflected by the scene onto itself

A material ambient coefficient Ka

represents the absorption of the ambient lighting

A=Ka Iaambient term

Ambient Reflection(2/2)

Very poor but useful

No physical interpretation

No cue of shape of objects

looks the same seen from anywhere no matter light position

increasing Ka

Diffuse Reflection(1/2)

All materials have diffuse properties, due to the ‘roughness’ of

a surface at the microscopic level.

Ideal diffuse reflection refers to light hitting a surface and then

scattering evenly in all directions due to the surface

‘roughness’.

Lambertian material

light reflected equally in every direction

reflected light depends of

material absorption Kd and light color Id

local surface orientation

light

D=Kd Id cos θdiffuse term

surface normal

D

nDq

D

D

D

DD D

Diffuse Reflection(2/2)

Shading varies along surface

gives cue of object’s shape

increasing Kd

Specular Reflection(1/3)

The ideal case: mirrors

Snell’s law

light is reflected with an outgoing angle equals to

incoming angle

problem : the reflection of a point light is visible at only one

point on the surface

Shiny objects (e.g. metallic) reflect light in preferred direction

R

determined by surface normal N

lightq

surface normal

q

q

Specular Reflection(2/3)

The real life: glossy objects

light is reflected

“around” the reflected vector

with exponential decay n (shininess)

material absorption Ks light color Is

lightq

surface normal

q

f S

S=Ks Is (cos f)nspecular term

Specular Reflection(3/3)

n

ks

Phong reflection model

The Phong model uses the four vectors shown in Figure below

to calculate a color for an arbitrary point p on a surface.

If the surface is curved, all four vectors can change as we

move from point to point. The vector n is the normal at p.

Phong reflection model

The vector v is in the direction from p to the viewer

or COP. The vector l is in the direction of a line from p to an

arbitrary point on the source for a distributed light source or,

as we are assuming for now, to the pointlight source.

Finally, the vector r is in the direction that a perfectly reflected

ray from l would take. Note that r is determined by n and l

Phong reflection model

The Phong model supports the three types of material–light

interactions— ambient, diffuse, and specular

Flat Shading

Flat shading is a lighting technique used in 3D computer

graphics to shade each polygon of an object based on the

angle between the polygon's surface normal and the direction

of the light source.

Illumination value depends only on polygon normal ⇒ each

polygon is colored with a uniform intensity

Looks non-smooth

As a result of flat shading all of the polygon's vertices are

colored with one color, allowing differentiation between

adjacent polygons

Smooth Shading

Smooth shading of a polygon displays the points in a polygon

with smoothly-changing colors across the surface of the

polygon.

This requires you to define a separate color for each vertex of

your polygon

Types of smooth shading include:

-Gouraud shading

-Phong shading

Gouraud Shading

Is an interpolation method used in computer graphics to

produce continuous shading of surfaces represented by

polygon meshes.

In practice, Gouraud shading is most often used to achieve

continuous lighting on triangle surfaces by computing the

lighting at the corners of each triangle and linearly

interpolating the resulting colours for each pixel covered by

the triangle.

Gouraud Shading con..

Advantages

Polygons, more complex than triangles, can also have

different colors specified for each vertex. In these instances,

the underlying logic for shading can become more intricate.

Problems

Even the smoothness introduced by Gouraud shading may not

prevent the appearance of the shading differences between

adjacent polygons.

Gouraud shading is more CPU intensive and can become a

problem when rendering real time environments with many

polygons

Phong Shading

• Phong shading refers to an interpolation technique for surface

shading in 3D computer graphics.

• It improves upon Gouraud shading and provides a better

approximation of the shading of a smooth surface.

• Interpolate (at the vertices in image space) normal vectors

instead of illumination intensities

• Apply the illumination equation for each interior pixel with its

own (interpolated) normal

Flat vs. smooth shading

Flat

Uses the same color for every pixel in a face - usually the

color of the first vertex.

Same color for any point of the face

Not suitable for smooth objects

Less expensive

Smooth

Smooth shading uses linear interpolation of colors between

vertices

Each point of the face has its own color

Suitable for any objects

More expensive

Phong VS. Gouraud Shading

If the polygon mesh approximates surfaces with a high

curvatures, Phong shading may look smooth while Gouraud

shading may show edges.

• Phong shading is more expensive but well worth the effort

Can achieve good looking specular highlight effects.

• Both need data structures to represent meshes so we can

obtain vertex normals

• Both the Gouraud and Phong shading schemes are performed

in the image plane and fit well into a polygonal scan-

conversion fill scheme

• Both the Gouraud and Phong are view dependent

Flat & Gouraud & Phong Shading