Computer Graphics Chapter 9 Rendering
Rendering Three dimensional object rendering is the set of collective processes which make the object model appear more realistic on the display screen. These processes include The elimination of surfaces (polygonal segments) on the object that are not visible with respect to the user’s view direction. Incorporating shading and shadowing effects. RM
Computing Surface Normal V1 = P2P1 = (x2x1, y2y1, z2z1). V2 = P3P1 = (x3x1, y3y1, z3z1). N = V1 V2. Surface Normal: RM
Components of Surface Normal Nx = (y2y1) (z3z1) (y3y1) (z2z1) Ny = (z2z1) (x3x1) (z3z1) (x2x1) Nz = (x2x1) (y3y1) (x3x1) (y2y1) OR Nx = y1(z2-z3)+ y2(z3-z1)+ y3(z1-z2) Ny = z1(x2-x3)+ z2(x3-x1)+ z3(x1-x2) Nz = x1(y2-y3)+ x2(y3-y1)+ x3(y1-y2) RM
Back-Face Culling Nz < 0 The polygon is hidden RM
Back-Face Culling - Limitations Requires specific ordering of the vertices in the polygon table to determine the outward normal direction. The algorithm will work only with convex objects. A polygon is either completely displayed, or totally eliminated from the display. RM
Back-Face Culling (General Case) V.N > 0 The polygon is hidden RM
Back-Face Culling (Example) RM
Back-Face Culling (OpenGL) RM
Painter’s Algorithm RM
Painters Algorithm Basic Steps: Sort polygons in the ascending order of z-coordinates Fill polygons in the sorted order. RM
Painters Algorithm - Limitations Requires sorting of polygons. All polygons must be necessarily filled. May lead to erroneous images if a failure condition (see below) occurs. RM
Painters Algorithm Failure Conditions (1) Polygons with depth and region overlap. (1) Z Polygons having both depth-overlap and region overlap may require re-sequencing of the polygons in the sorted list. (2) RM
Painters Algorithm Failure Conditions (2) Polygons with cyclic overlap. RM
Painter’s Algorithm Illustration of failure conditions Correct Wrong RM
Depth-Buffer Algorithm Z Minimum Depth Value Color Value RM Frame Buffer Depth Buffer
Depth-Buffer Algorithm For each pixel (i, j), a line passing through the pixel and the viewer is considered, and the depths of the polygons on this line are computed. The value d(i, j) in the depth buffer contains the pseudo-depth of the closest polygon encountered at pixel (i, j). The value p(i, j) in the frame buffer (the color of the pixel) is the color of the closest polygon. RM
Depth-Buffer Algorithm Limitations: The algorithm requires a large amount of additional memory to store the pseudo depth at each pixel value. Since the analysis is based on a point by point test, the algorithm is time consuming. RM
Shading Models A shading model dictates how light is scattered or reflected from a surface. A surface is shaded by adjusting the color intensity value of each polygon according to the shading algorithm. Main components: Light source vector, surface normal vector, viewer direction. Material characteristics of the surface The illumination model. RM
Shading Models Vectors RM
Shading Models Surface Properties (1) abs (Coeff. of absorption): Specifies how much of the incident light is absorbed. If all of the incident light is absorbed, the object appears black. spec (Coeff. of specular reflection) Specifies how much of the incident light is specularly reflected in one direction. For a highly reflective surface such as a mirror, the value is close to 1.0 RM
Shading Models Surface Properties (2) diff (Coeff. of diffuse reflection): Diffuse scattering occurs when the incident light is re-radiated uniformly in all directions. For a rough non-reflective surface, the value is close to 1.0. amb (Coeff. of ambient reflection): Specifies how much of the ambient light is reflected by the surface. Often this is same as the diffuse reflection coefficient diff. abs + spec +diff = 1.0 RM
Surface Properties I If I is the incident light intensity, then I abs is absorbed by the surface. I spec is specularly reflected. I diff is diffusely reflected. RM
Illumination Models Point Source Ambient Light Ambient Light Surface Element RM
Illumination Models Ambient Light Produces uniform illumination (also known as background light). Has no spatial or directional characteristics. Assumed to be incident from all directions with constant intensity Ia. Ambient light reflection from a surface is constant along all visible directions, and does not depend on the surface orientation. RM
Illumination Models Point Light Source Defined in terms of both the position of the source, and the intensity of the source Is. The reflection from a point light source depends on the surface orientation, and varies with respect to the view direction. Light source reflection consists of both specular reflection and diffuse reflection. RM
Light Perceived by the Viewer Diffuse Reflection Point Source Id = Is diff cos Since diffuse scattering is uniform in all directions, the orientation of the polygon relative to the viewer is not significant. RM
Light Perceived by the Viewer Specular Reflection Isp = (Is spec cos f ) The vector h = s + v is known as the half-way vector. f is an experimentally determined constant RM
Light Perceived by the Viewer Specular Reflection f is specular reflection parameter determine type of surface. (in OpenGL the value range 0 to 128). A very shiny surface is modeled with a large value, and smaller value (down to 0) are used for dull object. RM
Light Perceived by the Viewer Ambient Reflection Ambient reflection is independent of surface orientation. Ambient reflection is independent of viewers position. The ambient light Ia is uniformly reflected with intensity Ia amb. This is denoted as the ambient reflection Iamb. Iamb = Ia amb RM
Computation of Total Reflected Light Total light intensity perceived by the user = Iamb+ Isp + Id = (Ia amb) + (Is spec cos f ) + Is diff cos RM
Shading (OpenGL) RM
Flat and Smooth Shading Flat Shading Gouraud Shading The entire polygon is drawn with the same shade or color. The shades at the vertices are interpolated to determine the shade at an interior point RM
Gouraud Shading The color at P1 is obtained by linearly interpolating the colors C1 and C2. Similarly, the color at P2 is found by linearly interpolating the colors C3 and C4. Having found P1 and P2, the algorithm then fills along the scan line by linearly interpolating between P1 and P2 to determine the color at an intermediate pixel Q. RM
Flat and Smooth Shading (OpenGL) RM
Flat and Smooth Shading Flat Shading Gouraud Shading Gouraud shading provides a much smoother appearance of surfaces. RM
Texture Mapping (Examples) RM
Texture Mapping The basic techniques begin with some texture functions, texture(s,t),in texture space which is traditionally marked off by parameters named s and t. The function texture(s,t) produces a color or intensity value for each value of s and t between 0 and 1. Texture mapping is the process of mapping a region in the 2D texture space to a region in the 3D space defined by the boundary points. RM
Texture Mapping Texture Space RM
Texture Mapping (OpenGL) RM
Texture types Bitmap Textures: Often formed from bitmap representations of images. Defined by a mathematical function or procedure. RM