illumination illumination. light sources directional light (infinitely far away) point light (emit...

Post on 17-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

IlluminationIllumination

Light Sources

Directional Light(Infinitely far away)

Point Light(Emit in all directions)

Spot Light(Emit within a cone)

Inner

cone

outer

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

Directional Light Sources

00 < ≤ 900

Object is within the spot light if cos ≥ cos l

Vobj . Vlight = cos Vlight

Vobj

l

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

Extended Light Sources

Warn Model

Approximate it as a light-emitting surface

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

Ambient Lighting

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

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

Diffuse Lighting

• Assume light bounces in all directions

Diffuse surface

Diffuse Lighting

Diffuse Lighting

Surface Normaln

Surface Normaln

Surface Normaln

Full Reflection NonePartial

L

Diffuse Lighting

DiffuseMaterial Color Light Color

Ambient +Diffuse

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

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

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)

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

Diffuse Lighting

Diffuse Lighting

Specular Lighting

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

Ex: a bright spot on shiny surfaces

Specular Lighting

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

Ambient +Diffuse +SpecularMaterial Color Light Color

Specular

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

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

Specular Lighting

A larger ns shows more concentration of the reflection

Specular Lighting

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)

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

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

Lighting

Diffuse and Specular Lightings

I = Idiff + Ispec

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

Multiple Light Sources

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

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

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.

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

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

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.

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}

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

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.

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

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

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

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.

Light Refraction

Light Refraction

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

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

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)

Polygon Rendering

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

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

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

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

Polygon Rendering

Phong Surface Rendering

Interpolates normal vectors.N N3

N1

N2

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.

Polygon Rendering

Flat shading Gouraud shading Phong shading

Source: Michal Necasek

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

Texture Mapping

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

s

0.0

1.0

3 x n elements

RGB

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)

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)

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.

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

Texture Mapping

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

s

3 x m x n x k elements

t r

Surface Light Emission

Divide surfaces to eliminate the overlap.

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

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

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)

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

Light Sources

Point light source

Infinitely distant light source

top related