Original Post
I recently started learning GLSL but I'm have some problems with trying to use a normal map along side a texture for color aswell. The problem is, no matter what I specify through openGL (ie. glBindTexture() ) and no matter what I specify as the uniforms, the shader simply uses the last texture I loaded for its normal map and then for its texture.
I cannot get it to use seperate textures for the normals and then the color, it will always use the same one. here are my shaders:
Vertex:
fragment:
and I'm loading/setting uniforms like this:
Any help would be appreciated, I just can't see why setting the uniforms seems to have no impact on the program at all, it always uses the last texture loaded.
Thanks
I cannot get it to use seperate textures for the normals and then the color, it will always use the same one. here are my shaders:
Vertex:
varying vec3 normal, lightDir, eyeVec;void main(){ gl_FrontColor = gl_Color; gl_TexCoord[0] = gl_MultiTexCoord0; normal = gl_NormalMatrix * gl_Normal; vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); lightDir = vec3(gl_LightSource[0].position.xyz - vVertex); eyeVec = -vVertex; gl_Position = ftransform(); }fragment:
varying vec3 normal, lightDir, eyeVec;uniform sampler2D normalMap;uniform sampler2D colorMap;void main (){ vec4 base = texture2D( colorMap, gl_TexCoord[0].xy); vec3 bump = normalize( texture2D(normalMap, gl_TexCoord[0].xy).xyz * 2.0 - 1.0); vec4 final_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + (gl_LightSource[0].ambient * gl_FrontMaterial.ambient); vec3 N = normalize(normal*bump); vec3 L = normalize(lightDir); float lambertTerm = dot(N,L); if(lambertTerm > 0.0) { final_color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm * base;//gl_Color; vec3 E = normalize(eyeVec); vec3 R = reflect(-L, N); float specular = pow( max(dot(R, E), 0.0), gl_FrontMaterial.shininess ); final_color += gl_LightSource[0].specular * gl_FrontMaterial.specular * specular; } gl_FragColor = final_color; }and I'm loading/setting uniforms like this:
loadShader("Shaders/bump.vert.txt", "Shaders/bump.frag.txt", &shader[0]); glUniform1i(glGetUniformLocation(shader[0], "normalMap"), texture[2]); glUniform1i(glGetUniformLocation(shader[0], "colorMap"), texture[3]); glUseProgram(shader[0]);Any help would be appreciated, I just can't see why setting the uniforms seems to have no impact on the program at all, it always uses the last texture loaded.
Thanks