Graphics Reference
In-Depth Information
is known as a smooth pulse function and is very useful in smoothly blending a
new color or value in a given tolerance (here uTol ) of a given value range (here
0.5 - uP to 0.5 + uP ). This function is shown in Figure 9.4.
Using Texture Coordinates
The texture coordinates that you define with your model can be used for more
than simple texture lookup. In the fragment processor, they appear as inter-
polated variables whose values can be used to compute a procedural texture
directly. One example of doing this is a simple brick texture, in which the val-
ues of the texture coordinates are scaled up and tested for position. The code
that determines the color of a pixel might look like that below. (This example
assumes that a test for position is done in the Boolean colorTest( ) function.)
vec3 theColor;
vec2 st = vST;
st.s = fract( st.s * s_Mag_Factor );
st.t = fract( st.t * t_Mag_Factor );
if ( colorTest( st ) )
theColor = vec3( 0.8, 0.3. 0.0 ); // color of brick
else
theColor = vec3( 0.9, 0.6, 0.4 ); // color of mortar
fFragColor = vec4( theColor, 1. );
And, as before, we quickly note that the lines
st.s = fract( st.s * s_Mag_Factor );
st.t = fract( st.t * t_Mag_Factor );
could be writen more eiciently as
st = fract( st * vec2(s_Mag_Factor,t_Mag_Factor) );
A more sophisticated example of a procedural texture computes the
Mandelbrot function [28] given by the texture coordinates of each vertex,
using an iterative process. For a particular complex number c , we can define a
sequence fz
() =+ and f zfz c
+ () = () +
1
{
k ()
} recursively by seting fz zc
2
2
0
n
n
for a complex number z . If we start with the initial value z = 0 + 0 i , this sequence
will converge for some values of c and not for others. If it converges, the num-
ber c is said to be in the Mandelbrot set. Of perhaps more interest are those
numbers c for which the sequence does not converge. Because the sequence
will always converge if it is bounded, the usual computational approach is to
iterate it a large number of times to see if the magnitude of f k ( z ) 2 ever exceeds
some limit. If it does, the number of iterations it takes to reach that magnitude
is said to be the Mandelbrot number of c . The sketch below shows the way this
is computed and used to color a space.
Search WWH ::




Custom Search