I’ve been trying to get this code from the ever-wonderful Ozone3D.net working with my normal map.

It’s not working at the moment (in a variety of exciting ways), and I’m pretty sure that’s because my shader is not receiving a value for the attribute vec3 ‘vTangent’. I can turn this attribute into a uniform and set it manually, but I assume I need to calculate this value per-vertex inside the Vertex Shader for it to work properly. Sadly, I have no idea how I might go about doing this

Anyone any ideas? All suggestions gratefully accepted.

The tangent should indeed be an attribute. What you need to do is either compute the tangent in your code ( http://www.terathon.com/code/tangent.php ), or export the tangents from a modeling program such as Maya.

thanks for getting back to me.
Doesn’t look like this bumpmapping method is a goer then. I’m planning to use the normal map to create lighting on a height field, with the height field texture also being used to create the normal map. Any static tangent information will be incorrect after vertex displacement, I guess.

Well, it could still be done. The tangent is the vector tat points in the same direction as the u-direction of your texture space (or maybe it is the bitangent, I always swap them, well, no matter). So if your texture coordinates behave in a regular way, for example, the texture is a planar projection onto the heightfield, then you could compute the bitangent and the tangent in the shader. For example, if the texture space axis correspond to the heightfield X and Z axis (as it is often done) and you know the world space normal vector, you will also know tha the world tangent will arise by transforming the (1, 0, 0) vetor by the same means that would also transform (0, 1, 0) – the normal — to the space normal vector. Hovewer, I don’t have the math right here and it would take me too much time to figure out (my linear algera is really bad), but I am sure it can be solved.

Similarly, you could compute the tangent from the heightfield in your CPU code at the same time when also computing your normal.

Thanks for the explanation. Unfortunately, the development environment I’m using doesn’t give me access to OpenGL instructions, so I’m not able to precompute normals for the mesh. I’m deforming the mesh with the heightfield in the Vertex Shader, so any calculations need to be done in the Vertex or Fragment Shaders.

It’s odd, because I sort-of got the normal map to work without doing any real conversion of the normal vector from tangent space (see my last 2 posts on my blog here ). It was a bit glitchy, but kind of worked. Thinking about it now, I’m not sure why it should work at all…