Graphics Reference
In-Depth Information
Note the use of the LinesAdjacency primitive. Figure 12.3 shows the
fixed-function handling of this primitive—a line from point #1 to point #2. But
with a geometry shader turned on, this primitive is really just a way of geting
four grouped points into the shader. What you do with them after that is up to
you. So, in this case, the geometry shader will turn those four points into a line
strip. The vertex and fragment shaders are not given, because they are very
simple and very standard; the vertex shader simply sets gl_Position from
the ModelViewProjection matrix and the vertex position, and the fragment
shader simply sets the vec4 fFragColor .
Bezier.glib
Vertex bezier.vert
Geometry bezier.geom
Fragment bezier.frag
Program Bezier uNum <2 10 50>
LineWidth 3.
LinesAdjacency [0. 0. 0.] [1. 1. 1.] [2. 1. 2.] [3. -1. 0.]
The geometry shader is the key point of this example. It calculates the
standard Bézier curve by using the standard basis on the four points in the
input line with adjacency and then calculates the vertices on that curve by tak-
ing evenly spaced points in the parameter space:
() =−
(
) +−
3
(
)
2
(
)
Pt
1
tP t
3 1
t Pt
+
3
2
1
tP tP
+
3
3 .
0
1
2
Each point that is generated is emited into a line strip. When the geom-
etry shader ends, there is an implicit EndPrimitive( ) that sends the line strip
on to the rest of the graphics pipeline.
Bezier.geom
#version 330
#extension GL_EXT_geometry_shader4: enable
uniform int uNum;
layout( lines_adjacency ) in;
layout( line_strip, max_vertices=1024 ) out;
void main( )
{
float dt = 1. / float(uNum);
float t = 0.;
for( int i = 0; i <= uNum; i++, t += dt )
{
Search WWH ::




Custom Search