Still not working - but I think I have worked out the problem.
Running the shader below, I always get a red square - ie: no diffuse color. Running
float nl = dot(lightVector, normal);
seems to always result in nl being a 0 - which my basic understanding of maths is that dot(lightVector, 0) - will always result in a 0.
The normals are there - as can be seen in the top right texture, and I have checked them as the file is loaded. I have modified the normal line to make sure they are in worldspace ( I think ).
Does the transformation of the normals look right to you?
#version 330
uniform sampler2D tDepth;
uniform sampler2D tDiffuse;
uniform sampler2D tPosition;
uniform sampler2D tNormals;
uniform vec4 lightPosition;
uniform vec3 cameraPosition;
uniform mat4 u_modelMat;
uniform mat4 u_viewProjectionMat;
//vec3 lightPosition = vec3(0, 10, 0);
vec3 lightDiffuse = vec3(0.5, 0.5, 0.5);
vec4 lightSpecular = vec4(1.0, 1.0, 1.0, 200.0);
vec3 ambient = vec3(0.3, 0.3, 0.3);
uniform float nearPlane;
uniform float farPlane;
uniform float viewWidth;
uniform float viewHeight;
uniform vec2 texelSize;
in vec2 fragTexCoord0;
out vec4 outColor;
void main()
{
vec3 normal = normalize(transpose(inverse(mat3(u_modelMat))) * texture2D(tNormals, fragTexCoord0.xy).rgb);
// vec3 normal = texture2D(tNormals, fragTexCoord0.xy).rgb;
vec3 color = texture2D(tDiffuse, fragTexCoord0.xy).rgb;
vec3 position = texture2D(tPosition, fragTexCoord0.xy).rgb;
float dist = 50.0f / distance(position, lightPosition.xyz);
//
// lighting
//
vec3 lightVector = normalize(lightPosition.xyz - position);
vec3 viewVector = normalize(position - cameraPosition);
vec3 halfVector = normalize(lightVector + viewVector);
float nl = dot(lightVector, normal);
vec3 diffuse = lightDiffuse * max(0.0, nl);
vec3 specular = vec3(0.0);
// diffuse = vec3(1,1,1);
if (nl > 0.0)
specular = lightSpecular.rgb * pow(max(0.0, dot(halfVector, normal)), lightSpecular.w);
outColor.rgb = 1.0 * (color.rgb * diffuse * dist + specular * dist);
outColor.a = 1.0f;
//
// Testing - gives a full red square
//
if (diffuse.x == 0)
outColor.r = 1.0;
// outColor.rgb = 1.0 * (color.rgb * diffuse * dist);
// outColor.rgb = outColor.rgb + halfVector.xyz;
// outColor.a = 1.0f;
}