From Farshid Lashkari, "In many game engines it is common to set the W component of the tangent vector to -1 if the UVs are mirrored and 1 if not. I've updated the osgUtil::TangentSpaceGenerator class to do the same."

This commit is contained in:
Robert Osfield
2013-06-24 08:18:08 +00:00
parent 0a4bf71fbb
commit db4b7584fb

View File

@@ -152,16 +152,19 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit
osg::Vec4 &vN = (*N_)[i];
osg::Vec3 txN = osg::Vec3(vT.x(), vT.y(), vT.z()) ^ osg::Vec3(vB.x(), vB.y(), vB.z());
bool flipped = txN * osg::Vec3(vN.x(), vN.y(), vN.z()) < 0;
if (txN * osg::Vec3(vN.x(), vN.y(), vN.z()) >= 0) {
vN = osg::Vec4(txN, 0);
} else {
if (flipped) {
vN = osg::Vec4(-txN, 0);
} else {
vN = osg::Vec4(txN, 0);
}
vT.normalize();
vB.normalize();
vN.normalize();
vT[3] = flipped ? -1.0f : 1.0f;
}
/* TO-DO: if indexed, compress the attributes to have only one
* version of each (different indices for each one?) */