Graphics Reference
In-Depth Information
void main( )
{
vec3 transNorm = normalize( vec3( uNormalMatrix * aNormal )
);
vec3 ECposition = vec3( uModelViewMatrix * aVertex );
vLightIntensity = dot( normalize(LIGHTPOS-ECposition),
transNorm );
vLightIntensity = clamp( .3 + abs( vLightIntensity ), 0., 1.
);
vST = aTexCoord0.st;
vColor = aColor;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
Below is the fragment shader for Figure 3.5. It takes the s and t coor-
dinates provided by the vertex shader and uses them to decide whether to
discard a pixel.
uniform float uDensity;
uniform float uFrequency;
in vec4 vColor;
in float vLightIntensity;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
float sf = vST.s * uFrequency;
float tf = vST.t * uFrequency;
if( fract( sf ) >= uDensity && fract( tf ) >= uDensity )
discard;
fFragColor = vec4( vLightIntensity*vColor.rgb, 1. );
}
Again, a more efficient implementation that takes advantage of the paral-
lelism in graphics hardware would be
vec2 stf = vST * uFrequency;
if( all( fract(stf) >= vec2(uDensity, uDensity) ) )
discard;
Search WWH ::




Custom Search