Graphics Reference
In-Depth Information
in float vLightIntensity;
in vec3 vMCposition;
out vec4 fFragColor;
void main( )
{
vec4 nv = uNoiseMag * texture( Noise3, uNoiseScale*vMCposition
);
vec3 location = vMCposition + nv.rgb;
float dist = length( location.xz )
dist *= uRingFreq;
// create an up-down ramp:
float t = fract( dist + nv.r + nv.g + nv.b ) * 2.0;
if( t > 1.0 )
t = 2.0 - t;
vec4 color = mix( uLightWoodColor, uDarkWoodColor, t );
color *= vLightIntensity;
fFragColor = vec4( color.rgb, 1. );
}
One of the most common uses of a wood shader is to cre-
ate wood surfaces that model the look of wooden furniture or
the like. We can see in Figure 10.15 that we can modify this
shader to create the texture of a wood surface (or, more pre-
cisely, a bookmatched veneer surface). This is done by chang-
ing the expression for the dist variable by adding terms as
sqrt(location.x*location.x+location.z*location.z)+
sqrt(8.+location.y)+sqrt(8.+abs(location.x));
Figure 10.15. The wood
shader applied to a flat surface.
and, as before, note that
sqrt( location.x*location.x + location.z*location.z )
can be written more efficiently as
length( location.xz )
Search WWH ::




Custom Search