calculate tangents - bump mapping

    Aug 02 2010 | 4:24 pm
    Hi everybody
    Maybe this question relates maths rather than jitter... I am following the bump mapping example of the Orange book, and in order to transform the vertex position, normal and light position into tangent space, I need to calculate tangent on every vertex. There seems to be no "gl_Tangent" or built-in variable which allows the application to pass these values to the shader. Also, does not allow the message "auto_tangents 1"...
    So, how do I calculate tangents? See .zip file for the patch, the initial vertices are generated by a into the shader.
    Any clues? Thanx!

    • Aug 02 2010 | 5:20 pm will automatically calculate tangents for you. set @auto_tangents 1 on the gl.mesh.
      gl.mesh will pass the tangent as a vertex attribute to your shader, but you need to do a few things. add the following lines to your jxs param declarations and bind declarations
      add this to your vertex program, same place as the varrying decs:attribute vec3 tangent;
      now just remove the line "vec3 tangent =;" from your original code, and you should be good to go.
    • Aug 02 2010 | 6:12 pm
      Thanks for your post robtherich However the patch is not working yet, it shows the right lighting calculations and the right color, but the bumps appear chaotic, and change at every frame (kind of nice but it is not what I want). I checked the shader code and it looks right...maybe defines the tangents in an inconsistent way?
      Another question is, why do you write "state", instead of "value" when defining the parameter tangent?
      see attached patch
    • Aug 03 2010 | 4:20 pm
      well you can try and calculate them yourself. the first three planes of the matrixoutput matrix are the xyz position values.
      you can create your own tangent matrix, and supply it to gl.mesh as a custom vertex attribute matrix.
      this post here provides a great example for using vertex attribute matrices:
      fwiw, the tangents calculated by gl.mesh have worked fine for me for a normal-map shader.
      "state" is simply the property you us when declaring an attribute (as opposed to a uniform). if that's not clear, read back up on the difference between glsl attributes and uniforms.
    • Aug 03 2010 | 4:32 pm
      Many thanks! that was clear :)