diff options
| author | raysan5 <[email protected]> | 2018-04-30 11:21:44 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2018-04-30 11:21:44 +0200 |
| commit | 400c345f96538299b5c40078c4e4d25a1b958408 (patch) | |
| tree | 2bb5ebf219f5c51b87a0ce0c7a14995ecf84e64e /src/models.c | |
| parent | 23e335d93355a948adeb8d10ee6277939aaab43e (diff) | |
| download | raylib-400c345f96538299b5c40078c4e4d25a1b958408.tar.gz raylib-400c345f96538299b5c40078c4e4d25a1b958408.zip | |
Added tangent computation alternative method
As stated in the note, I'm not sure if math is right, just followed a
reference implementation...
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/models.c b/src/models.c index 3ed3678e..38791747 100644 --- a/src/models.c +++ b/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); |
