Results 1 to 2 of 2

Thread: glsl tangente space bump mapping

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    7

    glsl tangente space bump mapping

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

  2. #2
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: glsl tangente space bump mapping

    You can look at my WebGL "Bump mapping demo"
    http://www.ibiblio.org/e-notes/webgl/bump_hi.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •