SOFTWARE DEPARTMENT COMPUTER GRAPHICS SHADING

advertisement
SOFTWARE DEPARTMENT
THIRD CLASS
COMPUTER GRAPHICS
SHADING
‫م عالء الدين عباس عبد الحسن‬.‫م‬
Sunday 9/12/2012
SHADING


Shading
For the most part, interactive computer graphics
systems are polygon processors. From the hardware
perspective, systems are optimized for passing
polygons down the pipeline. Performance is
measured in terms of polygons per second, a
measurement that always includes lighting and
shading. From the application perspective, a large
class of CAD applications have the user design
polygonal meshes. Even if the software supports
curved surfaces, these surfaces are rendered as
polygonal meshes that approximate the surface.
SHADING

Because a polygon has the same normal for
the entire surface, normals only need be
computed once. Often normals are stored in an
application data structure. Further efficiencies
can be obtained for many special conditions
such as a distant light source, and we must
also be careful to avoid visual artifacts. We will
investigate two methods for shading a
polygonal mesh : flat shading, and smooth or
interpolative (Gouraud) shading.
SHADING
SHADING
Flat Shading :
 The three vectors need for shading ( L, n, and v
) can vary as we move from point to point on a
surface. For a flat polygon, however, n is
constant. If we assume a distant viewer, v is
constant over the polygon. Finally, if the light
source is distant, L is constant. Here distant
could be interpreted in the strict sense of
meaning that the source is at infinity.

SHADING
SHADING


If the three vectors are constant, then the
shading calculation needs to be carried out
only once for each polygon, and each point on
the polygon is assigned the same shade. This
technique is known as flat, or constant,
shading. In OpenGL, we specify flat shading as
follows :
SHADING
Flat Shading.
SHADING
Flat shading will show differences in shading
for the polygons in our mesh. If the light
sources and viewer are near the polygon, the
vectors L and v will be different for each
polygon.
 Smooth
Shading
(Gouraud
Shading)
(Interpolation):
 Smooth shading is the default in OpenGL. We
can also set the mode explicitly as follows:

SHADING

Suppose that we have enabled both smooth
shading and lighting and that we assign to each
vertex the normal of the polygon being shaded.
The lighting calculation is made at each vertex
using the material properties and the vectors v
and 1 computed for each vertex. Note that if the
light source is distant, and either the viewer is
distant or there are no specular reflections, then
smooth (or interpolative) shading shades a
polygon in a constant color.
SHADING

If we consider our mesh, the idea of a normal
existing at a vertex should cause concern to
anyone
worried
about
mathematical
correctness. Because multiple polygons meet
at interior vertices of the mesh, each of which
has its own normal, the normal at the vertex is
discontinuous. Gouraud realized that the
normal at the vertex could be defined in such a
way as to achieve smoother shading through
interpolation.
SHADING

Consider an interior vertex, as shown in Figure
11.4, where four polygons meet. Each has its
own normal. In Gouraud shading, we define the
normal at a vertex to be the normalized
average of the normals of the polygons that
share the vertex. For our example, the vertex
normal is given by:
SHADING
A comparison between two methods.
REFLECTION
REFLECTION
2D SHEAR
2D SHEAR
2D SHEAR
Download