Graphics Reference
In-Depth Information
Figure 12.7. The original triangle (left) is subdivided into four triangles (middle),
and then each of these four is subdivided again into four (right).
spheresubd.geom
The geometry shader has three parts: some header information, a function that
produces a vertex from a pair ( s , t ) of parameters, and the main shader func-
tion. The header information for the shader is below; this supplies the level
that is set in the GLIB file, the light intensity that the geometry shader will
develop to pass on to rasterization, and the values of the three vertices of the
triangle that we will subdivide.
#version 330
#extension GL_EXT_geometry_shader4: enable
layout( triangles ) in;
layout( triangle_strip, max_vertices=1024 ) out;
uniform int uLevel;
out float gLightIntensity;
vec3 V0, V01, V02;
The function ProduceVertex( ) below produces a vertex from the param-
eters s and t in the parameterized definition of a triangle as shown above.
The position computation uses the point v, derived from the parameters and
normalized as a unit vector to give it a unit distance from the center of the
sphere, as the suface normal. That position is then multiplied by the radius of
the sphere to place it on the surface of the sphere. Thus, when the triangle is
Search WWH ::




Custom Search