Lighting and Reflection Angel 6.1-6.3 Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 1.

Slides:



Advertisements
Similar presentations
Computer Graphics - Shading -
Advertisements

Computer Graphics Shading Lecture 13 John Shearer
Computer Graphics I, Fall 2010 Shading II.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
CSPC 352: Computer Graphics
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Lighting and Shading Wen-Chieh (Steve) Lin
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
LIGHTING Part One - Theory based on Chapter 6. Lights in the real world Lights bounce off surfaces and reflect colors, scattering light in many directions.
Shading Surface can either (both) 1.Emit light. E.g. light bult 2.Reflect light. E.g. Mirror.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
CS 445 / 645: Introductory Computer Graphics
Computer Graphics Lighting.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Shading I Shandong University Software College Instructor: Zhou Yuanfeng
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 6: Shading Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
Illumination & Reflectance Dr. Amy Zhang. Outline 2  Illumination and Reflectance  The Phong Reflectance Model  Shading in OpenGL.
Shading in OpenGL.
1 Chapter 6 Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
Computer Graphics I, Fall 2010 Shading in OpenGL.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Introduction to Computer Graphics with WebGL
Shading. For Further Reading Angel 7 th Ed: ­Chapter 6 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Local Illumination and Shading
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Computer Graphics Lecture 25 Fasih ur Rehman. Last Class Shading.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Computer Graphics: Illumination
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 Computer Graphics Three-Dimensional Graphics V.
Illumination : Hearn & Baker Ch. 10
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Unit-7 Lighting and Shading
CSC461: Lecture 23 Shading Computation
Vectors, Normals, & Shading
Shading in OpenGL Ed Angel
Introduction to Computer Graphics with WebGL
Fundamentals of Computer Graphics Part 6 Shading
Lighting and Materials
CS5500 Computer Graphics April 10, 2006.
Isaac Gang University of Mary Hardin-Baylor
CS 480/680 Computer Graphics Shading.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley

Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build a simple reflection model---the Phong model--- that can be used with real time graphics hardware Angel: Interactive Computer Graphics 5E © Addison-Wesley

Why we need shading Suppose we build a model of a sphere using many polygons and color it with glColor. We get something like But we want Angel: Interactive Computer Graphics 5E © Addison-Wesley

Shading Why does the image of a real sphere look like Light-material interactions cause each point to have a different color or shade Need to consider –Light sources –Material properties –Location of viewer –Surface orientation Angel: Interactive Computer Graphics 5E © Addison-Wesley

Scattering Light strikes A –Some scattered –Some absorbed Some of scattered light strikes B –Some scattered –Some absorbed Some of this scattered light strikes A and so on Angel: Interactive Computer Graphics 5E © Addison-Wesley

Rendering Equation The infinite scattering and absorption of light can be described by the rendering equation –Cannot be solved in general –Ray tracing is a special case for perfectly reflecting surfaces Rendering equation is global and includes –Shadows –Multiple scattering from object to object Angel: Interactive Computer Graphics 5E © Addison-Wesley

Global Effects Angel: Interactive Computer Graphics 5E © Addison-Wesley translucent surface shadow multiple reflection

Local vs Global Rendering Correct shading requires a global calculation involving all objects and light sources –Incompatible with pipeline model which shades each polygon independently (local rendering) However, in computer graphics, especially real time graphics, we are happy if things “look right” –Many techniques for approximating global effects exist Angel: Interactive Computer Graphics 5E © Addison-Wesley

Light-Material Interaction Light that strikes an object is partially absorbed and partially scattered (reflected) The amount reflected determines the color and brightness of the object –A surface appears red under white light because the red component of the light is reflected and the rest is absorbed The reflected light is scattered in a manner that depends on the smoothness and orientation of the surface Angel: Interactive Computer Graphics 5E © Addison-Wesley

Bidirectional Reflection Distribution Function (BDRF) Five variables –Two input angles –Two output angles –Frequency of light Difficult to compute in real time Thus we approximate with other models –Additive of diffuse, specular, ambient –Transmission if needed Angel: Interactive Computer Graphics5E © Addison-Wesley

Light Source Illumination function –Point of origin (x,y,z) –Wavelength ( ) –Direction of emission ( ,  ) Angel: Interactive Computer Graphics5E © Addison-Wesley

Light Sources General light sources are difficult to work with because we must integrate light coming from all points on the source Angel: Interactive Computer Graphics 5E © Addison-Wesley

Simple Light Sources Ambient light –Same amount of light everywhere in scene –Can model contribution of many sources and reflecting surfaces Point source –Model with position and color –Distant source = infinite distance away (parallel) Spotlight –Restrict light from ideal point source Angel: Interactive Computer Graphics 5E © Addison-Wesley

Color Sources Reduce to just 3 tristimulus factors RGB L = (L r, L g, L b ) Future equations expressed via L where L  {L r, L g, L b } Angel: Interactive Computer Graphics5E © Addison-Wesley

Ambient Light Applies light to all spaces within the scene –Without it, everything would be dark (unless self-emitting) Uniform light Components RGB –L ar, L ag, L ab OpenGL allows us to specify ambient Angel: Interactive Computer Graphics5E © Addison-Wesley

Ambient Light Ambient light is the result of multiple interactions between (large) light sources and the objects in the environment Amount and color depend on both the color of the light(s) and the material properties of the object Add k a I a to diffuse and specular terms Angel: Interactive Computer Graphics 5E © Addison-Wesley reflection coef intensity of ambient light

Point Source Angel: Interactive Computer Graphics5E © Addison-Wesley Light in all directions Proportional to inverse square We can add a factor of the form 1/(a + bd +cd 2 ) The constant and linear terms soften the effect of the point source

Spotlight Point source P s Pointing in direction of l s Cone width of  –If  = 180, this is point source More realistic spotlights adjust intensity as we move from center –Typically cos e  Angel: Interactive Computer Graphics5E © Addison-Wesley

Distant Light Sources Homogeneous systems Point vs. vector Angel: Interactive Computer Graphics5E © Addison-Wesley

Surface Types The smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the light A very rough surface scatters light in all directions Angel: Interactive Computer Graphics 5E © Addison-Wesley smooth surface Rough/diffuse surface

Phong Model A simple model that can be computed rapidly Has three components –Ambient ( I a ) –Diffuse ( I d ) –Specular ( I s ) Uses four vectors –To source (l) –To viewer (v) –Normal (n) –Perfect reflector (r) Angel: Interactive Computer Graphics 5E © Addison-Wesley

Phong: Ambient Ambient intensity ( I a ) same at every point on surface Amount not absorbed is ambient reflection coefficient (k a ) I a = k a L a Angel: Interactive Computer Graphics5E © Addison-Wesley

Ideal Reflector Normal is determined by local orientation Angle of incidence = angle of relection The three vectors must be coplanar Angel: Interactive Computer Graphics 5E © Addison-Wesley r = 2 (l · n ) n - l

Lambertian Surface Perfectly diffuse reflector Light scattered equally in all directions Amount of light reflected is proportional to the vertical component of incoming light –reflected light ~ cos  i – cos  i = l · n if vectors normalized –There are also three coefficients, k r, k b, k g that show how much of each color component is reflected Angel: Interactive Computer Graphics 5E © Addison-Wesley

Phong: Diffuse Reflection Only see vertical component of light As u is lowered, same amount of light is spread across broader area Angel: Interactive Computer Graphics5E © Addison-Wesley I d = k d (l  n)L d

Specular Surfaces Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors) Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection Angel: Interactive Computer Graphics 5E © Addison-Wesley specular highlight

Modeling Specular Relections Phong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increased Angel: Interactive Computer Graphics 5E © Addison-Wesley  I s = k s L s cos   shininess coef absorption coef incoming intensity reflected intensity

The Shininess Coefficient Values of  between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plastic Angel: Interactive Computer Graphics 5E © Addison-Wesley cos   

Vectors, Normals, & Shading Angel Angel: Interactive Computer Graphics5E © Addison-Wesley

Objectives Discuss vectors & normals Introduce the OpenGL shading functions Discuss polygonal shading –Flat –Smooth –Gouraud Angel: Interactive Computer Graphics 5E © Addison-Wesley

Steps in OpenGL shading Enable shading and select model Specify normals Specify material properties Specify lights Angel: Interactive Computer Graphics 5E © Addison-Wesley

Normal for Triangle Angel: Interactive Computer Graphics 5E © Addison-Wesley p0p0 p1p1 p2p2 n plane n ·(p - p 0 ) = 0 n = (p 2 - p 0 ) ×(p 1 - p 0 ) normalize n  n/ |n| p Note that right-hand rule determines outward face

Normals and Gradients For a non-linear surface, we can find the plane where the normal to this plane is the gradient. Doing this many times across the surface allows us to do shading… Angel: Interactive Computer Graphics5E © Addison-Wesley n p

Normals In OpenGL the normal vector is part of the state Set by glNormal*() – glNormal3f(x, y, z); – glNormal3fv(p); Usually we want to set the normal to have unit length so cosine calculations are correct –Length can be affected by transformations –Note that scaling does not preserved length – glEnable(GL_NORMALIZE) allows for autonormalization at a performance penalty Angel: Interactive Computer Graphics 5E © Addison-Wesley

Enabling Shading Shading calculations are enabled by – glEnable(GL_LIGHTING) –Once lighting is enabled, glColor() ignored Must enable each light source individually – glEnable(GL_LIGHTi) i=0,1….. Can choose light model parameters – glLightModeli(parameter, GL_TRUE) GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently Angel: Interactive Computer Graphics 5E © Addison-Wesley

Polygonal Shading Shading calculations are done for each vertex –Vertex colors become vertex shades By default, vertex shades are interpolated across the polygon – glShadeModel(GL_SMOOTH); If we use glShadeModel(GL_FLAT); the color at the first vertex will determine the shade of the whole polygon Angel: Interactive Computer Graphics 5E © Addison-Wesley

Polygon Normals Angel: Interactive Computer Graphics 5E © Addison-Wesley Polygons have a single normal –Shades at the vertices as computed by the Phong model can be almost same –Identical for a distant viewer (default) or if there is no specular component Consider model of sphere Want different normals at each vertex even though this concept is not quite correct mathematically

Smooth Shading Angel: Interactive Computer Graphics 5E © Addison-Wesley We can set a new normal at each vertex Easy for sphere model –If centered at origin n = p Now smooth shading works Note silhouette edge

Mesh Shading The previous example is not general because we knew the normal at each vertex analytically For polygonal models, Gouraud proposed we use the average of the normals around a mesh vertex Angel: Interactive Computer Graphics 5E © Addison-Wesley n = (n 1 +n 2 +n 3 +n 4 )/ |n 1 +n 2 +n 3 +n 4 |

Gouraud and Phong Shading Gouraud Shading –Find average normal at each vertex (vertex normals) –Apply modified Phong model at each vertex –Interpolate vertex shades across each polygon Phong shading –Find vertex normals –Interpolate vertex normals across edges –Interpolate edge normals across polygon –Apply modified Phong model at each fragment Angel: Interactive Computer Graphics 5E © Addison-Wesley

Comparison If the polygon mesh approximates surfaces with a high curvatures, Phong shading may look smooth while Gouraud shading may show edges Phong shading requires much more work than Gouraud shading –Until recently not available in real time systems –Now can be done using fragment shaders (see Chapter 9) Both need data structures to represent meshes so we can obtain vertex normals Angel: Interactive Computer Graphics 5E © Addison-Wesley