Graphics Reference
In-Depth Information
Geometry Shaders
The geometry shader is another kind of shader available with OpenGL and the
GLSL shader language. This shader's operations change or expand the origi-
nal geometry sent to the shader by developing new vertices and vertex groups.
As an example, each triangle in a model could be replaced by a triangle shrunk
about its centroid, as shown in Figure 3.7.
The source code for this geometry shader is more complicated, and it
involves more new concepts than the previous vertex and fragment shaders do,
but it is still worth seeing as a way to understand where we are headed. The basic
idea is that all the vertices in each triangle primitive are being passed together
( vec4 gl_PositionIn[i] ). From these, a centroid is computed, and all
three vertices are shrunk about it and emited to become a new triangle. A
more complete discussion is found in Chapter 12.
layout( triangles ) in;
layout( triangle_strip, max_vertices=32 ) out;
uniform float uShrink;
uniform mat4 uModelViewProjectionMatrix;
in vec3 vNormal[3];
out float gLightIntensity;
const vec3 LIGHTPOS = vec3( 0., 10., 0. );
Figure 3.7. Triangles in different models shrunk with a geometry shader (this is useful for
examining how fine the triangularization of a particular model is).
Search WWH ::




Custom Search