diff --git a/forward.frag b/forward.frag index 30d99a7..1260f5d 100644 --- a/forward.frag +++ b/forward.frag @@ -43,7 +43,7 @@ in vec3 halfVecInView; layout(location = 0)out vec4 outColor; vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){ - float diffuseComponent = max(dot(normal, lightDir), 0); + float diffuseComponent = max(dot(normal, lightDir), 0); float specularComponent = max(dot(halfVec, normal), 0); return color*diffuseComponent*(kd+ks*pow(specularComponent, ns)); } @@ -56,7 +56,7 @@ void main(void) { #endif #ifdef NORMAL_MAP - vec3 normal = normalize(texture(normalMap, varTexCoord).xyz * tangentSpace); + vec3 normal = normalize(texture(normalMap, varTexCoord).xyz * tangentSpace); #else vec3 normal = normalize(varNormal); #endif @@ -80,9 +80,9 @@ void main(void) { #endif #ifdef AMBIENT_LIGHT - outColor = vec4(ambient + lightColor*diffuse, 1); + outColor = vec4(lightColor*ambient, 1); #else - vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView); + vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView); outColor = vec4(light, 1); #endif } diff --git a/forward.vert b/forward.vert index b1d037c..0d5976a 100644 --- a/forward.vert +++ b/forward.vert @@ -39,18 +39,19 @@ void main(void) { #ifdef DIRECTIONNAL_LIGHT lightDirInView = normalize(mat3(viewMatrix)*dirLight); - halfVecInView = normalize(lightDirInView - normalize(posInView)); + halfVecInView = normalize(lightDirInView - normalize(posInView)); #endif #ifdef POINT_LIGHT - lightDirInView = normalize(viewMatrix*pointLight - posInView); - halfVecInView = normalize(lightDirInView - posInView); + vec4 lightPosInView = viewMatrix*vec4(pointLight, 1); + lightDirInView = normalize(lightPosInView.xyz - posInView); + halfVecInView = normalize(lightDirInView - normalize(posInView)); #endif #ifdef NORMAL_MAP - tangentSpace = mat3(normalize(normalMatrix*inNormal), - normalize(normalMatrix*inTangent), - normalize(normalMatrix*inBinormal)); + tangentSpace = transpose(mat3(normalize(normalMatrix*inTangent), + normalize(normalMatrix*inBinormal), + normalize(normalMatrix*inNormal))); #else varNormal = normalize(normalMatrix*inNormal); #endif diff --git a/shader.cpp b/shader.cpp index 0003a5c..3846a9f 100644 --- a/shader.cpp +++ b/shader.cpp @@ -104,6 +104,7 @@ GLuint Shader::createShader(const std::string &source, GLenum shaderType) break; } std::cerr << type_str << " shader not compiled : " << std::endl; + std::cout << "Shader source :" << std::endl << source << std::endl; printShaderInfoLog(shaderId); return 0; }