16
computer graphics & visualization Lighting & Shading

Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

Embed Size (px)

Citation preview

Page 1: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Lighting & Shading

Page 2: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Illumination

Without Local Global

Page 3: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Global Illumination- Interaction with matter - Consider multiple reflections, transmission, shadows

Rendering Equation:

iiiinrirrer dxIxfxIxI cos,,,,,

BRDF

Page 4: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local Illumination - Phong LightingGeneral Idea:

- Consider only (non-area) light sources that are directly visible from the point on the objects surface without reflections.

- Each point is illuminated independent of its “global” surroundings (except “self”-occlusion of light sources)

- Idea: Approximate illumination by three additive components, representing ambient, diffuse and specular lighting.

Page 5: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationAmbient Lighting- Hack for replacing true global illumination

(i.e. light bouncing off from other objects)- No direction- Incoming light component that is identical everywhere in the

whole scene

where- ka is the ambient material coefficient of reflection with

0.0 <= ka <= 1.0 and- Ia is the intensity of the ambient light

aaamb IkI

Page 6: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationDiffuse Lighting- Rough material - Brightness ~ incoming Energy (Lambertian reflection)- Object scatters light into all directions equally- Heuristic reflection model but plausible for certain materials

Page 7: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationDiffuse LightingPower per unit area arriving at point x depends on the angle of

the surface to the light direction (Johann Friedrich Lambert)

dA

dA‘

Iin

N

J

J cosI

Page 8: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationDiffuse Lighting- Rough material - Brightness ~ incoming Energy (Lambertian reflection)- Object scatters light into all directions equally- Heuristic reflection model but physically plausible for certain kd

N

L

Intersection Point

)()()),(cos()()( LNxIkLNxIkxI indinddiff

Page 9: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationSpecular Lighting- Glossy/smooth material - Light is mostly reflected into the directions around the mirror

direction RL of L

Diffuse SpecularGlossy

Page 10: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local IlluminationSpecular Lighting: The Phong model- Use cosine power as heuristic - Light is mostly reflected into the directions

around the mirror direction RL of L (Rapid decay)- Perfect mirroring only in direction RL (perfect mirror: n )

nLinspec

ninspecspec RVxIkxIkxI )()()(cos)()(

a

cosn

aJ J

N

LRL

V

eye

Page 11: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Local Illumination

Careful! If a light is situated behind the object (α > 90°) then cos(α) < 0. Discard negative intensity values by clamping the dot products dot to the range [0,1] ! dot = max(0,dot)

ka = 0.1

kd = 0.5

ks = 0.4Ambient Diffuse Specular Phong

nLinsspecinddiffaaamb RVxIkxILNxIkxIIkI )()()(,)()()(,

Page 12: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Incorporating color• So far we have only dealt with Intensity:

One possible approach to incorporate color: – diffusely reflected light results from the reflection via multiple scattering

events in the micro-scale geometry reflected light is coloured by selective absorption by the surface i.e. a green surface absorbs all wavelengths except green

– specularly reflected light interacts once with the surface and is thus not “coloured” by the surface i.e. the reflection of a light source remains the colour of the source

))()(((0

numLights

x specdiffamblocal xIxIII

Page 13: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Color of Material and LightUsually we define Colors as 3 component vector C(r,g,b) Therefore the Phong model becomes:

Camb global ambient lighting color defined once in the whole scene

Cdiff defined per material

Cspec specified per light source

(To increase flexibility the specular color can additionally be scaled by a color defined per material)

))()(((0 spec

numLights

x specdiffdiffambamblocal CxICxICIC

Page 14: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Graphics Pipeline (DirectX 10)Input Data

Input AssemblerStage (IA)

Vertex ShaderStage (VS)

Geometry ShaderStage (GS)

Stream OutputStage (SO)

Rasterizer Stage(RS)

Pixel ShaderStage (PS)

Output MergerStage (OM)

Output Data

Memory Resources:

Buffers, Textures,

Constant Buffers

Buffer

Texture, Constant Buffer

Texture, Constant Buffer

Texture, Constant Buffer

Buffer

States

Buffer, Texture, Constant Buffer

VB

IB

Page 15: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Shading: Flat vs. Gouraud vs. Phong

Phong Lighting

Gouraud Shading

Phong Lighting

Phong Shading

Phong Lighting

Flat Shading

Page 16: Computer graphics & visualization. Seminar SS 2010 – Game Engine Design Lighting & Shading Illumination WithoutLocalGlobal

computer graphics & visualization

Seminar SS 2010 – Game Engine DesignLighting & Shading

Shading: Gouraud vs. PhongGouraud Shading Phong Shading

evaluates lighting per vertex evaluates lighting per fragment