Graphics Reference
In-Depth Information
glBegin gl_patches
glVertex 0. 0. 0. .2 # x, y, z sphere center; w radius
glVertex 0. 1. 0. .3
glVertex 0. 0. 1. .4
glEnd
The vertex shader for this example,
spheresubd.vert
, gets the center and
radius of the sphere from the input vertex value; it simply sets the output
variables
Center
and
Radius
and sets the required
gl_Position
to the origin.
#version 400 compatibility
out vec3 vCenter;
out float vRadius;
void main( )
{
vCenter = aVertex.xyz;
vRadius = aVertex.w;
gl_Position = vec4( 0., 0., 0., 1. );
}
The TCS, defined in
spheresubd.tcs
, takes the input from the vertex shader as
two arrays,
vRadius[ ]
and
vCenter[ ]
. Each array has only one element in it,
because the number of patch vertices was set to 1. The TCS sets up the tessel-
lation levels for the primitive generator. It uses the uniform variable
uDetail
and the value of the radius to set the tessellation levels. Levels
uOuter[0]
and
uOuter[2]
are the number of divisions at the poles,
uOuter[1]
and
uOuter[3]
are the number of divisions at the vertical seams, and
uInner[0]
and
uIn-
ner[1]
give the real internal sphere detail.
#version 400 compatibility
#extension GL_ARB_tessellation_shader : enable
in vec3 vCenter[ ];
in float vRadius[ ];
patch out vec3 tcCenter;
patch out float tcRadius;
uniform float uDetail, uScale;
layout( vertices = 1 ) out;