Shading Contents from: Interactive Computer Graphics: A top-Down Approach Using OpenGL Chapter 6 Edit by Ching-Shoei Chiang
Shading Surface can either (both) Emit light. E.g. light bult Reflect light. E.g. Mirror
Shading Rendering equation Cannot solved in general Even by numerical method.
Shading Approximation of rendering equation Radiosity (slow) Ray tracing (slow) Phong Reflection Model similar to ray tracing Consider only single interaction (between light source & surface) Two independent parts of the problem Light source Reflection model (between light and material)
Shading How refection model works: Light directly to your eyes Light reflect from the surface Single/multiple interaction between rays and object.
Shading When light strikes a surface, Some of it is absorbed, Some of it is reflected. If the surface is opaque, reflection and absorption account for all the light striking the surface. Surface is translucent, some light transmitted through the material (& interact with other objects).
Shading An object illuminated by white light appears red because it absorbs most of the incident light but reflects light in the red range of frequencies. A shiny object appears so because its surface is smooth. Conversely, a dull object has a rough surface. The shading of objects also depends on the orientation of their surfaces, a factor that is characterized by the normal vector at each point.
Classification of Surface Specular surface appear shiny because most of the light that is reflected is scattered in a narrow range of angle close to the angle of reflection. Mirrors are perfectly specular surfaces. Diffuse surfaces are characterized by reflected light being scattered in all directions. Perfectly diffuse surfaces scatter light equally in all directions and thus appear the same to all viewer. Translucent surfaces allow some light to pentrate the surface and to emerge from another location on the object. This process of refraction characterizes glass and water.
Light Source There are four basic types of light sources: Ambient Light. Point light Spot Lights Distance Light. We describe a source through a three component intensity or luminance function I=[Ir, Ig, Ib]
Ambient Light In some rooms, such as in certain classrooms or kitchens, the lights have been designed and positioned to provide uniform illumination throughout the room. This uniform lighting is called ambient light. Ia = [Iar, Iag, Iab]
Point Light An ideal point source emits light equally in all direction. I(p0) = [Ir(p0), Ig(p0), Ib(p0)]. i(p,p0) = I(p0) /|p-p0|2 Or i(p,p0) = I(p0) /a+bd+cd2 where d=|p-p0|
SpotLight Apex: ps Direction: Ls Angle: How rapidly the light intensity drops off: Cose. 0< < . Notice that cos = sl, l is the direction of the light, s is a vector from apex to the surface. The angle between s and l is . Both s and l are unit length.
Distance Light If the light source is far from the surface, the l vector does not change much as we move from point to point, just as the light from the sun strikes all objects that are in close proximity to one another at the same angle. We call this kind of light the distance light. The direction vector whose representation in homogeneous coordinates is: P0=[x,y,z,0]
Phong Reflection Model The model uses four vectors, l, n, v, r, to calculate a color for an arbitrary point p on the surface. l: point from p to the light. n: normal of p on the surface v: point from p to the eye. r: reflection vector for the vector from light to p. r=2(l n)n-l
Phong Model The Phong model supports the three types of material-light interactions: ambient, diffuse, and specular. Suppose that we have a set of point sources. We assume that each source can have separate ambient, diffuse, and specular components for each of the three primary color. We need 9 coefficients to characterize these terms at any point p on the surface. Li=
Phong Model For each point, we have 9 coefficients that we can place in matrix of reflection terms of the form: Ri = We can then compute the contribution for each color source by adding the ambient, diffuse, and specular components. E.g. The red intensity that we see at p from source i: Iir = RiraLira +RirdLird+RirsLirs =Iira+Iird+Iirs
Phong Reflection Model We obtain the total intensity by adding the contributions of all sources and, possibly, a global ambient term. The red term is: Ir = (Iira+Iird+Iirs)+Iar Where Iar is the red component of the global ambient light. I = Ia+Id+Is=LaRa+LdRd+LsRs
Ambient Reflection The intensity of ambient light La is the same at every point of the surface. Ra=ka, 0<=ka<=1 (only a positive fration of the light is reflected) Thus, Ia=kaLa A surface has, of course, three ambient coefficients – kar, kag, and kab – and they can differ. A sphere appears red under white ambient light if its red ambient coefficient is large and its green and blue coefficients are large.
Diffuse Reflection Diffuse reflections are characterized by rough surfaces. Perfectly diffuse surfaces are so rough that there is no preferred angle of reflection. Such surfaces, sometimes called Lambertian surfaces, can be modeled mathematically with Lambert’s Law. Lambert’s Law states: Rdcos =l n The surface is brightest at noon and dimmest at dawn and dusk because, according to Lambert’s law, we see only the vertical component of the incoming light. Add in a reflection coefficient kd: Id = kd(l n)Ld Incorporate a distance term(D): Id =(kd/a+bD+cD2)(l n)Ld
Specular Reflection A Specular surface is smooth The amount of light that the viewer sees depends on the angle between r and v. v: point from p to the eye. r: reflection vector for the vector from light to p. Is = ksLs cos = ksLs (r v) Where is a shininess coefficient Incorporate a distance term(D): Is =(ks/(a+bD+cD2))(r v) Ls
Phong Model I =(a+bD+cD2)-1(ksLs (r v) + kdLd (l n))+kaLa Where is a shininess coefficient D: distance term l: point from p to the light. n: normal of p on the surface v: point from p to the eye. r: reflection vector for the vector from light to p. a,b,c can be chosen to soften the light. Ka, kd, ks: ambient, diffuse and specular reflection coefficient La, Ls, Ld: Parameter for the light source with ambient, diffuse and specular term.