From cccc40db51a0b73d396952be65ef351a7c68ed4f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 6 Dec 2018 19:50:05 +0100 Subject: Fix T57963: Cycles crash using AO for displacement. Note this is not supported, there exists no geometry at this point, but it should not crash at least. --- intern/cycles/kernel/svm/svm_ao.h | 5 +++++ intern/cycles/kernel/svm/svm_bevel.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/intern/cycles/kernel/svm/svm_ao.h b/intern/cycles/kernel/svm/svm_ao.h index 0337c88a543..15d074780c4 100644 --- a/intern/cycles/kernel/svm/svm_ao.h +++ b/intern/cycles/kernel/svm/svm_ao.h @@ -33,6 +33,11 @@ ccl_device_noinline float svm_ao(KernelGlobals *kg, return 1.0f; } + /* Can't raytrace from shaders like displacement, before BVH exists. */ + if (kernel_data.bvh.bvh_layout == BVH_LAYOUT_NONE) { + return 1.0f; + } + if(flags & NODE_AO_INSIDE) { N = -N; } diff --git a/intern/cycles/kernel/svm/svm_bevel.h b/intern/cycles/kernel/svm/svm_bevel.h index 79d0fb6ddbe..96d132acd73 100644 --- a/intern/cycles/kernel/svm/svm_bevel.h +++ b/intern/cycles/kernel/svm/svm_bevel.h @@ -34,6 +34,11 @@ ccl_device_noinline float3 svm_bevel( return sd->N; } + /* Can't raytrace from shaders like displacement, before BVH exists. */ + if (kernel_data.bvh.bvh_layout == BVH_LAYOUT_NONE) { + return sd->N; + } + /* Don't bevel for blurry indirect rays. */ if(state->min_ray_pdf < 8.0f) { return sd->N; -- cgit v1.2.3 From 27e77d4f9c16b8b6c67d9275b9bc373357f713b0 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Dec 2018 00:02:56 +0100 Subject: Fix Alembic indexed UVs being merged for different vertices. Other software uses this to define UV islands, so we can't just merge any UVs with the same coordinate. They have to share a vertex too. Contributed by Maxime Robinot, with changes by me. Differential Revision: https://developer.blender.org/D4006 --- source/blender/alembic/intern/abc_customdata.cc | 69 +++++++++++-------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc index 424475dc61b..96685b6ac3a 100644 --- a/source/blender/alembic/intern/abc_customdata.cc +++ b/source/blender/alembic/intern/abc_customdata.cc @@ -52,29 +52,6 @@ using Alembic::Abc::V2fArraySample; using Alembic::AbcGeom::OV2fGeomParam; using Alembic::AbcGeom::OC4fGeomParam; - -typedef std::unordered_map uv_index_map; - -static inline uint64_t uv_to_hash_key(Imath::V2f v) -{ - /* Convert -0.0f to 0.0f, so bitwise comparison works. */ - if (v.x == 0.0f) { - v.x = 0.0f; - } - if (v.y == 0.0f) { - v.y = 0.0f; - } - - /* Pack floats in 64bit. */ - union { - float xy[2]; - uint64_t key; - } tmp; - tmp.xy[0] = v.x; - tmp.xy[1] = v.y; - return tmp.key; -} - static void get_uvs(const CDStreamConfig &config, std::vector &uvs, std::vector &uvidx, @@ -88,45 +65,59 @@ static void get_uvs(const CDStreamConfig &config, const int num_poly = config.totpoly; MPoly *polygons = config.mpoly; + MLoop *mloop = config.mloop; if (!config.pack_uvs) { int cnt = 0; uvidx.resize(config.totloop); uvs.resize(config.totloop); + /* Iterate in reverse order to match exported polygons. */ for (int i = 0; i < num_poly; ++i) { MPoly ¤t_poly = polygons[i]; - MLoopUV *loopuvpoly = mloopuv_array + current_poly.loopstart + current_poly.totloop; + MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; for (int j = 0; j < current_poly.totloop; ++j, ++cnt) { - --loopuvpoly; + --loopuv; uvidx[cnt] = cnt; - uvs[cnt][0] = loopuvpoly->uv[0]; - uvs[cnt][1] = loopuvpoly->uv[1]; + uvs[cnt][0] = loopuv->uv[0]; + uvs[cnt][1] = loopuv->uv[1]; } } } else { - uv_index_map idx_map; + /* Mapping for indexed UVs, deduplicating UV coordinates at vertices. */ + std::vector> idx_map(config.totvert); int idx_count = 0; for (int i = 0; i < num_poly; ++i) { MPoly ¤t_poly = polygons[i]; - MLoopUV *loopuvpoly = mloopuv_array + current_poly.loopstart + current_poly.totloop; + MLoop *looppoly = mloop + current_poly.loopstart + current_poly.totloop; + MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; for (int j = 0; j < current_poly.totloop; ++j) { - loopuvpoly--; - Imath::V2f uv(loopuvpoly->uv[0], loopuvpoly->uv[1]); - uint64_t k = uv_to_hash_key(uv); - uv_index_map::iterator it = idx_map.find(k); - if (it == idx_map.end()) { - idx_map[k] = idx_count; - uvs.push_back(uv); - uvidx.push_back(idx_count++); + --looppoly; + --loopuv; + + Imath::V2f uv(loopuv->uv[0], loopuv->uv[1]); + bool found_same = false; + + /* Find UV already in uvs array. */ + for (uint32_t uv_idx : idx_map[looppoly->v]) { + if (uvs[uv_idx] == uv) { + found_same = true; + uvidx.push_back(uv_idx); + break; + } } - else { - uvidx.push_back(it->second); + + /* UV doesn't exists for this vertex, add it. */ + if (!found_same) { + uint32_t uv_idx = idx_count++; + idx_map[looppoly->v].push_back(uv_idx); + uvidx.push_back(uv_idx); + uvs.push_back(uv); } } } -- cgit v1.2.3 From d6d76759f8493ca156c597840f9d41a64e326eba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 7 Dec 2018 15:40:38 +1100 Subject: Fix error in Main cleanup See 481cdb08ed6f3 --- source/blender/blenkernel/BKE_library.h | 6 ++++-- source/blender/windowmanager/intern/wm_files.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index c2b971a91cd..2ab9ac3ee58 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -174,8 +174,10 @@ struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data); void BKE_main_thumbnail_create(struct Main *bmain); -const char *BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL(); -const char *BKE_main_blendfile_path_from_global(void); +const char *BKE_main_blendfile_path(const struct Main *bmain) + ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; +const char *BKE_main_blendfile_path_from_global(void) + ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value); void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value); diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index effd1c89077..91b04c982fc 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -578,7 +578,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) Main *bmain = CTX_data_main(C); /* when loading startup.blend's, we can be left with a blank path */ - if (BKE_main_blendfile_path(bmain)) { + if (BKE_main_blendfile_path(bmain)[0] != '\0') { G.save_over = 1; } else { -- cgit v1.2.3