Graphics Reference
In-Depth Information
{
vec4 nv = texture( Noise3, uNoiseScale*vMCposition );
float sum = nv.r + nv.g + nv.b + nv.a;
sum = ( sum - 1. ) /2.; // range: 0. -> 1.
if( sum < uMin )
discard;
if( sum > uMax )
discard;
fFragColor = vec4( vLightIntensity*vColor.rgb, 1. );
}
We look at some other examples of using noise in the sections below. These
show the use of noise to simulate some natural materials, where a noise texture
can add some of the complexity that is found in nature. This is a very rich subject,
and our relatively simple examples can only suggest how much can be done.
Noise effects begin by choosing the domain that is to be used for the noise
function, and the way the noise is to be used. The domain can be 1D, 2D, or 3D,
depending on whether you want linear, surface, or solid effects. It can also be
chosen to come from model space, eye space, or texture space. So you have a
variety of choices that can affect the way the noise effects are generated. There
are also several ways to use the noise values that you generate. You can use
them directly, as we saw in the erosion example above, or you can use them to
select how different colors are to be blended; the examples below all use noise
to determine how blends are to be done.
Marble Shader
Marble is a material that exhibits noisy-looking
veins in a base-color stone, and the nature of the
veins makes it a natural material to model with
a noise-based texture. The marble fragment
shader whose effects are shown in Figure 10.12
implements this kind of modeling. Its domain is
the 3D model coordinates of the geometry being
textured, and it uses all four octaves of noise.
The resulting value, along with the position of
the point in model space, is then taken as input
to a sine function, making the texture somewhat
periodic, as the veins in marble tend to be.
Figure 10.12. The teapot with a marble texture.
Search WWH ::




Custom Search