Illumination and Shading Illumination Lighting n n Model

  • Slides: 40
Download presentation
Illumination and Shading

Illumination and Shading

Illumination (Lighting) n n Model the interaction of light with surface points to determine

Illumination (Lighting) n n Model the interaction of light with surface points to determine their final color and brightness Open. GL computes illumination at vertices illumination

Shading n Apply the lighting model at a set of points across the entire

Shading n Apply the lighting model at a set of points across the entire surface Shading

Illumination Model n n The governing principles for computing the illumination A illumination model

Illumination Model n n The governing principles for computing the illumination A illumination model usually considers: n n Light attributes (light intensity, color, position, direction, shape) Object surface attributes (color, reflectivity, transparency, etc) Interaction among lights and objects (object orientation) Interaction between objects and eye (viewing dir. )

Illumination Calculation n Local illumination: only consider the light, the observer position, and the

Illumination Calculation n Local illumination: only consider the light, the observer position, and the object material properties q n Example: Open. GL

Illumination Models n Global illumination: take into account the interaction of light from all

Illumination Models n Global illumination: take into account the interaction of light from all the surfaces in the scene object 4 object 3 object 2 object 1 n Example: Ray Tracing (CIS 681)

Basic Light Sources sun Point light Spot light Directional light Light intensity can be

Basic Light Sources sun Point light Spot light Directional light Light intensity can be independent or dependent of the distance between object and the light source

Calculating Reflection Vector The scalar projection of Lon N is a scalar equal to

Calculating Reflection Vector The scalar projection of Lon N is a scalar equal to

Simple local illumination n Consider three types of light contribution to compute the final

Simple local illumination n Consider three types of light contribution to compute the final illumination of an object n n Ambient Diffuse Specular Final illumination of a point (vertex) = ambient + diffuse + specular

Ambient light contribution n n Ambient light (background light): the light that is scattered

Ambient light contribution n n Ambient light (background light): the light that is scattered by the environment A very simple approximation of global illumination object 4 object 3 object 2 object 1 n Independent of the light position, object orientation, observer’s position or orientation – ambient light has no direction (Radiosity is the calculation of ambient light)

Ambient lighting example

Ambient lighting example

Ambient light calculation n Each light source has an ambient light contribution (Ia) Different

Ambient light calculation n Each light source has an ambient light contribution (Ia) Different objects can reflect different amounts of ambient (different ambient reflection coefficient Ka, 0 <= Ka <= 1) So the amount of ambient light that can be seen from an object is: Ambient = Ia * Ka

Diffuse light contribution n Diffuse light: The illumination that a surface receives from a

Diffuse light contribution n Diffuse light: The illumination that a surface receives from a light source and reflects equally in all direction It does not matter where the eye is

Diffuse lighting example

Diffuse lighting example

Diffuse light calculation n Need to decide how much light the object point receive

Diffuse light calculation n Need to decide how much light the object point receive from the light source – based on Lambert’s Law Receive more light Receive less light

Diffuse light calculation (2) n Lambert’s law: the radiant energy D that a small

Diffuse light calculation (2) n Lambert’s law: the radiant energy D that a small surface patch receives from a light source is: D = I * cos (q) I: light intensity q: angle between the light vector and the surface normal light vector (vector from object to light) q N : surface normal

Diffuse light calculation (3) n n Like the ambient light case, different objects can

Diffuse light calculation (3) n n Like the ambient light case, different objects can reflect different amount of diffuse light (different diffuse reflection coefficient Kd, 0 <= Kd <= 1)) So, the amount of diffuse light that can be seen is: Diffuse = Kd * I * cos (q) q N L q cos(q) = N. L

Specular light contribution n n The bright spot on the object The result of

Specular light contribution n n The bright spot on the object The result of total reflection of the incident light in a concentrate region See nothing!

Specular light example

Specular light example

Specular light calculation n How much reflection you can see depends on where you

Specular light calculation n How much reflection you can see depends on where you are The only position the eye can see specular from P if the object has an ideal reflection surface q ? p f But for a non-perfect surface you will still see specular highlight when you move a little bit away from the idea reflection direction When f is small, you see more specular highlight

Specular light calculation (2) n Phong lighting model specular = Ks * I *

Specular light calculation (2) n Phong lighting model specular = Ks * I * cosn(f) Ks: specular reflection coefficient N: surface normal at P I: light intensity f: angle between V and R n cos(f): the larger is n, the smaller is the cos value cos(f) = R. V L N q q p R f V

Specular light calculation (3) n The effect of ‘n’ in the phong model n

Specular light calculation (3) n The effect of ‘n’ in the phong model n = 10 n = 90 n = 30 n = 270

Put it all together n Illumination from a light: n Illum = ambient +

Put it all together n Illumination from a light: n Illum = ambient + diffuse + specular = Ka * I + Kd * I * (N. L) + Ks * I * (R. V)n or If there are N lights Total illumination for a point P = n S (Illum) Some more terms to be added (in Open. GL): n n n Self emission Global ambient Light distance attenuation and spot light effect (N. H)

Polygon shading model n Flat shading – compute lighting once and assign the color

Polygon shading model n Flat shading – compute lighting once and assign the color to the whole polygon

Flat shading n n n Only use one vertex (usually the first one) normal

Flat shading n n n Only use one vertex (usually the first one) normal and material property to compute the color for the polygon Benefit: fast to compute It is used when: n n The polygon is small enough The light source is far away (why? ) The eye is very far away (why? ) Open. GL command: gl. Shade. Model(GL_FLAT)

Mach Band Effect n n Flat shading suffers from “mach band effect” Mach band

Mach Band Effect n n Flat shading suffers from “mach band effect” Mach band effect – human eyes accentuate the discontinuity at the boundary perceived intensity Side view of a polygonal surface

Smooth shading n n Reduce the mach band effect – remove value discontinuity Compute

Smooth shading n n Reduce the mach band effect – remove value discontinuity Compute lighting for more points on each face Flat shading smooth shading

Gouraud Shading n n Gouraud shading attempts to smooth out the shading across the

Gouraud Shading n n Gouraud shading attempts to smooth out the shading across the polygon facets Begin by calculating the normal at each vertex N

Gouraud Shading n n A feasible way to do this is by averaging the

Gouraud Shading n n A feasible way to do this is by averaging the normals from surrounding facets Then apply the reflection model to calculate intensities at each vertex N

Gouraud Shading We use linear interpolation to calculate intensity at edge intersection P IPRED

Gouraud Shading We use linear interpolation to calculate intensity at edge intersection P IPRED = (1 - )IP 1 RED + IP 2 RED where P divides P 1 P 2 in the ratio 1 - n Similarly for Q n P 3 P 2 P Q P 1 P 4

Gouraud Shading n Then we do further linear interpolation to calculate colour of pixels

Gouraud Shading n Then we do further linear interpolation to calculate colour of pixels on scanline PQ P 3 P 2 P P 1 Q

Gouraud Shading

Gouraud Shading

Gouraud Shading Limitations Specular Highlights n Gouraud shading gives intensities within a polygon which

Gouraud Shading Limitations Specular Highlights n Gouraud shading gives intensities within a polygon which are a weighted average of the intensities at vertices n n a specular highlight at a vertex tends to be smoothed out over a larger area than it should cover a specular highlight in the middle of a polygon will never be shown

Gouraud Shading Limitations Mach Bands n n The rate of change of pixel intensity

Gouraud Shading Limitations Mach Bands n n The rate of change of pixel intensity is even across any polygon, but changes as boundaries are crossed This ‘discontinuity’ is accentuated by the human visual system, so that we see either light or dark lines at the polygon edges - known as Mach banding

Phong Shading n Phong shading has a similar first step, in that vertex normals

Phong Shading n Phong shading has a similar first step, in that vertex normals are calculated typically as average of normals of surrounding faces N

Phong Shading n n However rather than calculate intensity at vertices and then interpolate

Phong Shading n n However rather than calculate intensity at vertices and then interpolate intensities as we do in Gouraud shading. . . In Phong shading P 3 P 2 N P Q N 1 P 4

Phong Shading n . . . and apply the reflection model at each pixel

Phong Shading n . . . and apply the reflection model at each pixel to calculate the intensity - IRED, IGREEN, IBLUE P 3 P 2 N P Q N 1 P 4

Phong Shading

Phong Shading

Phong versus Gouraud Shading n n A major advantage of Phong shading over Gouraud

Phong versus Gouraud Shading n n A major advantage of Phong shading over Gouraud is that specular highlights tend to be much more accurate n vertex highlight is much sharper n a highlight can occur within a polygon Also Mach banding greatly reduced The cost is a substantial increase in processing time because reflection model applied per pixel But there are limitations to both Gouraud and Phong

Gouraud versus Phong

Gouraud versus Phong