Graphics Reference
In-Depth Information
6.3.2 Specifying Surfaces to Achieve Faceted
and Smooth Effects
Positions
Index
X
Y
Z
0
0
75
0
WPF's rendering engine uses Gouraud shading unconditionally; in other words,
WPF does not offer a rendering “mode” allowing the application to select between
flat shading and smooth shading. Yet, in Section 6.2 we were able to create a pyra-
mid with a faceted appearance, and in Figure 6.21 we showed a WPF-generated
flat-shaded depiction of the teapot. How were we able to force WPF to generate a
flat look?
Examine Figure 6.9 to review how we specified the first two pyramid faces
in Section 6.2. Each shared vertex was placed redundantly in the Positions list
to ensure that each was referenced by only one face. This causes the calculation
of the vertex normal to involve no averaging, since each vertex is attached to
only one triangle. The normal at each vertex will thus match the triangle's surface
normal. Since Gouraud smoothing at edges and vertices is based on the averaging
of vertex normals, the use of an unshared vertex effectively disables smoothing at
that vertex.
Now, suppose that these two faces are part of a pyramid approximating a cir-
cular cone. In this case, we do want smooth shading. So, let's specify the same
two triangular faces, but in the TriangleIndices list, let's “reuse” the vertex data
for the shared apex ( V 0 in Figure 6.27) and the shared basepoint ( V 2 ):
1
2
3
-50
0
50
50
0
50
50
0
-50
TriangleIndices
0,1,2
0,2,3
Figure 6.26: Tabular representa-
tion of geometric specification of
a two-triangle mesh with reuse of
shared vertices (the apex and the
shared base vertex).
V 0
1
2
3
<MeshGeometry3D x:Key= "RSRCmeshPyramid"
Positions= "0,75,0 -50,0,50 50,0, 50 50,0,-50"
TriangleIndices= "0 1 2 023 " />
V 1
V 3
V 2
In this specification (shown in Figure 6.26), vertices V 0 and V 2 are shared by
two triangles, resulting in their vertex normals being computed via the averag-
ing technique. The result is shown in Figure 6.28, with a smoothing of the edge
between V 0 and V 2 being quite apparent.
Figure
6.27:
Assignment
of
indices
to
the
vertices
in
our
pyramid model.
In summary, WPF mesh specification requires following a simple rule: You
should share vertices that need to participate in Gouraud smoothing, and you
should duplicate vertices (i.e., so that each is referenced by only face) that need to
be points of discontinuity in the rendered image.
You will find a need for both of these techniques, because typically, complex
objects are a hybrid of both smooth curved surfaces and discontinuities where
a crease or seam is located and needs to be visible in the rendering. Examples of
discontinuities include the location on a teapot where the spout joins the body, and
the seam on an airplane where wings join the fuselage. By using vertex sharing
appropriately, you can easily represent such hybrid surfaces.
Figure 6.28: Gouraud shaded
pyramid, produced in WPF by
specifying that the two triangles
share vertices V 0 and V 2 , caus-
ing their vertex normals to be the
average of the surface normals of
the two triangles.
6.4 Surface Texture in WPF
We posit that any computer graphics professional confronted with the question,
“What was the single most effective reality-approximation trick in the early his-
tory of real-time rendering?” will scarcely skip a beat before exclaiming, “Tex-
ture mapping!” When faced with the need to display a “rough” or color-varying
material such as gravel, brick, marble, or wood—or to create a background such
as a grassy plain or dense forest—it is not advisable to try to create a mesh
 
 
 
 
Search WWH ::




Custom Search