Cycles: code refactoring, to do render layer visibility test a bit different,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Dec 2011 20:51:43 +0000 (20:51 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Dec 2011 20:51:43 +0000 (20:51 +0000)
replacing the camera visibility flag with object layer flags.

intern/cycles/app/cycles_test.cpp
intern/cycles/app/cycles_xml.cpp
intern/cycles/blender/blender_object.cpp
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/integrator.cpp
intern/cycles/render/integrator.h

index 838167274048a0689678d74d26608274080a7018..d162dbf12a9d794e5c93f4081b36aa1654fa6ebf 100644 (file)
@@ -82,9 +82,9 @@ static void session_print_status()
        session_print(status);
 }
 
-static BufferParams session_buffer_params()
+static BufferParams& session_buffer_params()
 {
-       BufferParams buffer_params;
+       static BufferParams buffer_params;
        buffer_params.width = options.width;
        buffer_params.height = options.height;
        buffer_params.full_width = options.width;
index f5cc01cd0626528419e8dfaf73263adc3d1091e4..21b03b56b7a4ae040f8134a00779132a699aaae7 100644 (file)
@@ -258,7 +258,6 @@ static void xml_read_integrator(const XMLReadState& state, pugi::xml_node node)
        xml_read_int(&integrator->min_bounce, node, "min_bounce");
        xml_read_int(&integrator->max_bounce, node, "max_bounce");
        xml_read_bool(&integrator->no_caustics, node, "no_caustics");
-       xml_read_float(&integrator->blur_caustics, node, "blur_caustics");
 }
 
 /* Camera */
index ec22d3db6f71c197ef79495cd59ee19b2c39f63c..db8ea5fbf1e57aee9db4631dc61d3069021d93b8 100644 (file)
@@ -154,7 +154,7 @@ void BlenderSync::sync_light(BL::Object b_parent, int b_index, BL::Object b_ob,
 
 /* Object */
 
-void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm, uint visibility)
+void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm, uint layer_flag)
 {
        /* light is handled separately */
        if(object_is_light(b_ob)) {
@@ -181,11 +181,19 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob,
        if(object_updated || (object->mesh && object->mesh->need_update)) {
                object->name = b_ob.name().c_str();
                object->tfm = tfm;
-               
-               object->visibility = object_ray_visibility(b_ob) & visibility;
+
+               /* visibility flags for both parent */
+               object->visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL;
                if(b_parent.ptr.data != b_ob.ptr.data)
                        object->visibility &= object_ray_visibility(b_parent);
 
+               /* camera flag is not actually used, instead is tested
+                  against render layer flags */
+               if(object->visibility & PATH_RAY_CAMERA) {
+                       object->visibility |= layer_flag << PATH_RAY_LAYER_SHIFT;
+                       object->visibility &= ~PATH_RAY_CAMERA;
+               }
+
                object->tag_update(scene);
        }
 }
@@ -196,7 +204,6 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d)
 {
        /* layer data */
        uint scene_layer = render_layer.scene_layer;
-       uint layer = render_layer.layer;
        
        /* prepare for sync */
        light_map.pre_sync();
@@ -212,11 +219,6 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d)
                uint ob_layer = get_layer(b_ob->layers());
 
                if(!hide && (ob_layer & scene_layer)) {
-                       uint visibility = PATH_RAY_ALL;
-                       
-                       if(!(ob_layer & layer))
-                               visibility &= ~PATH_RAY_CAMERA;
-
                        if(b_ob->is_duplicator()) {
                                /* dupli objects */
                                object_create_duplilist(*b_ob, b_scene);
@@ -226,7 +228,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d)
 
                                for(b_ob->dupli_list.begin(b_dup); b_dup != b_ob->dupli_list.end(); ++b_dup) {
                                        Transform tfm = get_transform(b_dup->matrix());
-                                       sync_object(*b_ob, b_index, b_dup->object(), tfm, visibility);
+                                       sync_object(*b_ob, b_index, b_dup->object(), tfm, ob_layer);
                                        b_index++;
                                }
 
@@ -244,7 +246,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d)
                        if(!hide) {
                                /* object itself */
                                Transform tfm = get_transform(b_ob->matrix_world());
-                               sync_object(*b_ob, 0, *b_ob, tfm, visibility);
+                               sync_object(*b_ob, 0, *b_ob, tfm, ob_layer);
                        }
                }
        }
index 4c8fe350b88209a3b0f771ca8f8a7cfc53c61205..52555fadefb8e34508c38cd300991c516e0bce2c 100644 (file)
@@ -122,9 +122,9 @@ bool BlenderSync::sync_recalc()
 
 void BlenderSync::sync_data(BL::SpaceView3D b_v3d)
 {
+       sync_render_layer(b_v3d);
        sync_integrator();
        sync_film();
-       sync_render_layer(b_v3d);
        sync_shaders();
        sync_objects(b_v3d);
 }
@@ -152,9 +152,8 @@ void BlenderSync::sync_integrator()
        integrator->transparent_shadows = get_boolean(cscene, "use_transparent_shadows");
 
        integrator->no_caustics = get_boolean(cscene, "no_caustics");
-       integrator->blur_caustics = get_float(cscene, "blur_caustics");
-
        integrator->seed = get_int(cscene, "seed");
+       integrator->layer_flag = render_layer.layer;
 
        if(integrator->modified(previntegrator))
                integrator->tag_update(scene);
index 824904cd81d2a64cbd2a87654a4a36ffc33a8c96..cd667205854be08f222899117757ced14267d289 100644 (file)
@@ -78,7 +78,7 @@ private:
 
        void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree);
        Mesh *sync_mesh(BL::Object b_ob, bool object_updated);
-       void sync_object(BL::Object b_parent, int b_index, BL::Object b_object, Transform& tfm, uint visibility);
+       void sync_object(BL::Object b_parent, int b_index, BL::Object b_object, Transform& tfm, uint layer_flag);
        void sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm);
 
        /* util */
index 05707f31352e38fa778f53db6504dd522c4a1381..d27ad861c6add93c300574dfaeaa925eaddc6e2a 100644 (file)
@@ -130,13 +130,16 @@ __device_inline void path_state_next(KernelGlobals *kg, PathState *state, int la
        }
 }
 
-__device_inline uint path_state_ray_visibility(PathState *state)
+__device_inline uint path_state_ray_visibility(KernelGlobals *kg, PathState *state)
 {
        uint flag = state->flag;
 
        /* for visibility, diffuse/glossy are for reflection only */
        if(flag & PATH_RAY_TRANSMIT)
                flag &= ~(PATH_RAY_DIFFUSE|PATH_RAY_GLOSSY);
+       /* for camera visibility, use render layer flags */
+       if(flag & PATH_RAY_CAMERA)
+               flag |= kernel_data.integrator.layer_flag;
 
        return flag;
 }
@@ -249,7 +252,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
        for(;; rng_offset += PRNG_BOUNCE_NUM) {
                /* intersect scene */
                Intersection isect;
-               uint visibility = path_state_ray_visibility(&state);
+               uint visibility = path_state_ray_visibility(kg, &state);
 
                if(!scene_intersect(kg, &ray, visibility, &isect)) {
                        /* eval background shader if nothing hit */
index ea73f87a8a56385e09e891f4a81e900612346b79..56db4d2b78a46c5e5c7aded2472965a31b31291e 100644 (file)
@@ -100,7 +100,10 @@ enum PathTraceDimension {
 
 /* these flag values correspond exactly to OSL defaults, so be careful not to
  * change this, or if you do, set the "raytypes" shading system attribute with
- * your own new ray types and bitflag values */
+ * your own new ray types and bitflag values.
+ *
+ * for ray visibility tests in BVH traversal, the upper 20 bits are used for
+ * layer visibility tests. */
 
 enum PathRayFlag {
        PATH_RAY_CAMERA = 1,
@@ -117,7 +120,9 @@ enum PathRayFlag {
 
        PATH_RAY_MIS_SKIP = 512,
 
-       PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512)
+       PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512),
+
+       PATH_RAY_LAYER_SHIFT = (32-20)
 };
 
 /* Closure Label */
@@ -383,10 +388,12 @@ typedef struct KernelIntegrator {
 
        /* caustics */
        int no_caustics;
-       float blur_caustics;
 
        /* seed */
        int seed;
+
+       /* render layer */
+       int layer_flag;
 } KernelIntegrator;
 
 typedef struct KernelBVH {
index 9d129d8e8db07f1c48076845fbe7fa8f5b73e12e..47059a0a009207f8e326e3290ebc4b1492532956 100644 (file)
@@ -41,9 +41,8 @@ Integrator::Integrator()
        transparent_shadows = false;
 
        no_caustics = false;
-       blur_caustics = 0.0f;
-
        seed = 0;
+       layer_flag = ~0;
 
        need_update = true;
 }
@@ -81,9 +80,8 @@ void Integrator::device_update(Device *device, DeviceScene *dscene)
        kintegrator->transparent_shadows = transparent_shadows;
 
        kintegrator->no_caustics = no_caustics;
-       kintegrator->blur_caustics = blur_caustics;
-
        kintegrator->seed = hash_int(seed);
+       kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT;
 
        /* sobol directions table */
        int dimensions = PRNG_BASE_NUM + (max_bounce + transparent_max_bounce + 2)*PRNG_BOUNCE_NUM;
@@ -115,7 +113,7 @@ bool Integrator::modified(const Integrator& integrator)
                transparent_probalistic == integrator.transparent_probalistic &&
                transparent_shadows == integrator.transparent_shadows &&
                no_caustics == integrator.no_caustics &&
-               blur_caustics == integrator.blur_caustics &&
+               layer_flag == integrator.layer_flag &&
                seed == integrator.seed);
 }
 
index 52032fa1a261714c582ca17ab796942ac10ea2ec..e610d670142fda087a154c2589226d13e602cd5e 100644 (file)
@@ -41,9 +41,9 @@ public:
        bool transparent_shadows;
 
        bool no_caustics;
-       float blur_caustics;
 
        int seed;
+       int layer_flag;
 
        bool need_update;