I am having a slight problem with my Bump Mapping project. Although everything works OK (at least from what I know) there is a slight mistake somewhere and I get incorrect shading on the brick wall when the light goes to the one side or the other as seen in the picture below:

enter image description here

The light is on the right side so the shading on the wall should be the other way. I have provided the shaders to help find the issue (I do not have much experience with shaders).


varying vec3 viewVec;
varying vec3 position;
varying vec3 lightvec;
attribute vec3 tangent; 
attribute vec3 binormal;
uniform vec3 lightpos;
uniform mat4 cameraMat;

void main()

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();

    position = vec3(gl_ModelViewMatrix * gl_Vertex);
    lightvec = vec3(cameraMat * vec4(lightpos,1.0)) - position ;

    vec3 eyeVec = vec3(gl_ModelViewMatrix * gl_Vertex);
    viewVec = normalize(-eyeVec);


uniform sampler2D colormap;
uniform sampler2D normalmap;

varying vec3 viewVec;
varying vec3 position;
varying vec3 lightvec;

vec3 vv;

uniform float diffuset;
uniform float specularterm;
uniform float ambientterm;

void main() {


    vec3 normals = normalize(texture2D(normalmap,gl_TexCoord[0].st).rgb * 2.0 - 1.0);

    normals.y = -normals.y;

    //normals = (normals * gl_NormalMatrix).xyz ;

    vec3  distance = lightvec;
    float dist_number =length(distance);
    float final_dist_number = 2.0/pow(dist_number,diffuset);
    vec3  light_dir=normalize(lightvec);
    vec3  Halfvector = normalize(light_dir+vv);
    float angle=max(dot(Halfvector,normals),0.0);
          angle= pow(angle,specularterm);
    vec3 specular=vec3(angle,angle,angle);
    float diffuseterm=max(dot(light_dir,normals),0.0);
    vec3 diffuse = diffuseterm * texture2D(colormap,gl_TexCoord[0].st).rgb;
    vec3 ambient = ambientterm *texture2D(colormap,gl_TexCoord[0].st).rgb;
    vec3 diffusefinal = diffuse * final_dist_number;
    vec3 finalcolor=diffusefinal+specular+ambient;

    gl_FragColor = vec4(finalcolor, 1.0);

  • \$\begingroup\$ well I would suspect your cameraMat having wrong values. You are also flipping you normals y why is that ? \$\endgroup\$ – concept3d Oct 8 '13 at 21:58
  • 1
    \$\begingroup\$ This is not bump mapping, it is normal mapping. You will need to calculate a "tangent space to object space" transformation per vertex, you can handle right or left handed bumpmaps through that too. \$\endgroup\$ – MickLH Nov 10 '13 at 8:10

I am flipping y because the bricks were lit on the opposite side, and that fixed it.

I found the problem with the shadow: I had to do position = cameraMAT *gl_Vertex instead of gl_Modelviewmatrixi.

I do not really know why this fixed the problem though.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.