Download Understanding Illumination and Shading in Computer Graphics: Reflections and more Study notes Computer Graphics in PDF only on Docsity! Today: Illumination & Shading (1 million triangles drawn with 1 color per triangle) Determining an Object’s Appearance Ultimately, we’re interested in modeling light transport in scene • Light is emitted from light sources and interacts with surfaces • on impact with an object, some is reflected and some is absorbed • distribution of reflected light determines “finish” (matte, glossy, …) • composition of light arriving at eye determines what we see Let’s focus on the local interaction of light with single surface point Incident light Some light is absorbed Reflected light Some reaches eye Modeling Light Sources In general, light sources have a very complex structure • incandescent light bulbs, the sun, CRT monitors, … To simplify things, we’ll focus on point light sources for now • light source is a single infinitesimal point • emits light equally in all directions (isotropic illumination) • outgoing light is set of rays originating at light point Creating lights in OpenGL • glEnable(GL_LIGHTING) — turn on lighting of objects • glEnable(GL_LIGHT0) — turn on specific light • glLight(…) — specify position, emitted light intensity, … Basic Local Illumination Model We’re only interested in light that finally arrives at view point • a function of the light & viewing positions • and local surface reflectance Characterize light using RGB triples • can operate on each channel separately Given a point, compute intensity of reflected light L n v Examples of Phong Specular Model Diffuse only Diffuse + Specular (shininess 5) Diffuse + Specular (shininess 50) The Ambient Glow So far, areas not directly illuminated by any light appear black • this tends to look rather unnatural • in the real world, there’s lots of ambient light To compensate, we invent new light source • assume there is a constant ambient “glow” • this ambient glow is purely fictitious Just add in another term to our illumination equation I = Id + Is + Iaka Ia : ambient light intensity ka : (ambient) surface reflectance coefficient [0,1] Our Three Basic Components of Illumination Diffuse Specular Ambient I = Id I = Is I = Iaka Combined for the Final Result I = Id + Is + Iaka Recall How to Color Polygons Hard-coded colors on surface of model • maybe from pre-computed illumination (e.g., radiosity) • explicitly specify 1 color per face/vertex Flat Shaded: glBegin(GL_TRIANGLES); for(int j=0; j<n; j++) { glColor3fv(c); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); } glEnd(); Smooth Shaded: glBegin(GL_TRIANGLES); for(int j=0; j<n; j++) { glColor3fv(c1); glVertex3fv(v1); glColor3fv(c2); glVertex3fv(v2); glColor3fv(c3); glVertex3fv(v3); } glEnd(); Drawing Polygons with Lighting We usually want OpenGL to infer colors via illumination model • specify 1 normal per face/vertex Flat Shaded: glBegin(GL_TRIANGLES); for(int j=0; j<n; j++) { glNormal3fv(n); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); } glEnd(); Smooth Shaded: glBegin(GL_TRIANGLES); for(int j=0; j<n; j++) { glNormal3fv(n1); glVertex3fv(v1); glNormal3fv(n2); glVertex3fv(v2); glNormal3fv(n3); glVertex3fv(v3); } glEnd(); Defining Lights in OpenGL A fixed set of lights are available (at least 8) • turn them on with glEnable(GL_LIGHTx) • set their values with glLight(…) GLfloat white[] = {1.0, 1.0, 1.0, 1.0} GLfloat p[] = {-2.0, -3.0, 10.0, 1.0}; // w=0 for directional light glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightfv(GL_LIGHT0, GL_POSITION, p); glLightfv(GL_LIGHT0, GL_DIFFUSE, white); glLightfv(GL_LIGHT0, GL_SPECULAR, white); // can be different glEnable(GL_NORMALIZE); // guarantee unit normals Summarizing the Shading Model We describe local appearance with illumination equations • consists of a sum of set of components — light is additive • treat each wavelength independently • currently: diffuse, specular, and ambient terms Must shade every pixel covered by polygon • flat shading: constant color • Gouraud shading: interpolate corner colors • Phong shading: interpolate corner normals L n ! v r " I = ILkd max(cos θ, 0) + ILks max(cos φ, 0) n + Iaka What Have We Ignored? Some local phenomena • shadows — every point is illuminated by every light source • attenuation — intensity falls off with square of distance to light • transparent objects — light can be transmitted through surface Global illumination • reflections of objects in other objects • indirect diffuse light — ambient term is just a hack Realistic surface detail • can make an orange sphere • but it doesn’t have the texture of the real fruit Realistic light sources