Interpolation using scanline algorithm Idea: Exploit knowledge about already computed color values. Traverse projected triangle top-down using scanline. Compute start and end color value of each pixel row using linear interpolation along the triangle s edges. Fill each pixel row using linear interpolation between the start and end color of that row. 320322: Graphics and Visualization 454
Interpolation using scanline algorithm 320322: Graphics and Visualization 455
Gouraud shading 320322: Graphics and Visualization 456
Shading in OpenGL Setting State glshademodel( GL_SMOOTH GL_FLAT); GL_FLAT: flat shading GL_SMOOTH: Gouraud shading 320322: Graphics and Visualization 457
Gouraud shading Gouraud shading produces smooth transitions of light intensities, but silhouettes remain polygonal. However, typically triangles are small such that this cannot be noticed. 320322: Graphics and Visualization 458
Gouraud shading Using Gouraud shading, illumination is only evaluated at the vertices of the triangles. Specular highlights that do not stretch over vertices of the mesh are missed. specular highlight 320322: Graphics and Visualization 459
Gouraud shading During animation, specular highlights can show some flickering when using Gouraud shading. 320322: Graphics and Visualization 460
6.3 Phong Shading 320322: Graphics and Visualization 461
Phong shading Improve shading by applying the illumination model at each unprojected pixel, i.e., at those points of a triangle that are projected onto a pixel of the screen. 320322: Graphics and Visualization 462
Phong shading algorithm Use a scanline that traverses the triangle top-down in screen space. For each start and end point of a pixel row, linearly interpolate the surface normal along the triangle s edges. For each pixel row, linearly interpolate the surface normal between start and end point of that row. Apply the illumination model at each unprojected pixel value using the interpolated surface normal. 320322: Graphics and Visualization 463
Phong shading algorithm Apply same interpolation formula as in Gouraud shading, but interpolate normals instead of color values. 320322: Graphics and Visualization 464
Phong shading 320322: Graphics and Visualization 465
Phong shading Specular highlights are always correctly and exactly computed. Highlights appear much smoother. No flickering during animations. 320322: Graphics and Visualization 466
Comparison: flat, Gouraud, Phong shading 320322: Graphics and Visualization 467
Phong shading The evaluation of the illumination model at each unprojected screen pixel is expensive. Illumination needs to be applied in object space rather than screen space. The pixel can be easily unprojected when storing depth information (cf. depth buffer). 320322: Graphics and Visualization 468
Phong shading Phong shading is not supported by OpenGL. It is nowadays implemented using pixel or fragment shaders. The normals can be handed to the shader encoded as colors. Gouraud shading using these colors then interpolates the normals. 320322: Graphics and Visualization 469
7. Global Illumination 320322: Graphics and Visualization 470
Global Illumination The Phong, Blinn-Phong, and BRDF models are local illumination models, i.e., they only take into account the local geometry of an object. Global illumination models take into account the entire geometry that is present in the scene. In particular, global illumination considers the interference of objects with each other. For example, when one object occludes the light source with respect to another object, the other object should appear to be in the shadow of the first object. 320322: Graphics and Visualization 471
7.1 Ray Tracing 320322: Graphics and Visualization 472
Ray tracing Ray tracing is a global illuminiation method. It allows for the computation of all shadows in the scene. 320322: Graphics and Visualization 473
Observation In nature, light from a light source gets reflected at a point p. The amount of incoming light that is reflected in direction v to the viewer determines the color of the object at position p. 320322: Graphics and Visualization 474
Ray tracing idea Trace the light ray through the scene. Since many light rays are being sent out from each light source in all directions, this can be computationally very intense. For efficiency purposes, trace in backward direction. Start rays from the viewpoint. Send a ray through each pixel of the screen onto the scene. Trace the ray to the light sources. 320322: Graphics and Visualization 475
Ray tracing idea light 1 light 2 secondary rays viewpoint object 1 primary ray object 2 screen Primary rays are sent from the viewer through the center of each pixel of the screen When the primary rays hit an object, secondary rays are sent from the point of intersection towards each light source. 320322: Graphics and Visualization 476
Ray tracing idea light 1 light 2 secondary rays viewpoint object 1 object 2 primary rays screen If a secondary ray hits an object, that object occludes the light source. The color of the pixel is computed by applying a local ilumination model at the position, where the primary ray hits the object, taking into account all light sources that are not occluded. 320322: Graphics and Visualization 477
Ray-tracing idea 320322: Graphics and Visualization 478
Ray-tracing idea 320322: Graphics and Visualization 479
Ray-triangle intersection Let the objects be given as triangular meshes. To find intersections of (primary or secondary) rays with the objects, one has to find and compute intersection points of rays with triangles. Ifmanytrianglesarepresentin thescene, onemay want to reduce the amount of triangles that are considered by using spatial partitioning. Spatial partitioning stores for each cell only those triangles that lie (completely or partially) in the cell. The ray-triangle intersection can be limited to those cells that are intersected by the ray (in the order in which it intersects). 320322: Graphics and Visualization 480
Ray-triangle intersection 1. Compute intersection of ray with plane. 2. Check whether intersection point lies within the triangle. 320322: Graphics and Visualization 481
Ray-triangle intersection Compute intersection of ray with plane. 320322: Graphics and Visualization 482
Ray-triangle intersection 320322: Graphics and Visualization 483
Ray-triangle intersection 320322: Graphics and Visualization 484
convex polygons Other polygons plane-intersection: like triangles inside test: algebraically concave polygons plane-intersection: like triangles inside test: ray intersection non-planar polygons triangulate 320322: Graphics and Visualization 485