Graphics Reference
In-Depth Information
Normals in Geometry Shaders
When we discussed vertex shaders, we recognized that handling only one ver-
tex at a time made it difficult to compute normals based on cross products of
edges. If we did not have enough information to compute analytic normals
from the changed vertex geometry, we could not get the normals we needed
for the ambient-diffuse-specular lighting model.
Working with geometry shaders, we still want to use normals computed
from the original geometry whenever we can, because that is beter informa-
tion than normals computed from cross products of edges. However, geometry
shaders do give us access to all the information in all the vertices of an input
triangle or triangle with adjacency, and this can let us compute cross-product
normals. In fact, it may well be worth adding a geometry shader to an applica-
tion that uses a vertex or tessellation shader but that does not support analytic
normals, simply to be able to compute the cross-product normals for lighting.
Examples
Perhaps the best way to become familiar with geometry shaders is to consider
several examples that operate in different ways. Below we have four examples,
with the first two examples showing the use of geometry shaders to create lim-
ited LOD effects, and the next two examples showing instances where geom-
etry shaders create new geometry to add extra meaning to a figure. The first
example takes four vertices (two vertices with adjacent vertices) and produces
a Bézier spline curve. The second example takes a triangle and outputs the
same triangle, but shrunk about its centroid. The third example takes a single
triangle and expands it into an octant of a sphere. The fourth example takes a
3D object and develops the silhouete of the object.
Bézier Curves
In our first geometry shader example, we will show how you can expand four
points into a Bézier curve with a variable number of line segments. The GLIB
file shown sets up the example in the same way we saw in Chapter 3, with
some additions for geometry shaders. These are
Specifying the types of input and output geometry.
Specifying the geometry shader to be used.
Seting the input values for the LinesAdjacency primitive.
 
Search WWH ::




Custom Search