Page 72 - Computer Graphics Handout
P. 72
every point in the viewing volume maps to a distinct color. In the vertex shader, we can set the color using the components of
vPosition, so our shader becomes
in vec4 vPosition;
out vec4 color;
void main()
{
color = vec4((1.0 + vPosition.xyz)/2.0, 1.0);
gl_Position = vPosition;
}
This color is output to the rasterizer so the fragment shader can use it as input to set the color of a fragment, so the fragment shader
becomes
in vec4 color;
void main()
{
gl_FragColor = color;
}
Figure 2.41 shows that if we generate enough points, the resulting figure will look like the initial tetrahedron with increasingly
smaller tetrahedrons removed.
2.10.2 Use of Polygons in Three Dimensions
There is a more interesting approach to the three-dimensional Sierpinski gasket that uses both polygons and subdivision of a
tetrahedron into smaller tetrahedrons. Suppose that we start with a tetrahedron and find the midpoints of its six edges and connect
these midpoints as shown in Figure 2.42. There are now four smaller tetrahedrons, one for each of the original vertices, and another
area in the middle that we will discard. Following our second approach to a single triangle, we will use recursive subdivision to
subdivide the four tetrahedrons that we keep. Because the faces of a tetrahedron are the four triangles determined by its four
72

