Normal Mapping Vectors with Wrapping

The function D3DXComputeTangent computes normal mapping gradients (tangents and binormals) for each vertex in a D3DXMesh. This function has a parameter which sets Wrapping to true or false. How does this parameter affect the gradient calculations?
[248 byte] By [jcampana] at [2008-3-1]
# 1
Set Wrapping to true if you want to tile your normal map over your mesh using wrapped mode texture addressing. Otherwise you will notice first derivative shading discontinuties (mach bands) when you render using the normals at the edges of your normal map textures.

It's worth trying it both ways so you can learn to recognize this kind of artifact. :)

Ben

BenLuna at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 2
Thx for the reply Ben. The reason I ask this question is, I am not using d3dxmesh, and so cannot use d3dxcomputetangent. I do my own tangent/binormal calculations in my exporter. and i do get banding artifacts, but only with cylindrical mappings from 3ds max. so i would like to know exactly how wrapping affects these calculations, so i can modify my exporter to handle the cylindrical mapping wraparound problem.
jcampana at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 3

The actual algorithm that it uses is fairly simple, what wrapping does is essentially give you 3 options to place the texture coordinate at in a given dimension. So that means that a texture coordinate (u, v) in the range [0,1) x [0,1) (you can get this pretty easily by taking the floating point modulus wrt 1), if wrapping in both dimensions is enabled, is equivalent to (u +/- 1, v +/- 1).

What this means is that in this case, there are 9 possible locations that you might want to make the actual texture coordinate be located at, for the purpose of calculating partial derivatives. What ComputeTangent does is it locks the first vertex location, and then tries the 81 possible locations of the other two vertices, and chooses the combination with the smallest perimeter (only because choosing based solely on area could prefer long skinny triangles over reasonably sized fat ones).

It's not perfect (nor particularly fast), but if the triangles are relatively small in tangent space, then it works relatively well. It's not a well defined problem, so there will always be cases where it won't work.

If you're only wrapping u (as your reference to a cylindrical mapping suggests), then you only have to check 3 locations per vertex, and 9 combinations of the two vertices, which will probably be faster, if that's important to you.

JohnRapp at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...