Skip to main content
GameDev.net gamedev.net
🔒 Locked

ComputeTangent()

Started by Bulma Jul 14, 2004 at 9:17 AM 1 replies 1.5k views
Original Post
Bulma
Bulma
Hopefully I`ll get some answers here ;) I have a typical mesh with Position, Normal and Texture coordinates... I have code that goes like this:

Mesh original = Mesh.FromFile(...)
VertexElement[] decl = original.Declaration;
decl[3] = new VertexElement(0, 32, DeclarationType.Float3,
DeclarationMethod.Default, DeclarationUsage.Tangent, 0);
decl[4] = new VertexElement(0, 44, DeclarationType.Float3,
DeclarationMethod.Default, DeclarationUsage.BiNormal, 0);
decl[5] = VertexElement.VertexDeclarationEnd;
bumpMappedMesh = original.Clone(MeshFlags.Managed, decl, original.Device );
bumpMappedMesh.ComputeTangent(0, 0, 0, 0);

In my shader i have:

VS_OUTPUT VS( float4 Pos : POSITION, float3 Norm : NORMAL, float2 Tex :
TEXCOORD0, float3 Tangent : TANGENT0, float3 Binormal : BINORMAL0 )
{
    VS_OUTPUT Out = (VS_OUTPUT)0;
    ....

I checked with shader debugger and I get all values for Tangent and Binormal = (0,0,0); Other values (position, normal, tex) are ok... I tried with different objects too... What am I doing wrong? No errors with maximum validation...
Bulma
IFooBar
IFooBar
not quite sure this will work, but try to change your code to:

decl[3] = new VertexElement(0, 32, DeclarationType.Float3,DeclarationMethod.Default, DeclarationUsage.Tangent, 1);decl[4] = new VertexElement(0, 44, DeclarationType.Float3,DeclarationMethod.Default, DeclarationUsage.BiNormal, 2);



and then call Compute Tangent as:

bumpMappedMesh.ComputeTangent(0, 1, 2, 1);

[edit]

Actually, yeah, that *should* work. Because if you specify 0 as the tangentIndex and 0 as the binormalIndex, then ComputeTangent doesnt touch the tangent and binormal data. But you also have to change the usage index of your declarations to match teh new usage indices of the tangent and binormal data

[/edit]
[size=2]aliak.net
Bulma
Bulma
I tried that, but it still doesn`t work... Still zeros for binormal and tangent :(
Bulma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.