i try to make a tangent space bump mapping but it doesn’t work why?
here is my code :
vertex shader :
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
attribute vec3 aVertexNormal;
attribute vec3 aVertexTangente;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;
uniform vec3 uLightingDirection;
varying vec2 vTextureCoord;
varying vec3 lightVec;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
vec4 n = normalize(uNMatrix * vec4(aVertexNormal, 1.0));
vec4 t = normalize(uNMatrix * vec4(aVertexTangente, 1.0));
vec3 b = cross(n.xyz, t.xyz);
lightVec.x = dot(uLightingDirection, t.xyz);
lightVec.y = dot(uLightingDirection, b.xyz);
lightVec.z = dot(uLightingDirection, n.xyz);
}
fragment shader :
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D color_texture;
uniform sampler2D normal_texture;
uniform vec3 uLightingDirection;
varying vec2 vTextureCoord;
varying vec3 lightVec;
//uniform vec3 uDirectionalColor;
//uniform vec3 uAmbientColor;
void main() {
vec3 normal = normalize(texture2D(normal_texture, vec2(vTextureCoord.s, vTextureCoord.t)).rgb * 2.0 – 1.0);
vec3 light_pos = normalize(lightVec);
float diffuse = max(dot(normal, light_pos), 0.0);
vec3 color = diffuse * texture2D(color_texture, vec2(vTextureCoord.s, vTextureCoord.t)).rgb;
gl_FragColor = vec4(color, 1.0);
}