Commit: 5a618ab737225869555bb9782265a90f7ca2c373 Author: Sergey Sharybin Date: Thu Aug 10 09:19:40 2017 +0200 Branches: master https://developer.blender.org/rB5a618ab737225869555bb9782265a90f7ca2c373
Cycles: De-duplicate trace-time object visibility calculation We already have enough files to worry about in BVH builders. no need to add yet another copy-paste code which is tempting to be running out of sync. =================================================================== M intern/cycles/bvh/bvh.cpp M intern/cycles/bvh/bvh2.cpp M intern/cycles/bvh/bvh4.cpp M intern/cycles/render/object.cpp M intern/cycles/render/object.h =================================================================== diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index c7e11539cf9..0ad3c8a7429 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -153,7 +153,6 @@ void BVH::pack_primitives() if(pack.prim_index[i] != -1) { int tob = pack.prim_object[i]; Object *ob = objects[tob]; - if((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) { pack_triangle(i, (float4*)&pack.prim_tri_verts[3 * prim_triangle_index]); pack.prim_tri_index[i] = 3 * prim_triangle_index; @@ -162,15 +161,10 @@ void BVH::pack_primitives() else { pack.prim_tri_index[i] = -1; } - - pack.prim_visibility[i] = ob->visibility; - - if(pack.prim_type[i] & PRIMITIVE_ALL_CURVE) + pack.prim_visibility[i] = ob->visibility_for_tracing(); + if(pack.prim_type[i] & PRIMITIVE_ALL_CURVE) { pack.prim_visibility[i] |= PATH_RAY_CURVE; - if (ob->is_shadow_catcher) - pack.prim_visibility[i] &= ~PATH_RAY_SHADOW_NON_CATCHER; - else - pack.prim_visibility[i] &= ~PATH_RAY_SHADOW_CATCHER; + } } else { pack.prim_tri_index[i] = -1; diff --git a/intern/cycles/bvh/bvh2.cpp b/intern/cycles/bvh/bvh2.cpp index 3e3a5d604d8..9aa8e71dfd0 100644 --- a/intern/cycles/bvh/bvh2.cpp +++ b/intern/cycles/bvh/bvh2.cpp @@ -312,14 +312,8 @@ void BVH2::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility) } } } - - visibility |= ob->visibility; - if (ob->is_shadow_catcher) - visibility &= ~PATH_RAY_SHADOW_NON_CATCHER; - else - visibility &= ~PATH_RAY_SHADOW_CATCHER; + visibility |= ob->visibility_for_tracing(); } - /* TODO(sergey): De-duplicate with pack_leaf(). */ float4 leaf_data[BVH_NODE_LEAF_SIZE]; leaf_data[0].x = __int_as_float(c0); diff --git a/intern/cycles/bvh/bvh4.cpp b/intern/cycles/bvh/bvh4.cpp index 0e460db7ed7..aeedd802f49 100644 --- a/intern/cycles/bvh/bvh4.cpp +++ b/intern/cycles/bvh/bvh4.cpp @@ -438,14 +438,8 @@ void BVH4::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility) } } } - - visibility |= ob->visibility; - if (ob->is_shadow_catcher) - visibility &= ~PATH_RAY_SHADOW_NON_CATCHER; - else - visibility &= ~PATH_RAY_SHADOW_CATCHER; + visibility |= ob->visibility_for_tracing(); } - /* TODO(sergey): This is actually a copy of pack_leaf(), * but this chunk of code only knows actual data and has * no idea about BVHNode. diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 375abfeb27a..b00e5624266 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -262,6 +262,17 @@ bool Object::is_traceable() return true; } +uint Object::visibility_for_tracing() const { + uint trace_visibility = visibility; + if (is_shadow_catcher) { + trace_visibility &= ~PATH_RAY_SHADOW_NON_CATCHER; + } + else { + trace_visibility &= ~PATH_RAY_SHADOW_CATCHER; + } + return trace_visibility; +} + /* Object Manager */ ObjectManager::ObjectManager() diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index 12d7b2c81cf..6927bbfe4c7 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -60,7 +60,7 @@ public: ParticleSystem *particle_system; int particle_index; - + Object(); ~Object(); @@ -75,6 +75,11 @@ public: * kernel scene. */ bool is_traceable(); + + /* Combine object's visibility with all possible internal run-time + * determined flags which denotes trace-time visibility. + */ + uint visibility_for_tracing() const; }; /* Object Manager */ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs