Forums > Jitter

calculate tangents – bump mapping

August 2, 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, jit.gl.gridshape 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 jit.gl.gridshape into the shader.

Any clues?
Thanx!

Attachments:
  1. bump_mapping.zip

August 2, 2010 | 5:20 pm

jit.gl.mesh 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 = gl_MultiTexCoord6.xyz;" from your original code, and you should be good to go.


August 2, 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 jit.gl.mesh 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

Attachments:
  1. bump_mapping_2.zip

August 3, 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:

http://www.cycling74.com/forums/topic.php?id=18070

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.


August 3, 2010 | 4:32 pm

Many thanks! that was clear :)


Viewing 5 posts - 1 through 5 (of 5 total)