cs 325 introduction to computer graphics 03 / 29 / 2010 instructor: michael eckmann
TRANSCRIPT
CS 325Introduction to Computer Graphics
03 / 29 / 2010
Instructor: Michael Eckmann
Michael Eckmann - Skidmore College - CS 325 - Spring 2010
Today’s Topics• Questions?
• Program 3 comments
• Surface Rendering / Shading models
– Flat
– Gouraud
– Phong
• Ray tracing
– Ray Sphere intersections
– Ray Polygon intersections
Michael Eckmann - Skidmore College - CS 325 - Spring 2010
Program 3 comments• Let's consider the steps you need to go about getting an object
specified in 3d to be shown on screen.
• NOTE WELL: Whatever min/max x,y coordinates you specify in gluOrtho2d, that is the window in WORLD coordinates that will be displayed in your viewport.
Michael Eckmann - Skidmore College - CS 325 - Spring 2010
Illumination• Illumination models are used to calculate the color of a point on
the surface of an object.
• A surface rendering (aka shading) method uses the calculations from the illumination model to determine the pixel colors of all the projected points in a scene.
– Can be done by doing illumination model calculations at each pixel position (like you'll see is done in ray tracing).
OR
– Can be done by doing a small number of illumination calculations and interpolating between pixels (like is often done in scan line algorithms.)
Surface Rendering• Now that we have an illumination model built, we can use it in different
ways to do surface rendering aka shading.
Shading Models• Constant shading (aka flat shading, aka faceted shading) is the simplest
shading model.
• It is accurate when a polygon face of an object is not approximating a
curved surface, all light sources are far and the viewer is far away from
the object. Far meaning sufficiently far enough away that N • L and R •
V are constant across the polygon.
• If we use constant shading but the light and viewer are not sufficiently far
enough away then we need to choose a value for each of the dot products
and apply it to the whole surface. This calculation is usually done on the
centroid of the polygon.
• Advantages: fast & simple
• Disadvantages: inaccurate shading if the assumptions are not met.
Shading Models• Interpolated shading model
– Assume we're shading a polygon. The shading is interpolated
linearly. That is, we calculate a value at two points and interpolate
between them to get the value at the points in between --- this saves
lots of computation (over computing at each position) and results in a
visual improvement over flat shading.
– This technique was created for triangles e.g. compute the color at the
three vertices and interpolate to get the edge colors and then
interpolate across the triangle's surface from edge to edge to get the
interior colors.
– Gouraud shading is an interpolation technique that is generalized to
arbitrary polygons. Phong shading is another interpolation technique
but doesn't interpolate intensities.
Shading Models• Gouraud shading (aka Gouraud Surface Rendering) is a form of
interpolated shading.
– How to calculate the intensity at the vertices?
• we have normal vectors to all polygons so, consider all the
polygons that meet at that vertex. Drawing on the board.
• Suppose for example, n polygons all meet at one vertex. We
want to approximate the normal of the actual surface at the
vertex. We have the normals to all n polygons that meet there.
So, to approximate the normal to the vertex we take the average
of all n polygon normals.
• What good is knowing the normal at the vertex? Why do we
want to know that?
Shading Models• Gouraud shading.
– What good is knowing the normal at the vertex? Why do we want to
know that?
• so we can calculate the intensity at that vertex from the
illumination equations.
– Calculate the intensity at each vertex using the normal we estimate
there.
– Then linearly interpolate the intensity along the edges between the
vertices.
– Then linearly interpolate the intensity along a scan line for the
intensities of interior points of the polygon.
– Example on the board.
Shading Models• Advantages: easy to implement if already doing a scan line algorithm.
• Disadvantages:
– Unrealistic if the polygon doesn't accurately represent the object.
This is typical with polygon meshes representing curved surfaces.
– Mach banding problem
• when there are discontinuities in intensities at polygon edges, we
can sometimes get this unfortunate effect.
• let's see an example.
– The shading of the polygon depends on its orientation. If it rotates,
we will see an unwanted effect due to the interpolation along a
scanline. Example on board.
– Specular reflection is also averaged over polygons and therefore
doesn't accurately show these reflections.
Shading Models• Phong shading (aka Phong Surface Rendering).
– Assume we are using a polygon mesh to estimate a surface.
– Compute the normals at the vertices like we did for Gouraud.
– Then instead of computing the intensity (color) at the vertices and
interpolating the intensities, we interpolate the normals.
– So, given normals at two points of a polygon, we interpolate over the
surface to estimate the normals between the two points.
– Example picture on the board.
– Then we have to apply the illumination equation at all the points in
between to compute intensity. We didn't have to do this for Gouraud.
– Problems arise since the interpolation is done in the 3d world space
and the pixel intensities are in the image space.
– More accurate intensity value calculations, more realistic surface
highlights and reduced Mach banding.
Shading Models• Recap
– Flat Shading
– Gouraud Shading --- interpolates intensities
– Phong Shading --- interpolates normal vectors (before calculating
illumination.)
– For these three methods, as speed/efficiency decreases, realism
increases (as you'd expect.)
– They all have the problem of silhouetting. Edges of polygons on the
visual edge of an object are apparent.
– Let's see examples of Gouraud and Phong shading.