Graphics Reference
In-Depth Information
The fragment shader below implements this modeling approach to simu-
late a marble texture. It uses three uniform variables: two colors, the color of
the marble base and the color of the marble vein, and one scale that changes
the general texture of the noise values that could be set up with glman , so you
could experiment with the texture to get the effect you want.
uniform sampler3D Noise3;
uniform vec4 uMarbleColor;
uniform vec4 uVeinColor;
uniform float uNoiseScale;
uniform float uNoiseMag;
in float vLightIntensity;
in vec3 vMCposition;
out vec4 fFragColor;
void main( )
{
vec4 nv = texture( Noise3, vMCposition * uNoiseScale );
float sum = abs(nv.r - 0.5) + abs(nv.g - 0.5)
+ abs(nv.b - 0.5) + abs(nv.a - 0.5);
sum = clamp( uNoiseMag * sum, 0.0, 1.0 );
float sineval = sin(vMCposition.y*6.0+sum*12.0)*0.5 + 0.5;
vec3 color = mix(uVeinColor.rgb, uMarbleColor.rgb,
sineval) * vLightIntensity;
fFragColor = vec4( color, 1.0 );
}
Cloud Shader
Clouds are another effect that can be readily created using a fragment shader.
There are so many different kinds of clouds that one shader cannot begin to
capture them, but a very simple model is that clouds occur in the sky with
a noise-like patern that mixes cloud color and sky color, with gradations
between them. A cloud shader might produce effects like those shown in
Figure 10.13, with a parameter determining the way the clouds thin out so the
sky color can be seen. Other kinds of cloud models might assume a particular
geometry for cloud paterns and density and then use noise to determine what
happens at the cloud region boundaries, but they could have similarities to
this shader if you use the geometry to drive the mix( ) function and use the
noise effects at the boundaries.
Search WWH ::




Custom Search