Lighting and Shading Lighting and Shading
Total Page:16
File Type:pdf, Size:1020Kb
Lighting and Shading Reading Assignment: Chapter 6 Lighting and Shading Is this a plate or a ball? What color should I set for each pixel? Physical Reality As light hits the surface: –Part is absorbed –Part is reflected Visible light includes all colors of the rainbow Physical Reality Physically, objects can be said to have the color of the light leaving their surfaces: W hite Light Colours Absorbed t n Ligh Gree If a blue object is illuminated with red light, it will appear as ________. Our Objective: Understand and model what light does in a scene. A Model for Lighting Follow rays from light source Only light that reaches the eye is ever seen –direct light is seen as the color of the light source – indirect light depends on interaction between material and light Lighting in Computer Graphics For Computer graphics we replace viewer with projection plane Rays which reach COP after passing through viewing plane are actually seen Color of pixels is determined by our interaction model Light‐Material Interactions Determine whether an object appears red or brown, light or dark, dull or shiny Reflection of light from a surface can be: Specular Diffuse Translucent Specular Surfaces Smooth, shiny, glossy Mirror‐like Reflection focused to one direction (angle of incidence = angle of reflection) Diffuse Surfaces Rough (grainy, matte) Light reflected almost uniformly in all directions Translucent Surfaces Allow some light to pass through Glass or water‐like Light‐Material Interaction Summary Surfaces may be – Specular –Diffuse –Translucent A surface is never perfectly diffuse or perfectly translucent or perfectly specular. May have all these properties! To model these properties, we must understand how light reflects off each of these surface types. Basic Illumination Model Basic Illumination Model We will consider a basic illumination model which gives reasonably good results and is used in most graphics systems The important components are: –Diffuse reflection – Specular reflection – Ambient light Example The total reflected light from a surface is the sum of the contributions from light sources and reflected light Ambient Light Walk around the back of box. No light beams hit it directly. Can you see the back face? This type of indirect light is called ambient light. Ambient Light Like sunlight on a totally clouded day! Uniform level of light, position‐independent Tells us how bright an object looks when no light source can directly reach it Ambient Light Also called background light Not created by any light source A constant lighting from all directions Contributed by scattered light in a surrounding When used alone, does not produce very interesting pictures Ambient light only Ambient Light To incorporate background light we simply set a general brightness level Ia for a scene Different surfaces may reflect different amount of ambient light, based on their reflectance properties. We model this by a constant factor for each surface: ka × Ia RGB Color Considerations For an RGB colour description each intensity specification is a three element vector Ia = ()IaR , IaG , IaB Similarly, the reflectance is given as a vector: ka = ()kaR ,kaG ,kaB Red, green and blue ambient light intensities are ()kaR IaR ,kaG IaG ,kaB IaB Illumination: Ambient Light ⊗ Material Color Light Color Hands‐on Session Run the lightmaterial tutor, and right‐click select “Material Parameters” Make the light source ambient‐ only (set all other material reflectivity coefficients to 0). Try different color combinations of ambient light and material, and see how the scene reacts to these changes. Diffuse Reflection •Light scattered with equal intensity in all directions (ideal diffuse reflection) •Light from a point is independent on viewing direction (equally bright in all directions) Intermezzo: Surface Normals N N where p0 is the center of the sphere Diffuse Reflection The angle between the incoming light direction and a surface normal is referred to as the angle of incidence, denoted θ. L = unit vector to light source N = unit vector normal to surface Law of reflection: the angle of incidence equals the angle of reflection, and L, N and R(eflection) directions are co‐planar. Modeling Diffuse Reflection The amount of incident light depends on the orientation of the surface relative to the light source direction. Diffuse Reflection •The amount of incident light on a surface depends on the angle of incidence: •As θ increases, the brightness of the surface decreases by L L N θ N ____________ ? d Recall: Dot Product N θ N∙L = |N||L|cos θ L If N and L are unit vectors, then N∙L = cos θ Diffuse Reflection If surface has brightness Ι when facing light, it has brightness Ι*cos(θ) when tilted at angle θ. N N∙L = cos θ θ L (N, L are unit vectors) You will see the brightness written as I(N∙L) Diffuse Reflection A parameter kd set for each surface determines the fraction of incident light scattered as diffuse reflections from that surface This parameter is known as the diffuse reflection coefficient or the diffuse reflectivity kd is assigned a value between 0.0 and 1.0 –0.0 for dull surface that absorbs almost all light –1.0 for shiny surface that reflects almost all light Diffuse Reflection Diffuse reflections: ⎪⎧kd I(N ⋅ L) if N ⋅ L > 0 Id = ⎨ ⎩⎪ 0 if N ⋅ L ≤ 0 Diffuse Reflection Spheres lit by diffuse (kd) values of 0.0, 0.25, 0.5, 0.75, 1 respectively Ambient Light vs. Diffuse Reflection Ambient lighting only With diffuse lighting Hands‐on Session Run the lightmaterial tutor Make the light source diffuse‐only Check the color of a blue object illuminated with red light Try different color combinations of diffuse light and material Change the light position and observe the changes in the brightest spots on the torus Combine diffuse and ambient light Diffuse Lighting: What’s Missing? ⊗ Diffuse Ambient + Material Color Light Color Diffuse Ambient + diffuse reflections produce shaded images that appear three‐dimensional But the surfaces look dull, somewhat like chalk What is missing? Specular Reflection Intensity depends on where the viewer is! White specular highlight The white specular highlight is the reflection of white light from the source in the direction of the viewer Specular Reflection The bright spot that we see on a shiny surface is the result of incident light reflected in a concentrated region around the specular reflection angle The specular reflection angle equals the angle of the incident light L = vector to light source N = vector normal to surface R = direction of reflected light V = vector to viewer Specular Reflection A perfect mirror reflects light only in the specular‐reflection direction Other objects exhibit specular reflections over a finite range of viewing positions around vector R The Phong Specular Reflection Model The Phong model sets the intensity of specular reflection as proportional to the angle φ between the viewing vector and the specular reflection vector: α I s = I × k s × cos φ α = shineness exponent ks = specular reflectivity of material The Phong Specular Model α I s = I × k s × cos φ α = shininess ks = reflectivity The shineness α is determined by the type of surface we want to display – Shiny surfaces have a very large value (>100) – Rough surfaces would have a value near 1 The larger the α, the more concentrated the light is around R. For mirrors, α Æ infinity. The Phong Specular Model α I s = I × k s × cos φ α = shininess ks = reflectivity Recall that R∙V = cos φ ⎧ α if V ⋅ R > 0 and N ⋅ L > 0 ⎪ks I (V ⋅ R) I s = ⎨ ⎩⎪ 0.0 if V ⋅ R < 0 or N ⋅ L ≤ 0 Illumination: Specular Lighting Ambient + Specular Diffuse + Material Color Light Color Specular Create shining surface (surface perfectly reflects) Viewpoint dependent Specular+Diffuse Reflection Example Phong Reflection Model Summary Due to the ambient light, nothing can be entirely black Mirror reflections are possible Can be computed very fast (used in VR and games) Very good approximation of diffuse surfaces Physically inaccurate Expressed in terms of vector geometry Putting it All Together The intensity of light from one point is a sum of the diffuse, specular and ambient components: ++ Red Bluish Specular ambient diffuse Highlight I = I a + I d + I s Putting it All Together 0.2 0.4 0.6 0.8 1.0 diffuse specular = 0 shininess = 0 0.2 0.4 0.6 0.8 1.0 specular diffuse = 0.5 shininess = 120 10 30 60 160 250 shininess diffuse = 0.5 specular = 0.5 OpenGL Lighting Functions OpenGL Lighting Functions OpenGL provides functions for – setting up point light sources and spotlights, – selecting surface reflection coefficients – choosing values for several parameters in the basic illumination model Implements the Phong reflection model Steps in OpenGL Lighting 1. Enable lighting and select shading model 2. Specify normals 3. Specify material properties 4. Specify lights Enable Lighting Calculations Lighting calculations are enabled globally in an OpenGL program using glEnable (GL_LIGHTING); Once lighting is enabled, glColor*() ignored Enable Individual Light Sources Up to eight light sources (GL_MAX_LIGHTS) can be included in a standard OpenGL implementation –Some implementations may allow more than 8 Each light source is referenced by its identifier: GL_LIGHT0, GL_LIGHT1, ..., GL_LIGHT7 A light source is enabled with: glEnable (lightName); Example: glEnable (GL_LIGHT0); Select the Light Model Select the light model: glLightModeli(parameter, GL_TRUE); Parameter can be: • GL_LIGHT_MODEL_LOCAL_VIEWER