Graphics Reference
In-Depth Information
Figure 16.22. Comparison of shapes of t n , sin, and
cubic functions.
Figure 16.23. Comparison of shapes of sin(2π st )
functions.
Using the glman Timer Function
The glman tool has a built-in Timer function that ranges from 0. to 1. in 10 sec-
onds, by default, though you can make that interval any length you choose.
All you have to do is declare a uniform floating-point variable named Timer :
uniform float Timer;
in your shader, and it will magically be assigned a number that repeatedly
ramps from 0. to 1. over time. We can use the Timer function within a shader
to create moving effects, using the “Fun with One” ideas in the previous sec-
tion to get many different kinds of motion. You can get similar effects in your
applications using the GLUT timer events.
Disco Ball
You can also take advantage of the Timer in many kinds of animation pro-
cesses. As an example of this, consider the disco ball example shown in Fig-
ure 16.24, where several geometric objects are lit by a set of moving lights.
The scene uses a variable number of lights, controlled by a uniform slider
variable in the fragment shader. The vertex shader for the disco example sim-
ply sets up the usual normal, eye coordinate position, light intensity, and
gl_Position . This is familiar and so is not included here, but we do show the
fragment shader for the disco example. It uses the uniform Timer variable, in
the highlighted statement in the code below. This controls the offset angle of
 
Search WWH ::




Custom Search