diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2017-07-04 16:03:04 +0300 |
---|---|---|
committer | Alexander Romanov <a.romanov@blend4web.com> | 2017-07-04 16:25:49 +0300 |
commit | 0ef48ad504350b934af42ddf47f73c9e096ce846 (patch) | |
tree | 640ac747907c1e9117938f2c39799ae66174ddc0 /source | |
parent | f23ed929ee021e11e8d47973d25f9039e9f91c17 (diff) |
One more fix for merged 'normal map tangents not working correctly when there are no UV maps.'
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/editmesh_tangent.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_tangent.c | 6 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 26 |
3 files changed, 26 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c index 314c50d42c6..589c346b248 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.c +++ b/source/blender/blenkernel/intern/editmesh_tangent.c @@ -287,8 +287,6 @@ void BKE_editmesh_loop_tangent_calc( { BMesh *bm = em->bm; - BLI_assert(CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV) != 0); - int act_uv_n = -1; int ren_uv_n = -1; bool calc_act = false; @@ -374,7 +372,7 @@ void BKE_editmesh_loop_tangent_calc( continue; /* needed for orco lookups */ htype_index |= BM_VERT; - *tangent_mask_curr_p |= DM_TANGENT_MASK_ORCO; + tangent_mask_curr |= DM_TANGENT_MASK_ORCO; } else { /* Fill the resulting tangent_mask */ @@ -382,7 +380,7 @@ void BKE_editmesh_loop_tangent_calc( int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV); BLI_assert(uv_ind != -1 && uv_start != -1); BLI_assert(uv_ind - uv_start < MAX_MTFACE); - *tangent_mask_curr_p |= 1 << (uv_ind - uv_start); + tangent_mask_curr |= 1 << (uv_ind - uv_start); } if (mesh2tangent->precomputedFaceNormals) { /* needed for face normal lookups */ diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c index 294ed604885..d370e202134 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.c +++ b/source/blender/blenkernel/intern/mesh_tangent.c @@ -573,7 +573,7 @@ void BKE_mesh_calc_loop_tangent_ex( if (tangent_names[i][0]) BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, tangent_names[i]); if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(loopdata, CD_TANGENT, "") == -1) - CustomData_add_layer_named(loopdata, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, ""); + CustomData_add_layer_named(loopdata_out, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, ""); if (calc_act && act_uv_name[0]) BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, act_uv_name); if (calc_ren && ren_uv_name[0]) @@ -642,14 +642,14 @@ void BKE_mesh_calc_loop_tangent_ex( if (!mesh2tangent->orco) continue; - *tangent_mask_curr_p |= DM_TANGENT_MASK_ORCO; + tangent_mask_curr |= DM_TANGENT_MASK_ORCO; } else { int uv_ind = CustomData_get_named_layer_index(loopdata, CD_MLOOPUV, loopdata->layers[index].name); int uv_start = CustomData_get_layer_index(loopdata, CD_MLOOPUV); BLI_assert(uv_ind != -1 && uv_start != -1); BLI_assert(uv_ind - uv_start < MAX_MTFACE); - *tangent_mask_curr_p |= (short)(1 << (uv_ind - uv_start)); + tangent_mask_curr |= (short)(1 << (uv_ind - uv_start)); } mesh2tangent->tangent = loopdata_out->layers[index].data; diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index b8875ec79fd..495e72fc9ac 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -241,7 +241,7 @@ static bool bm_edge_has_visible_face(const BMEdge *e) static void mesh_cd_calc_used_gpu_layers( CustomData *UNUSED(cd_vdata), uchar cd_vused[CD_NUMTYPES], - CustomData *cd_ldata, uchar cd_lused[CD_NUMTYPES], + CustomData *cd_ldata, ushort cd_lused[CD_NUMTYPES], struct GPUMaterial **gpumat_array, int gpumat_array_len) { /* See: DM_vertex_attributes_from_gpu for similar logic */ @@ -308,6 +308,11 @@ static void mesh_cd_calc_used_gpu_layers( if (layer != -1) { cd_lused[CD_TANGENT] |= (1 << layer); } + else { + /* no UV layers at all => requesting orco */ + cd_lused[CD_TANGENT] |= DM_TANGENT_MASK_ORCO; + cd_vused[CD_ORCO] |= 1; + } break; } case CD_MCOL: @@ -477,7 +482,7 @@ static MeshRenderData *mesh_render_data_create_ex( /* Add edge/poly if we need them */ uchar cd_vused[CD_NUMTYPES] = {0}; - uchar cd_lused[CD_NUMTYPES] = {0}; + ushort cd_lused[CD_NUMTYPES] = {0}; mesh_cd_calc_used_gpu_layers( cd_vdata, cd_vused, @@ -647,6 +652,9 @@ 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; if (rdata->edit_bmesh) { BMEditMesh *em = rdata->edit_bmesh; BMesh *bm = em->bm; @@ -661,7 +669,7 @@ static MeshRenderData *mesh_render_data_create_ex( BKE_editmesh_loop_tangent_calc( em, calc_active_tangent, - tangent_names, rdata->cd.layers.tangent_len, + tangent_names, actual_tangent_len, poly_normals, loop_normals, rdata->orco, &rdata->cd.output.ldata, bm->totloop, @@ -687,7 +695,7 @@ static MeshRenderData *mesh_render_data_create_ex( rdata->mlooptri, rdata->tri_len, cd_ldata, calc_active_tangent, - tangent_names, rdata->cd.layers.tangent_len, + tangent_names, actual_tangent_len, poly_normals, loop_normals, rdata->orco, &rdata->cd.output.ldata, me->totloop, @@ -708,7 +716,8 @@ static MeshRenderData *mesh_render_data_create_ex( BLI_assert(CustomData_number_of_layers(&rdata->cd.output.ldata, CD_TANGENT) == rdata->cd.layers.tangent_len); - for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) { + int i_dst = 0; + for (int i_src = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) { if ((cd_lused[CD_TANGENT] & (1 << i_src)) == 0) { i_dst--; if (rdata->cd.layers.tangent_active >= i_src) { @@ -733,6 +742,13 @@ static MeshRenderData *mesh_render_data_create_ex( } } } + if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) { + const char *name = CustomData_get_layer_name(&rdata->cd.output.ldata, CD_TANGENT, i_dst); + unsigned int hash = BLI_ghashutil_strhash_p(name); + BLI_snprintf(rdata->cd.uuid.tangent[i_dst], sizeof(*rdata->cd.uuid.tangent), "t%u", hash); + + rdata->cd.layers.tangent[i_dst] = CustomData_get_layer_n(&rdata->cd.output.ldata, CD_TANGENT, i_dst); + } } #undef me |