浏览代码

Added tangent computation alternative method

As stated in the note, I'm not sure if math is right, just followed a
reference implementation...
pull/531/head
raysan5 7 年前
父节点
当前提交
400c345f96
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. +10
    -3
      src/models.c

+ 10
- 3
src/models.c 查看文件

@ -2175,14 +2175,21 @@ void MeshTangents(Mesh *mesh)
Vector3 normal = { mesh->normals[i*3 + 0], mesh->normals[i*3 + 1], mesh->normals[i*3 + 2] };
Vector3 tangent = tan1[i];
//Vector3 tmp = (t - n * Vector3.Dot(n, t)).normalized;
//tangents[i] = (Vector4){ tmp.x, tmp.y, tmp.z };
// TODO: Review, not sure if tangent computation is right, just used reference proposed maths...
#if defined(COMPUTE_TANGENTS_METHOD_01)
Vector3 tmp = Vector3Subtract(tangent, Vector3Multiply(normal, Vector3DotProduct(normal, tangent)));
tmp = Vector3Normalize(tmp);
mesh->tangents[i*4 + 0] = tmp.x;
mesh->tangents[i*4 + 1] = tmp.y;
mesh->tangents[i*4 + 2] = tmp.z;
mesh->tangents[i*4 + 3] = 1.0f;
#else
Vector3OrthoNormalize(&normal, &tangent);
mesh->tangents[i*4 + 0] = tangent.x;
mesh->tangents[i*4 + 1] = tangent.y;
mesh->tangents[i*4 + 2] = tangent.z;
mesh->tangents[i*4 + 3] = (Vector3DotProduct(Vector3CrossProduct(normal, tangent), tan2[i]) < 0.0f) ? -1.0f : 1.0f;
#endif
}
free(tan1);

||||||
x
 
000:0
正在加载...
取消
保存