Graphics Reference
In-Depth Information
this case, the components of the
gl_in
array are simply copied to the
gl_out
array, where they will serve as inputs to the TES shader. The other new detail
is the
gl_TessLevelOuter[ ]
array that is to set the tessellation levels for the
outer level in the TES.
Finally, we see the TES shader
beziercurve.tes
that uses the isolines
patern for its layout. Notice that the
gl_Position
value is computed with
vector arithmetic since the
p[0-3]
parameters from the TCS are all
vec4
val-
ues. And, because
vec4
arithmetic is being used, this code will also work for
rational
Bézier cubic curves.
In this example, the variable
gl_TessCoord
is the (
u
,
v
,
w
) value of the ver-
tex being processed by the TES, and the value of the curve parameter
u
is
derived from the
x
-coordinate of this variable. Other ways of developing the
single parameter
u
are also possible.
#version 400
#extension GL_ARB_tessellation_shader: enable
layout( isolines, equal_spacing) in;
void main( )
{
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
vec4 p2 = gl_in[2].gl_Position;
vec4 p3 = gl_in[3].gl_Position;
float u = gl_TessCoord.x;
// the basis functions:
float b0 = (1.-u) * (1.-u) * (1.-u);
float b1 = 3. * u * (1.-u) * (1.-u);
float b2 = 3. * u * u * (1.-u);
float b3 = u * u * u;
gl_Position = b0*p0 + b1*p1 + b2*p2 + b3*p3;
}
We assign the intermediate
p[0-3]
variables here to make the code more
readable. In general, the GLSL compiler will optimize this away rather than
creating temporary variables it doesn't really need. Similarly, we can safely
write out the
b[0-3]
variables in full detail for readability, and the GLSL com-
piler will assemble like terms rather than re-compute them.
Figure 13.9 shows the coordinate axes as well as two examples of the
curve generated by these shaders. In the left image, you can easily see the five