[Bf-blender-cvs] [429f6bee284] blender2.8: Fix T51561: Normal maps fail w/ quad + eevee

Campbell Barton noreply at git.blender.org
Wed May 24 14:36:13 CEST 2017


Commit: 429f6bee2845489a82983b54b6d63cc260a76387
Author: Campbell Barton
Date:   Wed May 24 22:33:21 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB429f6bee2845489a82983b54b6d63cc260a76387

Fix T51561: Normal maps fail w/ quad + eevee

Generalize derived-mesh tangent calculation so
it can be used by Batch cache creation too.

===================================================================

M	source/blender/blenkernel/BKE_DerivedMesh.h
M	source/blender/blenkernel/BKE_mesh.h
A	source/blender/blenkernel/BKE_mesh_tangent.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/editderivedmesh.c
M	source/blender/blenkernel/intern/editmesh_tangent.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
A	source/blender/blenkernel/intern/mesh_tangent.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/makesrna/intern/rna_mesh_api.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index c7bcf036f5b..1ac1fd10da6 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -785,17 +785,11 @@ void DM_draw_attrib_vertex_uniforms(const DMVertexAttribs *attribs);
 void DM_calc_tangents_names_from_gpu(
         const struct GPUVertexAttribs *gattribs,
         char (*tangent_names)[MAX_NAME], int *tangent_names_count);
-void DM_add_named_tangent_layer_for_uv(
-        CustomData *uv_data, CustomData *tan_data, int numLoopData,
-        const char *layer_name);
-void DM_calc_loop_tangents_step_0(
-        const CustomData *loopData, bool calc_active_tangent,
-        const char (*tangent_names)[MAX_NAME], int tangent_names_count,
-        bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
-        char *ract_uv_name, char *rren_uv_name, char *rtangent_mask);
+
 void DM_calc_loop_tangents(
         DerivedMesh *dm, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME],
         int tangent_names_count);
+
 void DM_calc_auto_bump_scale(DerivedMesh *dm);
 
 /** Set object's bounding box based on DerivedMesh min/max data */
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index e0f62cfd894..64f71f0ade5 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -186,13 +186,6 @@ void BKE_mesh_calc_normals_looptri(
         const struct MLoop *mloop,
         const struct MLoopTri *looptri, int looptri_num,
         float (*r_tri_nors)[3]);
-void BKE_mesh_loop_tangents_ex(
-        const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
-        float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
-        const int numLoops, const struct MPoly *mpolys, const int numPolys,
-        struct ReportList *reports);
-void BKE_mesh_loop_tangents(
-        struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
 
 /**
  * References a contiguous loop-fan with normal offset vars.
diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h
new file mode 100644
index 00000000000..66b8a26e35b
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -0,0 +1,59 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __BKE_MESH_TANGENT_H__
+#define __BKE_MESH_TANGENT_H__
+
+void BKE_mesh_calc_loop_tangent_single_ex(
+        const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
+        float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
+        const int numLoops, const struct MPoly *mpolys, const int numPolys,
+        struct ReportList *reports);
+void BKE_mesh_calc_loop_tangent_single(
+        struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
+
+void BKE_mesh_calc_loop_tangent_ex(
+        const struct MVert *mvert,
+        const struct MPoly *mpoly, const uint mpoly_len,
+        const struct MLoop *mloop,
+        const struct MLoopTri *looptri, const uint looptri_len,
+
+        struct CustomData *loopdata,
+        bool calc_active_tangent,
+        const char (*tangent_names)[64], int tangent_names_len,
+        const float (*poly_normals)[3],
+        const float (*loop_normals)[3],
+        const float (*vert_orco)[3],
+        /* result */
+        struct CustomData *loopdata_out,
+        const uint  loopdata_out_len,
+        char *tangent_mask_curr_p);
+
+/* Helpers */
+void BKE_mesh_add_loop_tangent_named_layer_for_uv(
+        struct CustomData *uv_data, struct CustomData *tan_data, int numLoopData,
+        const char *layer_name);
+void BKE_mesh_calc_loop_tangent_step_0(
+        const struct CustomData *loopData, bool calc_active_tangent,
+        const char (*tangent_names)[64], int tangent_names_count,
+        bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
+        char *ract_uv_name, char *rren_uv_name, char *rtangent_mask);
+
+#endif /* __BKE_MESH_TANGENT_H__ */
+
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 1acc45c9f00..7af0b5d092a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -136,6 +136,7 @@ set(SRC
 	intern/mesh_evaluate.c
 	intern/mesh_mapping.c
 	intern/mesh_remap.c
+	intern/mesh_tangent.c
 	intern/mesh_validate.c
 	intern/modifier.c
 	intern/modifiers_bmesh.c
@@ -263,6 +264,7 @@ set(SRC
 	BKE_mesh.h
 	BKE_mesh_mapping.h
 	BKE_mesh_remap.h
+	BKE_mesh_tangent.h
 	BKE_modifier.h
 	BKE_movieclip.h
 	BKE_multires.h
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 150a919bf6b..a6b9a048763 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -60,6 +60,7 @@
 #include "BKE_modifier.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
+#include "BKE_mesh_tangent.h"
 #include "BKE_object.h"
 #include "BKE_object_deform.h"
 #include "BKE_paint.h"
@@ -3038,234 +3039,6 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int
 
 /* ******************* GLSL ******************** */
 
-/** \name Tangent Space Calculation
- * \{ */
-
-/* Necessary complexity to handle looptri's as quads for correct tangents */
-#define USE_LOOPTRI_DETECT_QUADS
-
-typedef struct {
-	float (*precomputedFaceNormals)[3];
-	float (*precomputedLoopNormals)[3];
-	const MLoopTri *looptri;
-	MLoopUV *mloopuv;   /* texture coordinates */
-	MPoly *mpoly;       /* indices */
-	MLoop *mloop;       /* indices */
-	MVert *mvert;       /* vertices & normals */
-	float (*orco)[3];
-	float (*tangent)[4];    /* destination */
-	int numTessFaces;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	/* map from 'fake' face index to looptri,
-	 * quads will point to the first looptri of the quad */
-	const int    *face_as_quad_map;
-	int       num_face_as_quad_map;
-#endif
-
-} SGLSLMeshToTangent;
-
-/* interface */
-#include "mikktspace.h"
-
-static int dm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
-{
-	SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	return pMesh->num_face_as_quad_map;
-#else
-	return pMesh->numTessFaces;
-#endif
-}
-
-static int dm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
-{
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
-	if (pMesh->face_as_quad_map) {
-		const MLoopTri *lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
-		const MPoly *mp = &pMesh->mpoly[lt->poly];
-		if (mp->totloop == 4) {
-			return 4;
-		}
-	}
-	return 3;
-#else
-	UNUSED_VARS(pContext, face_num);
-	return 3;
-#endif
-}
-
-static void dm_ts_GetPosition(
-        const SMikkTSpaceContext *pContext, float r_co[3],
-        const int face_num, const int vert_index)
-{
-	//assert(vert_index >= 0 && vert_index < 4);
-	SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
-	const MLoopTri *lt;
-	int loop_index;
-	const float *co;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	if (pMesh->face_as_quad_map) {
-		lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
-		const MPoly *mp = &pMesh->mpoly[lt->poly];
-		if (mp->totloop == 4) {
-			loop_index = mp->loopstart + vert_index;
-			goto finally;
-		}
-		/* fall through to regular triangle */
-	}
-	else {
-		lt = &pMesh->looptri[face_num];
-	}
-#else
-	lt = &pMesh->looptri[face_num];
-#endif
-	loop_index = lt->tri[vert_index];
-
-finally:
-	co = pMesh->mvert[pMesh->mloop[loop_index].v].co;
-	copy_v3_v3(r_co, co);
-}
-
-static void dm_ts_GetTextureCoordinate(
-        const SMikkTSpaceContext *pContext, float r_uv[2],
-        const int face_num, const int vert_index)
-{
-	//assert(vert_index >= 0 && vert_index < 4);
-	SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
-	const MLoopTri *lt;
-	int loop_index;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	if (pMesh->face_as_quad_map) {
-		lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
-		const MPoly *mp = &pMesh->mpoly[lt->poly];
-		if (mp->totloop == 4) {
-			loop_index = mp->loopstart + vert_index;
-			goto finally;
-		}
-		/* fall through to regular triangle */
-	}
-	else {
-		lt = &pMesh->looptri[face_num];
-	}
-#else
-	lt = &pMesh->looptri[face_num];
-#endif
-	loop_index = lt->tri[vert_index];
-
-finally:
-	if (pMesh->mloopuv != NULL) {
-		const float *uv = pMesh->mloopuv[loop_index].uv;
-		copy_v2_v2(r_uv, uv);
-	}
-	else {
-		const float *orco = pMesh->orco[pMesh->mloop[loop_index].v];
-		map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
-	}
-}
-
-static void dm_ts_GetNormal(
-        const SMikkTSpaceContext *pContext, float r_no[3],
-        const int face_num, const int vert_index)
-{
-	//assert(vert_index >= 0 && vert_index < 4);
-	SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
-	const MLoopTri *lt;
-	int loop_index;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-	if (pMesh->face_as_quad_map) {
-		lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
-		const MPoly *mp = &pMesh->mpoly[lt->poly];
-		if (mp->totloop == 4) {
-			loop_index = mp->loopstart + vert_index;
-			goto finally;
-		}
-		/* fall through to regular triangle */
-	}
-	else {
-		lt = &pMesh->looptri[face_num];
-	}
-#else
-	lt = &pMesh->looptri[fac

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list