varying vec3 normal;
varying vec3 tangent;
varying vec3 binormal;
varying vec3 taneye;
varying float pos;

uniform sampler2D Normal; // normal map with bump!

const float scale = 0.014;
const float bias  = 0.005;

void main()
{
  vec3 norm;

  // parallax bump
  float height = scale * texture2D( Normal, gl_TexCoord[0].st ).b + bias;

  // offset texture look up
  vec2 texCoord = gl_TexCoord[0].st + height * taneye.xy;

  // normal is offset
  vec3 tangentspacenormal = texture2D( Normal, texCoord ).xyz;
  // unpack
  tangentspacenormal = tangentspacenormal * 2.0 - 1.0;
  // transform
  /* normalized ver */
  vec3 t1 = normalize( tangent );
  vec3 b1 = normalize( binormal );
  vec3 n1 = normalize( normal );
  norm.x = dot( vec3( t1.x, b1.x, n1.x ), tangentspacenormal );
  norm.y = dot( vec3( t1.y, b1.y, n1.y ), tangentspacenormal );
  norm.z = dot( vec3( t1.z, b1.z, n1.z ), tangentspacenormal );
  
  gl_FragColor = vec4( norm * 0.5 + 0.5, pos );
}