Cycles: De-duplicate trace-time object visibility calculation
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 10 Aug 2017 07:19:40 +0000 (09:19 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 10 Aug 2017 07:21:02 +0000 (09:21 +0200)
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.

intern/cycles/bvh/bvh.cpp
intern/cycles/bvh/bvh2.cpp
intern/cycles/bvh/bvh4.cpp
intern/cycles/render/object.cpp
intern/cycles/render/object.h

index c7e11539cf9f9defbe78ac65b52aab733d7aa3e7..0ad3c8a74290858b625e5dc39efd35d971897d20 100644 (file)
@@ -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;
index 3e3a5d604d85d54af393966392027888d7e885c3..9aa8e71dfd0db65ec257df75003a8ea7361e3303 100644 (file)
@@ -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);
index 0e460db7ed77124e260dc4a8ca1107254c08d915..aeedd802f497762e3112b1f6171ae44f43d6bdea 100644 (file)
@@ -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.
index 375abfeb27a7a9a08549b0d3ff56c0ec4d5c2d72..b00e5624266ec848565c6dbeea159a906a7814ce 100644 (file)
@@ -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()
index 12d7b2c81cfe58b37e43910bc23c7b9e2c5b7fe7..6927bbfe4c7f4a1662f63954f47f9edab999b825 100644 (file)
@@ -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 */