**0**

# Tangents and Binormals?

###
#2
Members - Reputation: **502**

Posted 04 February 2011 - 04:48 PM

Other possibility is to store the normals in a normal map in object-space (or any other you wish). In this case you do not need tangents and bitangents since, for example, transforming the normals form the sampled normal map would only require to use world transform to get them in world-space.

If you want some solid reference, Eric Lengyel's "Mathematics for 3D Game Programming and Computer Graphics" gives a very nice dicussion on this topic.

###
#3
Members - Reputation: **102**

Posted 04 February 2011 - 04:55 PM

###
#5
Members - Reputation: **502**

Posted 04 February 2011 - 05:48 PM

Object-space normal map: http://www.3dkingdoms.com/tut2.jpg

###
#6
Members - Reputation: **136**

Posted 04 February 2011 - 07:07 PM

Of course that workings with object-space normal maps is much easier . But... imagine you have a wall texture that appears notorously on many walls. For every "orientation" of a wall using that texture you would need one separate normal map. Having normal maps in tangent space and doind computations in that space is thus much more universal and much less memory consuming. You can imagine this using for example for characters. A character's texture will probably be used only on that particular character so having normal map in object-space in this case makes sense. Moreover, you avoid many problems associated with tangent-space computations, like sheared texture coordinates, non-orthogonal tangent basis and so on. So a good idea seems to be to have unique objects with object-space normal maps and "general" textures (like walls, decals, floors) in tangent-space. Note however that this requires from you to keep two slightly distinc shader paths for rendering one type of meshes and the other.

Object-space normal map: http://www.3dkingdoms.com/tut2.jpg

I am generating a normal map per-pixel from a different height map texture for every object anyway. Unfortunately the way I'm generating it places it in tangent space. I was trying to avoid sending more data with my vertices. Is there anything I can do on a per-pixel or per-vertex basis (in the hlsl shader)?

###
#7
Members - Reputation: **502**

Posted 04 February 2011 - 07:48 PM

bitangent = determinant * cross(normal, tangent)Passing a normal, a tangent and a determinant takes 7 floats, whereas passing the whole basis takes 9 floats. 2 floats my is not much, but is a good step to start . Maybe someone has some better idea on how to save sending to much data to a vertex shader?

###
#8
Members - Reputation: **136**

Posted 04 February 2011 - 07:55 PM

http://www.gamedev.net/topic/594781-hlsl-height-map-to-normal-algorithm/

###
#9
Members - Reputation: **102**

Posted 05 February 2011 - 10:03 AM

I my engine I send a normal and a tangent, leaving a bitangent to be computed with the cross product of the normal and the tangent. Certainly, we have two perpendicular vectors to normal and tangent and we must choose the proper one. The idea I use is to send a normal, a tangent, and a determinant of a matrix formed with (tangent, bitangent, normal). The determinant gives the handedness of the basis. So in my vertex shader I do something like:

bitangent = determinant * cross(normal, tangent)Passing a normal, a tangent and a determinant takes 7 floats, whereas passing the whole basis takes 9 floats. 2 floats my is not much, but is a good step to start . Maybe someone has some better idea on how to save sending to much data to a vertex shader?

Personally I send normals, tangents, and bitangents to the vertex shader. I suppose I'd just rater compute all the stuff once per mesh and construct the tangent space matrix in the vertex shader instead of having it computer anything more. Not really sure if thats more efficient or not in the long run.

###
#10
Members - Reputation: **1577**

Posted 05 February 2011 - 10:50 AM

I my engine I send a normal and a tangent, leaving a bitangent to be computed with the cross product of the normal and the tangent. Certainly, we have two perpendicular vectors to normal and tangent and we must choose the proper one. The idea I use is to send a normal, a tangent, and a determinant of a matrix formed with (tangent, bitangent, normal). The determinant gives the handedness of the basis. So in my vertex shader I do something like:

bitangent = determinant * cross(normal, tangent)Passing a normal, a tangent and a determinant takes 7 floats, whereas passing the whole basis takes 9 floats. 2 floats my is not much, but is a good step to start . Maybe someone has some better idea on how to save sending to much data to a vertex shader?

Personally I send normals, tangents, and bitangents to the vertex shader. I suppose I'd just rater compute all the stuff once per mesh and construct the tangent space matrix in the vertex shader instead of having it computer anything more. Not really sure if thats more efficient or not in the long run.

I'm currently doing the same, as i'm running into shader complexity issues(PS2.0/running out of instruction space). Efficiency one way or the other will depend on many factors such as scene complexity/geometry complexity, and will probably need to be looked at on a per project basis.

###
#11
Members - Reputation: **502**

Posted 05 February 2011 - 11:24 AM

###
#12
Members - Reputation: **236**

Posted 05 February 2011 - 12:30 PM

at this -> http://image.diku.dk...ikkelsen.08.pdf

It's a big file, 50 megs, but at least the server is good.

A clear order independent way to define which triangles are to share tangents (averaged) is given at the end of page 47

Order independence is important because otherwise you risk different tools pipelines creating different tangent spaces

for what is essentially the same mesh but with triangles or vertices in a different order. It's also important for getting perfectly

mirrored tangent spaces for mirrored meshes,

Adjacent triangles must share tangent space if and only if the 4 criteria are met.

The first 3 are trivial. The triangles must share

position, normal and texture coordinate at both end-points of the shared edge.

The fourth rule means that the winding (CW/CCW) of the texture coordinates must be the same on both triangles.

The fourth rule is important in the general case but it also allows us to handle mirroring correctly (a split will be created).

The thesis also shows how most commercial products out there have many problems.

Check pages: 44, 45, 52-56

Using the strategy of the thesis gives a perfect result as shown on page 68 (see the tspaces on 67).

Page 7 gives an explanation of the relation between bump mapping and normal mapping.

Hope someone finds this useful.

Cheers,

Morten