
struct myVertexOut {
    float4 texCoord0 : TEXCOORD0;
    float4 lightDir : TEXCOORD1; // the diffuse light direction
    float4 halfAngle : TEXCOORD2; // half-angle vector
    float4 texCoord3 : TEXCOORD3;
};

float4 main(myVertexOut I,
            uniform sampler2D normalMap,
            uniform sampler2D intensityMap,
            uniform sampler2D colorMap) : COLOR
{
    // Lookup the normal map
    float4 normal = 2 * (tex2D(normalMap, I.texCoord0.xy) - 0.5);

    // Multiply
    // 3 X 2 matrix generated using lightDir and halfAngle with
    // scaled normal
    // followed by lookup in intensity map with the result.
    float2 intensCoord = float2(dot(I.lightDir.xyz, normal.xyz),
                                dot(I.halfAngle.xyz, normal.xyz));
    float4 intensity = tex2D(intensityMap, intensCoord);

    // Lookup color
    float4 color = tex2D(colorMap, I.texCoord3.xy);

    // Blend/Modulate intensity with color
    return color * intensity;
}

