fixed tangent space, added shader source displayed when compilation error occurs

This commit is contained in:
Anselme 2015-12-03 23:59:55 +01:00
parent 84662d2c9f
commit 87a2c2c906
3 changed files with 12 additions and 10 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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;
}