Hi everyone,

I implemented a simple point light with normal mapping on RenderMonkey and copied it over to my own framework in C++ and for some odd reason I am having issues as you can see below:

First of all it’s not a spotlight, though it looks like it. The normal map seems fine as the highlights are correct.

I am doing my light and view direction vector calculations in eye space (premultiplying the light position and view position in the application by the current view matrix) however; I get this strange result. There is not a problem in the calculation of the view matrix. I believe I have checked everything but I hope I can get some input here or maybe someone can suggest somewhere else to look for the source of the problem.

Thanks!

Vertex Shader

```
uniform vec3 eyePosition; /*In eye space*/
uniform vec3 lightPosition; /*In eye space*/
varying vec3 lightDirection;
varying vec3 viewDirection;
varying vec2 texcoord;
varying float d;
attribute vec3 tangent;
attribute vec3 bitangent;
void main(void)
{
gl_Position = ftransform();
vec4 vertPosition = gl_ModelViewMatrix * gl_Vertex;
texcoord = gl_MultiTexCoord0.xy;
vec3 normal = gl_NormalMatrix * gl_Normal;
vec3 esTangent = gl_NormalMatrix * tangent;
vec3 esBitangent = gl_NormalMatrix * bitangent;
vec3 lightVector = lightPosition - vertPosition.xyz;
float l = length( lightVector );
float k0 = 0.0001;
float k1 = 0.0001;
float k2 = 0.0002;
d = 1.0 / ( k0 + k1 * l + k2 * l * l );
lightDirection.x = dot( esTangent, lightVector );
lightDirection.y = dot( esBitangent, lightVector );
lightDirection.z = dot( normal, lightVector );
vec3 viewVector = eyePosition - vertPosition.xyz;
viewDirection.x = dot( esTangent, viewVector );
viewDirection.y = dot( esBitangent, viewVector );
viewDirection.z = dot( normal, viewVector );
}
```

Fragment Shader

```
varying vec3 lightDirection;
varying vec2 texcoord;
varying vec3 viewDirection;
varying float d;
uniform sampler2D texture0;
uniform sampler2D texture1;
void main(void)
{
lightDirection = normalize( lightDirection );
viewDirection = normalize( viewDirection );
vec3 normal = normalize( texture2D( texture1, texcoord ).xyz * 2.0 - 1.0 );
float dotNL = max( 0.0, dot( normal, lightDirection ) );
vec3 reflection = normalize( ( ( 2.0 * normal ) * dotNL ) - lightDirection );
float dotRV = max( 0.0, dot( reflection, viewDirection ) );
vec4 base = texture2D( texture0, texcoord );
vec4 ambient = vec4( 0.1, 0.1, 0.1, 1.0 ) * base;
vec4 diffuse = 0.5 * vec4( 1.0, 0.5, 0.5, 1.0 ) * base * dotNL * d;
vec4 specular = 10.5 * vec4( 1.0, 0.5, 0.5, 1.0 ) * pow( dotRV, 10.0 ) * dotNL * d;
gl_FragColor = vec4( ambient.xyz + diffuse.xyz + specular.xyz, 1.0 );
}
```