JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
Previous Page
Next Page

15.6. Granite

With noise, it's also easy just to try and make stuff up. In this example, I wanted to simulate a grayish rocky material with small black specks. To generate a relatively high-frequency noise texture, I used only the fourth component (the highest frequency one). I scaled it by an arbitrary amount to provide an appropriate intensity level and then used this value for each of the red, green, and blue components. The shader in Listing 15.7 generates an appearance similar to granite, as shown in Color Plate 24.

Listing 15.7. Granite fragment shader

varying float LightIntensity;
varying vec3  MCposition;

uniform sampler3D Noise;
uniform float NoiseScale;

void main()
    vec4  noisevec  = texture3D(Noise, NoiseScale * MCposition);
    float intensity = min(1.0, noisevec[3] * 18.0);
    vec3  color     = vec3(intensity * LightIntensity);
    gl_FragColor    = vec4(color, 1.0);

Previous Page
Next Page

JavaScript EditorAjax Editor     JavaScript Editor