Normal map node with named UV map crashes material preview #56545

Closed
opened 2018-08-26 06:13:26 +02:00 by Jason Clarke · 29 comments

System Information
Windows 10, Nvidia GTX 980

Blender Version
Broken: 2.80 b30d103cf6

Short description of error
If you use the normal map node in tangent space mode, you have an option to set a UV map to determine the tangent space. If you do this with Eevee, the material preview will crash.

Exact steps for others to reproduce the error

  • Unwrap an object, give the UV set a name other than the default "UVMap"
  • Add a material with nodes, plug in a normal map node.
  • In the tangent map selector on the normal map node, select the UV map from step 1.
  • Attempt to open the Eevee material preview. Blender will crash.

.blend file here, material preview will crash. Remove the normal map node or clear the UV map selection on the normal map node, no crash. nrm_crash.blend

**System Information** Windows 10, Nvidia GTX 980 **Blender Version** Broken: 2.80 b30d103cf63 **Short description of error** If you use the normal map node in tangent space mode, you have an option to set a UV map to determine the tangent space. If you do this with Eevee, the material preview will crash. **Exact steps for others to reproduce the error** - Unwrap an object, give the UV set a name other than the default "UVMap" - Add a material with nodes, plug in a normal map node. - In the tangent map selector on the normal map node, select the UV map from step 1. - Attempt to open the Eevee material preview. Blender will crash. .blend file here, material preview will crash. Remove the normal map node or clear the UV map selection on the normal map node, no crash. [nrm_crash.blend](https://archive.blender.org/developer/F4391355/nrm_crash.blend)
Author

Added subscriber: @JasonClarke

Added subscriber: @JasonClarke

#58576 was marked as duplicate of this issue

#58576 was marked as duplicate of this issue

#59132 was marked as duplicate of this issue

#59132 was marked as duplicate of this issue

#58722 was marked as duplicate of this issue

#58722 was marked as duplicate of this issue

#60071 was marked as duplicate of this issue

#60071 was marked as duplicate of this issue

#59993 was marked as duplicate of this issue

#59993 was marked as duplicate of this issue

#57664 was marked as duplicate of this issue

#57664 was marked as duplicate of this issue

#58131 was marked as duplicate of this issue

#58131 was marked as duplicate of this issue

Added subscribers: @fclem, @mont29

Added subscribers: @fclem, @mont29
Clément Foucault was assigned by Bastien Montagne 2018-08-26 11:26:07 +02:00
BLI_assert failed: /home/i74700deb64/blender/__work__/src/source/blender/draw/intern/draw_cache_impl_mesh.c:781, mesh_render_data_create_ex(), at 'CustomData_number_of_layers(&rdata->cd.output.ldata, CD_TANGENT) == rdata->cd.layers.tangent_len'

Confirmed, @fclem something very weird in that code, doing nasty black magic and dramatically failing… :/

``` BLI_assert failed: /home/i74700deb64/blender/__work__/src/source/blender/draw/intern/draw_cache_impl_mesh.c:781, mesh_render_data_create_ex(), at 'CustomData_number_of_layers(&rdata->cd.output.ldata, CD_TANGENT) == rdata->cd.layers.tangent_len' ``` Confirmed, @fclem something very weird in that code, doing nasty black magic and dramatically failing… :/
Clément Foucault removed their assignment 2018-09-11 18:00:44 +02:00
Campbell Barton was assigned by Clément Foucault 2018-09-11 18:00:44 +02:00

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Well that's @ideasman42 code so I would look at it only if he cannot fix it easily because it is indeed black magic to me.

That's strange because if does not crash for a mesh that does not have the said UVs.

Well that's @ideasman42 code so I would look at it only if he cannot fix it easily because it is indeed black magic to me. That's strange because if does not crash for a mesh that does not have the said UVs.
Member

Added subscribers: @fjg3d, @lichtwerk, @TakeshiFunahashi

Added subscribers: @fjg3d, @lichtwerk, @TakeshiFunahashi
Member

Added subscribers: @JulienDuroure, @mikhluz

Added subscribers: @JulienDuroure, @mikhluz

With recent build version: 2.80 (sub 35), branch: blender2.8, commit date: 2018-12-08 17:06, hash: e79bb957fc, type:
build date: 2018/12/09, 17:21

this problem seems solved, have someone tested again?
Though I still often see crush with some scene, it seems not matter about this normal map node problem I think.

With recent build version: 2.80 (sub 35), branch: blender2.8, commit date: 2018-12-08 17:06, hash: e79bb957fc3, type: build date: 2018/12/09, 17:21 this problem seems solved, have someone tested again? Though I still often see crush with some scene, it seems not matter about this normal map node problem I think.

NO! sorry it worked about my scene files,, but downloaded file still cause crush when select material.

NO! sorry it worked about my scene files,, but downloaded file still cause crush when select material.

Added subscribers: @gdube, @capnm, @ZedDB

Added subscribers: @gdube, @capnm, @ZedDB
Member

Added subscriber: @Poulpator

Added subscriber: @Poulpator

Added subscriber: @artutava

Added subscriber: @artutava

Same thing happening here, with latest build. More specifically when you enable option "tangent space" under normal map node.

Same thing happening here, with latest build. More specifically when you enable option "tangent space" under normal map node.
Member

Added subscriber: @mhcall

Added subscriber: @mhcall
Member

Added subscriber: @Magister

Added subscriber: @Magister
Member

Added subscribers: @Noah-Catan, @JacquesLucke, @Sergey

Added subscribers: @Noah-Catan, @JacquesLucke, @Sergey
Member

This is being reported quite often now, so I'll poke @ideasman42 again to share his wisdom (or put on someone elses desk...) and set on High priority...

This is being reported quite often now, so I'll poke @ideasman42 again to share his wisdom (or put on someone elses desk...) and set on High priority...

Added subscriber: @mano-wii

Added subscriber: @mano-wii

This seems to fix the problem:

diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 9d9f7c47b14..c737c44dee5 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -440,7 +440,6 @@ static void mesh_cd_calc_used_gpu_layers(
 						}
 						else {
 							/* no UV layers at all => requesting orco */
-							cd_lused[CD_TANGENT] |= DM_TANGENT_MASK_ORCO;
 							cd_vused[CD_ORCO] |= 1;
 						}
 						break;
@@ -969,8 +968,7 @@ static MeshRenderData *mesh_render_data_create_ex(
 			}
 
 			/* If tangent from orco is requested, decrement tangent_len */
-			int actual_tangent_len = (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) ?
-			        rdata->cd.layers.tangent_len - 1 : rdata->cd.layers.tangent_len;
+			int actual_tangent_len = rdata->cd.layers.tangent_len;
 			if (rdata->edit_bmesh) {
 				BMEditMesh *em = rdata->edit_bmesh;
 				BMesh *bm = em->bm;
@@ -1056,7 +1054,7 @@ static MeshRenderData *mesh_render_data_create_ex(
 					}
 				}
 			}
-			if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) {
+			if (cd_vused[CD_ORCO]) {
 				const char *name = CustomData_get_layer_name(&rdata->cd.output.ldata, CD_TANGENT, i_dst);
 				uint hash = BLI_ghashutil_strhash_p(name);
 				BLI_snprintf(rdata->cd.uuid.tangent[i_dst], sizeof(*rdata->cd.uuid.tangent), "t%u", hash);

But it's an obscure area for me and I don't quite understand what I did.

This seems to fix the problem: ``` diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 9d9f7c47b14..c737c44dee5 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -440,7 +440,6 @@ static void mesh_cd_calc_used_gpu_layers( } else { /* no UV layers at all => requesting orco */ - cd_lused[CD_TANGENT] |= DM_TANGENT_MASK_ORCO; cd_vused[CD_ORCO] |= 1; } break; @@ -969,8 +968,7 @@ static MeshRenderData *mesh_render_data_create_ex( } /* If tangent from orco is requested, decrement tangent_len */ - int actual_tangent_len = (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) ? - rdata->cd.layers.tangent_len - 1 : rdata->cd.layers.tangent_len; + int actual_tangent_len = rdata->cd.layers.tangent_len; if (rdata->edit_bmesh) { BMEditMesh *em = rdata->edit_bmesh; BMesh *bm = em->bm; @@ -1056,7 +1054,7 @@ static MeshRenderData *mesh_render_data_create_ex( } } } - if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) { + if (cd_vused[CD_ORCO]) { const char *name = CustomData_get_layer_name(&rdata->cd.output.ldata, CD_TANGENT, i_dst); uint hash = BLI_ghashutil_strhash_p(name); BLI_snprintf(rdata->cd.uuid.tangent[i_dst], sizeof(*rdata->cd.uuid.tangent), "t%u", hash); ``` But it's an obscure area for me and I don't quite understand what I did.

@mano-wii, thanks for looking into this, but we want to keep tangent from orco when there are no UV layers.

Looked into this, here are possible solutions.

diff --git a/source/blender/blenkernel/BKE_editmesh_tangent.h b/source/blender/blenkernel/BKE_editmesh_tangent.h
index 9553fbc1a5c..c9c962cad67 100644
--- a/source/blender/blenkernel/BKE_editmesh_tangent.h
+++ b/source/blender/blenkernel/BKE_editmesh_tangent.h
@@ -28,7 +28,8 @@
  */
 
 void BKE_editmesh_loop_tangent_calc(
-        BMEditMesh *em, bool calc_active_tangent,
+        BMEditMesh *em,
+        bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[MAX_NAME], int tangent_names_len,
         const float (*poly_normals)[3],
         const float (*loop_normals)[3],
diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h
index 62d8f3ada84..8367b3a88fe 100644
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -39,7 +39,7 @@ void BKE_mesh_calc_loop_tangent_ex(
         const struct MLoopTri *looptri, const uint looptri_len,
 
         struct CustomData *loopdata,
-        bool calc_active_tangent,
+        bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[64], int tangent_names_len,
         const float (*poly_normals)[3],
         const float (*loop_normals)[3],
@@ -50,7 +50,8 @@ void BKE_mesh_calc_loop_tangent_ex(
         short *tangent_mask_curr_p);
 
 void BKE_mesh_calc_loop_tangents(
-        struct Mesh *me_eval, bool calc_active_tangent,
+        struct Mesh *me_eval,
+        bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[MAX_NAME], int tangent_names_len);
 
 /* Helpers */
@@ -60,7 +61,8 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv(
 
 #define DM_TANGENT_MASK_ORCO (1 << 9)
 void BKE_mesh_calc_loop_tangent_step_0(
-        const struct CustomData *loopData, bool calc_active_tangent,
+        const struct CustomData *loopData,
+        bool calc_active_tangent, bool calc_orco_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, short *rtangent_mask);
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index b2fe4ff742e..0b19d5bc4a0 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2556,7 +2556,7 @@ void DM_calc_loop_tangents(
 	        dm->getLoopArray(dm),
 	        dm->getLoopTriArray(dm), dm->getNumLoopTri(dm),
 	        &dm->loopData,
-	        calc_active_tangent,
+	        calc_active_tangent, false,
 	        tangent_names, tangent_names_len,
 	        CustomData_get_layer(&dm->polyData, CD_NORMAL),
 	        dm->getLoopDataArray(dm, CD_NORMAL),
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c
index 4231ad54ea8..b263a1df032 100644
--- a/source/blender/blenkernel/intern/editmesh_tangent.c
+++ b/source/blender/blenkernel/intern/editmesh_tangent.c
@@ -277,7 +277,8 @@ static void emDM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), v
  * This is done because #CD_TANGENT is cache data used only for drawing.
  */
 void BKE_editmesh_loop_tangent_calc(
-        BMEditMesh *em, bool calc_active_tangent,
+        BMEditMesh *em,
+        bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[MAX_NAME], int tangent_names_len,
         const float (*poly_normals)[3],
         const float (*loop_normals)[3],
@@ -299,7 +300,8 @@ void BKE_editmesh_loop_tangent_calc(
 	short tangent_mask_curr = *tangent_mask_curr_p;
 
 	BKE_mesh_calc_loop_tangent_step_0(
-	        &bm->ldata, calc_active_tangent, tangent_names, tangent_names_len,
+	        &bm->ldata, calc_active_tangent, calc_orco_tangent,
+	        tangent_names, tangent_names_len,
 	        &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
 
 	if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) {
diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c
index a222c681a5e..39fd6575ad0 100644
--- a/source/blender/blenkernel/intern/mesh_tangent.c
+++ b/source/blender/blenkernel/intern/mesh_tangent.c
@@ -473,7 +473,8 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv(
  * If tangent_mask has changed, then recalculate tangents.
  */
 void BKE_mesh_calc_loop_tangent_step_0(
-        const CustomData *loopData, bool calc_active_tangent,
+        const CustomData *loopData,
+        bool calc_active_tangent, bool calc_orco_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, short *rtangent_mask)
@@ -532,8 +533,9 @@ void BKE_mesh_calc_loop_tangent_step_0(
 			*rtangent_mask |= (short)(1 << n);
 	}
 
-	if (uv_layer_num == 0)
+	if (calc_orco_tangent || uv_layer_num == 0) {
 		*rtangent_mask |= DM_TANGENT_MASK_ORCO;
+	}
 }
 
 /**
@@ -547,7 +549,7 @@ void BKE_mesh_calc_loop_tangent_ex(
         const uint looptri_len,
 
         CustomData *loopdata,
-        bool calc_active_tangent,
+        bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[MAX_NAME], int tangent_names_len,
         const float (*poly_normals)[3],
         const float (*loop_normals)[3],
@@ -567,7 +569,7 @@ void BKE_mesh_calc_loop_tangent_ex(
 	short tangent_mask_curr = *tangent_mask_curr_p;
 
 	BKE_mesh_calc_loop_tangent_step_0(
-	        loopdata, calc_active_tangent, tangent_names, tangent_names_len,
+	        loopdata, calc_active_tangent, calc_orco_tangent, tangent_names, tangent_names_len,
 	        &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
 	if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) {
 		/* Check we have all the needed layers */
@@ -693,7 +695,7 @@ void BKE_mesh_calc_loop_tangent_ex(
 }
 
 void BKE_mesh_calc_loop_tangents(
-        Mesh *me_eval, bool calc_active_tangent,
+        Mesh *me_eval, bool calc_active_tangent, bool calc_orco_tangent,
         const char (*tangent_names)[MAX_NAME], int tangent_names_len)
 {
 	BKE_mesh_runtime_looptri_ensure(me_eval);
@@ -706,7 +708,7 @@ void BKE_mesh_calc_loop_tangents(
 	        me_eval->mloop,
 	        me_eval->runtime.looptris.array, (uint)me_eval->runtime.looptris.len,
 	        &me_eval->ldata,
-	        calc_active_tangent,
+	        calc_active_tangent, calc_orco_tangent,
 	        tangent_names, tangent_names_len,
 	        CustomData_get_layer(&me_eval->pdata, CD_NORMAL),
 	        CustomData_get_layer(&me_eval->ldata, CD_NORMAL),
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 9d9f7c47b14..e651721d591 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -969,8 +969,15 @@ static MeshRenderData *mesh_render_data_create_ex(
 			}
 
 			/* If tangent from orco is requested, decrement tangent_len */
-			int actual_tangent_len = (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) ?
-			        rdata->cd.layers.tangent_len - 1 : rdata->cd.layers.tangent_len;
+
+			int actual_tangent_len = rdata->cd.layers.tangent_len;
+			bool calc_orco_tangent = false;
+
+			if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) {
+				actual_tangent_len -= 1;
+				calc_orco_tangent = true;
+			}
+
 			if (rdata->edit_bmesh) {
 				BMEditMesh *em = rdata->edit_bmesh;
 				BMesh *bm = em->bm;
@@ -985,7 +992,8 @@ static MeshRenderData *mesh_render_data_create_ex(
 				bool calc_active_tangent = false;
 
 				BKE_editmesh_loop_tangent_calc(
-				        em, calc_active_tangent,
+				        em,
+				        calc_active_tangent, calc_orco_tangent,
 				        tangent_names, actual_tangent_len,
 				        rdata->poly_normals, rdata->loop_normals,
 				        rdata->orco,
@@ -1008,7 +1016,7 @@ static MeshRenderData *mesh_render_data_create_ex(
 				        me->mloop,
 				        rdata->mlooptri, rdata->tri_len,
 				        cd_ldata,
-				        calc_active_tangent,
+				        calc_active_tangent, calc_orco_tangent,
 				        tangent_names, actual_tangent_len,
 				        rdata->poly_normals, rdata->loop_normals,
 				        rdata->orco,
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index 6aa888d9f90..6f62ef3aa63 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -420,7 +420,7 @@ static TriTessFace *mesh_calc_tri_tessface(
 
 	if (tangent) {
 		BKE_mesh_ensure_normals_for_display(me_eval);
-		BKE_mesh_calc_loop_tangents(me_eval, true, NULL, 0);
+		BKE_mesh_calc_loop_tangents(me_eval, true, false, NULL, 0);
 
 		tspace = CustomData_get_layer(&me_eval->ldata, CD_TANGENT);
 		BLI_assert(tspace);

diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 9d9f7c47b14..fd9c44431b7 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -434,6 +434,11 @@ static void mesh_cd_calc_used_gpu_layers(
 							layer = (name- [x] != '\0') ?
 							        CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
 							        CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
+
+							/* Only fallback to orco (below) when we have no UV layers, see: #56545 */
+							if (layer == -1 && name- [x] != '\0') {
+								layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
+							}
 						}
 						if (layer != -1) {
 							cd_lused[CD_TANGENT] |= (1 << layer);

  • uses the active uv layer for tangents when the requested UV layer isn't available.

I'll commit P887, since this is keeps 2.7x logic where we only use tangents from orcos when there are no UV layers. This is simpler and doesn't add even more options to tangent calculation just to support an error case.

@mano-wii, thanks for looking into this, but we want to keep tangent from orco when there are no UV layers. Looked into this, here are possible solutions. - [P886: Fix #56545 (ensure tangents from orcos)](https://archive.blender.org/developer/P886.txt) ``` diff --git a/source/blender/blenkernel/BKE_editmesh_tangent.h b/source/blender/blenkernel/BKE_editmesh_tangent.h index 9553fbc1a5c..c9c962cad67 100644 --- a/source/blender/blenkernel/BKE_editmesh_tangent.h +++ b/source/blender/blenkernel/BKE_editmesh_tangent.h @@ -28,7 +28,8 @@ */ void BKE_editmesh_loop_tangent_calc( - BMEditMesh *em, bool calc_active_tangent, + BMEditMesh *em, + bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len, const float (*poly_normals)[3], const float (*loop_normals)[3], diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h index 62d8f3ada84..8367b3a88fe 100644 --- a/source/blender/blenkernel/BKE_mesh_tangent.h +++ b/source/blender/blenkernel/BKE_mesh_tangent.h @@ -39,7 +39,7 @@ void BKE_mesh_calc_loop_tangent_ex( const struct MLoopTri *looptri, const uint looptri_len, struct CustomData *loopdata, - bool calc_active_tangent, + bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[64], int tangent_names_len, const float (*poly_normals)[3], const float (*loop_normals)[3], @@ -50,7 +50,8 @@ void BKE_mesh_calc_loop_tangent_ex( short *tangent_mask_curr_p); void BKE_mesh_calc_loop_tangents( - struct Mesh *me_eval, bool calc_active_tangent, + struct Mesh *me_eval, + bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len); /* Helpers */ @@ -60,7 +61,8 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv( #define DM_TANGENT_MASK_ORCO (1 << 9) void BKE_mesh_calc_loop_tangent_step_0( - const struct CustomData *loopData, bool calc_active_tangent, + const struct CustomData *loopData, + bool calc_active_tangent, bool calc_orco_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, short *rtangent_mask); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index b2fe4ff742e..0b19d5bc4a0 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2556,7 +2556,7 @@ void DM_calc_loop_tangents( dm->getLoopArray(dm), dm->getLoopTriArray(dm), dm->getNumLoopTri(dm), &dm->loopData, - calc_active_tangent, + calc_active_tangent, false, tangent_names, tangent_names_len, CustomData_get_layer(&dm->polyData, CD_NORMAL), dm->getLoopDataArray(dm, CD_NORMAL), diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c index 4231ad54ea8..b263a1df032 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.c +++ b/source/blender/blenkernel/intern/editmesh_tangent.c @@ -277,7 +277,8 @@ static void emDM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), v * This is done because #CD_TANGENT is cache data used only for drawing. */ void BKE_editmesh_loop_tangent_calc( - BMEditMesh *em, bool calc_active_tangent, + BMEditMesh *em, + bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len, const float (*poly_normals)[3], const float (*loop_normals)[3], @@ -299,7 +300,8 @@ void BKE_editmesh_loop_tangent_calc( short tangent_mask_curr = *tangent_mask_curr_p; BKE_mesh_calc_loop_tangent_step_0( - &bm->ldata, calc_active_tangent, tangent_names, tangent_names_len, + &bm->ldata, calc_active_tangent, calc_orco_tangent, + tangent_names, tangent_names_len, &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask); if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) { diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c index a222c681a5e..39fd6575ad0 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.c +++ b/source/blender/blenkernel/intern/mesh_tangent.c @@ -473,7 +473,8 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv( * If tangent_mask has changed, then recalculate tangents. */ void BKE_mesh_calc_loop_tangent_step_0( - const CustomData *loopData, bool calc_active_tangent, + const CustomData *loopData, + bool calc_active_tangent, bool calc_orco_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, short *rtangent_mask) @@ -532,8 +533,9 @@ void BKE_mesh_calc_loop_tangent_step_0( *rtangent_mask |= (short)(1 << n); } - if (uv_layer_num == 0) + if (calc_orco_tangent || uv_layer_num == 0) { *rtangent_mask |= DM_TANGENT_MASK_ORCO; + } } /** @@ -547,7 +549,7 @@ void BKE_mesh_calc_loop_tangent_ex( const uint looptri_len, CustomData *loopdata, - bool calc_active_tangent, + bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len, const float (*poly_normals)[3], const float (*loop_normals)[3], @@ -567,7 +569,7 @@ void BKE_mesh_calc_loop_tangent_ex( short tangent_mask_curr = *tangent_mask_curr_p; BKE_mesh_calc_loop_tangent_step_0( - loopdata, calc_active_tangent, tangent_names, tangent_names_len, + loopdata, calc_active_tangent, calc_orco_tangent, tangent_names, tangent_names_len, &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask); if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) { /* Check we have all the needed layers */ @@ -693,7 +695,7 @@ void BKE_mesh_calc_loop_tangent_ex( } void BKE_mesh_calc_loop_tangents( - Mesh *me_eval, bool calc_active_tangent, + Mesh *me_eval, bool calc_active_tangent, bool calc_orco_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len) { BKE_mesh_runtime_looptri_ensure(me_eval); @@ -706,7 +708,7 @@ void BKE_mesh_calc_loop_tangents( me_eval->mloop, me_eval->runtime.looptris.array, (uint)me_eval->runtime.looptris.len, &me_eval->ldata, - calc_active_tangent, + calc_active_tangent, calc_orco_tangent, tangent_names, tangent_names_len, CustomData_get_layer(&me_eval->pdata, CD_NORMAL), CustomData_get_layer(&me_eval->ldata, CD_NORMAL), diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 9d9f7c47b14..e651721d591 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -969,8 +969,15 @@ static MeshRenderData *mesh_render_data_create_ex( } /* If tangent from orco is requested, decrement tangent_len */ - int actual_tangent_len = (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) ? - rdata->cd.layers.tangent_len - 1 : rdata->cd.layers.tangent_len; + + int actual_tangent_len = rdata->cd.layers.tangent_len; + bool calc_orco_tangent = false; + + if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) { + actual_tangent_len -= 1; + calc_orco_tangent = true; + } + if (rdata->edit_bmesh) { BMEditMesh *em = rdata->edit_bmesh; BMesh *bm = em->bm; @@ -985,7 +992,8 @@ static MeshRenderData *mesh_render_data_create_ex( bool calc_active_tangent = false; BKE_editmesh_loop_tangent_calc( - em, calc_active_tangent, + em, + calc_active_tangent, calc_orco_tangent, tangent_names, actual_tangent_len, rdata->poly_normals, rdata->loop_normals, rdata->orco, @@ -1008,7 +1016,7 @@ static MeshRenderData *mesh_render_data_create_ex( me->mloop, rdata->mlooptri, rdata->tri_len, cd_ldata, - calc_active_tangent, + calc_active_tangent, calc_orco_tangent, tangent_names, actual_tangent_len, rdata->poly_normals, rdata->loop_normals, rdata->orco, diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index 6aa888d9f90..6f62ef3aa63 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -420,7 +420,7 @@ static TriTessFace *mesh_calc_tri_tessface( if (tangent) { BKE_mesh_ensure_normals_for_display(me_eval); - BKE_mesh_calc_loop_tangents(me_eval, true, NULL, 0); + BKE_mesh_calc_loop_tangents(me_eval, true, false, NULL, 0); tspace = CustomData_get_layer(&me_eval->ldata, CD_TANGENT); BLI_assert(tspace); ``` - ensures tangent orcos are calculated. - [P887: Fix #56545 (fallback to active UV layer)](https://archive.blender.org/developer/P887.txt) ``` diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 9d9f7c47b14..fd9c44431b7 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -434,6 +434,11 @@ static void mesh_cd_calc_used_gpu_layers( layer = (name- [x] != '\0') ? CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) : CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); + + /* Only fallback to orco (below) when we have no UV layers, see: #56545 */ + if (layer == -1 && name- [x] != '\0') { + layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); + } } if (layer != -1) { cd_lused[CD_TANGENT] |= (1 << layer); ``` - uses the active uv layer for tangents when the requested UV layer isn't available. I'll commit [P887](https://archive.blender.org/developer/P887.txt), since this is keeps 2.7x logic where we only use tangents from orcos when there are no UV layers. This is simpler and doesn't add even more options to tangent calculation just to support an error case.

This issue was referenced by 369e1d46f0

This issue was referenced by 369e1d46f0dbdd7904de7a5350ae7825800588df

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
10 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#56545
No description provided.