Graphics Reference
In-Depth Information
Figure 10.11. The discard-based screen of Chapter 2 (left) and noise-based discard to simu-
late erosion (right).
was shown in Figure 3.5, repeated here as the left-hand image in Figure 10.11.
We can take a different approach by using 2D texture coordinates to generate
a noise value that will determine which pixels should be discarded. When this
is applied to a sphere, the resulting figure is shown as the right-hand image in
Figure 10.11—a very different kind of image. The erosion shader operates by
generating a patern from a noise function, but instead of using it to change
the color of the surface, the values are used to decide whether or not to discard
pixels. The shader uses two uniform variables, Min and Max , that determine the
range of values that allow pixels to be kept, and the kept pixels are colored as
if the sphere had no texture.
The fragment shader for the erosion example is given below. The two
uniform variables for the noise frequency and cutoff values would probably
be defined as slider variables in the glman GLIB file, and you can experiment
with them to achieve the look you want.
uniform sampler3D Noise3;
uniform float uMin, uMax;
uniform float uNoiseScale;
in vec4 vColor;
in float vLightIntensity;
in vec3 vMCposition;
out vec4 fFragColor;
void main( )
Search WWH ::




Custom Search