Local Illumination and Shading
Computer Graphics – Lecture 5
Taku Komura [email protected]
Institute for Perception, Action & Behaviour
Taku Komura Computer Graphics What affects how the colour appears? The incident light • Position of light source • Direction • Its own color The object • Reflectance Viewer • Position
Taku Komura Computer Graphics Overview
Illumination (how to calculate the colour) Shading (how to colour the whole surface)?
Taku Komura Computer Graphics Illumination Simple 3 parameter model − The sum of 3 illumination terms: • Ambient : 'background' illumination • Specular : bright, shiny reflections • Diffuse : non-shiny illumination and shadows
+ + =
Ambient Diffuse Specular Rc (colour) (directional) (highlights)
Taku Komura Computer Graphics Ambient Lighting
− Light from the environment — light reflected or scattered from other objects — Coming uniformly from all directions — and then reflected equally to all directions − A precise simulation of such effects requires a lot of computation
Object
Taku Komura Computer Graphics Ambient Lighting Simple approximation to complex 'real-world' process
Result: globally uniform colour for object I = resulting intensity Example: sphere Ia = light intensity
ka = reflectance
= Object I ka Ia
Taku Komura Computer Graphics Diffuse Lighting • When light hits an object – If the object has a rough surface, it is reflected to various directions – If the object is translucent, it enters an object and traverses inside, before it goes out • Result: Light reflected to all directions
– considers the angle of incidence of light on surface – (angle between light and surface normal) – Also known as Lambertian reflection – Result: lighting varies over surface with orientation to light
Taku Komura Computer Graphics Diffuse Lighting
L Infinite point n Example: sphere light source (lit from left) = θ θ N I I I pkd cos
I p : Light Intensity θ : the angle between the normal vector Object No dependence on camera angle! direction towards the light kd : diffuse reflectivity
Taku Komura Computer Graphics
• Light reflected to all directions – considers the angle of incidence of light on surface – (angle between light and surface normal) – Also known as Lambertian reflection – Result: lighting varies over surface with orientation to light Specular Lighting • Direct reflections of light source off shiny object – The object has a very smooth surface
– specular highlight on object
Taku Komura Computer Graphics Specular Lighting • Direct reflections of light source off shiny object – specular intensity n = shiny reflectance of object – Result: specular highlight on object
Ln N Infinite point light source R (Reflection) θ θ α
Object
No dependence on object colour.
Taku Komura Computer Graphics
Ip: light intensity
I : output color R: reflection vector
S : direction towards the camera α : angle between R and S Specular Light
Taku Komura Computer Graphics Combined Lighting Models
• Summing it altogether : Phong Illumination Model = + θ + n α Iλ Iaka I p[kd cos ks cos ]
+ + =
Ambient Diffuse Specular Rc (colour) (directional) (highlights)
Taku Komura Computer Graphics When you implement it…
Use dot product of the vectors instead of calculating the angles θ,α N L R θ θ lights α = + • + • n Iλ Iaka ∑ I p[kd (N L) ks (V R) ] V p=1 Object V : Vector from the surface to the viewer N : Normal vector at the colored point R : Normalized reflection vector L : Normalized vector from the coloured point towards the light source Taku Komura Computer Graphics Color lights R = R R + R R • + R • n Iλ Ia ka ∑ I p [kd (N L) ks (V R) ] p=1
lights G = G G + G G • + G • n Iλ Ia ka ∑ I p [kd (N L) ks (V R) ] p=1
lights B = B B + B B • + B • n Iλ Ia ka ∑ I p [kd (N L) ks (V R) ] p=1 • Finally color the pixel by the RGB color
Taku Komura Computer Graphics Demo applets
http://www.cs.auckland.ac.nz/~richard/research- topics/PhongApplet/PhongDemoApplet.html
Taku Komura Computer Graphics Exercise 1
Taku Komura Computer Graphics Attenuation Haven’t considered light attenuation – the light gets weaker when the object is far away Use 1/(s+k) where s relates to eye-object distance and k is some constant for scene.
lights I I = I k + ∑ p [k (N • L) + k (V • R)n ]+ I k λ a a + d s t t p=1 (so k)
Taku Komura Computer Graphics Local Illumination Model
Considers light sources and surface properties only. − Not considering the light reflected back onto other surfaces
Fast real-time interactive rendering. Cost increases with respect to the number of light sources Most real-time graphics (games, virtual environments) are based on local illumination models Implementation - OpenGL, Direct3D
Taku Komura Computer Graphics Overview
Illumination (how to calculate the color) Shading (how to color the whole surface)?
Taku Komura Computer Graphics How often do we do the computation of illumination?
At all the points on the surface?
But usually we have normals only at the vertices
Depends on the shading model – Flat Shading (once per polygon) (less computation needed) – Gouraud shading (once per vertex) – Phong Shading (once per pixel) (heavy computation needed)
Taku Komura Computer Graphics Flat Shading
Compute the colour at the middle of the polygon All points in the same polygon are coloured by the same colour
Taku Komura Computer Graphics Shading Polyhedra
Flat (facet) shading: Works well for objects really made of flat faces. Appearance depends on number of polygons for curved surface objects. • If polyhedral model is an approximation then need to smooth.
Taku Komura Computer Graphics Gouraud shading
Taku Komura Computer Graphics Gouraud shading
•Computing the colour per vertex by local illumination model •Then, interpolating the colours within the polygons
B
A
Ibc
Iac C
Iac interpolated A to C, Ibc interpolated B to C.
Taku Komura Computer Graphics Gouraud Shading.
N1 Find vertex normals by averaging face normals ∑ Ni N NV ≤ ≤ 4 = 1 i n NV
N ∑ N 2 i 1≤i≤n
N3 - Use vertex normals with desired shading model,
- Interpolate vertex intensities along edges.
- Interpolate edge values across a scanline.
Taku Komura Computer Graphics Gouraud Shading.
For specular reflection, highlight falls off with cosn α
Gouraud shading linear interpolates – makes Direction of maximum highlight too big. highlight
Gouraud shading may well miss a highlight that occurs in the middle of the face.
Taku Komura Computer Graphics Phong Shading
interpolating the normal vectors at the vertices Do the computation of illumination at each point in the polygon
Taku Komura Computer Graphics Phong shading. For specular reflection, highlight falls off with cosn α
Direction of maximum Can well produce a highlight highlight that occurs in the middle of the face.
Highlight on surface.
Taku Komura Computer Graphics Phong example
Taku Komura Computer Graphics Gouraud Shaded Floor Phong Shaded Floor
Gouraud shading is not good when the polygon count is low
Taku Komura Computer Graphics Exercise 2
Taku Komura Computer Graphics Problems with interpolation shading.
Problems with computing vertex normals.
A A,B are shared by all polygons, but C is not shared by the polygon on the left.
C -Shading information calculated to the right of C will be different from that to the left. B - Shading discontinuity.
Solution 1: subdivide into triangles that that share all the vertices Solution 2 : introduce a ‘ghost’ vertex that shares C’s values
Taku Komura Computer Graphics Problems with interpolation shading.
Problems with computing vertex normals.
Face surface normals and averaged vertex normals shown.
Unrepresentative so add small polygon strips along edges or test angle and threshold to defeat averaging.
Taku Komura Computer Graphics Problems with interpolation shading.
Rotational invariance? − When interpolating the colour inside a polygon, the edge colours are determined first, and then they are interpolated to compute the internal colour − If the number of edges is >= 4, the results of interpolation shading can change with orientation of the polygon.
A Point on left is interpolated B between AD & AB ,
A Point on right is interpolated D B C between AB & BC
D C
Taku Komura Computer Graphics Recommended Reading
Foley et al. Chapter 16, sections 16.1.6 up to and including section 16.3.4. Introductory text Chapter 14, sections 14.1.6 up to and including section 14.2.6.
Taku Komura Computer Graphics