Graphics Reference
In-Depth Information
on or off very easily. This might mean that you would need to create more
variables in your vertex shader than you would need for any one particular
fragment shader, because other versions of the same shader might need them.
Most shader compilers are fiercely optimizing, and you will likely not find that
there is a penalty for including variables that don't affect the generation of the
scene detail.
Exercises
1. Replace the simple fixed-function vertex processing for a straightforward
example with a vertex shader. Use the shader to compute each vertex
position and vertex color, and pass on the color values as new variables
to a fragment shader to get smooth shading. If your implementation of
GLSL supports flat shading, implement that as well.
2. Take a straightforward vertex shader such as one you would use for
smooth shading, and design two different ways to organize informa-
tion that you would pass on to a fragment shader to complete an image.
Sketch out the fragment shader you would use, and discuss how your
choices would affect the design of the fragment shader.
3. Look at the section of Chapter 14 that covers user-deined atribute and
uniform variables. Think of an application that can use this kind of atri-
bute or uniform data, and assuming that these have been designed, write
a vertex shader that takes this data and prepares it for a fragment shad-
er's use. Sketch how the fragment shader would use that data in seting
pixel colors.
4. Create a simple scene that is made up of a few primitives, each with its
own modeling transformation. Create a model-space shader similar to
that used for Figure 7.3, applying the appropriate modeling transforma-
tions to each vertex as it is used.
5. Implement the Cartesian hyperbolic vertex shader, described in the
Hyperbolic Geometry section of the Scientific Visualization shader. Do it
using glman , so that you can make the parameter K a uniform slider vari-
able and experiment with the effect of different values of K .
6. As we did in the discussion in Chapter 3 around Figure 3.4, define a 2D
grid on a plane, and display any surface defined by analytic expressions
by writing a vertex shader to compute the position and normals at the
domain points. The vertex shader shown with the example in Chapter 3
will be a good starting point, and you might consider implementing the
Enneper surface whose equations are given in this chapter.
Search WWH ::




Custom Search