Graphics Reference
In-Depth Information
Fun with One
Many GLSL variables range linearly from 0. to 1., such
as texture components, the noise function, color compo-
nents, etc. But just because a variable ranges linearly from
0. to 1. doesn't mean that you have to actually use it that
way. There are a number of ways you can manipulate the
range [0.,1.] to get different effects. This is especially fun
with the glman Timer function, introduced in Chapter 4
and discussed in the next section. Some of the possibili-
ties are shown in Table 16.2, and the shapes of some of
these functions are shown in Figures 16.21 to 16.23.
Figure 16.21. Comparison of shapes
of t n functions.
Efect
Code
Collection of curves from
0. to 1.
float tm = Timer;
float tm = Timer*Timer;
float tm = Timer*Timer*Timer;
float tm = 3.*Timer 2 - 2.*Timer 3 ;
float tm = 10.*Timer 3 - 15.*Timer 4 + 6.*Timer 5
Ramp from 0. to 1. and back
to 0.
float tm;
if( Timer <= .5 )
tm = 2.*Timer;
else
tm = 2. - 2.*Timer;
Smooth oscillation from -1.
to 1. and back to -1.
float tm = sin( 2.*π*Timer );
Faster oscillation with
parameter S.
float tm = sin( 2.*π*S*Timer );
Bigger oscillation with
parameter M.
float tm = M * sin( 2.*π*S*Timer );
Smooth oscillation from 0.
to 1. and back to 0.
float tm = .5 + .5*sin(2.*π*Timer );
Table 16.2. Some effects of different functions with range between 0 and 1.
Search WWH ::




Custom Search