Cycles: Ignore zero size instances in BVH
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 6 Jun 2016 07:15:34 +0000 (09:15 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 6 Jun 2016 07:23:53 +0000 (09:23 +0200)
In certain types of animation it's possible to have some objects
scaling to zero. In this case we can save render times by avoid
traversing such instances.

Better to do ti ahead of a time, so traversal stays simple.

Reviewers: lukasstockner97, dingto, brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D2048

intern/cycles/bvh/bvh_build.cpp
intern/cycles/render/object.cpp
intern/cycles/render/object.h

index 87a889955fe0ac9000b5a39eaf52a1b16a5deef7..d00de007b2d50b1c2c6a07c6700f7f36a31017c1 100644 (file)
@@ -205,6 +205,9 @@ void BVHBuild::add_references(BVHRange& root)
 
        foreach(Object *ob, objects) {
                if(params.top_level) {
+                       if(!ob->is_traceable()) {
+                               continue;
+                       }
                        if(!ob->mesh->is_instanced()) {
                                num_alloc_references += ob->mesh->num_triangles();
                                num_alloc_references += count_curve_segments(ob->mesh);
@@ -226,6 +229,9 @@ void BVHBuild::add_references(BVHRange& root)
 
        foreach(Object *ob, objects) {
                if(params.top_level) {
+                       if(!ob->is_traceable()) {
+                               continue;
+                       }
                        if(!ob->mesh->is_instanced())
                                add_reference_mesh(bounds, center, ob->mesh, i);
                        else
index 9ee1a9ef7a6612348519d89b6b462b29d8221672..644e581bf4b972a59d211ec4239b13d30ddecf18 100644 (file)
@@ -225,6 +225,16 @@ vector<float> Object::motion_times()
        return times;
 }
 
+bool Object::is_traceable()
+{
+       /* Mesh itself can be empty,can skip all such objects. */
+       if (bounds.size() == make_float3(0.0f, 0.0f, 0.0f)) {
+               return false;
+       }
+       /* TODO(sergey): Check for mesh vertices/curves. visibility flags. */
+       return true;
+}
+
 /* Object Manager */
 
 ObjectManager::ObjectManager()
index 57614c95580e169a323d9c025f5d73888b9bf807..7ab73f3c91a4b8bc9d915ec226634c306e9705a1 100644 (file)
@@ -68,6 +68,11 @@ public:
        void apply_transform(bool apply_to_motion);
 
        vector<float> motion_times();
+
+       /* Check whether object is traceable and it worth adding it to
+        * kernel scene.
+        */
+       bool is_traceable();
 };
 
 /* Object Manager */