Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-10-23 18:57:49 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-10-23 18:57:49 +0400
commitb131359834e7ae6834dba574657327cb596cacb7 (patch)
tree17940be0b6ee802e814a90f182d562869c692dd6 /source/blender/blenkernel/intern/DerivedMesh.c
parentcfcab31c4536f5368b130a356755510af2f021f8 (diff)
Fix #32867: normal map baking issue with flat shaded faces since bmesh. Also
removed the old unused normal map tangent computation code.
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.c')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c96
1 files changed, 6 insertions, 90 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 84691362a93..eb42ecd8b3a 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2492,15 +2492,11 @@ static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[
void DM_add_tangent_layer(DerivedMesh *dm)
{
/* mesh vars */
- MTFace *mtface, *tf;
- MFace *mface, *mf;
- MVert *mvert, *v1, *v2, *v3, *v4;
- MemArena *arena = NULL;
- VertexTangent **vtangents = NULL;
+ MVert *mvert;
+ MTFace *mtface;
+ MFace *mface;
float (*orco)[3] = NULL, (*tangent)[4];
- float *uv1, *uv2, *uv3, *uv4, *vtang;
- float fno[3], tang[3], uv[4][2];
- int i, j, len, mf_vi[4], totvert, totface, iCalcNewMethod;
+ int totvert, totface;
float *nors;
if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
@@ -2526,14 +2522,8 @@ void DM_add_tangent_layer(DerivedMesh *dm)
DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
tangent = DM_get_tessface_data_layer(dm, CD_TANGENT);
- /* allocate some space */
- arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena");
- BLI_memarena_use_calloc(arena);
- vtangents = MEM_callocN(sizeof(VertexTangent *) * totvert, "VertexTangent");
-
/* new computation method */
- iCalcNewMethod = 1;
- if (iCalcNewMethod != 0) {
+ {
SGLSLMeshToTangent mesh2tangent = {0};
SMikkTSpaceContext sContext = {0};
SMikkTSpaceInterface sInterface = {0};
@@ -2556,82 +2546,8 @@ void DM_add_tangent_layer(DerivedMesh *dm)
sInterface.m_setTSpaceBasic = SetTSpace;
/* 0 if failed */
- iCalcNewMethod = genTangSpaceDefault(&sContext);
+ genTangSpaceDefault(&sContext);
}
-
- if (!iCalcNewMethod) {
- /* sum tangents at connected vertices */
- for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++) {
- v1 = &mvert[mf->v1];
- v2 = &mvert[mf->v2];
- v3 = &mvert[mf->v3];
-
- if (mf->v4) {
- v4 = &mvert[mf->v4];
- normal_quad_v3(fno, v4->co, v3->co, v2->co, v1->co);
- }
- else {
- v4 = NULL;
- normal_tri_v3(fno, v3->co, v2->co, v1->co);
- }
-
- if (mtface) {
- uv1 = tf->uv[0];
- uv2 = tf->uv[1];
- uv3 = tf->uv[2];
- uv4 = tf->uv[3];
- }
- else {
- uv1 = uv[0]; uv2 = uv[1]; uv3 = uv[2]; uv4 = uv[3];
- map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]);
- map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]);
- map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]);
- if (v4)
- map_to_sphere(&uv[3][0], &uv[3][1], orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]);
- }
-
- tangent_from_uv(uv1, uv2, uv3, v1->co, v2->co, v3->co, fno, tang);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v2], tang, uv2);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3);
-
- if (mf->v4) {
- v4 = &mvert[mf->v4];
-
- tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3);
- sum_or_add_vertex_tangent(arena, &vtangents[mf->v4], tang, uv4);
- }
- }
-
- /* write tangent to layer */
- for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++, tangent += 4) {
- len = (mf->v4) ? 4 : 3;
-
- if (mtface == NULL) {
- map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]);
- map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]);
- map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]);
- if (len == 4)
- map_to_sphere(&uv[3][0], &uv[3][1], orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]);
- }
-
- mf_vi[0] = mf->v1;
- mf_vi[1] = mf->v2;
- mf_vi[2] = mf->v3;
- mf_vi[3] = mf->v4;
-
- for (j = 0; j < len; j++) {
- vtang = find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]);
- normalize_v3_v3(tangent[j], vtang);
- ((float *) tangent[j])[3] = 1.0f;
- }
- }
- }
-
- BLI_memarena_free(arena);
- MEM_freeN(vtangents);
}
void DM_calc_auto_bump_scale(DerivedMesh *dm)