Introduction to Computer Graphics Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces
Outline Computational tools Reflection models Polygon shading
Computation tools Surface normals Vector perpendicular to the tangent plane of the surface at particular location Angle of incidence & reflection Irradiance at a surface point is proportional to cosine of incident angle. Incident vector Tangent plane Normal vector θ Reflection angle Incident angle θ Reflected vector Surface patch
Calculating Surface Normals T 2 =df surface (u,/dv T 1 =df surface (u,/du N=T 1 XT 2 Surface: set of points satisfying: {F x (u,,f y (u,,f z (u,} Tangents: df (, ) x( u, dfy u v dfz,, } du du du df (, ) x dfy u v dfz,, } dv dv dv T = { 1 u= u v= v T = { 2 u= u v= v Normal vector: outer product of T 1 & T 2 1, 1, 1 1 S=F surface (u, N =det i dfx du dfx dv df y j du df y dv k df z du dfz dv
Surface Reflection Diffuse reflection Lambertian reflection Light source attenuation Colored lights & surfaces Specular reflection Shiny surfaces highlights
Diffuse Reflection Object s brightness only depends on: Direction of light source Distance from light source Lambertian reflection: (dull, matte surfaces) Equally bright from all viewing angles Reflect light equally in all directions does NOT follow incident/reflected angle law Incident intensity proportional to cosine of incident angle Illumination : I = I p k d cosθ (I p :source intensity, k d :material coefficient) L=P 1 -P 0 P 0 T L N P 1
Diffuse Reflection w/attenuation Light source attenuation factor: f att =(1/(dist) 2 ) Incident intensity also inversely proportional to distance from source Illumination (with ambient light intensity) : I=I a k a + f att I p k d cosθ I a : ambient light intensity I p : point light intensity k a,k d : surface material coefficients Material coefficients depend on surface type for example: wood has a higher diffuse reflection (higher k d ) vs metal which has high specularity
Colored lights and surfaces Colored lights represented by intensity for each red,green,blue component Surface color represented by red,green,blue component Red component illumination: I R =I ar k ar + f att I pr k d O dr cosθ Green component : I G =I ag k ag + f att I pg k d O dg cosθ Blue component : I B =I ab k ab + f att I pb k d O db cosθ K d : diffuse material coefficient O dr,o dg,o db : defines surface s diffuse color NOTE: In OpenGL, diffuse material coefficient is actually k d O dr, k d O dg or k d O db premultiplied
Specular Reflection Specularity: property of shiny surface Light reflected unequally in different directions Example: highlight on an apple Perfectly specular surface: mirror Light reflected only in direction of reflection vector Phong reflectance: maximum brightness if viewing angle = angle of reflection, otherwise falloff by cos n α n: material s specular reflection exponent I=I a k a + f att I p cosθ (k d + k s cos n α ) Direction of incidence Direction of reflection α θ θ Viewing direction
Polygon Shading Models Shading a surface 1. Using normal at each surface point, calculate illumination at that point. Need to render each point! 2. Shade polygons using their normals and illumination model Constant or Flat shading Gouraud shading: intensity interpolated across polygon Phong shading: normal vector interpolated across polygon
Constant Shading Assumptions: 1. Light source at infinity, cosθ is constant across polygon 2. Viewer is at infinity 3. Polygon actually represents a planar surface, not approximation to curved surface Illumination model calculated once per polygon Polygon rasterized with one color based on illumination model
Gouraud Shading Illumination model calculated at each vertex normal Polygon is shaded by linear interpolation 1. Polygon edges are shaded by interpolation between adjacent vertex colors 2. Polygon interior is shaded along each scan line by interpolation between adjacent edges Color interpolation can be easily integrated in scan line algorithms Implemented in hardware
Phong shading Normal vectors between vertices interpolated, rather than intensity Interpolation across edges first Normals then interpolated across each scan line Illumination model computed for each point in scan line Computationally expensive, but much more realistic for specular highlights Still cheaper than evaluating normal at each surface pointæwhy?
Comparison of different shading FLAT GOURAUD PHONG