[Bf-committers] Blender tangent space calculation
Eugene Minov
minov.eug at gmail.com
Sun Nov 13 17:46:22 CET 2011
Hi.
I am sorry if I subscribe into a wrong place, I am new and I've not
actually planned to change or to debug the blender sources yet.
But I trying to write app that'll be render models with normal mapping
exported from blender, and I have a question about how exactly is blender
calculates a tangent vectors when Unwrap operation in the editing mode
performs?
Calculating tangents in my app in usual manner (using UV coords and verts
positions) gives me different tangents for each face of the same vertex
indexed from, and thus crumpled normal map looking.
Then by looking into blender sources (searching by 'tangent' keyword) I've
found a couple of functions with tangents calculations, like:
float axis[3] = {0.0f, 0.0f, 1.0f};
cross_v3_v3v3(tangent, normal, up);
normalize_v3(tangent);
After I tried same method in my program I've gotten almost perfect looking
model, depending on what initial axis I've used.
To choose, which axis to use (0, 0, 1), (0, 1, 0) or (1, 0, 0) for each
normal, I calculate max dot product of tangent calculated by each axis with
tangent calculated from UV coords.
But still it seems that in some rare vertices tangent is calculates wrong,
maybe because of wrong initial axis.
So, can anyone please give me any information about tangents calculation
formula that blender uses while generates UV coords or some advice about
choosing initial axis.
Thanks for help.
Eugene
More information about the Bf-committers
mailing list