420 likes | 778 Views
Illumination and Shading. Illumination (Lighting). Model the interaction of light with surface points to determine their final color and brightness OpenGL computes illumination at vertices. illumination. Shading. Apply the lighting model at a set of points across the entire surface. Shading.
E N D
Illumination (Lighting) • Model the interaction of light with surface points to determine their final color and brightness • OpenGL computes illumination at vertices illumination
Shading • Apply the lighting model at a set of points across the entire surface Shading
Illumination Model • The governing principles for computing the illumination • A illumination model usually considers: • 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.)
q Illumination Calculation • Local illumination: only consider the light, the observer position, and the object material properties • Example: OpenGL
object 4 object 3 object 2 object 1 Illumination Models • Global illumination:take into account the interaction of light from all the surfaces in the scene • Example: Ray Tracing (CIS681)
Basic Light Sources sun Light intensity can be independent or dependent of the distance between object and the light source Point light Directional light Spot light
Calculating Reflection Vector The scalar projection of Lon N is a scalar equal to
Simple local illumination • Consider three types of light contribution to compute the final illumination of an object • Ambient • Diffuse • Specular • Final illumination of a point (vertex) = ambient + diffuse + specular
Ambient light contribution • Ambient light (background light): the light that is scattered by the environment • A very simple approximation of global illumination • Independent of the light position,object orientation, observer’s position or orientation – ambient light has no direction (Radiosity is the calculation of ambient light) object 4 object 3 object 2 object 1
Ambient light calculation • 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 • 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 light calculation • Need to decide how much light the object point receive from the light source – based on Lambert’s Law Receive less light Receive more light
Diffuse light calculation (2) • 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
q N L q Diffuse light calculation (3) • 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) cos(q) = N.L
Specular light contribution • The bright spot on the object • The result of total reflection of the incident light in a concentrate region See nothing!
f q ? p Specular light calculation • 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 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
N L R f q q V p Specular light calculation (2) • 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 cos(f): the larger is n, the smaller is the cos value cos(f) = R.V n
Specular light calculation (3) • The effect of ‘n’ in the phong model n = 10 n = 90 n = 30 n = 270
Put it all together • Illumination from a light: Illum = ambient + diffuse + specular = Ka * I + Kd * I * (N.L) + Ks * I * (R.V)n • If there are N lights Total illumination for a point P = S (Illum) • Some more terms to be added (in OpenGL): • Self emission • Global ambient • Light distance attenuation and spot light effect or (N.H)
Polygon shading model • Flat shading – compute lighting once and assign the color to the whole polygon
Flat shading • 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: • The polygon is small enough • The light source is far away (why?) • The eye is very far away (why?) • OpenGL command: glShadeModel(GL_FLAT)
Mach Band Effect • 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 Flat shading Smooth shading • Reduce the mach band effect – remove value discontinuity • Compute lighting for more points on each face
Gouraud Shading • Gouraud shading attempts to smooth out the shading across the polygon facets • Begin by calculating the normal at each vertex N
N Gouraud Shading • 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
P3 P2 Q P P1 P4 Gouraud Shading • We use linear interpolation to calculate intensity at edge intersection P IPRED = (1-)IP1RED + IP2RED where P divides P1P2 in the ratio 1- • Similarly for Q
P3 P2 Q P P1 Gouraud Shading • Then we do further linear interpolation to calculate colour of pixels on scanline PQ
Gouraud Shading Limitations - Specular Highlights • Gouraud shading gives intensities within a polygon which are a weighted average of the intensities at vertices • 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 • 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
N Phong Shading • Phong shading has a similar first step, in that vertex normals are calculated - typically as average of normals of surrounding faces
P3 P2 N2 N Q P N1 P1 P4 Phong Shading • However rather than calculate intensity at vertices and then interpolate intensities as we do in Gouraud shading ... • In Phong shading we interpolate normals at each pixel ...
P3 P2 N2 N Q P N1 P1 P4 Phong Shading • ... and apply the reflection model at each pixel to calculate the intensity - IRED, IGREEN, IBLUE
Phong versus Gouraud Shading • A major advantage of Phong shading over Gouraud is that specular highlights tend to be much more accurate • vertex highlight is much sharper • 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