Graphics Reference
In-Depth Information
{
vec4 nv = texture( Noise3, uNoiseScale * vMCposition );
float sum = ( 3.* nv.r + nv.g + nv.b + nv.a - 2. ) / 2.;
sum = ( 1. + cos(PI * sum) ) / 2.;
float t = clamp( uBias + sum, 0., 1. );
vec3 color = mix( uSkyColor.rgb, uCloudColor.rgb, t );
color *= vLightIntensity;
fFragColor = vec4( color, 1.0 );
}
Wood Shader
Wood is characterized by the rings that form as
trees grow. These rings are something like the
veins in marble, but rings have clearly defined
edges between the light and dark wood, and
the variation lies in the shape of the rings
themselves. These are approximately cylindri-
cal, with variation in their width and spacing.
A wood fragment shader must try to capture
those kinds of variations. In Figure 10.14, we see
an example of a wood shader applied to a tea-
pot. This solid-texture wood shader operates by
adding a noise value (based on the model-space
coordinates of a point) to the distance from the
modeling Y -axis, and uses that distance to mix
the light and dark wood colors.
A wood fragment shader that implements this approach is shown below.
This uses five uniform variables, three shader parameters and two color vari-
ables that control the ring colors and the parameters that simulate the rings.
These could be used with glman as slider or color selection variables in a GLIB
file to let you experiment with the colors and parameters to achieve the look
you want in your shader. For example, you could use light colors and wide
and fairly regular ring spacing to simulate pine.
Figure 10.14. The teapot shown with a wood
texture.
uniform sampler3D Noise3;
uniform vec4 uLightWoodColor;
uniform vec4 uDarkWoodColor;
uniform float uRingFreq;
uniform float uNoiseScale;
uniform float uNoiseMag;
Search WWH ::




Custom Search