[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60874] branches/vgroup_modifiers/source/ blender/blenkernel/intern/DerivedMesh.c: Use loop normals for usual tspace (baking & co), when enabled on an Object.

Bastien Montagne montagne29 at wanadoo.fr
Sun Oct 20 22:14:40 CEST 2013


Revision: 60874
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60874
Author:   mont29
Date:     2013-10-20 20:14:39 +0000 (Sun, 20 Oct 2013)
Log Message:
-----------
Use loop normals for usual tspace (baking & co), when enabled on an Object.

Should work OK, but really needs tests to check it actually does what's expected!

Modified Paths:
--------------
    branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c

Modified: branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c	2013-10-20 17:53:29 UTC (rev 60873)
+++ branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c	2013-10-20 20:14:39 UTC (rev 60874)
@@ -2625,7 +2625,8 @@
 /* ******************* GLSL ******************** */
 
 typedef struct {
-	float *precomputedFaceNormals;
+	float (*precomputedFaceNormals)[3];
+	float (*precomputedLoopNormals)[3];
 	MTFace *mtface;     /* texture coordinates */
 	MFace *mface;       /* indices */
 	MVert *mvert;       /* vertices & normals */
@@ -2677,11 +2678,14 @@
 {
 	//assert(vert_index >= 0 && vert_index < 4);
 	SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
+	const bool smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH) != 0;
 
-	const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH);
-	if (!smoothnormal) {    // flat
+	if (pMesh->precomputedLoopNormals) {
+		copy_v3_v3(r_no, pMesh->precomputedLoopNormals[face_num * 4 + vert_index]);
+	}
+	else if (!smoothnormal) {    // flat
 		if (pMesh->precomputedFaceNormals) {
-			copy_v3_v3(r_no, &pMesh->precomputedFaceNormals[3 * face_num]);
+			copy_v3_v3(r_no, pMesh->precomputedFaceNormals[face_num]);
 		}
 		else {
 			MFace *mf = &pMesh->mface[face_num];
@@ -2703,6 +2707,7 @@
 		normal_short_to_float_v3(r_no, no);
 	}
 }
+
 static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign, const int face_num, const int iVert)
 {
 	//assert(vert_index >= 0 && vert_index < 4);
@@ -2712,7 +2717,6 @@
 	pRes[3] = fSign;
 }
 
-
 void DM_add_tangent_layer(DerivedMesh *dm)
 {
 	/* mesh vars */
@@ -2721,12 +2725,14 @@
 	MFace *mface;
 	float (*orco)[3] = NULL, (*tangent)[4];
 	int /* totvert, */ totface;
-	float *nors;
+	float (*fnors)[3], (*tlnors)[3];
 
 	if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
 		return;
 
-	nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
+	fnors = dm->getTessFaceDataArray(dm, CD_NORMAL);
+	/* Note, we assume we do have tessellated loop normals at this point, have to check this is valid... */
+	tlnors = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL);
 
 	/* check we have all the needed layers */
 	/* totvert = dm->getNumVerts(dm); */ /* UNUSED */
@@ -2752,7 +2758,8 @@
 		SMikkTSpaceContext sContext = {NULL};
 		SMikkTSpaceInterface sInterface = {NULL};
 
-		mesh2tangent.precomputedFaceNormals = nors;
+		mesh2tangent.precomputedFaceNormals = fnors;
+		mesh2tangent.precomputedLoopNormals = tlnors;
 		mesh2tangent.mtface = mtface;
 		mesh2tangent.mface = mface;
 		mesh2tangent.mvert = mvert;




More information about the Bf-blender-cvs mailing list