• Search in book...
• Toggle Font Controls

#### Turbulence

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. 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 8.28.

Figure 8.28. Absolute value noise or “turbulence”

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 Figure 8.27 (see Example 8.18). This technique can be extended to change the results over time, using another dimension of noise for time, resulting in animation of the effect.

Example 8.18. Sun Surface Fragment Shader

#version 330 core

in float LightIntensity;
in vec3 MCposition;

uniform sampler3D Noise;
uniform vec3  Color1;       // (0.8, 0.7, 0.0)
uniform vec3  Color2;       // (0.6, 0.1, 0.0)
uniform float NoiseScale;   // 1.2

out vec4 FragColor;

void main()
{
vec4 noisevec = texture(Noise, MCposition * NoiseScale);

float intensity = abs(noisevec[0] - 0.25) +
abs(noisevec[1] - 0.125) +
abs(noisevec[2] - 0.0625) +
abs(noisevec[3] - 0.03125);

intensity = clamp(intensity * 6.0, 0.0, 1.0);
vec3 color = mix(Color1, Color2, intensity) * LightIntensity;
FragColor = vec4(color, 1.0);
}

• No Comment
..................Content has been hidden....................