// Fragment Shader: Bump mapping using normal map.
uniform sampler2D normalmap;
uniform sampler2D diffusmap;
uniform sampler2D bloodmap;

float DiffuseFactor=1.0;
float SpecularFactor=1.0;

varying vec3 LightDir;      // interpolated surface local coordinate light direction 
varying vec3 ViewDir;       // interpolated surface local coordinate view direction

void main (void)
{
    vec3 norm, r, color;
    float intensity, spec, d;
    vec3 c;
    vec4 bc;  
    // Fetch normal from normal map
    c = vec3(texture2D(diffusmap, vec2 (gl_TexCoord[0] * 8.0)));

    bc = vec4(texture2D(bloodmap, vec2 (gl_TexCoord[0])));
 
    c = mix(c,bc.rgb,bc.a);

    norm   = vec3(texture2D(normalmap, vec2 (gl_TexCoord[0] * 8.0)));
    norm   = (norm - 0.5) * 2.0;

    intensity = max(dot(LightDir, norm), 0.0) * DiffuseFactor;

    // Compute specular reflection component
    d = 2.0 * dot(LightDir, norm);
    r = d * norm;
    r = LightDir - r;
    spec = pow(max(dot(r, ViewDir), 0.0) , 6.0) * SpecularFactor;
    intensity += min (spec, 1.0);

     // Compute final color value
    color = clamp(c.rgb * intensity, 0.0, 1.0);
 
    // Write out final fragment color
    gl_FragColor = vec4 (color, 1.0);
}