Object Info node support for GLSL mode and the internal render
[blender-staging.git] / intern / cycles / blender / blender_object.cpp
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "render/camera.h"
18 #include "render/integrator.h"
19 #include "render/graph.h"
20 #include "render/light.h"
21 #include "render/mesh.h"
22 #include "render/object.h"
23 #include "render/scene.h"
24 #include "render/nodes.h"
25 #include "render/particles.h"
26 #include "render/shader.h"
27
28 #include "blender/blender_object_cull.h"
29 #include "blender/blender_sync.h"
30 #include "blender/blender_util.h"
31
32 #include "util/util_foreach.h"
33 #include "util/util_hash.h"
34 #include "util/util_logging.h"
35
36 CCL_NAMESPACE_BEGIN
37
38 /* Utilities */
39
40 bool BlenderSync::BKE_object_is_modified(BL::Object& b_ob)
41 {
42         /* test if we can instance or if the object is modified */
43         if(b_ob.type() == BL::Object::type_META) {
44                 /* multi-user and dupli metaballs are fused, can't instance */
45                 return true;
46         }
47         else if(ccl::BKE_object_is_modified(b_ob, b_scene, preview)) {
48                 /* modifiers */
49                 return true;
50         }
51         else {
52                 /* object level material links */
53                 BL::Object::material_slots_iterator slot;
54                 for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot)
55                         if(slot->link() == BL::MaterialSlot::link_OBJECT)
56                                 return true;
57         }
58
59         return false;
60 }
61
62 bool BlenderSync::object_is_mesh(BL::Object& b_ob)
63 {
64         BL::ID b_ob_data = b_ob.data();
65
66         return (b_ob_data && (b_ob_data.is_a(&RNA_Mesh) ||
67                 b_ob_data.is_a(&RNA_Curve) || b_ob_data.is_a(&RNA_MetaBall)));
68 }
69
70 bool BlenderSync::object_is_light(BL::Object& b_ob)
71 {
72         BL::ID b_ob_data = b_ob.data();
73
74         return (b_ob_data && b_ob_data.is_a(&RNA_Lamp));
75 }
76
77 static uint object_ray_visibility(BL::Object& b_ob)
78 {
79         PointerRNA cvisibility = RNA_pointer_get(&b_ob.ptr, "cycles_visibility");
80         uint flag = 0;
81
82         flag |= get_boolean(cvisibility, "camera")? PATH_RAY_CAMERA: 0;
83         flag |= get_boolean(cvisibility, "diffuse")? PATH_RAY_DIFFUSE: 0;
84         flag |= get_boolean(cvisibility, "glossy")? PATH_RAY_GLOSSY: 0;
85         flag |= get_boolean(cvisibility, "transmission")? PATH_RAY_TRANSMIT: 0;
86         flag |= get_boolean(cvisibility, "shadow")? PATH_RAY_SHADOW: 0;
87         flag |= get_boolean(cvisibility, "scatter")? PATH_RAY_VOLUME_SCATTER: 0;
88
89         return flag;
90 }
91
92 /* Light */
93
94 void BlenderSync::sync_light(BL::Object& b_parent,
95                              int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
96                              BL::Object& b_ob,
97                              Transform& tfm,
98                              bool *use_portal)
99 {
100         /* test if we need to sync */
101         Light *light;
102         ObjectKey key(b_parent, persistent_id, b_ob);
103
104         if(!light_map.sync(&light, b_ob, b_parent, key)) {
105                 if(light->is_portal)
106                         *use_portal = true;
107                 return;
108         }
109         
110         BL::Lamp b_lamp(b_ob.data());
111
112         /* type */
113         switch(b_lamp.type()) {
114                 case BL::Lamp::type_POINT: {
115                         BL::PointLamp b_point_lamp(b_lamp);
116                         light->size = b_point_lamp.shadow_soft_size();
117                         light->type = LIGHT_POINT;
118                         break;
119                 }
120                 case BL::Lamp::type_SPOT: {
121                         BL::SpotLamp b_spot_lamp(b_lamp);
122                         light->size = b_spot_lamp.shadow_soft_size();
123                         light->type = LIGHT_SPOT;
124                         light->spot_angle = b_spot_lamp.spot_size();
125                         light->spot_smooth = b_spot_lamp.spot_blend();
126                         break;
127                 }
128                 case BL::Lamp::type_HEMI: {
129                         light->type = LIGHT_DISTANT;
130                         light->size = 0.0f;
131                         break;
132                 }
133                 case BL::Lamp::type_SUN: {
134                         BL::SunLamp b_sun_lamp(b_lamp);
135                         light->size = b_sun_lamp.shadow_soft_size();
136                         light->type = LIGHT_DISTANT;
137                         break;
138                 }
139                 case BL::Lamp::type_AREA: {
140                         BL::AreaLamp b_area_lamp(b_lamp);
141                         light->size = 1.0f;
142                         light->axisu = transform_get_column(&tfm, 0);
143                         light->axisv = transform_get_column(&tfm, 1);
144                         light->sizeu = b_area_lamp.size();
145                         if(b_area_lamp.shape() == BL::AreaLamp::shape_RECTANGLE)
146                                 light->sizev = b_area_lamp.size_y();
147                         else
148                                 light->sizev = light->sizeu;
149                         light->type = LIGHT_AREA;
150                         break;
151                 }
152         }
153
154         /* location and (inverted!) direction */
155         light->co = transform_get_column(&tfm, 3);
156         light->dir = -transform_get_column(&tfm, 2);
157         light->tfm = tfm;
158
159         /* shader */
160         vector<Shader*> used_shaders;
161         find_shader(b_lamp, used_shaders, scene->default_light);
162         light->shader = used_shaders[0];
163
164         /* shadow */
165         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
166         PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
167         light->cast_shadow = get_boolean(clamp, "cast_shadow");
168         light->use_mis = get_boolean(clamp, "use_multiple_importance_sampling");
169         
170         int samples = get_int(clamp, "samples");
171         if(get_boolean(cscene, "use_square_samples"))
172                 light->samples = samples * samples;
173         else
174                 light->samples = samples;
175
176         light->max_bounces = get_int(clamp, "max_bounces");
177
178         if(light->type == LIGHT_AREA)
179                 light->is_portal = get_boolean(clamp, "is_portal");
180         else
181                 light->is_portal = false;
182
183         if(light->is_portal)
184                 *use_portal = true;
185
186         /* visibility */
187         uint visibility = object_ray_visibility(b_ob);
188         light->use_diffuse = (visibility & PATH_RAY_DIFFUSE) != 0;
189         light->use_glossy = (visibility & PATH_RAY_GLOSSY) != 0;
190         light->use_transmission = (visibility & PATH_RAY_TRANSMIT) != 0;
191         light->use_scatter = (visibility & PATH_RAY_VOLUME_SCATTER) != 0;
192
193         /* tag */
194         light->tag_update(scene);
195 }
196
197 void BlenderSync::sync_background_light(bool use_portal)
198 {
199         BL::World b_world = b_scene.world();
200
201         if(b_world) {
202                 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
203                 PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
204                 bool sample_as_light = get_boolean(cworld, "sample_as_light");
205
206                 if(sample_as_light || use_portal) {
207                         /* test if we need to sync */
208                         Light *light;
209                         ObjectKey key(b_world, 0, b_world);
210
211                         if(light_map.sync(&light, b_world, b_world, key) ||
212                             world_recalc ||
213                             b_world.ptr.data != world_map)
214                         {
215                                 light->type = LIGHT_BACKGROUND;
216                                 light->map_resolution  = get_int(cworld, "sample_map_resolution");
217                                 light->shader = scene->default_background;
218                                 light->use_mis = sample_as_light;
219                                 light->max_bounces = get_int(cworld, "max_bounces");
220
221                                 int samples = get_int(cworld, "samples");
222                                 if(get_boolean(cscene, "use_square_samples"))
223                                         light->samples = samples * samples;
224                                 else
225                                         light->samples = samples;
226
227                                 light->tag_update(scene);
228                                 light_map.set_recalc(b_world);
229                         }
230                 }
231         }
232
233         world_map = b_world.ptr.data;
234         world_recalc = false;
235 }
236
237 /* Object */
238
239 Object *BlenderSync::sync_object(BL::Object& b_parent,
240                                  int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
241                                  BL::DupliObject& b_dupli_ob,
242                                  Transform& tfm,
243                                  uint layer_flag,
244                                  float motion_time,
245                                  bool hide_tris,
246                                  BlenderObjectCulling& culling,
247                                  bool *use_portal)
248 {
249         BL::Object b_ob = (b_dupli_ob ? b_dupli_ob.object() : b_parent);
250         bool motion = motion_time != 0.0f;
251         
252         /* light is handled separately */
253         if(object_is_light(b_ob)) {
254                 /* don't use lamps for excluded layers used as mask layer */
255                 if(!motion && !((layer_flag & render_layer.holdout_layer) && (layer_flag & render_layer.exclude_layer)))
256                         sync_light(b_parent, persistent_id, b_ob, tfm, use_portal);
257
258                 return NULL;
259         }
260
261         /* only interested in object that we can create meshes from */
262         if(!object_is_mesh(b_ob)) {
263                 return NULL;
264         }
265
266         /* Perform object culling. */
267         if(culling.test(scene, b_ob, tfm)) {
268                 return NULL;
269         }
270
271         /* key to lookup object */
272         ObjectKey key(b_parent, persistent_id, b_ob);
273         Object *object;
274
275         /* motion vector case */
276         if(motion) {
277                 object = object_map.find(key);
278
279                 if(object && (scene->need_motion() == Scene::MOTION_PASS ||
280                               object_use_motion(b_parent, b_ob)))
281                 {
282                         /* object transformation */
283                         if(tfm != object->tfm) {
284                                 VLOG(1) << "Object " << b_ob.name() << " motion detected.";
285                                 if(motion_time == -1.0f || motion_time == 1.0f) {
286                                         object->use_motion = true;
287                                 }
288                         }
289
290                         if(motion_time == -1.0f) {
291                                 object->motion.pre = tfm;
292                         }
293                         else if(motion_time == 1.0f) {
294                                 object->motion.post = tfm;
295                         }
296
297                         /* mesh deformation */
298                         if(object->mesh)
299                                 sync_mesh_motion(b_ob, object, motion_time);
300                 }
301
302                 return object;
303         }
304
305         /* test if we need to sync */
306         bool object_updated = false;
307
308         if(object_map.sync(&object, b_ob, b_parent, key))
309                 object_updated = true;
310         
311         bool use_holdout = (layer_flag & render_layer.holdout_layer) != 0;
312         
313         /* mesh sync */
314         object->mesh = sync_mesh(b_ob, object_updated, hide_tris);
315
316         /* special case not tracked by object update flags */
317
318         /* holdout */
319         if(use_holdout != object->use_holdout) {
320                 object->use_holdout = use_holdout;
321                 scene->object_manager->tag_update(scene);
322                 object_updated = true;
323         }
324
325         /* visibility flags for both parent and child */
326         uint visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL_VISIBILITY;
327         if(b_parent.ptr.data != b_ob.ptr.data) {
328                 visibility &= object_ray_visibility(b_parent);
329         }
330
331         /* make holdout objects on excluded layer invisible for non-camera rays */
332         if(use_holdout && (layer_flag & render_layer.exclude_layer)) {
333                 visibility &= ~(PATH_RAY_ALL_VISIBILITY - PATH_RAY_CAMERA);
334         }
335
336         /* hide objects not on render layer from camera rays */
337         if(!(layer_flag & render_layer.layer)) {
338                 visibility &= ~PATH_RAY_CAMERA;
339         }
340
341         if(visibility != object->visibility) {
342                 object->visibility = visibility;
343                 object_updated = true;
344         }
345
346         PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
347         bool is_shadow_catcher = get_boolean(cobject, "is_shadow_catcher");
348         if(is_shadow_catcher != object->is_shadow_catcher) {
349                 object->is_shadow_catcher = is_shadow_catcher;
350                 object_updated = true;
351         }
352
353         /* object sync
354          * transform comparison should not be needed, but duplis don't work perfect
355          * in the depsgraph and may not signal changes, so this is a workaround */
356         if(object_updated || (object->mesh && object->mesh->need_update) || tfm != object->tfm) {
357                 object->name = b_ob.name().c_str();
358                 object->pass_id = b_ob.pass_index();
359                 object->tfm = tfm;
360                 object->motion.pre = transform_empty();
361                 object->motion.post = transform_empty();
362                 object->use_motion = false;
363
364                 /* motion blur */
365                 if(scene->need_motion() == Scene::MOTION_BLUR && object->mesh) {
366                         Mesh *mesh = object->mesh;
367
368                         mesh->use_motion_blur = false;
369
370                         if(object_use_motion(b_parent, b_ob)) {
371                                 if(object_use_deform_motion(b_parent, b_ob)) {
372                                         mesh->motion_steps = object_motion_steps(b_ob);
373                                         mesh->use_motion_blur = true;
374                                 }
375
376                                 vector<float> times = object->motion_times();
377                                 foreach(float time, times)
378                                         motion_times.insert(time);
379                         }
380                 }
381
382                 /* dupli texture coordinates and random_id */
383                 if(b_dupli_ob) {
384                         object->dupli_generated = 0.5f*get_float3(b_dupli_ob.orco()) - make_float3(0.5f, 0.5f, 0.5f);
385                         object->dupli_uv = get_float2(b_dupli_ob.uv());
386                         object->random_id = b_dupli_ob.random_id();
387                 }
388                 else {
389                         object->dupli_generated = make_float3(0.0f, 0.0f, 0.0f);
390                         object->dupli_uv = make_float2(0.0f, 0.0f);
391                         object->random_id =  hash_int_2d(hash_string(object->name.c_str()), 0);
392                 }
393
394                 object->tag_update(scene);
395         }
396
397         return object;
398 }
399
400 static bool object_render_hide_original(BL::Object::type_enum ob_type,
401                                         BL::Object::dupli_type_enum dupli_type)
402 {
403         /* metaball exception, they duplicate self */
404         if(ob_type == BL::Object::type_META)
405                 return false;
406
407         return (dupli_type == BL::Object::dupli_type_VERTS ||
408                 dupli_type == BL::Object::dupli_type_FACES ||
409                 dupli_type == BL::Object::dupli_type_FRAMES);
410 }
411
412 static bool object_render_hide(BL::Object& b_ob,
413                                bool top_level,
414                                bool parent_hide,
415                                bool& hide_triangles)
416 {
417         /* check if we should render or hide particle emitter */
418         BL::Object::particle_systems_iterator b_psys;
419
420         bool hair_present = false;
421         bool show_emitter = false;
422         bool hide_emitter = false;
423         bool hide_as_dupli_parent = false;
424         bool hide_as_dupli_child_original = false;
425
426         for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
427                 if((b_psys->settings().render_type() == BL::ParticleSettings::render_type_PATH) &&
428                    (b_psys->settings().type()==BL::ParticleSettings::type_HAIR))
429                         hair_present = true;
430
431                 if(b_psys->settings().use_render_emitter())
432                         show_emitter = true;
433                 else
434                         hide_emitter = true;
435         }
436
437         if(show_emitter)
438                 hide_emitter = false;
439
440         /* duplicators hidden by default, except dupliframes which duplicate self */
441         if(b_ob.is_duplicator())
442                 if(top_level || b_ob.dupli_type() != BL::Object::dupli_type_FRAMES)
443                         hide_as_dupli_parent = true;
444
445         /* hide original object for duplis */
446         BL::Object parent = b_ob.parent();
447         while(parent) {
448                 if(object_render_hide_original(b_ob.type(),
449                                                parent.dupli_type()))
450                 {
451                         if(parent_hide) {
452                                 hide_as_dupli_child_original = true;
453                                 break;
454                         }
455                 }
456                 parent = parent.parent();
457         }
458         
459         hide_triangles = hide_emitter;
460
461         if(show_emitter) {
462                 return false;
463         }
464         else if(hair_present) {
465                 return hide_as_dupli_child_original;
466         }
467         else {
468                 return (hide_as_dupli_parent || hide_as_dupli_child_original);
469         }
470 }
471
472 static bool object_render_hide_duplis(BL::Object& b_ob)
473 {
474         BL::Object parent = b_ob.parent();
475
476         return (parent && object_render_hide_original(b_ob.type(), parent.dupli_type()));
477 }
478
479 /* Object Loop */
480
481 void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
482 {
483         /* layer data */
484         uint scene_layer = render_layer.scene_layer;
485         bool motion = motion_time != 0.0f;
486         
487         if(!motion) {
488                 /* prepare for sync */
489                 light_map.pre_sync();
490                 mesh_map.pre_sync();
491                 object_map.pre_sync();
492                 particle_system_map.pre_sync();
493                 motion_times.clear();
494         }
495         else {
496                 mesh_motion_synced.clear();
497         }
498
499         /* initialize culling */
500         BlenderObjectCulling culling(scene, b_scene);
501
502         /* object loop */
503         BL::Scene::object_bases_iterator b_base;
504         BL::Scene b_sce = b_scene;
505         /* modifier result type (not exposed as enum in C++ API)
506          * 1 : DAG_EVAL_PREVIEW
507          * 2 : DAG_EVAL_RENDER
508          */
509         int dupli_settings = preview ? 1 : 2;
510
511         bool cancel = false;
512         bool use_portal = false;
513
514         uint layer_override = get_layer(b_engine.layer_override());
515         for(; b_sce && !cancel; b_sce = b_sce.background_set()) {
516                 /* Render layer's scene_layer is affected by local view already,
517                  * which is not a desired behavior here.
518                  */
519                 uint scene_layers = layer_override ? layer_override : get_layer(b_scene.layers());
520                 for(b_sce.object_bases.begin(b_base); b_base != b_sce.object_bases.end() && !cancel; ++b_base) {
521                         BL::Object b_ob = b_base->object();
522                         bool hide = (render_layer.use_viewport_visibility)? b_ob.hide(): b_ob.hide_render();
523                         uint ob_layer = get_layer(b_base->layers(),
524                                                   b_base->layers_local_view(),
525                                                   object_is_light(b_ob),
526                                                   scene_layers);
527                         hide = hide || !(ob_layer & scene_layer);
528
529                         if(!hide) {
530                                 progress.set_sync_status("Synchronizing object", b_ob.name());
531
532                                 /* load per-object culling data */
533                                 culling.init_object(scene, b_ob);
534
535                                 if(b_ob.is_duplicator() && !object_render_hide_duplis(b_ob)) {
536                                         /* dupli objects */
537                                         b_ob.dupli_list_create(b_scene, dupli_settings);
538
539                                         BL::Object::dupli_list_iterator b_dup;
540
541                                         for(b_ob.dupli_list.begin(b_dup); b_dup != b_ob.dupli_list.end(); ++b_dup) {
542                                                 Transform tfm = get_transform(b_dup->matrix());
543                                                 BL::Object b_dup_ob = b_dup->object();
544                                                 bool dup_hide = (b_v3d)? b_dup_ob.hide(): b_dup_ob.hide_render();
545                                                 bool in_dupli_group = (b_dup->type() == BL::DupliObject::type_GROUP);
546                                                 bool hide_tris;
547
548                                                 if(!(b_dup->hide() || dup_hide || object_render_hide(b_dup_ob, false, in_dupli_group, hide_tris))) {
549                                                         /* the persistent_id allows us to match dupli objects
550                                                          * between frames and updates */
551                                                         BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_dup->persistent_id();
552
553                                                         /* sync object and mesh or light data */
554                                                         Object *object = sync_object(b_ob,
555                                                                                      persistent_id.data,
556                                                                                      *b_dup,
557                                                                                      tfm,
558                                                                                      ob_layer,
559                                                                                      motion_time,
560                                                                                      hide_tris,
561                                                                                      culling,
562                                                                                      &use_portal);
563
564                                                         /* sync possible particle data, note particle_id
565                                                          * starts counting at 1, first is dummy particle */
566                                                         if(!motion && object) {
567                                                                 sync_dupli_particle(b_ob, *b_dup, object);
568                                                         }
569
570                                                 }
571                                         }
572
573                                         b_ob.dupli_list_clear();
574                                 }
575
576                                 /* test if object needs to be hidden */
577                                 bool hide_tris;
578
579                                 if(!object_render_hide(b_ob, true, true, hide_tris)) {
580                                         /* object itself */
581                                         Transform tfm = get_transform(b_ob.matrix_world());
582                                         BL::DupliObject b_empty_dupli_ob(PointerRNA_NULL);
583                                         sync_object(b_ob,
584                                                     NULL,
585                                                     b_empty_dupli_ob,
586                                                     tfm,
587                                                     ob_layer,
588                                                     motion_time,
589                                                     hide_tris,
590                                                     culling,
591                                                     &use_portal);
592                                 }
593                         }
594
595                         cancel = progress.get_cancel();
596                 }
597         }
598
599         progress.set_sync_status("");
600
601         if(!cancel && !motion) {
602                 sync_background_light(use_portal);
603
604                 /* handle removed data and modified pointers */
605                 if(light_map.post_sync())
606                         scene->light_manager->tag_update(scene);
607                 if(mesh_map.post_sync())
608                         scene->mesh_manager->tag_update(scene);
609                 if(object_map.post_sync())
610                         scene->object_manager->tag_update(scene);
611                 if(particle_system_map.post_sync())
612                         scene->particle_system_manager->tag_update(scene);
613         }
614
615         if(motion)
616                 mesh_motion_synced.clear();
617 }
618
619 void BlenderSync::sync_motion(BL::RenderSettings& b_render,
620                               BL::SpaceView3D& b_v3d,
621                               BL::Object& b_override,
622                               int width, int height,
623                               void **python_thread_state)
624 {
625         if(scene->need_motion() == Scene::MOTION_NONE)
626                 return;
627
628         /* get camera object here to deal with camera switch */
629         BL::Object b_cam = b_scene.camera();
630         if(b_override)
631                 b_cam = b_override;
632
633         Camera prevcam = *(scene->camera);
634
635         int frame_center = b_scene.frame_current();
636         float subframe_center = b_scene.frame_subframe();
637         float frame_center_delta = 0.0f;
638
639         if(scene->need_motion() != Scene::MOTION_PASS &&
640            scene->camera->motion_position != Camera::MOTION_POSITION_CENTER)
641         {
642                 float shuttertime = scene->camera->shuttertime;
643                 if(scene->camera->motion_position == Camera::MOTION_POSITION_END) {
644                         frame_center_delta = -shuttertime * 0.5f;
645                 }
646                 else {
647                         assert(scene->camera->motion_position == Camera::MOTION_POSITION_START);
648                         frame_center_delta = shuttertime * 0.5f;
649                 }
650                 float time = frame_center + subframe_center + frame_center_delta;
651                 int frame = (int)floorf(time);
652                 float subframe = time - frame;
653                 python_thread_state_restore(python_thread_state);
654                 b_engine.frame_set(frame, subframe);
655                 python_thread_state_save(python_thread_state);
656                 sync_camera_motion(b_render, b_cam, width, height, 0.0f);
657                 sync_objects(b_v3d, 0.0f);
658         }
659
660         /* always sample these times for camera motion */
661         motion_times.insert(-1.0f);
662         motion_times.insert(1.0f);
663
664         /* note iteration over motion_times set happens in sorted order */
665         foreach(float relative_time, motion_times) {
666                 VLOG(1) << "Synchronizing motion for the relative time "
667                         << relative_time << ".";
668
669                 /* fixed shutter time to get previous and next frame for motion pass */
670                 float shuttertime = scene->motion_shutter_time();
671
672                 /* compute frame and subframe time */
673                 float time = frame_center + subframe_center + frame_center_delta + relative_time * shuttertime * 0.5f;
674                 int frame = (int)floorf(time);
675                 float subframe = time - frame;
676
677                 /* change frame */
678                 python_thread_state_restore(python_thread_state);
679                 b_engine.frame_set(frame, subframe);
680                 python_thread_state_save(python_thread_state);
681
682                 /* sync camera, only supports two times at the moment */
683                 if(relative_time == -1.0f || relative_time == 1.0f) {
684                         sync_camera_motion(b_render,
685                                            b_cam,
686                                            width, height,
687                                            relative_time);
688                 }
689
690                 /* sync object */
691                 sync_objects(b_v3d, relative_time);
692         }
693
694         /* we need to set the python thread state again because this
695          * function assumes it is being executed from python and will
696          * try to save the thread state */
697         python_thread_state_restore(python_thread_state);
698         b_engine.frame_set(frame_center, subframe_center);
699         python_thread_state_save(python_thread_state);
700
701         /* tag camera for motion update */
702         if(scene->camera->motion_modified(prevcam))
703                 scene->camera->tag_update();
704 }
705
706 CCL_NAMESPACE_END
707