• No results found

10-lighting-shading.ppt

N/A
N/A
Protected

Academic year: 2020

Share "10-lighting-shading.ppt"

Copied!
90
0
0

Loading.... (view fulltext now)

Full text

(1)

Lighting

The other side of rendering

Computing the light

– How much

– Which colour

arriving

– From a point in the scene

– To the eye

(2)

Lighting: relevant factors

light

eye

object

Trasmission (with rifraction)

absorption

Inner reflection

Absorption by the environment

(e.g. fog)

Sub-surface scattering

Additional light

blo

ck

er

shade

reflection

(3)

Lighting: relevant factors

Multiple reflections

(indirect Lighting)

light

(4)

Lighting: global VS local

– Only takes into account:

• Light conditions

– N. lights

– their position

– Their color

• Surface area to lite

– orientation (normal)

– Optical charcateristics

» E.g, color

– Anything else is ignored

– Multiple reflections

– shadows

– Sub-surface scattering

– refraction

– ...

Local lighting

Global lighting

Much easier

to do on our

(5)

Local lighting

light

eye

object

reflection

(6)

What can be easily accomplished

Local lighting:

– Light reflections on objects

• Using simplified optical properties

– wiht multiple light sources

• But simplifies: point-sized

Global lighting:

– Multiple reflections

• VERY simplified

– Absorption by the environment

• Simplified case (uniform fog)

– Everything else only “ad-hoc"

(7)

The 3 factors we take into account

total light

=

ambient

+

reflection

+

emission

For any factor we have the

R, G and B components.

Defined for both the

object

,

(vertex attributes)

And for each

light

used

The optical properties of the

object

,

(usually vertex attributes)

Collected together form the

"

material

"

(8)

Component

emission

LEDs, light bulbs...

Not related to the lights

– Only to the object

It is only an addittive Component

– costant for R, G and B

Note: it does not send light to nearby objects

– It isn’t Global lighting

(9)

The 3 factors we take into account

total light

=

ambient

+

reflection

+

(10)

Component

ambient

It models (very approximately) the light hitting

the object after multiple reflections

Assumption:

“a small amount of light hits any surface from

every direction"

– Even surfaces in shadow

Small additive

constant

(11)

Component

ambient

Product of:

– “

ambient

” color of the material ( R

M

G

M

B

M

)

– “

ambient

” color of the light ( R

L

G

L

B

L

)

Note: the RGB colors can be different

(12)

Component

ambient

It models (very approximately) the light hitting

the object after multiple reflections

without

(13)

The 3 factors we take into account

total light

=

ambient

+

reflection

+

emission

diffuse reflection

+

specular reflection

only

Component

(14)

The 4 factors we take into account

total light

=

ambient

+

diffuse reflection

+

specular reflection

+

(15)

Component

diffuse reflection

Effect shown by a few materiale (e.g.):

– chalk

– wood (almost)

– Very opaque materials(not shiny)

Also known as

– diffuse reflection

– Lambertian reflection

(16)

Component

diffuse reflection

The light hitting a lambertian

surface is reflected in all

directions (in the half-sphere)

(17)

Component

diffuse reflection

The light hitting a lambertian

surface is reflected in all

directions (in the half-sphere)

(18)

Component

diffuse reflection

The light hitting a lambertian

surface is reflected in all

directions (in the half-sphere)

(19)

Component

diffuse reflection

It only depends on:

– Surface orientation

• (the "normal")

– Light direction

(20)

Component

diffuse reflection

It only depends on:

– Surface orientation

N

• (the "normal")

– Light direction

L

• (Light ray)

cos

light

diff

material

diff

diff

I

k

I

R, G, B

(usually white: 1,1,1)

R, G, B

(the "color" of the object)

(21)

property of the

"material"

(associated to

the object)

Component

diffuse reflection

It only depends on:

– Surface orientation

N

• (the "normal")

– Light direction

L

• (Light ray)

cos

light

diff

material

diff

diff

I

k

(22)

Component

diffuse reflection

It only depends on:

– Surface orientation

N

• (the "normal")

– Light direction

L

• (Light ray)

cos

light

diff

material

diff

diff

I

k

(23)

Component

diffuse reflection

It only depends on:

– Surface orientation

N

• (the "normal")

– Light direction

L

• (Light ray)

)

(

I

light

diff

k

material

diff

Angle between

0⁰ and 90⁰

,

otherwise 0,

(object in its own shadow)

cos

light

diff

material

diff

diff

I

k

(24)

Component

diffuse reflection

L

N

Component

diffuse

small

=70⁰

L

N

Component

diffuse

large

=35⁰

L

N

Component

diffuse

largest

(25)

Component

diffuse reflection

L

N

Component

diffuse

ZERO

=90⁰

L

N

Component

diffuse

ZERO

>90⁰

(26)

Component

diffuse reflection

Properties

– Accurate model of the optical characteristics

of a number of real materials

– But only a small number

– The model is physically coherent

• As an example, energy is conserved

(27)

The 4 factors we take into account

total light

=

ambient

+

diffuse reflection

+

specular reflection

+

(28)

Component

specular reflection

"Specular" reflection

For shiny materials

– With bright reflections

– ("highlights")

(29)

Component

specular reflection

Basic idea:

light

is not

reflected

by

shiny materiale

(30)

Component

specular reflection

L: light ray

N: normal

R: reflected ray

V: view direction

N

L

R

V

 

(31)

Component

specular reflection

Phong light model

– by Bui-Tuong Phong, 1975

in 3D

cos

light

spec

material

spec

spec

I

k

(32)

Component

specular reflection

By using higher exponents for the cosine, we can

(33)

Component

specular reflection

Phong light model

– by Bui-Tuong Phong, 1975

in 3D

Belong to the "material"

(properties of the object)

n

spec

material

spec

light

spec

I

k

I

cos

cos

light

spec

material

spec

spec

I

k

(34)

Component

specular reflection

Phong light model

– by Bui-Tuong Phong, 1975

in 3D

cos

light

spec

material

spec

spec

I

k

I

n

spec

material

spec

light

k

R

V

I

(

ˆ

ˆ

)

n

spec

material

spec

light

spec

I

k

(35)

Component

specular reflection

1

n

n

5

n

10

n

100

(36)

Component

specular reflection

• Blinn-Phong light model:

• Simplification of the Phong light model

• Similar results, different formula:

n

spec

material

spec

light

spec

I

k

R

V

I

(

ˆ

ˆ

)

phong:

blinn-phong:

I

spec

I

light

spec

k

material

spec

(

H

ˆ

N

ˆ

)

n

N

L

R

V

 

(37)

Component

specular reflection

• Blinn-Phong light model:

• Simplification of the Phong light model

• Similar results, different formula:

Jim Blinn

(MEGA-MEGA-GURU)

phong:

blinn-phong:

n

spec

material

spec

light

spec

I

k

R

V

I

(

ˆ

ˆ

)

n

spec

material

spec

light

spec

I

k

H

N

(38)

The 4 factors we take into account

total light

=

ambient

+

diffuse reflection

+

specular reflection

+

(39)

Complete lighting equation

n

specular

material

specular

light

k

H

N

I

(

)

k

(

L

N

)

I

light

diffuse

material

diffuse

material

ambient

ambient

light

k

I

emission

material

k

tot

I

property of the

(40)
(41)

Lighting equation: lights modeling

emission

materiale

k

tot

I

property of the light

L

V

V

L

ˆ

ˆ

)

ˆ

ˆ

(

n

specular

material

specular

light

k

H

N

I

(

)

k

(

L

N

)

I

light

diffuse

material

diffuse

material

ambient

ambient

light

k

(42)

Lights modeling

How does L change ?

– constant in the scene: "

directional

" light sources

• Used for light sources very far away, e.g. the sun

– Variable in the scene: "

positional

" light sources

(43)

Lights modeling: positional lights

The positional lights, have their

intensity

dimmed according to the

distance

In theory (according to physics)

intensity = 1 / distance

2





2

L

1

d

c

(44)

Lights modeling: positional lights

In practice, it leads to light attenuations that are

too quick

We rather use:





min

1

2

,

1

L

3

L

2

1

c

d

c

d

(45)

Lighting equation

tot

I

f

light

attenuatio

n





min

1

2

,

1

L

3

L

2

1

c

d

c

d

c

f

light

attenuatio

n

n

specular

material

specular

light

k

H

N

I

(

)

k

(

L

N

)

I

light

diffuse

material

diffuse

material

ambient

(46)

Kind of lights

Kind of lights:

(47)

Spotlights

(48)

Lighting equation

effect

spotlight

f

direction

cutoff

Angle

beam

width

effect

spotlight

L

spot

spot

spot

f

f

,

,

,

tot

I

light

attenuatio

n

f

n

specular

material

specular

light

k

H

N

I

(

)

k

(

L

N

)

I

light

diffuse

material

diffuse

material

ambient

ambient

light

k

I

emission

material

k





min

1

2

,

1

L

3

L

2

1

c

d

c

d

(49)

Lighting: Where?

Lighting & Shading

Computer Graphics Pagina 49

y

z

v

0

v

1

v

2

v

0

v

1

v

2

Final pixels

(50)

The 4 factors we take into account

total light

=

ambient

+

diffuse reflection

+

specular reflection

+

(51)

Lighting equation

n

specular

material

specular

light

k

H

N

I

(

ˆ

ˆ

)

k

(

L

ˆ

N

ˆ

)

I

luight

diffuse

material

diffuse

material

ambient

ambient

light

k

I

emission

material

k

tot

I

f

light

attenuatio

n





min

1

2

,

1

L

3

L

2

1

c

d

c

d

c

f

light

attenuatio

n

effect

spotlight

f

direction

cutoff

Angle

beam

width

effect

spotlight

L

spot

spot

spot

f

f

,

,

,

properties of the light

properties of the

material

(52)

^

Normal of a triangle

That is its orientation in space

N

v

0

v

2

v

1

)

(

)

(

v

1

v

0

v

2

v

0

N

|

|

ˆ

(53)

Lighting face by face

"flat shading"

1.

Initial geometry

2.

For each face,

Compute the normal

3.

(54)

Definition

Shading

:

Recipe to apply

lighting

As an example:

flatshading

1. Apply lighting to each face normal

- (obtaining a color)

(55)

Flat shading: problem

When we approximate curved surfaces with

triangles and apply flat shading the result is:

– Edges very visible on curved surfaces

bad

artifact

!

(56)

Flat shading: problem

(57)

Flat shading: problem

Increasing the number

of faces, makes the

problem less visible

>10.000 faces,

and we still see

the artifact

edges

(58)

Flat shading: problem

To make things worse:

the

Mach-band optical effect

The contrast between different

uniform areas catches our eye.

(even when areas are a lot,

and their difference is small).

The brain increases the

contrast between uniform

areas.

(59)

Idea

(60)

"Gouraud" Shading

To apply the lighting, I need to have the

normal!

The normal is defined for a face, not for a

vertex

by Henri Gouraud,

1971

Idea

Use color interpolation within a face

1- Apply lighting to the 3 vertices of each triangle

• (obtain a color)

(61)

Vertex normals

In many cases, the vertex normals are defined

at the same time of the 3D model.

– As an example,

• When we model a sphere, a cylinder, a cone...

• When we compute the surface of a volume

• When we a triangulated surface sampling a parametric surface

• ...

(62)

Vertex normals

Normal of a triangle:

v

1

v

2

v

1

×

v

2

v

N

ˆ

1

ˆ

N

2

ˆ

N

3

ˆ

N

4

ˆ

N

5

ˆ

N

6

ˆ

N

Normal of a vertex

Shared by

n

triangles:

n

N

N

N

N

ˆ

1

ˆ

2

...

ˆ

(63)

Where do we compute lighting?

x

y

z

v

0

v

1

v

2

v

0

v

1

v

2

Final pixels

(64)

Fundamental decision

In our rendering paradigm, the (vertex) normal:

• Is NOT

computed in the pipeline

• Is introduced as an

ATTRIBUTE

of each

VERTEX

The normale “is in the model"

• Exactly similar to vertex position

• When necessary, the normals computation is tipically a

pre-processing

(65)

Final pixels

(66)

Gouraud shading

(67)

How to improve the result

Rather than interpolating the

color

after the

lighting

, we interpolate the

normal

before of the

lighting

!

Be careful:

interpolating two normal vectors, the result is

not always a normal:

(68)

How to improve the result

Rather than interpolating the

color

after the

lighting

, we interpolate the

normal

before of the

lighting

!

"Phong" Shading

by Bui-Tuong Phong ,

1973

1- Interpolate the normal in the face

2- Normalize

3- Compute lighting

* Do not confuse Phong Shading with the Phong Lighting Model

(69)

Final pixels

(filling of the screen-buffer)

fr

a

gm

e

nt

s

(c

an

di

da

te

p

ix

el

s)

V

e

rt

ic

e

s

(p

oi

nt

s

in

R

3

)

P

ro

je

ct

ed

ve

rt

ic

es

(p

oi

nt

s

in

R

2

)

Z

V

er

te

x

c

om

pu

ta

tio

ns

F

ra

gm

en

t

co

m

pu

ta

tio

ns

set-up

set-up

set-up

rasterizer

triangoli

Segments

rasterizer

rasterizer

punti

Triangles

rasterizer

Points

rasterizer

Phong shading

including:

property

of the

material

and

normal

Projection

of

vertices

and

normals

Normal

interpol

ation

including:

interrpolate

d normal

including:

Transforme

d normal

Normalize

and compute

lighting

To obtain the

(70)

Gouraud vs Phong shading

Goraud Shading

-

lighting per vertex much less

computationally expensive:

Compute the lighting once per vertex!

Phong Shading

-

lighting per fragment offers better results

Especially suited for bright and small highlights (high shiness)

(71)

Gouraud and Phong shading

flat shading

Goraud shading

(72)

Gouraud and Phong shading

Goraud and Phong suited for curved surfaces

– They hide the artifact edges

– Also hide the REAL edges

(73)

Gouraud or Phong shading?

The OpenGL specifications

do not recommend

which one should be used

– In most cases (at least now) Gouraud

It dipends on the HW implementation

(74)

Its use in OpenGL

Turn on lighting:

( currbet color – that is

glColor3f

is now ignored. Only the current material!)

glEnable(GL_LIGHTING);

(75)

Normals

We set the “current normal". Similarly to colors:

glNormal3d(x,y,z);

(76)

What happens to the normals?

Pagina 76

world Coordinates

x

y

z

v

0

v

1

v

2

y

-z

v

0

v

1

v

2

view Coordinates

(a.k.a. eye Coordinates)

y

x

-z

v

0

v

1

v

2

v

0

v

2

v

1

Normalized Device

Coordinates

1

-1

1

-1

x

x

y

z

v

0

v

1

v

2

object Coordinates

modeling

v

ie

w

p

ro

je

ct

io

n

v

0

v

1

v

2

screen Space

viewport

Modeling + View transformations:

(keep the angles)

Projection:

All angles are modified

(77)

Are normals preserved in the Transform?

Only when the modeling-view transformations

are rigid

modeling-view = V ‧ M

rotations,

translations

(always rigid)

rotations,

translations

(78)

Are normals preserved in the Transform?

Note: if the ModelView includes

scaling

we

need to

normalize

the normals before Lighting

Tell OpenGL to normalize:

or not to do it:

(default)

glEnable(GL_NORMALIZE);

(79)

Normals as attributes

Exactly like the color:

glBegin(GL_TRIANGLES);

glNormal3fv( n );

glVertex3fv( v0 );

glVertex3fv( v1 );

glVertex3fv( v2 );

glBegin(GL_END);

glBegin(GL_TRIANGLES);

glNormal3fv( n0 );

glVertex3fv( v0 );

glNormal3fv( n1 );

glVertex3fv( v1 );

glNormal3fv( n2 );

glVertex3fv( v2 );

glBegin(GL_END);

flat shading !

(80)

Normals as attributes

Shortcut:

– When we set:

glShadeModel(GL_FLAT);

glShadeModel(GL_SMOOTH);

(81)

OpenGL: lights!

We have N lights available

– remember: their effects

(ambient + diffuse + specular) add up

How many ?

– Dependent on the specific OpenGL implementation

– The OpenGL standard requires at least 8

– The exact number is the value of the constant

(82)

OpenGL: lights!

Each light can be on or off

where

GL_LIGHT0

,

GL_LIGHT1

etc are costants

– note:

GL_LIGHT

k

is

GL_LIGHT0

+

k

.

useful for the

for

By default, the light 0 is the only one on

(83)

OpenGL: lights!

For each light, we set the colors

glLightfv(GL_LIGHT0, GL_DIFFUSE, v);

glLightfv(GL_LIGHT0, GL_AMBIENT, v);

(84)

OpenGL: lights!

For each light, we can also set:

– The spotlight effect:

glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,v);

glLightf (GL_LIGHT0,GL_SPOT_CUTOFF,v);

glLightf (GL_LIGHT0,GL_SPOT_EXPONENT,v);

default:

(0,0,-1)

180

0.0

glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,a);

glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,b);

glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,c);

– distance attenuation:

default:

(85)

OpenGL: lights!

For each light, we set the position:

glLightfv(GL_LIGHT0,GL_POSITION,v);

– If it is a positional light,

v = {x,y,z,1}

– If it is a directional light, (“infinite distance")

v = {x,y,z,0}

(86)

OpenGL: lights!

For each light, we set the position :

Note: the position of the lights is multiplied by

the MODEL_VIEW matrix

glLightfv(GL_LIGHT0,GL_POSITION,v);

(87)

Lighting equation

n

specular

material

specular

light

k

H

N

I

(

ˆ

ˆ

)

k

(

L

ˆ

N

ˆ

)

I

luight

diffuse

material

diffuse

material

ambient

ambient

light

k

I

emission

material

k

tot

I

f

light

attenuatio

n





min

1

2

,

1

L

3

L

2

1

c

d

c

d

c

f

light

attenuatio

n

effect

spotlight

f

direction

cutoff

Angle

beam

width

effect

spotlight

L

spot

spot

spot

f

f

,

,

,

properties of the light

properties of the

material

(88)

OpenGL: materials!

Let us set the parameters of the materials:

– the colors:

glMaterialfv(

face

, GL_AMBIENT, colorvec);

glMaterialfv(

face

, GL_EMISSION, colorvec);

glMaterialfv(

face

, GL_DIFFUSE, colorvec);

glMaterialfv(

face

, GL_SPECULAR, colorvec);

glMaterialf (

face

, GL_SHININESS, intval);

– The specular exponent:

"GL_FRONT"

shortcut: we can use

asdasdsadasdasd

To set both colors to the same

value

(89)

Other option: Color - Material

glEnable(GL_COLOR_MATERIAL);

activate:

use:

glColorMaterial(

face

,

mode

);

glColorMaterial(GL_FRONT, GL_DIFFUSE);

e.g.: when we set

The diffuse color of the material will be the

(otherwise ignored) current color

(90)

Two-sided Lighting

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);

glColorMaterial3f(

GL_BACK

,

...

);

glColorMaterial3f(

GL_FRONT

,

...

);

glColorMaterial3f(

GL_FRONT_AND_BACK

,

...

);

activation:

References

Related documents

Certified Surgical Technologist Saddleback Memorial Medical Center Laguna Hills, CA.. Hanne Smith

Eutrophication is a process driven by enrichment of water by nutrients, especially compounds of nitrogen and/or phosphorus, leading to: increased growth, primary production and

2017: Academy of Management, Austrian Economics Research Conference, Bocconi University (Depart- ment of Management and Entrepreneurship), Francisco Marroquin University

In this paper, we analyze the expected Information captured Per unit of Energy consumption (IPE) as a function of the event type (in terms of the utility function), the event

The aim of this study was to compare glottic view, time of intubation and success rate of the McGrath ® Series 5 and GlideScope ® Ranger video laryngoscopes with the

Interestingly we also showed that hypoxic and BMPR-II R899X+/- mice dosed with miRNA-96 mimic had a reduction in 5-HT 1B protein expression compared to those dosed

Additionally, Texas State University-San Marcos’ research expenditures have grown dramatically, and now far exceed the $14 million threshold cited in the Coordinating Board’s

The proposed method (FORCe: Fully Online and auto- mated artifact Removal for brain-Computer interfacing) is first described. Then the artifact removal methods LAMIC and FASTER,