// Vertex shader for bump mapping in surface local coordinates
vec3 LightPosition=vec3(-10,25,15); // eye space position of light

attribute vec3 rm_Tangent;

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

void main(void)
{

    vec3 b, n, t, pos, lightVec, r, v;

    // Do standard vertex stuff

    gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;

    // Compute the binormal
    n = normalize(gl_NormalMatrix * gl_Normal);
    t = normalize(gl_NormalMatrix * rm_Tangent); //rm_Tangent
    b = cross(n, t);
    
    // Transform light position into surface local coordinates
    v.x = dot(LightPosition, t);
    v.y = dot(LightPosition, b);
    v.z = dot(LightPosition, n);

    LightDir = normalize(v);

    pos      = vec3 (gl_ModelViewMatrix * gl_Vertex);

    v.x = dot(pos, t);
    v.y = dot(pos, b);  
    v.z = dot(pos, n);

    ViewDir = normalize(v);
 }