diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-07-30 15:43:58 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-07-30 15:43:58 +0300 |
commit | 2ec00ea0c1be1ace7cd0c7b68e43cc8e87dd07c7 (patch) | |
tree | bcea6f830039d7ef67dcd1a9a95b767d2af19958 /source/blender/blenkernel/intern/mesh_evaluate.c | |
parent | 9d335d29c775939b22dffedc303ecce9fec4e52f (diff) |
Move tangents and baking to looptris:
Notes:
* Code in rendering and in game engine will still convert
tangents to a tessface representation. Added code that
takes care of tangent layer only, might be removed
when BGE and rendering goes full mlooptri mode.
* Baking should work discovered some dead code while
I was working on the patch, also tangents are broken
when baking from multires (also in master), but those
are separate issues that can be fixed later.
This should fix T45491 as well
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_evaluate.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_evaluate.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 74c5fb8114d..a334951c772 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -2243,6 +2243,7 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData const bool hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL); const bool hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP); const bool hasLoopNormal = CustomData_has_layer(ldata, CD_NORMAL); + const bool hasLoopTangent = CustomData_has_layer(ldata, CD_TANGENT); int findex, i, j; const int *pidx; unsigned int (*lidx)[4]; @@ -2307,6 +2308,51 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData } } } + + if (hasLoopTangent) { + /* need to do for all uv maps at some point */ + float (*ftangents)[4] = CustomData_get_layer(fdata, CD_TANGENT); + float (*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT); + + for (findex = 0, pidx = polyindices, lidx = loopindices; + findex < num_faces; + pidx++, lidx++, findex++) + { + int nverts = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; + for (j = nverts; j--;) { + copy_v4_v4(ftangents[findex * 4 + j], ltangents[(*lidx)[j]]); + } + } + } +} + +void BKE_mesh_tangent_loops_to_tessdata(CustomData *fdata, CustomData *ldata, MFace *mface, + int *polyindices, unsigned int (*loopindices)[4], const int num_faces) +{ + /* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code... + * Issue is, unless having two different functions with nearly the same code, there's not much ways to solve + * this. Better imho to live with it for now. :/ --mont29 + */ + const bool hasLoopTangent = CustomData_has_layer(ldata, CD_TANGENT); + int findex, j; + const int *pidx; + unsigned int (*lidx)[4]; + + if (hasLoopTangent) { + /* need to do for all uv maps at some point */ + float (*ftangents)[4] = CustomData_get_layer(fdata, CD_TANGENT); + float (*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT); + + for (findex = 0, pidx = polyindices, lidx = loopindices; + findex < num_faces; + pidx++, lidx++, findex++) + { + int nverts = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; + for (j = nverts; j--;) { + copy_v4_v4(ftangents[findex * 4 + j], ltangents[(*lidx)[j]]); + } + } + } } /** |