Graphics Reference
In-Depth Information
uniform sampler3D Noise3;
. . .
vec3 stp = ...
vec4 nv = texture( Noise3, stp );
The noise texture is a vec4 whose components have separate meanings,
described in Table 4.1. The [0] component is the low frequency noise. The [1]
component is twice the frequency and half the amplitude of the [0] component,
and similarly for the [2] and [3]
components. Each component is
centered around a value of .5, so
that if you want a plus-or-minus
effect, subtract .5 from each
component. To get a nice four-
octave noise value between 0
and 1 (useful for noisy mixing),
add up all four components,
subtract 1, and divide the result
by 2, as shown in the follow-
ing table and GLSL code. More
details on this can be found in
Chapter 10.
Component
Term
Term Range Term Limits
0
nv.r
0.5 ± .5000
0.0000 → 1.0000
1
nv.g
0.5 ± .2500 0.2500 → 0.7500
2
nv.b
0.5 ± .1250 0.3750 → 0.6250
3
nv.a 0.5 ± .0625 0.4375 → 0.5625
sum 2.0 ± ~ 1.0 ~ 1.0 → 3.0
sum - 1 1.0 ± ~ 1.0 ~ 0.0 → 2.0
(sum - 1) / 2 0.5 ± ~ 0.5 ~ 0.0 → 1.0
( sum - 2 ) 0.0 ± ~ 1.0 ~ −1.0 1.0
Table 4.1. The range of the four octaves of noise and some useful
combinations.
float sum = nv.r + nv.g + nv.b + nv.a; // range is 1. -> 3.
sum = (sum - 1.) / 2.; // range is now 0. -> 1.
By default, the glman 3D noise texture has dimensions 64 × 64 × 64. You
can change this by puting a command in your GLIB ile of the form
Noise3D 128
to get size 128, or choose whatever resolution you want (up to around 400).
Remember that for the most general use, the resolution should be a power of
two. The first time glman creates a 3D noise texture for you, it will take a few
seconds. But glman then writes it to a file, and the next time this 3D texture is
needed it is read from the file, which is a lot faster.
A 2D noise texture works the same way, except you get at it with
uniform sampler2D Noise2;
. . .
vec2 st = ...
vec4 nv = texture( Noise2, st );
 
Search WWH ::




Custom Search