   GLSL Diffuse lighting doesn't work
  I'm working with GLSL and for some reason my diffuse calculation keeps coming out to 0s...frag shader, everything is in eye spaceuniform vec3 lightPosition; // a directional lightuniform vec4 lightAmbient;// I'm getting this data from a texturevec4 color;vec3 normal;vec3 vertex; // this is the interpolated vertexvec3 E = normalize(- vertex.xyz);vec3 L= normalize(lightPosition);vec4 Idiff = color * max(dot(normal,L),0.0);vec4 Iamb  = lightAmbient * color;gl_FragColor =  Iamb + Idiff;but for some reason my scene always shows ONLY the Iamb color only.  I even tried substituting (normal,L) to (normal,vec3(0.0, 1.0, 0.0)) just to see what would happen and that seems to work, but that only gives the light direction in relation to the eye orientation.  Every frame, I update lightPosition by multiplying the camera's viewMatrix by the light's position then sending THAT vector as the position in eye space.  I know this works because on the CPU side, I have my light set at (0,1,0) and when I point the camera straight up, the new value is (0,0,-1) which is the light in eye space, so that's right.  I has to be something in the shader[Edited by - BloodLust666 on April 28, 2010 12:41:45 AM]
  ok, the diffuse is working now, turns out I had a misspelling when I was updating that uniform... BUT now it seems as though the diffuse is very exaggerated.  When I look up, nothing is lit (except ambiance), but when I look down everything is lit, including walls that weren't lit when I looked up.  Am I doing this correclty?  I'm "pretty" sure everything is in eye space...Backing up a bit, I'm doing deferred shading, on my first pass I haveVertex shadervarying vec2 texCoord;varying vec3 normal;varying vec4 position;void main (void){texCoord = gl_MultiTexCoord0.xy;normal = gl_NormalMatrix * gl_Normal;position= gl_ModelViewMatrix * gl_Vertex;gl_Position    = ftransform();}Fragment Shadervarying vec2 texCoord;varying vec3 normal;varying vec4 position;uniform sampler2D texture;void main (void){gl_FragData[0] = vec4(texture2D(texture, texCoord).rgb, 1.0);gl_FragData[1] = vec4(normal,1.0);gl_FragData[2] = vec4(position.xyz,gl_FrontMaterial.shininess);}As you can see at this step, the color and normals are in eye space.Then in my second pass, I'm pass in each light and render as a quadVertex shadervarying vec2 texCoord;void main (void){texCoord = gl_MultiTexCoord0.xy;gl_Position    = ftransform();}Fragment shadervarying vec2 texCoord;// geometryuniform sampler2D textureDiffuse;uniform sampler2D textureNormal;uniform sampler2D texturePosition;// lightuniform int lightType;uniform vec3 lightPosition;uniform vec4 lightAmbient;uniform vec4 lightDiffuse;uniform vec4 lightSpecular;void main (void){vec2 flipped = vec2(texCoord.x, 1.0 - texCoord.y);// render texture renders these upside down.  This is a fixvec4 Idiff;vec4 Iamb;vec4 Ispec = vec4(0.0, 0.0, 0.0, 0.0);vec4 color = texture2D(textureDiffuse, flipped );vec3 normal = normalize(texture2D( textureNormal, flipped ).xyz);vec4 position = texture2D(texturePosition, flipped );float shiny= position.a;position.a = 1.0;vec3 E = normalize(- position.xyz);vec3 L;vec3 H;float NdotHV;Iamb = lightAmbient * color;if ( lightType == 1 ) // directional{L = normalize(lightPosition);H = normalize(E - L);NdotHV = max(dot(normal, H),0.0);Idiff = color * max(dot(normal,L),0.0);//Ispec = lightSpecular * color * pow(NdotHV,shiny);}else if ( lightType == 2 ) // point light (not done yet.. help?){}gl_FragColor =  Idiff + Iamb + Ispec;};  Is your "lightPosition" provided in world space or in eye space?   ;  I'm pretty sure it's in eye space because before I pass lightPosition to the shader, I get the camera's ModelView Matrix and multiply it by the light's world position.  If that's eye space, then yes it's in eye space as well.lightPosition = light->GetPosition();lightPosition.Rotate(m_camera.GetViewMatrix());m_deferredPass2Shader.UpdateGlobalUniformData("lightPosition", cWUniformData(sWVector3(lightPosition)));   ;  Does lightPosition contain a position or a direction??   ;  lightPosition is a direction   ;  If I'm not wrong, you're calculating a direction in this line:H = normalize(E - L);However, if L (lightPosition) is a direction this doesn't make sense.Edit2: I guess your normals are normalized, aren't they?Edit3: What's your light direction? Could it point towards the camera? In that case your objects would be lit from the back and you wouldn't see that light.Edit: forget the following, never mindI'd say it should just be H = L; i.e. the next line should beNdotHV = max(dot(normal, L),0.0);[Edited by - Lord_Evil on April 28, 2010 2:20:28 PM];  The specular reflection isn't the problem.  My diffuse lighting isn't working correctly, but I imagine once I fix the diffuse problem, the specular issue should be fixed too.Edit: to clearify.  L is my light direction, H is the half vector between the eye and the light directionEdit2: yes all my normals are normalized   