Graphics Reference
In-Depth Information
it. In the left-hand image, you see that the
stripes follow the value of vX in model
space (running from the tip of the spout to
the handle), while in the right-hand image,
you see that the stripes follow the value of
vX in eye space (from right to left). It then
uses these variables to compute the color of
each pixel, either the original color of the
object or the color white, based on a simple
calculation—essentially computing the tex-
ture based only on the object's geometry in
the space that is passed to it. This fragment
shader function is designed for glman and
uses three uniform slider variables, uA , uP ,
and uTol , that let you experiment with the
frequency and width of the stripes, and the
blurring of the stripe edges, respectively.
Figure 9.4. The graph of the smoothpulse function.
uniform float uA;
uniform float uP;
uniform float uTol;
in float vX;
in vec4 vColor;
in float vLightIntensity;
out vec4 fFragColor;
const vec4 WHITE = vec4( 1., 1., 1., 1. );
void
main( )
{
float f = fract( uA*vX );
float t = smoothstep( 0.5-uP-uTol, 0.5-uP+uTol, f )
- smoothstep( 0.5+uP-uTol, 0.5+uP+uTol, f );
fFragColor = vec4(vLightIntensity*mix( WHITE, uColor, t ).rgb,
1.);
}
Combining two smoothstep( ) functions like this
smoothstep( 0.5-uP-uTol, 0.5-uP+uTol,f )
- smoothstep( 0.5+uP-uTol, 0.5+uP+uTol,f );
Search WWH ::




Custom Search