Graphics Reference
In-Depth Information
float omt = 1. - t;
float omt2 = omt * omt;
float omt3 = omt * omt2;
float t2 = t * t;
float t3 = t * t2;
vec4 xyzw = omt3 * gl_PositionIn[0] +
3. * t * omt2 * gl_PositionIn[1] +
3. * t2 * omt * gl_PositionIn[2] +
t3 * gl_PositionIn[3];
gl_Position = xyzw;
EmitVertex( );
}
}
The result of this shader's operation is shown in Figure 12.4
for two different values of the glman slider variable uNum . You can
see the granularity of the curve for a small number of segments
and the smoothness for a large number, as you would expect.
Note that it would have made no difference if the matrix
transformation had been made in the geometry shader with
gl_Position = uModelViewProjectionMatrix*xyzw;
as the last statement before EmitVertex( ) instead of multiplying
by uModelViewProjectionMatrix in the vertex shader. The inter-
polations that are done for the Bézier curve are the same in clip-
ping space as they are in the original world space. In either case, the vertices
are multiplied by the ModelViewProjection matrix and are then ready for pro-
cessing further down the graphics pipeline.
Figure 12.4. The Bézier
curve (top), with uNum = 5,
and the Bézier curve (bot-
tom), with uNum = 25.
Shrinking Triangles
An interesting question about any 3D object is how many triangles were used
to create it. In the shrinking triangles example, shown in Figure 12.5, each tri-
angle in the model is shrunken slightly about its centroid before it is displayed.
This opens up a gap between the triangles, so each one is visible. Notice that
the light on each triangle is exactly in agreement with its usual diffuse lighting,
and you can see through the gaps between the triangles to the triangles on the
back side of the model.
This geometry shader is shown below. It calculates the centroid of each
triangle, calls the ProduceVertex( ) function to compute the light intensity,
and moves each vertex toward the centroid, based on a uniform slider variable
uShrink :
V′ = Centroid + uShrink * (V − Centroid).
Search WWH ::




Custom Search