We can obtain some additional interesting effects by taking the absolute value of the noise function. This technique introduces a discontinuity of the derivative because the function folds on itself when it reaches 0 (see Figure 5.2 for an illustration of the absolute value function). When this folding is done to noise functions at several frequencies and the results are summed, the result is cusps or creases in the texture at various scales. Perlin started referring to this type of noise as TURBULENCE because it is reminiscent of turbulent flow. It shows up in a variety of places in nature, so this type of noise can be used to simulate various things like flames or lava. The two-dimensional appearance of this type of noise is shown in Figure 15.7.
Figure 15.7. Absolute value noise or "turbulence"
15.5.1. Sun Surface Shader
We can achieve an effect that looks like a pit of hot molten lava or the surface of the sun by using the same vertex shader as the cloud shader and a slightly different fragment shader. The main difference is that we scale each noise value and shift it over so that it is centered at 0; then we take its absolute value. After summing the values, we scale the result again to occupy nearly the full range of [0,1]. We clamp this value and use it to mix between yellow and red to get the result shown in Color Plate 24 (see Listing 15.5). (In Chapter 16, we examine some ways of animating these textures to make them more interesting.)
Listing 15.5. Sun surface fragment shader
Yet another variation on the noise function is to use it as part of a periodic function such as sine. By adding noise to the input value for the sine function, we get a "noisy" oscillating function. We use this to create a look similar to the alternating color veins of some types of marble. Listing 15.6 shows the fragment shader to do it. Again, we use the same vertex shader. Results of this shader are also shown in Color Plate 24.
Listing 15.6. Fragment shader for marble