Hello, im back again with another question. So I've been working on diffuse lighting for a couple of days now and I can't seem to get it working properly. I get the feeling that there is something messed up with my direction/position Vector of the light. But I can't seem to figure out what. Either way, here are my shaders:
VertexShader.glsl
#version 330
uniform mat4 perspectiveMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
layout(location = 0) in vec3 in_Position;
layout(location = 1) in vec2 in_TextureCoord;
layout(location = 2) in vec3 in_Normal;
out vec2 frag_TextureCoord;
out vec3 normal;
void main(void){
gl_Position = perspectiveMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0);
normal = mat3(modelMatrix) * in_Normal;
normal = normalize(normal);
frag_TextureCoord = in_TextureCoord;
}
FragmentShader.glsl
#version 330
uniform sampler2D texture_diffuse;
uniform vec3 lightPosition;
uniform vec3 lightColor;
uniform float lightPower;
in vec2 frag_TextureCoord;
in vec3 normal;
out vec3 out_Color;
void main(void){
float lightIntensity;
vec3 lightDir;
lightDir = -lightPosition;
lightIntensity = clamp(dot(normal, lightDir), 0.0f, 1.0f);
out_Color = clamp((lightColor * lightIntensity), 0.0f, 1.0f);
out_Color = out_Color * texture(texture_diffuse, frag_TextureCoord).rgb;
}
My position/direction vector that I send to my fragment shader in the uniform is: 0, -1, 0
and what I get is this: