uniform sampler2D Normal;

uniform vec3 ViewUp;

uniform float ScreenWidth;
uniform float ScreenHeight;

uniform vec3 LightAbove;
uniform vec3 LightBelow;
uniform vec3 LightHue;
uniform float LightAmbientScale;

void main()
{
  vec4 buff = texture2D( Normal, gl_TexCoord[0].st );

  vec3 norm = 2.0 * buff.xyz - 1.0;

  // get positive ndotl
  float NDotL = max( dot( norm, ViewUp ), 0.0 );// * 0.8 + 0.2;// * 0.5 + 0.5;
  float NDotL2= max( dot( norm, -ViewUp ), 0.0 ) * 0.8 + 0.2;// * 0.5 + 0.5;//

  vec3 Light   = NDotL  * LightAbove;
  vec3 Light2  = NDotL2 * LightBelow;
  
  // distance quequeing
  float distance = buff.a / 6000.0 - 0.3;
  distance = max( distance, 0.0 );
  vec3 Hue = distance * LightHue;

  Light += Light2;
  Light  = mix(Light, LightHue, 0.8 * smoothstep(400.0, 800.0, buff.a));
  Light += Hue;

  gl_FragColor = vec4(Light, 0.0);
}