shading
play

Shading Light Sources emit light Assignment 2 due on Friday EM - PowerPoint PPT Presentation

Announcements Illumination Shading Light Sources emit light Assignment 2 due on Friday EM spectrum Written Assignment 2 out later Position and direction Light Sources Light Sources today. Surfaces reflect light Diffuse & Specular


  1. Announcements Illumination Shading Light Sources emit light Assignment 2 due on Friday EM spectrum Written Assignment 2 out later Position and direction Light Sources Light Sources today. Surfaces reflect light Diffuse & Specular Reflection Diffuse & Specular Reflection Reflectance Phong Illumination Model Phong Illumination Model Geometry (position, orientation, micro-structure) Transmission with Refraction Transmission with Refraction Midterm next Thursday—or we Absorption Texture Mapping Texture Mapping Transmission could move it to 10/24 or 10/31? Watt, Chapter 6.2 and 6.3 COMPUTER GRAPHICS Illumination determined by the interactions between light sources and surfaces 15-462 9/23/02 1 3 Computer Graphics 15-462 Computer Graphics 15-462 Diffuse Reflection Types of Light Sources More Light Sources • Simplest kind of reflector (also known as Lambertian • Ambient: equal light in all directions Reflection ) – a hack to model inter-reflections • Models a matte surface -- rough at the microscopic level • Ideal diffuse reflector – incoming light is scattered equally in all directions • Directional: light rays oriented in same direction – viewed brightness does not depend on viewing direction – good for distance light sources (sunlight) – brightness does depend on direction of illumination • Point: light rays diverge from a single point Illumination direction • Spotlight: point source with directional fall-off – approximation to a light bulb (but harsher) – intensity is maximal along some direction D, falls off away from D – specified by color, point, direction, fall-off parameters • Area Source: Luminous 2D surface – radiates light from all points on its surface – generates soft shadows 4 5 6 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 1

  2. Examples of Diffuse Illumination Lambert’s Law Ambient + Diffuse Reflection CG started using the Lambertian model and then added = θ more terms as extra effects were required I k I cos diffuse d light = + • I k I k I ( N L ) = • + k I ( N L ) d a a a d light d light N L I : Light Source Intensity light I θ : Ambient light intensity (global) Same sphere lit diffusely from different lighting angles k : Surface reflectance coefficient in [0,1] a V d k : Ambient reflectance (local) θ N : Light/Normal angle a L θ N • L θ = cos N L V This is diffuse illumination plus a simple ambient light term a trick to account for a background light level caused by multiple See Watt if this is confusing reflections from all objects in the scene (less harsh appearance) 7 8 9 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 Phong Illumination Further Simple Illumination Effects Specular Reflection •Light attenuation: • Shiny surfaces change appearance when viewpoint is varied • One function that approximates specular falloff is called the Phong Illumination model – light intensity falls off with the square of the distance from the – specularities (highlights) are view-dependent source - so we add an extra term for this – caused by surfaces that are microscopically smooth = (cos φ n I k I ) shiny = + • specular s light f att = 1 • For shiny surfaces part of the incident light reflects I k I f k I ( N L ) where + d a a a att d light d 2 coherently – No real physical basis, yet widespread use in computer graphics with d the light source to surface distance - more complicated – an incoming ray is reflected in a single direction (or narrow beam) φ formulae are possible (see Foley) and work better : Angle between reflected light ray R and viewer V – direction is defined by the incoming direction and the surface normal k : Specular reflectance •Colored lights and surfaces: s • A mirror is a perfect specular reflector n : Rate of specular falloff – just have three separate equations for RGB shiny – approximate specular reflectors give fuzzy highlights •Atmospheric attenuation: N – use viewer-to-surface distance to give extra effects L R – the distance is used to blend the object’s radiant color with a θ θ θ θ θ θ θ θ φ φ φ φ “far” color (e.g., a nice hazy gray) V Greater n , more focused beam shiny 10 11 12 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 2

  3. Computing the Reflected Ray Phong Illumination Curves Phong Illumination • The specular exponents are often much larger than 1; N L R values of 100 are not uncommon. θ θ θ θ θ θ θ θ φ φ φ φ V = (cos φ n I k I ) shiny specular s light φ : angle between line of sight and perfect reflection Moving the light source k : Specular reflectance 2N(N•L) s n : Rate of specular falloff shiny L N(N•L) L L R = 2N(N•L) - L θ θ θ θ θ θ θ θ θ θ θ θ θ θ θ θ Project L onto N Double length of vector Subtract L Changing n shiny = • X N L 13 14 15 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 Some Examples OpenGL Materials Putting It All Together • Combining ambient, diffuse, and specular illumination [ ] = + θ + φ n I k I f I k cos k (cos ) shiny GLfloat white8[] = {.8, .8, .8, 1.}, white2 = {.2,.2,.2,1.},black={0.,0.,0.}; a a att light d s GLfloat mat_shininess[] = {50.}; /* Phong exponent */ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black); • For multiple light sources glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white8); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white2); – Repeat the diffuse and specular calculations for each light source glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); – Add the components from all light sources – The ambient term contributes only once • The different reflectance coefficients can differ. – Simple “metal”: k a and k d share material color, k s is white – Simple plastic: k s also includes material color 16 17 18 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 3

  4. OpenGL Lighting Transmission with Refraction Snell’s Law • Refraction: • Light bends by the physics principle of least time , a GLfloat white[] = {1., 1., 1., 1.}; – the bending of light due to its different velocities through different consequence of Huygens’ Principle materials GLfloat light0_position[] = {1., 1., 5., 0.}; /* directional light (w=0) */ – light travels from point A to point B by the fastest path • Refractive index: – when passing from a material of index n 1 to one of index n 2 glLightfv(GL_LIGHT0, GL_POSITION, light0_position); – light travels at speed c/n in a material of refractive index n glLightfv(GL_LIGHT0, GL_DIFFUSE, white); Snell’s law gives the angle of refraction : n 1 sin θ 1 = n 2 sin θ 2 glLightfv(GL_LIGHT0, GL_SPECULAR, white); – c is the speed of light in a vacuum where θ 1 and θ 2 are the angles from perpendicular glEnable(GL_LIGHT0); – varies with wavelength hence rainbows and prisms • When traveling into a denser material (larger n ), light glEnable(GL_NORMALIZE); /* normalize normal vectors */ MATERIAL INDEX OF REFRACTION bends to be more perpendicular (eg air to water) and glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); /* two-sided lighting*/ Air/Vacuum 1 vice versa glEnable(GL_LIGHTING); Water 1.33 – light travels further in the faster material Glass about 1.5 –i f the indices are the same the light doesn’t bend Diamond 2.4 • When traveling into a less dense material total internal reflection occurs if θ 1 >sin -1 ( n 2 / n 1 ) 19 20 21 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 Uniformly shaded surfaces are still unrealistic Shadows Shading • Shadows occur where objects are hidden from a light Given an equation to calculate surface radiance, we still source must apply it to the real model Real objects have surface features, or texture – omit any intensity contribution from hidden light sources – Usually performed during scan conversion One option: use a huge number of polygons with • Working out what it hidden is simply a visibility problem – There are efficient methods for doing this quickly (which we will appropriate surface coloring and reflectance – can the light source see the object? discuss in more detail later in the semester characteristics – use the z-buffer shadow algorithm: Texture mapping gets you further » run the algorithm from the light source’s viewpoint – Assign radiance based on an image » save the z-buffer as the shadow buffer Flat shaded » run the real z-buffer algorithm, transforming each point into the light Even better: use Procedural shaders to specify any Gouraud: Normal at vertex is average source’s coordinates and comparing the z value against the shadow function you want to define radiance buffer of normals for adjacent faces – The possibilities are endless… Phong: interpolate normals instead of – Generate radiance on the fly, during shading intensities – Key ingredient of high-end rendering systems » Pixar’s Renderman (used for “Toy Story”, “Bug’s Life”, etc.) 22 23 24 Computer Graphics 15-462 Computer Graphics 15-462 Computer Graphics 15-462 4

  5. Break for video… 25 Computer Graphics 15-462 5

Recommend


More recommend