69
Illumination Illumination

Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Embed Size (px)

Citation preview

Page 1: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

IlluminationIllumination

Page 2: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Sources

Directional Light(Infinitely far away)

Point Light(Emit in all directions)

Spot Light(Emit within a cone)

Inner

cone

outer

cone

Page 3: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Radial Intensity Attenuation

The amplitude of a radiant energy at the distance dl is attenuated by the factor 1/dl

2.

For realistic effects:

1/ (a0+a1dl+a2dl2) local

fl,radatten(dl)= 1.0 infinity

Page 4: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Directional Light Sources

00 < ≤ 900

Object is within the spot light if cos ≥ cos l

Vobj . Vlight = cos Vlight

Vobj

l

Page 5: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Angular Intensity Attenuation

fangatten() = cosa

1.0 if light source is not spotlight

fl,angatten = 0.0 if Vobj.Vlight=cos < cos l (outside of spotlight cone)

(Vobj . Vlight )al otherwise

Vobj

Vlight

l

Page 6: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Extended Light Sources

Warn Model

Approximate it as a light-emitting surface

Page 7: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Ambient Lighting

Background Light

A surface that is not directly exposed to a light source may still be visible due to the reflected light from nearby objects.

Ia: intensity parameter of ambient reflection

Ambient reflection is: independent of viewing direction and

surface orientation depends on the surface properties

eye

Page 8: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Ambient Lighting

Page 9: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Ambient Lighting Not created by any light source A constant lighting from all directions Contributed by scattered light in a surrounding

ambientambientambient LMC RGB multiplies separatelyMaterial Color Light Color

Page 10: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Light is scattered with equal intensity in all directions, independent of the viewing direction.

The surface appears equally bright from any viewing angle.

Ex: rough or grainy surfaces

Page 11: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

• Assume light bounces in all directions

Diffuse surface

Page 12: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Page 13: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Surface Normaln

Surface Normaln

Surface Normaln

Full Reflection NonePartial

L

Page 14: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

DiffuseMaterial Color Light Color

Ambient +Diffuse

)()0,max( diffdiffambientambientdiff LMnLLMC Ambient + Diffuse

Page 15: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Lambert’s cosine law:The amount of radiant energy coming from

any surface area dA in a direction N relative to the surface normal is proportional to cosN.

radiant energy per unit time intensity = -------------------------------------

projected area

cosN / (dA cosN) = constant

N (surface normal)

Radiant energy direction

N

N

dA

Page 16: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Background lighting with ambient light

Iambdiff = kd Ia

kd : Fraction of the incident light that is to be scattered as diffuse reflections (diffuse reflection coefficient)

Page 17: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse LightingIl,incident = Il cos

Il,diff = kd . Il,incident = kd . Il cos

kd . Il (N.L) if N.L > 0Il,diff =

0.0 if N.L ≤ 0

L = (Psource-Psurf) / |Psource-Psurf|

Ambient and point-source: ka . Ia + kd . Il (N.L) if

N.L>0Idiff =

ka . Ia if N.L≤0

N (surface normal)

L (to incident light source)

A (area)

A cos

cos= N.L

Page 18: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Page 19: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse Lighting

Page 20: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

The incident light is reflected in a concentrated region around specular reflection angle.

Ex: a bright spot on shiny surfaces

Page 21: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

Page 22: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting Create shining surface (surface perfectly reflects) Viewpoint dependent

Ambient +Diffuse +SpecularMaterial Color Light Color

Specular

Page 23: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

N – surface normalL – to light sourceR – direction of ideal specular

reflectionV – to viewer – viewer angle relative to specular

reflection directionif =0, ideal reflector (mirror)

NRL

V

Page 24: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

Sets the intensity of specular reflection proportional to cosns.

ns: specular reflection exponent

100 or more => shiny

near 1 => dull

infinite => perfect reflector

Page 25: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

A larger ns shows more concentration of the reflection

Page 26: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Specular Lighting

Page 27: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Phong Model

W(): specular reflection coefficient of the surface

Il,spec = W() Il cosns

opaque surface: W()=constant=ks (0.0-1.0)

transparent surface: reflection is appreciable if approaches to 900.

NRL

Shiny surface(large ns)

NRL

Dull surface(small ns)

Page 28: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Phong Model

cos = V . R

Il,spec = W() Il cosns

ks Il (V.R)ns if V.R>0 & N.L>0

Il,spec =

0.0 if V.R<0 & N.L≤0

R = (2N.L)N - L

NRL

V

Page 29: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Phong Model

H: halfway vector between V and L

H=(L+V) / |L+V|

Replace V.R (cos) by N.H (cos)

ks Il (N.H)ns if V.R>0 & N.L>0

Il,spec =

0.0 if V.R<0 & N.L≤0

Requires less computation

NRL

V

H

Page 30: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Lighting

Page 31: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Diffuse and Specular Lightings

I = Idiff + Ispec

= ka Ia + kd Il (N.L) + ks Il (N.H)ns

Page 32: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Multiple Light Sources

I = Iambdiff + ∑nl=1 (Il,diff + Il,spec )

= ka Ia + ∑nl=1 Il (kd(N.L) + ks(N.H)ns)

Page 33: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Surface Light Emission

Ex: light bulb, etc.

- Position a directional light source behind the surface- Simulate the emission with a set of point light sources

distributed over the surface

Radiocity model can be used to model realistic surface emission.

Page 34: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Surface Light Emission Color is emitted by the material only

ssn

ddaaeall LMHnLMnLLMCC ))0,(max()()0,max(

Ambient +Diffuse +Specular +Emissive

Material EmissiveColor

+

Ambient +Diffuse +Specular

Page 35: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Surface Light EmissionExtending the Light Model:

I = Isurfemission + Iambdiff + ∑nl=1 fl,radatten fl,angatten (Il,diff + Il,spec )

kd . Il (N.Ll) if N.L > 0Il,diff =

0.0 if N.L ≤ 0

ks Il max{0.0, (N.Hl)ns } if V.R>0 &

N.L>0Il,spec =

0.0 if V.R<0 & N.L≤0

1/ (a0+a1dl+a2dl2) local

fl,radatten(dl)= 1.0 infinity

1.0 if light source is not spotlight

fl,angatten = 0.0 if Vobj.Vlight=cos < cos l

(Vobj . Vlight )al otherwise

Page 36: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Surface Light Emission

Intensity Overflow:

- If any term exceeds the maximum intensity, set the intensity to maximum.

- Divide the intensity if each term by the magnitude of the largest term to scale intensities between 0.0-1.0

- Set negative intensities to 0.0.

Page 37: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

RGB Color

Il = (IlR, IlG, IlB)

ka = (kaR, kaG, kaB)

Ex: for blue component

IlB,diff = kdB IlB (N.Ll)

Il,spec = ksB IlB max{0.0, (N.Hl)ns}

Page 38: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

LuminanceLightness or darkness of a color (Brightness)

luminance = ∫visible f (f) I(f) df

f: frequencyI(f): intensity of light component with frequency f that is radiating in a particular

direction(f): experimentally determined proportionality function that varies with f and

illumination level

Green component contribute most to the luminanceBlue component contribute least to the luminance

luminance = 0.299 R + 0.587 G + 0.114 B orluminance = 0.2125 R + 0.7154 G + 0.0721 B

Page 39: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Transparency

Transparent: objects behind are seenOpaque: objects behind cannot be seenTranslucent: objects behind appear blurred

Transparent surfaces produce reflected and transmitted light.

Translucent surfaces have both diffuse and specular transmission. Ray tracing can be used.

Page 40: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

Snell’s Law:sin r = (i/r) sin i

i: angel of incidencei: index of refraction for the incident

material r: index of refraction for the refracting

material

Ex:air: 1.0glass: 1.61

NRL

T

i

r

i

reflection

refraction

i

r

airglass

air

Page 41: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

T = [(i/r) cos i - cos r] N - (i/r)L

Gives realistic effect but requires calculation

Ray tracing

NRL

T

i

r

i

reflection

refraction

i

r

Page 42: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

Ignoring path shift due to refraction:

I = (1-kt) Irefl + kt Itrans

Itrans: transmitted intensity

Irefl: reflected intensity

kt: transparency coefficient 1.0 – transparent0.0 – opaque

(1-kt): opacity factor

NRL

T

i

r

ireflection

refraction

i

r

Page 43: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

In Depth-Buffer Approach: Process opaque surfaces first Then, compare the depths of the transparent surfaces

with the depth-buffer If a transparent surface is visible, combine its intensity

with the intensity that is previously stored in the frame buffer.

Page 44: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

Page 45: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Refraction

Page 46: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Atmospheric Effects

fatmo(d) = e-d or fatmo(d) = e-(d)2

d: distance of the object to the viewing position: to set a positive density value for the atmosphere

Higher value means denser atmosphere, where colors are muted.

Combining atmosphere color with the object’s color:

I = fatmo(d) Iobj + (1- fatmo(d)) Iatmo

Page 47: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Shadows

Generated by a visible surface detection method

Surfaces that are visible from the view position are shaded according to the lighting model, which can be combined with texture patterns

Shadow areas are displayed with ambient light only or ambient light combined with textures

Page 48: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Constant-Intensity Surface Rendering

Accurate in the following cases:

Polygon is not a section of a curved surface

All light sources are sufficiently far from the surface (N.L is constant)

Viewing position is sufficiently far from the surface (V.R is constant)

Page 49: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Page 50: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Gouraud Surface Rendering

Linearly interpolates vertex intensities across the polygon faces.

1. Determine the average unit normal vector at each vertex of the polygon

2. Apply an illumination model at each polygon vertex to obtain the light intensity at that position

3. Linearly interpolate the vertex intensities over the projected area of the polygon

Page 51: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Gouraud Surface Rendering

(1) At each vertex, average the normal vectors of the polygons that share the same vertex, to obtain the normal vector of the vertex:

∑nk=1 Nk

NV = --------------------

| ∑nk=1 Nk |

V

N

N

NN

NV

Page 52: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Gouraud Surface Rendering

(3) Interpolate vertex values to obtain the intensities at the intersection of a scan line with the polygon

P

y

x

Page 53: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Scan conversion algorithm

RGB(255,0,0)

RGB(0,255,0)RGB(0,0,255)

RGB(127,0,127) RGB(127,127,0)

RGB(127,64,64)

Scan line

Page 54: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Phong Surface Rendering

Interpolates normal vectors.N N3

N1

N2

Page 55: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon RenderingPhong Surface Rendering

For each polygon:1. Determine the average unit normal vector at each vertex of

the polygon2. Linearly interpolate the vertex normals over the projected area

of the polygon (similar to Gouraud method)3. Apply an illumination model at positions along scan lines to

calculate pixel intensities using the interpolated normal vectors

Apply the same incremental methods to obtain normal vectors on successive scan lines.

Page 56: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Polygon Rendering

Flat shading Gouraud shading Phong shading

Source: Michal Necasek

Page 57: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Texel: a component of texture description

Four RGB components:- Red component- Green component- Blue component- an index into a color table or a single luminance value

Page 58: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Linear Texture Patterns (1D) s - coordinate texture space

s

0.0

1.0

3 x n elements

RGB

Page 59: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Surface Texture Patterns (2D) s,t - coordinate texture space

s(0,0)

3 x m x n elements

t

(1,0)

(0,1)

Page 60: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Surface Texture Patterns (2D)

Texture space(s,t-coord)

Texture-surface transformation

Viewing and projection transformation

Texture space

Object space

Image space

Texture-surface transformation

Viewing and projection transformation

Method 1

Method 2

Object space(u,v-coord)

Image space(x,y-coord)

Page 61: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Surface Texture Patterns (2D)Method 1: Mapping from Texture Space to Object Space –

u = u(s,t) = au s + bu t + cu

v = v(s,t) = av s + bv t + cv

Mapping from Object Space to Image Space – use viewing and projection transformations

Disadvantage: If the texture patch does not match up with the pixel boundaries, the fractional area of pixel coverage must be calculated.

Page 62: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Surface Texture Patterns (2D)

Method 2:

MVP-1: inverse viewing-projection

transformation

MT-1: inverse texture-map transformation

Pattern Array

projected pixel area

pixel areaSurface

MVP-1MT

-1

Page 63: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Texture Mapping

Volume Texture Patterns (3D) s,t,r - coordinate texture space

s

3 x m x n x k elements

t r

Page 64: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Surface Light Emission

Divide surfaces to eliminate the overlap.

Page 65: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Depth Cueing

fdepth(d) is multiplied by each pixel’s color

fdepth(d) = (dmax-d)/(dmax-dmin)

d: distance of a point from the viewing position

dmin: 0.0

dmax: 1.0

Page 66: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

OpenGL

glPolygonMode(GL_FRONT_AND BACK, GL_LINE)• displays both visible and hidden edges

glEnable (GL_FOG) glFogi (GL_FOG_MODE, GL_LINEAR)

• generates fog effect. Uses depth cueing.

glEnable (GL_CULL_FACE) glDisable (GL_CULL_FACE) glCullFace (mode)

• used for backface removal• GL_BACK (default), GL_FRONT (if inside a building),

GL_FRONT_AND_BACK

Page 67: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

OpenGL glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)

• initializes GLUT, requests a depth buffer and a frame buffer

glClear (GL_DEPTH_BUFFER_BIT)• initially depth buffer has the background color. It must be cleared every

time before displaying a new frame.

glEnable (GL_DEPTH_TEST) glDisable (GL_DEPTH_TEST)

• to activate depth buffer routines

glClearDepth (maxDept)• to set maxDepth to another value (0.0 – 1.0)

glDepthRange (nearNormDept, farNormDept)• to adjust normalization values (defaults: near- 0.0, far- 1.0)

Page 68: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

OpenGL

glDepthFunction (testCondition)

• to specify a test condition for depth-buffer routines

• GL_LESS (default), GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_LEQUAL, GL_GEQUAL, GL_NEVER, GL_ALWAYS

glDepthMask (writeStatus)

• to set the status of depth-buffer routines

• TRUE: read/write

• FALSE: read only

Page 69: Illumination Illumination. Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone)

Light Sources

Point light source

Infinitely distant light source