Fix Cycles to mostly work with render layer / depsgraph changes.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 26 Feb 2018 15:46:48 +0000 (16:46 +0100)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 27 Feb 2018 21:25:54 +0000 (18:25 -0300)
Point density texture and motion blur are still broken, and many more changes
are needed in general to used evaluated datablocks.

14 files changed:
intern/cycles/blender/addon/__init__.py
intern/cycles/blender/addon/engine.py
intern/cycles/blender/blender_curves.cpp
intern/cycles/blender/blender_mesh.cpp
intern/cycles/blender/blender_object.cpp
intern/cycles/blender/blender_python.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_shader.cpp
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/source/external_engine.c

index e5a0cbc316f8b3cec6b3ede4927c0363e3094aa6..a15a9e046df030bb87f0bd570fe48b60ab8d7b98 100644 (file)
@@ -66,31 +66,31 @@ class CyclesRender(bpy.types.RenderEngine):
         engine.free(self)
 
     # final render
-    def update(self, data, depsgraph, scene):
+    def update(self, data, scene):
         if not self.session:
             if self.is_preview:
                 cscene = bpy.context.scene.cycles
                 use_osl = cscene.shading_system and cscene.device == 'CPU'
 
-                engine.create(self, data, depsgraph, scene,
+                engine.create(self, data, scene,
                               None, None, None, use_osl)
             else:
-                engine.create(self, data, depsgraph, scene)
+                engine.create(self, data, scene)
         else:
             engine.reset(self, data, scene)
 
-    def render_to_image(self, data, scene):
-        engine.render(self, data, scene)
+    def render_to_image(self, depsgraph):
+        engine.render(self, depsgraph)
 
-    def bake(self, scene, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result):
-        engine.bake(self, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result)
+    def bake(self, depsgraph, scene, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result):
+        engine.bake(self, depsgraph, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result)
 
     # viewport render
     def view_update(self, context):
         if not self.session:
-            engine.create(self, context.blend_data, context.depsgraph, context.scene,
+            engine.create(self, context.blend_data, context.scene,
                           context.region, context.space_data, context.region_data)
-        engine.update(self, context.blend_data, context.scene)
+        engine.update(self, context.depsgraph, context.blend_data, context.scene)
 
     def render_to_view(self, context):
         engine.draw(self, context.depsgraph, context.region, context.space_data, context.region_data)
index cbc21b79da84bc137b7f63be5590520cfba142d7..8a13b67f91de573fa53aad8d3a3a230144b27eee 100644 (file)
@@ -123,13 +123,12 @@ def exit():
     _cycles.exit()
 
 
-def create(engine, data, depsgraph, scene, region=None, v3d=None, rv3d=None, preview_osl=False):
+def create(engine, data, scene, region=None, v3d=None, rv3d=None, preview_osl=False):
     import bpy
     import _cycles
 
     data = data.as_pointer()
     userpref = bpy.context.user_preferences.as_pointer()
-    depsgraph = depsgraph.as_pointer()
     scene = scene.as_pointer()
     if region:
         region = region.as_pointer()
@@ -144,7 +143,7 @@ def create(engine, data, depsgraph, scene, region=None, v3d=None, rv3d=None, pre
         _cycles.debug_flags_reset()
 
     engine.session = _cycles.create(
-            engine.as_pointer(), userpref, data, depsgraph, scene, region, v3d, rv3d, preview_osl)
+            engine.as_pointer(), userpref, data, scene, region, v3d, rv3d, preview_osl)
 
 
 def free(engine):
@@ -158,14 +157,14 @@ def free(engine):
 def render(engine, depsgraph):
     import _cycles
     if hasattr(engine, "session"):
-        _cycles.render(engine.session)
+        _cycles.render(engine.session, depsgraph.as_pointer())
 
 
-def bake(engine, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result):
+def bake(engine, depsgraph, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result):
     import _cycles
     session = getattr(engine, "session", None)
     if session is not None:
-        _cycles.bake(engine.session, obj.as_pointer(), pass_type, pass_filter, object_id, pixel_array.as_pointer(), num_pixels, depth, result.as_pointer())
+        _cycles.bake(engine.session, depsgraph.as_pointer(), obj.as_pointer(), pass_type, pass_filter, object_id, pixel_array.as_pointer(), num_pixels, depth, result.as_pointer())
 
 
 def reset(engine, data, scene):
@@ -175,9 +174,9 @@ def reset(engine, data, scene):
     _cycles.reset(engine.session, data, scene)
 
 
-def update(engine, data, scene):
+def update(engine, depsgraph, data, scene):
     import _cycles
-    _cycles.sync(engine.session)
+    _cycles.sync(engine.session, depsgraph.as_pointer())
 
 
 def draw(engine, depsgraph, region, v3d, rv3d):
index 9c210830cfe68ba14d49a642cb75c04d21a7c30f..6017ea502ed3afbeeb200e1ca93e7215cb11c64b 100644 (file)
@@ -326,14 +326,14 @@ static bool ObtainCacheParticleVcol(Mesh *mesh,
        return true;
 }
 
-static void set_resolution(BL::Object *b_ob, BL::Scene *scene, BL::ViewLayer *view_layer, bool render)
+static void set_resolution(BL::Object& b_ob, BL::Scene& scene, BL::ViewLayer& view_layer, bool render)
 {
        BL::Object::modifiers_iterator b_mod;
-       for(b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) {
+       for(b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
                if((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && ((b_mod->show_viewport()) || (b_mod->show_render()))) {
                        BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr);
                        BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr);
-                       b_psys.set_resolution(*scene, *view_layer, *b_ob, (render)? 2: 1);
+                       b_psys.set_resolution(scene, view_layer, b_ob, (render)? 2: 1);
                }
        }
 }
@@ -884,7 +884,8 @@ void BlenderSync::sync_curve_settings()
                curve_system_manager->tag_update(scene);
 }
 
-void BlenderSync::sync_curves(Mesh *mesh,
+void BlenderSync::sync_curves(BL::Depsgraph& b_depsgraph,
+                              Mesh *mesh,
                               BL::Mesh& b_mesh,
                               BL::Object& b_ob,
                               bool motion,
@@ -920,8 +921,9 @@ void BlenderSync::sync_curves(Mesh *mesh,
 
        ParticleCurveData CData;
 
+       BL::ViewLayer b_view_layer = b_depsgraph.view_layer();
        if(!preview)
-               set_resolution(&b_ob, &b_scene, &b_view_layer, true);
+               set_resolution(b_ob, b_scene, b_view_layer, true);
 
        ObtainCacheParticleData(mesh, &b_mesh, &b_ob, &CData, !preview);
 
@@ -1066,7 +1068,7 @@ void BlenderSync::sync_curves(Mesh *mesh,
        }
 
        if(!preview)
-               set_resolution(&b_ob, &b_scene, &b_view_layer, false);
+               set_resolution(b_ob, b_scene, b_view_layer, false);
 
        mesh->compute_bounds();
 }
index bda6306d11f6bfcc9ee7a90357a788666cc28538..9c8d317e6de26cc684ee13c920e48fa063e2ffa4 100644 (file)
@@ -1067,7 +1067,8 @@ static void sync_mesh_fluid_motion(BL::Object& b_ob, Scene *scene, Mesh *mesh)
        }
 }
 
-Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
+Mesh *BlenderSync::sync_mesh(BL::Depsgraph& b_depsgraph,
+                             BL::Object& b_ob,
                              BL::Object& b_ob_instance,
                              bool object_updated,
                              bool hide_tris)
@@ -1186,7 +1187,7 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
                BL::Mesh b_mesh = object_to_mesh(b_data,
                                                 b_ob,
                                                 b_scene,
-                                                b_view_layer,
+                                                b_depsgraph.view_layer(),
                                                 true,
                                                 !preview,
                                                 need_undeformed,
@@ -1204,7 +1205,7 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
                        }
 
                        if(view_layer.use_hair && mesh->subdivision_type == Mesh::SUBDIVISION_NONE)
-                               sync_curves(mesh, b_mesh, b_ob, false);
+                               sync_curves(b_depsgraph, mesh, b_mesh, b_ob, false);
 
                        if(can_free_caches) {
                                b_ob.cache_release();
@@ -1231,7 +1232,8 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
        return mesh;
 }
 
-void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
+void BlenderSync::sync_mesh_motion(BL::Depsgraph& b_depsgraph,
+                                   BL::Object& b_ob,
                                    Object *object,
                                    float motion_time)
 {
@@ -1301,7 +1303,7 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
                b_mesh = object_to_mesh(b_data,
                                        b_ob,
                                        b_scene,
-                                       b_view_layer,
+                                       b_depsgraph.view_layer(),
                                        true,
                                        !preview,
                                        false,
@@ -1412,7 +1414,7 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
 
        /* hair motion */
        if(numkeys)
-               sync_curves(mesh, b_mesh, b_ob, true, time_index);
+               sync_curves(b_depsgraph, mesh, b_mesh, b_ob, true, time_index);
 
        /* free derived mesh */
        b_data.meshes.remove(b_mesh, false, true, false);
index 6564eea47675cb772109959f9079a7a0638f0306..03c5ecddc441c4623c562627640f909c2731da20 100644 (file)
@@ -263,7 +263,8 @@ void BlenderSync::sync_background_light(bool use_portal)
 
 /* Object */
 
-Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
+Object *BlenderSync::sync_object(BL::Depsgraph& b_depsgraph,
+                                 BL::Depsgraph::duplis_iterator& b_dupli_iter,
                                  uint layer_flag,
                                  float motion_time,
                                  bool hide_tris,
@@ -366,7 +367,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
 
                        /* mesh deformation */
                        if(object->mesh)
-                               sync_mesh_motion(b_ob, object, motion_time);
+                               sync_mesh_motion(b_depsgraph, b_ob, object, motion_time);
                }
 
                return object;
@@ -379,7 +380,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
                object_updated = true;
        
        /* mesh sync */
-       object->mesh = sync_mesh(b_ob, b_ob_instance, object_updated, hide_tris);
+       object->mesh = sync_mesh(b_depsgraph, b_ob, b_ob_instance, object_updated, hide_tris);
 
        /* special case not tracked by object update flags */
 
@@ -520,7 +521,7 @@ static bool object_render_hide(BL::Object& b_ob,
 
 /* Object Loop */
 
-void BlenderSync::sync_objects(float motion_time)
+void BlenderSync::sync_objects(BL::Depsgraph& b_depsgraph, float motion_time)
 {
        /* layer data */
        bool motion = motion_time != 0.0f;
@@ -564,7 +565,8 @@ void BlenderSync::sync_objects(float motion_time)
 
                 if(!object_render_hide(b_ob, true, true, hide_tris)) {
                        /* object itself */
-                       sync_object(b_dupli_iter,
+                       sync_object(b_depsgraph,
+                                   b_dupli_iter,
                                    ~(0), /* until we get rid of layers */
                                    motion_time,
                                    hide_tris,
@@ -596,6 +598,7 @@ void BlenderSync::sync_objects(float motion_time)
 }
 
 void BlenderSync::sync_motion(BL::RenderSettings& b_render,
+                              BL::Depsgraph& b_depsgraph,
                               BL::Object& b_override,
                               int width, int height,
                               void **python_thread_state)
@@ -625,6 +628,8 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
                        assert(scene->camera->motion_position == Camera::MOTION_POSITION_START);
                        frame_center_delta = shuttertime * 0.5f;
                }
+
+               /* TODO: move frame on depsgraph. */
                float time = frame_center + subframe_center + frame_center_delta;
                int frame = (int)floorf(time);
                float subframe = time - frame;
@@ -632,7 +637,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
                b_engine.frame_set(frame, subframe);
                python_thread_state_save(python_thread_state);
                sync_camera_motion(b_render, b_cam, width, height, 0.0f);
-               sync_objects(0.0f);
+               sync_objects(b_depsgraph, 0.0f);
        }
 
        /* always sample these times for camera motion */
@@ -652,6 +657,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
                int frame = (int)floorf(time);
                float subframe = time - frame;
 
+               /* TODO: move frame on depsgraph. */
                /* change frame */
                python_thread_state_restore(python_thread_state);
                b_engine.frame_set(frame, subframe);
@@ -666,7 +672,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
                }
 
                /* sync object */
-               sync_objects(relative_time);
+               sync_objects(b_depsgraph, relative_time);
        }
 
        /* we need to set the python thread state again because this
index 17bf8ceef36876a667231cf4dd28882e1d481581..5c1181960c353a0f0075922ea88041a1fd8b7bc7 100644 (file)
@@ -280,13 +280,22 @@ static PyObject *free_func(PyObject * /*self*/, PyObject *value)
        Py_RETURN_NONE;
 }
 
-static PyObject *render_func(PyObject * /*self*/, PyObject *value)
+static PyObject *render_func(PyObject * /*self*/, PyObject *args)
 {
-       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value);
+       PyObject *pysession, *pydepsgraph;
+
+       if(!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
+               return NULL;
+
+       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
+
+       PointerRNA depsgraphptr;
+       RNA_pointer_create(NULL, &RNA_Depsgraph, (ID*)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->render();
+       session->render(b_depsgraph);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -296,16 +305,20 @@ static PyObject *render_func(PyObject * /*self*/, PyObject *value)
 /* pixel_array and result passed as pointers */
 static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
 {
-       PyObject *pysession, *pyobject;
+       PyObject *pysession, *pydepsgraph, *pyobject;
        PyObject *pypixel_array, *pyresult;
        const char *pass_type;
        int num_pixels, depth, object_id, pass_filter;
 
-       if(!PyArg_ParseTuple(args, "OOsiiOiiO", &pysession, &pyobject, &pass_type, &pass_filter, &object_id, &pypixel_array, &num_pixels, &depth, &pyresult))
+       if(!PyArg_ParseTuple(args, "OOOsiiOiiO", &pysession, &pydepsgraph, &pyobject, &pass_type, &pass_filter, &object_id, &pypixel_array, &num_pixels, &depth, &pyresult))
                return NULL;
 
        BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
 
+       PointerRNA depsgraphptr;
+       RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
+
        PointerRNA objectptr;
        RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyobject), &objectptr);
        BL::Object b_object(objectptr);
@@ -318,7 +331,7 @@ static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->bake(b_object, pass_type, pass_filter, object_id, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result);
+       session->bake(b_depsgraph, b_object, pass_type, pass_filter, object_id, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -371,13 +384,22 @@ static PyObject *reset_func(PyObject * /*self*/, PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *sync_func(PyObject * /*self*/, PyObject *value)
+static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
 {
-       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value);
+       PyObject *pysession, *pydepsgraph;
+
+       if(!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
+               return NULL;
+
+       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
+
+       PointerRNA depsgraphptr;
+       RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->synchronize();
+       session->synchronize(b_depsgraph);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -749,10 +771,10 @@ static PyMethodDef methods[] = {
        {"exit", exit_func, METH_VARARGS, ""},
        {"create", create_func, METH_VARARGS, ""},
        {"free", free_func, METH_O, ""},
-       {"render", render_func, METH_O, ""},
+       {"render", render_func, METH_VARARGS, ""},
        {"bake", bake_func, METH_VARARGS, ""},
        {"draw", draw_func, METH_VARARGS, ""},
-       {"sync", sync_func, METH_O, ""},
+       {"sync", sync_func, METH_VARARGS, ""},
        {"reset", reset_func, METH_VARARGS, ""},
 #ifdef WITH_OSL
        {"osl_update_node", osl_update_node_func, METH_VARARGS, ""},
index 952410c03f4fa64a6e4ebb83a074b87f7eb4edbb..86a0baf59ea6954761c09abed474d58c70ec8c9d 100644 (file)
@@ -141,7 +141,6 @@ void BlenderSession::create_session()
 
        session->scene = scene;
 
-#if 0
        /* There is no single depsgraph to use for the entire render.
         * So we need to handle this differently.
         *
@@ -149,28 +148,14 @@ void BlenderSession::create_session()
         * or perhaps move syncing further down in the pipeline.
         */
        /* create sync */
-       sync = new BlenderSync(b_engine, b_data, b_depsgraph, b_scene, scene, !background, session->progress);
+       sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
        BL::Object b_camera_override(b_engine.camera_override());
        if(b_v3d) {
-               if(session_pause == false) {
-                       /* full data sync */
-                       sync->sync_view(b_v3d, b_rv3d, width, height);
-                       sync->sync_data(b_render,
-                                       b_v3d,
-                                       b_camera_override,
-                                       width, height,
-                                       &python_thread_state,
-                                       b_rlay_name.c_str());
-               }
+               sync->sync_view(b_v3d, b_rv3d, width, height);
        }
        else {
-               /* for final render we will do full data sync per render layer, only
-                * do some basic syncing here, no objects or materials for speed */
-               sync->sync_view_layers(b_v3d, NULL);
-               sync->sync_integrator();
                sync->sync_camera(b_render, b_camera_override, width, height, "");
        }
-#endif
 
        /* set buffer parameters */
        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
@@ -218,20 +203,11 @@ void BlenderSession::reset_session(BL::BlendData& b_data_, BL::Scene& b_scene_)
         */
        session->stats.mem_peak = session->stats.mem_used;
 
-#if 0
        /* There is no single depsgraph to use for the entire render.
         * See note on create_session().
         */
        /* sync object should be re-created */
-       sync = new BlenderSync(b_engine, b_data, b_depsgraph, b_scene, scene, !background, session->progress);
-
-       /* for final render we will do full data sync per render layer, only
-        * do some basic syncing here, no objects or materials for speed */
-       BL::Object b_camera_override(b_engine.camera_override());
-       sync->sync_view_layers(b_v3d, NULL);
-       sync->sync_integrator();
-       sync->sync_camera(b_render, b_camera_override, width, height, "");
-#endif
+       sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
 
        BL::SpaceView3D b_null_space_view3d(PointerRNA_NULL);
        BL::RegionView3D b_null_region_view3d(PointerRNA_NULL);
@@ -379,7 +355,7 @@ void BlenderSession::update_render_tile(RenderTile& rtile, bool highlight)
                do_write_update_render_tile(rtile, false, false);
 }
 
-void BlenderSession::render()
+void BlenderSession::render(BL::Depsgraph& b_depsgraph)
 {
        /* set callback to write out render results */
        session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
@@ -390,122 +366,109 @@ void BlenderSession::render()
        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
 
        /* render each layer */
-       BL::Scene::view_layers_iterator b_layer_iter;
-       BL::RenderResult::views_iterator b_view_iter;
+       BL::ViewLayer b_view_layer = b_depsgraph.view_layer();
 
        /* We do some special meta attributes when we only have single layer. */
        const bool is_single_layer = (b_scene.view_layers.length() == 1);
 
-       for(b_scene.view_layers.begin(b_layer_iter); b_layer_iter != b_scene.view_layers.end(); ++b_layer_iter) {
-               b_rlay_name = b_layer_iter->name();
-
-               /* temporary render result to find needed passes and views */
-               BL::RenderResult b_rr = begin_render_result(b_engine, 0, 0, 1, 1, b_rlay_name.c_str(), NULL);
-               BL::RenderResult::layers_iterator b_single_rlay;
-               b_rr.layers.begin(b_single_rlay);
+       /* temporary render result to find needed passes and views */
+       BL::RenderResult b_rr = begin_render_result(b_engine, 0, 0, 1, 1, b_view_layer.name().c_str(), NULL);
+       BL::RenderResult::layers_iterator b_single_rlay;
+       b_rr.layers.begin(b_single_rlay);
+       BL::RenderLayer b_rlay = *b_single_rlay;
 
-               /* layer will be missing if it was disabled in the UI */
-               if(b_single_rlay == b_rr.layers.end()) {
-                       end_render_result(b_engine, b_rr, true, true, false);
-                       continue;
-               }
+       /* add passes */
+       array<Pass> passes = sync->sync_render_passes(b_rlay, b_view_layer, session_params);
+       buffer_params.passes = passes;
+
+       PointerRNA crl = RNA_pointer_get(&b_view_layer.ptr, "cycles");
+       bool use_denoising = get_boolean(crl, "use_denoising");
+       buffer_params.denoising_data_pass = use_denoising;
+       session->tile_manager.schedule_denoising = use_denoising;
+       session->params.use_denoising = use_denoising;
+       scene->film->denoising_data_pass = buffer_params.denoising_data_pass;
+       scene->film->denoising_flags = 0;
+       if(!get_boolean(crl, "denoising_diffuse_direct"))        scene->film->denoising_flags |= DENOISING_CLEAN_DIFFUSE_DIR;
+       if(!get_boolean(crl, "denoising_diffuse_indirect"))      scene->film->denoising_flags |= DENOISING_CLEAN_DIFFUSE_IND;
+       if(!get_boolean(crl, "denoising_glossy_direct"))         scene->film->denoising_flags |= DENOISING_CLEAN_GLOSSY_DIR;
+       if(!get_boolean(crl, "denoising_glossy_indirect"))       scene->film->denoising_flags |= DENOISING_CLEAN_GLOSSY_IND;
+       if(!get_boolean(crl, "denoising_transmission_direct"))   scene->film->denoising_flags |= DENOISING_CLEAN_TRANSMISSION_DIR;
+       if(!get_boolean(crl, "denoising_transmission_indirect")) scene->film->denoising_flags |= DENOISING_CLEAN_TRANSMISSION_IND;
+       if(!get_boolean(crl, "denoising_subsurface_direct"))     scene->film->denoising_flags |= DENOISING_CLEAN_SUBSURFACE_DIR;
+       if(!get_boolean(crl, "denoising_subsurface_indirect"))   scene->film->denoising_flags |= DENOISING_CLEAN_SUBSURFACE_IND;
+       scene->film->denoising_clean_pass = (scene->film->denoising_flags & DENOISING_CLEAN_ALL_PASSES);
+       buffer_params.denoising_clean_pass = scene->film->denoising_clean_pass;
+       session->params.denoising_radius = get_int(crl, "denoising_radius");
+       session->params.denoising_strength = get_float(crl, "denoising_strength");
+       session->params.denoising_feature_strength = get_float(crl, "denoising_feature_strength");
+       session->params.denoising_relative_pca = get_boolean(crl, "denoising_relative_pca");
+
+       scene->film->pass_alpha_threshold = b_view_layer.pass_alpha_threshold();
+       scene->film->tag_passes_update(scene, passes);
+       scene->film->tag_update(scene);
+       scene->integrator->tag_update(scene);
 
-               BL::RenderLayer b_rlay = *b_single_rlay;
-
-               /* add passes */
-               array<Pass> passes = sync->sync_render_passes(b_rlay, *b_layer_iter, session_params);
-               buffer_params.passes = passes;
-
-               PointerRNA crl = RNA_pointer_get(&b_layer_iter->ptr, "cycles");
-               bool use_denoising = get_boolean(crl, "use_denoising");
-               buffer_params.denoising_data_pass = use_denoising;
-               session->tile_manager.schedule_denoising = use_denoising;
-               session->params.use_denoising = use_denoising;
-               scene->film->denoising_data_pass = buffer_params.denoising_data_pass;
-               scene->film->denoising_flags = 0;
-               if(!get_boolean(crl, "denoising_diffuse_direct"))        scene->film->denoising_flags |= DENOISING_CLEAN_DIFFUSE_DIR;
-               if(!get_boolean(crl, "denoising_diffuse_indirect"))      scene->film->denoising_flags |= DENOISING_CLEAN_DIFFUSE_IND;
-               if(!get_boolean(crl, "denoising_glossy_direct"))         scene->film->denoising_flags |= DENOISING_CLEAN_GLOSSY_DIR;
-               if(!get_boolean(crl, "denoising_glossy_indirect"))       scene->film->denoising_flags |= DENOISING_CLEAN_GLOSSY_IND;
-               if(!get_boolean(crl, "denoising_transmission_direct"))   scene->film->denoising_flags |= DENOISING_CLEAN_TRANSMISSION_DIR;
-               if(!get_boolean(crl, "denoising_transmission_indirect")) scene->film->denoising_flags |= DENOISING_CLEAN_TRANSMISSION_IND;
-               if(!get_boolean(crl, "denoising_subsurface_direct"))     scene->film->denoising_flags |= DENOISING_CLEAN_SUBSURFACE_DIR;
-               if(!get_boolean(crl, "denoising_subsurface_indirect"))   scene->film->denoising_flags |= DENOISING_CLEAN_SUBSURFACE_IND;
-               scene->film->denoising_clean_pass = (scene->film->denoising_flags & DENOISING_CLEAN_ALL_PASSES);
-               buffer_params.denoising_clean_pass = scene->film->denoising_clean_pass;
-               session->params.denoising_radius = get_int(crl, "denoising_radius");
-               session->params.denoising_strength = get_float(crl, "denoising_strength");
-               session->params.denoising_feature_strength = get_float(crl, "denoising_feature_strength");
-               session->params.denoising_relative_pca = get_boolean(crl, "denoising_relative_pca");
-
-               scene->film->pass_alpha_threshold = b_layer_iter->pass_alpha_threshold();
-               scene->film->tag_passes_update(scene, passes);
-               scene->film->tag_update(scene);
-               scene->integrator->tag_update(scene);
-
-               int view_index = 0;
-               for(b_rr.views.begin(b_view_iter); b_view_iter != b_rr.views.end(); ++b_view_iter, ++view_index) {
-                       b_rview_name = b_view_iter->name();
-
-                       /* set the current view */
-                       b_engine.active_view_set(b_rview_name.c_str());
-
-                       /* update scene */
-                       BL::Object b_camera_override(b_engine.camera_override());
-                       sync->sync_camera(b_render, b_camera_override, width, height, b_rview_name.c_str());
-                       sync->sync_data(b_render,
-                                       b_v3d,
-                                       b_camera_override,
-                                       width, height,
-                                       &python_thread_state,
-                                       b_rlay_name.c_str());
-
-                       /* Make sure all views have different noise patterns. - hardcoded value just to make it random */
-                       if(view_index != 0) {
-                               scene->integrator->seed += hash_int_2d(scene->integrator->seed, hash_int(view_index * 0xdeadbeef));
-                               scene->integrator->tag_update(scene);
-                       }
+       BL::RenderResult::views_iterator b_view_iter;
+       int view_index = 0;
+       for(b_rr.views.begin(b_view_iter); b_view_iter != b_rr.views.end(); ++b_view_iter, ++view_index) {
+               b_rlay_name = b_view_layer.name();
+               b_rview_name = b_view_iter->name();
 
-                       /* Update number of samples per layer. */
-                       int samples = sync->get_layer_samples();
-                       bool bound_samples = sync->get_layer_bound_samples();
-                       int effective_layer_samples;
+               /* set the current view */
+               b_engine.active_view_set(b_rview_name.c_str());
 
-                       if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
-                               effective_layer_samples = samples;
-                       else
-                               effective_layer_samples = session_params.samples;
+               /* update scene */
+               BL::Object b_camera_override(b_engine.camera_override());
+               sync->sync_camera(b_render, b_camera_override, width, height, b_rview_name.c_str());
+               sync->sync_data(b_render,
+                                               b_depsgraph,
+                                               b_v3d,
+                                               b_camera_override,
+                                               width, height,
+                                               &python_thread_state);
 
-                       /* Update tile manager if we're doing resumable render. */
-                       update_resumable_tile_manager(effective_layer_samples);
+               /* Make sure all views have different noise patterns. - hardcoded value just to make it random */
+               if(view_index != 0) {
+                       scene->integrator->seed += hash_int_2d(scene->integrator->seed, hash_int(view_index * 0xdeadbeef));
+                       scene->integrator->tag_update(scene);
+               }
 
-                       /* Update session itself. */
-                       session->reset(buffer_params, effective_layer_samples);
+               /* Update number of samples per layer. */
+               int samples = sync->get_layer_samples();
+               bool bound_samples = sync->get_layer_bound_samples();
+               int effective_layer_samples;
 
-                       /* render */
-                       session->start();
-                       session->wait();
+               if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
+                       effective_layer_samples = samples;
+               else
+                       effective_layer_samples = session_params.samples;
 
-                       if(session->progress.get_cancel())
-                               break;
-               }
+               /* Update tile manager if we're doing resumable render. */
+               update_resumable_tile_manager(effective_layer_samples);
 
-               if(is_single_layer) {
-                       BL::RenderResult b_rr = b_engine.get_result();
-                       string num_aa_samples = string_printf("%d", session->params.samples);
-                       b_rr.stamp_data_add_field("Cycles Samples", num_aa_samples.c_str());
-                       /* TODO(sergey): Report whether we're doing resumable render
-                        * and also start/end sample if so.
-                        */
-               }
+               /* Update session itself. */
+               session->reset(buffer_params, effective_layer_samples);
 
-               /* free result without merging */
-               end_render_result(b_engine, b_rr, true, true, false);
+               /* render */
+               session->start();
+               session->wait();
 
                if(session->progress.get_cancel())
                        break;
        }
 
+       if(is_single_layer) {
+               BL::RenderResult b_rr = b_engine.get_result();
+               string num_aa_samples = string_printf("%d", session->params.samples);
+               b_rr.stamp_data_add_field("Cycles Samples", num_aa_samples.c_str());
+               /* TODO(sergey): Report whether we're doing resumable render
+                * and also start/end sample if so.
+                */
+       }
+
+       /* free result without merging */
+       end_render_result(b_engine, b_rr, true, true, false);
+
        double total_time, render_time;
        session->progress.get_time(total_time, render_time);
        VLOG(1) << "Total render time: " << total_time;
@@ -515,6 +478,8 @@ void BlenderSession::render()
        session->write_render_tile_cb = function_null;
        session->update_render_tile_cb = function_null;
 
+       /* TODO: find a way to clear this data for persistent data render */
+#if 0
        /* free all memory used (host and device), so we wouldn't leave render
         * engine with extra memory allocated
         */
@@ -523,6 +488,7 @@ void BlenderSession::render()
 
        delete sync;
        sync = NULL;
+#endif
 }
 
 static void populate_bake_data(BakeData *data, const
@@ -571,7 +537,8 @@ static int bake_pass_filter_get(const int pass_filter)
        return flag;
 }
 
-void BlenderSession::bake(BL::Object& b_object,
+void BlenderSession::bake(BL::Depsgraph& b_depsgraph,
+                          BL::Object& b_object,
                           const string& pass_type,
                           const int pass_filter,
                           const int object_id,
@@ -612,11 +579,11 @@ void BlenderSession::bake(BL::Object& b_object,
                BL::Object b_camera_override(b_engine.camera_override());
                sync->sync_camera(b_render, b_camera_override, width, height, "");
                sync->sync_data(b_render,
+                                               b_depsgraph,
                                                b_v3d,
                                                b_camera_override,
                                                width, height,
-                                               &python_thread_state,
-                                               b_rlay_name.c_str());
+                                               &python_thread_state);
        }
 
        BakeData *bake_data = NULL;
@@ -750,7 +717,7 @@ void BlenderSession::update_render_result(BL::RenderResult& b_rr,
        do_write_update_render_result(b_rr, b_rlay, rtile, true);
 }
 
-void BlenderSession::synchronize()
+void BlenderSession::synchronize(BL::Depsgraph& b_depsgraph)
 {
        /* only used for viewport render */
        if(!b_v3d)
@@ -793,11 +760,11 @@ void BlenderSession::synchronize()
        /* data and camera synchronize */
        BL::Object b_camera_override(b_engine.camera_override());
        sync->sync_data(b_render,
+                       b_depsgraph,
                        b_v3d,
                        b_camera_override,
                        width, height,
-                       &python_thread_state,
-                       b_rlay_name.c_str());
+                       &python_thread_state);
 
        if(b_rv3d)
                sync->sync_view(b_v3d, b_rv3d, width, height);
@@ -1318,6 +1285,7 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
                fprintf(stderr, "Cycles error: unexpected smoke volume resolution, skipping\n");
        }
        else {
+               /* TODO: fix point density to work with new view layer depsgraph */
 #if 0
                /* We originally were passing view_layer here but in reality we need a whole EvaluationContext
                 * in the RE_point_density_minmax() function.
index cbd2303d2825b04e3582308261a7e0e78c0736f2..bd71087c16a8cbb540dac80926c9eeb553a9976a 100644 (file)
@@ -58,9 +58,10 @@ public:
                           BL::Scene& b_scene);
 
        /* offline render */
-       void render();
+       void render(BL::Depsgraph& b_depsgraph);
 
-       void bake(BL::Object& b_object,
+       void bake(BL::Depsgraph& b_depsgrah,
+                 BL::Object& b_object,
                  const string& pass_type,
                  const int custom_flag,
                  const int object_id,
@@ -82,7 +83,7 @@ public:
        void update_render_tile(RenderTile& rtile, bool highlight);
 
        /* interactive updates */
-       void synchronize();
+       void synchronize(BL::Depsgraph& b_depsgraph);
 
        /* drawing */
        bool draw(int w, int h);
index 7d3abe35b2005104c4504a9bdbad8b9e7963c906..15689ca2391cae42f0c96d531fc6b82970153b90 100644 (file)
@@ -235,8 +235,7 @@ static ShaderNode *add_node(Scene *scene,
                             BL::RenderEngine& b_engine,
                             BL::BlendData& b_data,
                             BL::Scene& b_scene,
-                            BL::ViewLayer b_view_layer,
-                            const bool background,
+                            const bool /*background*/,
                             ShaderGraph *graph,
                             BL::ShaderNodeTree& b_ntree,
                             BL::ShaderNode& b_node)
@@ -835,6 +834,8 @@ static ShaderNode *add_node(Scene *scene,
                node = uvm;
        }
        else if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
+               /* TODO: fix point density to work with new view layer depsgraph */
+#if 0
                BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
                PointDensityTextureNode *point_density = new PointDensityTextureNode();
                point_density->filename = b_point_density_node.name();
@@ -874,6 +875,7 @@ static ShaderNode *add_node(Scene *scene,
                                transform_translate(-loc) * transform_scale(size) *
                                transform_inverse(get_transform(b_ob.matrix_world()));
                }
+#endif
        }
        else if(b_node.is_a(&RNA_ShaderNodeBevel)) {
                BL::ShaderNodeBevel b_bevel_node(b_node);
@@ -1006,7 +1008,6 @@ static void add_nodes(Scene *scene,
                       BL::RenderEngine& b_engine,
                       BL::BlendData& b_data,
                       BL::Scene& b_scene,
-                      BL::ViewLayer& b_view_layer,
                       const bool background,
                       ShaderGraph *graph,
                       BL::ShaderNodeTree& b_ntree,
@@ -1093,7 +1094,6 @@ static void add_nodes(Scene *scene,
                                          b_engine,
                                          b_data,
                                          b_scene,
-                                         b_view_layer,
                                          background,
                                          graph,
                                          b_group_ntree,
@@ -1141,7 +1141,6 @@ static void add_nodes(Scene *scene,
                                                b_engine,
                                                b_data,
                                                b_scene,
-                                               b_view_layer,
                                                background,
                                                graph,
                                                b_ntree,
@@ -1205,7 +1204,6 @@ static void add_nodes(Scene *scene,
                       BL::RenderEngine& b_engine,
                       BL::BlendData& b_data,
                       BL::Scene& b_scene,
-                      BL::ViewLayer& b_view_layer,
                       const bool background,
                       ShaderGraph *graph,
                       BL::ShaderNodeTree& b_ntree)
@@ -1215,7 +1213,6 @@ static void add_nodes(Scene *scene,
                  b_engine,
                  b_data,
                  b_scene,
-                 b_view_layer,
                  background,
                  graph,
                  b_ntree,
@@ -1225,7 +1222,7 @@ static void add_nodes(Scene *scene,
 
 /* Sync Materials */
 
-void BlenderSync::sync_materials(bool update_all)
+void BlenderSync::sync_materials(BL::Depsgraph& b_depsgraph, bool update_all)
 {
        shader_map.set_default(scene->default_surface);
 
@@ -1254,7 +1251,7 @@ void BlenderSync::sync_materials(bool update_all)
                        if(b_mat->use_nodes() && b_mat->node_tree()) {
                                BL::ShaderNodeTree b_ntree(b_mat->node_tree());
 
-                               add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
+                               add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
                        }
                        else {
                                DiffuseBsdfNode *diffuse = new DiffuseBsdfNode();
@@ -1325,7 +1322,7 @@ void BlenderSync::sync_world(bool update_all)
                if(b_world && b_world.use_nodes() && b_world.node_tree()) {
                        BL::ShaderNodeTree b_ntree(b_world.node_tree());
 
-                       add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
+                       add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
 
                        /* volume */
                        PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
@@ -1402,7 +1399,7 @@ void BlenderSync::sync_world(bool update_all)
 
 /* Sync Lamps */
 
-void BlenderSync::sync_lamps(bool update_all)
+void BlenderSync::sync_lamps(BL::Depsgraph& b_depsgraph, bool update_all)
 {
        shader_map.set_default(scene->default_light);
 
@@ -1427,7 +1424,7 @@ void BlenderSync::sync_lamps(bool update_all)
 
                                BL::ShaderNodeTree b_ntree(b_lamp->node_tree());
 
-                               add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
+                               add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
                        }
                        else {
                                float strength = 1.0f;
@@ -1454,7 +1451,7 @@ void BlenderSync::sync_lamps(bool update_all)
        }
 }
 
-void BlenderSync::sync_shaders()
+void BlenderSync::sync_shaders(BL::Depsgraph& b_depsgraph)
 {
        /* for auto refresh images */
        bool auto_refresh_update = false;
@@ -1468,8 +1465,8 @@ void BlenderSync::sync_shaders()
        shader_map.pre_sync();
 
        sync_world(auto_refresh_update);
-       sync_lamps(auto_refresh_update);
-       sync_materials(auto_refresh_update);
+       sync_lamps(b_depsgraph, auto_refresh_update);
+       sync_materials(b_depsgraph, auto_refresh_update);
 
        /* false = don't delete unused shaders, not supported */
        shader_map.post_sync(false);
index 148db9fc3cfb9f7701191275ae08051dec3acf72..bf35f61f07b6e73787e453a9aa9be59212f1ed76 100644 (file)
@@ -44,17 +44,13 @@ CCL_NAMESPACE_BEGIN
 
 BlenderSync::BlenderSync(BL::RenderEngine& b_engine,
                          BL::BlendData& b_data,
-                         BL::Depsgraph& b_depsgraph,
                          BL::Scene& b_scene,
-                         BL::ViewLayer& b_view_layer,
                          Scene *scene,
                          bool preview,
                          Progress &progress)
 : b_engine(b_engine),
   b_data(b_data),
-  b_depsgraph(b_depsgraph),
   b_scene(b_scene),
-  b_view_layer(b_view_layer),
   shader_map(&scene->shaders),
   object_map(&scene->objects),
   mesh_map(&scene->meshes),
@@ -193,16 +189,18 @@ bool BlenderSync::sync_recalc()
 }
 
 void BlenderSync::sync_data(BL::RenderSettings& b_render,
+                               BL::Depsgraph& b_depsgraph,
                             BL::SpaceView3D& b_v3d,
                             BL::Object& b_override,
                             int width, int height,
-                            void **python_thread_state,
-                            const char *layer)
+                            void **python_thread_state)
 {
-       sync_view_layers(b_v3d, layer);
+       BL::ViewLayer b_view_layer = b_depsgraph.view_layer();
+
+       sync_view_layer(b_v3d, b_view_layer);
        sync_integrator();
        sync_film();
-       sync_shaders();
+       sync_shaders(b_depsgraph);
        sync_images();
        sync_curve_settings();
 
@@ -212,9 +210,10 @@ void BlenderSync::sync_data(BL::RenderSettings& b_render,
           scene->need_motion() == Scene::MOTION_NONE ||
           scene->camera->motion_position == Camera::MOTION_POSITION_CENTER)
        {
-               sync_objects();
+               sync_objects(b_depsgraph);
        }
        sync_motion(b_render,
+                   b_depsgraph,
                    b_override,
                    width, height,
                    python_thread_state);
@@ -373,47 +372,31 @@ void BlenderSync::sync_film()
 
 /* Render Layer */
 
-void BlenderSync::sync_view_layers(BL::SpaceView3D& b_v3d, const char *layer)
+void BlenderSync::sync_view_layer(BL::SpaceView3D& /*b_v3d*/, BL::ViewLayer& b_view_layer)
 {
-       string layername;
-
-       /* 3d view */
-       if(b_v3d) {
-               layername = b_scene.view_layers.active().name();
-               layer = layername.c_str();
-       }
-
        /* render layer */
-       BL::Scene::view_layers_iterator b_view_layer;
-       bool first_layer = true;
        uint layer_override = get_layer(b_engine.layer_override());
        uint view_layers = layer_override ? layer_override : get_layer(b_scene.layers());
 
-       for(b_scene.view_layers.begin(b_view_layer); b_view_layer != b_scene.view_layers.end(); ++b_view_layer) {
-               if((!layer && first_layer) || (layer && b_view_layer->name() == layer)) {
-                       view_layer.name = b_view_layer->name();
+       view_layer.name = b_view_layer.name();
 
-                       view_layer.holdout_layer = 0;
-                       view_layer.exclude_layer = 0;
+       view_layer.holdout_layer = 0;
+       view_layer.exclude_layer = 0;
 
-                       view_layer.view_layer = view_layers & ~view_layer.exclude_layer;
-                       view_layer.view_layer |= view_layer.exclude_layer & view_layer.holdout_layer;
+       view_layer.view_layer = view_layers & ~view_layer.exclude_layer;
+       view_layer.view_layer |= view_layer.exclude_layer & view_layer.holdout_layer;
 
-                       view_layer.layer = (1 << 20) - 1;
-                       view_layer.layer |= view_layer.holdout_layer;
+       view_layer.layer = (1 << 20) - 1;
+       view_layer.layer |= view_layer.holdout_layer;
 
-                       view_layer.material_override = PointerRNA_NULL;
-                       view_layer.use_background_shader = b_view_layer->use_sky();
-                       view_layer.use_background_ao = b_view_layer->use_ao();
-                       view_layer.use_surfaces = b_view_layer->use_solid();
-                       view_layer.use_hair = b_view_layer->use_strand();
+       view_layer.material_override = PointerRNA_NULL;
+       view_layer.use_background_shader = b_view_layer.use_sky();
+       view_layer.use_background_ao = b_view_layer.use_ao();
+       view_layer.use_surfaces = b_view_layer.use_solid();
+       view_layer.use_hair = b_view_layer.use_strand();
 
-                       view_layer.bound_samples = false;
-                       view_layer.samples = 0;
-               }
-
-               first_layer = false;
-       }
+       view_layer.bound_samples = false;
+       view_layer.samples = 0;
 }
 
 /* Images */
index ce9155ee7ef4afd6388d8e41326890d8c7174f56..79ee22d5a352be0f5405fcf1bd0a80cadfa5934f 100644 (file)
@@ -52,9 +52,7 @@ class BlenderSync {
 public:
        BlenderSync(BL::RenderEngine& b_engine,
                    BL::BlendData& b_data,
-                   BL::Depsgraph& b_graph,
                    BL::Scene& b_scene,
-                   BL::ViewLayer& b_view_layer,
                    Scene *scene,
                    bool preview,
                    Progress &progress);
@@ -63,12 +61,12 @@ public:
        /* sync */
        bool sync_recalc();
        void sync_data(BL::RenderSettings& b_render,
+                      BL::Depsgraph& b_depsgraph,
                       BL::SpaceView3D& b_v3d,
                       BL::Object& b_override,
                       int width, int height,
-                      void **python_thread_state,
-                      const char *layer = 0);
-       void sync_view_layers(BL::SpaceView3D& b_v3d, const char *layer);
+                      void **python_thread_state);
+       void sync_view_layer(BL::SpaceView3D& b_v3d, BL::ViewLayer& b_view_layer);
        array<Pass> sync_render_passes(BL::RenderLayer& b_render_layer,
                                       BL::ViewLayer& b_view_layer,
                                       const SessionParams &session_params);
@@ -102,30 +100,34 @@ public:
 
 private:
        /* sync */
-       void sync_lamps(bool update_all);
-       void sync_materials(bool update_all);
-       void sync_objects(float motion_time = 0.0f);
+       void sync_lamps(BL::Depsgraph& b_depsgraph, bool update_all);
+       void sync_materials(BL::Depsgraph& b_depsgraph, bool update_all);
+       void sync_objects(BL::Depsgraph& b_depsgraph, float motion_time = 0.0f);
        void sync_motion(BL::RenderSettings& b_render,
+                     BL::Depsgraph& b_depsgraph,
                         BL::Object& b_override,
                         int width, int height,
                         void **python_thread_state);
        void sync_film();
        void sync_view();
        void sync_world(bool update_all);
-       void sync_shaders();
+       void sync_shaders(BL::Depsgraph& b_depsgraph);
        void sync_curve_settings();
 
        void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
-       Mesh *sync_mesh(BL::Object& b_ob,
+       Mesh *sync_mesh(BL::Depsgraph& b_depsgrpah,
+                       BL::Object& b_ob,
                        BL::Object& b_ob_instance,
                        bool object_updated,
                        bool hide_tris);
-       void sync_curves(Mesh *mesh,
+       void sync_curves(BL::Depsgraph& b_depsgraph,
+                        Mesh *mesh,
                         BL::Mesh& b_mesh,
                         BL::Object& b_ob,
                         bool motion,
                         int time_index = 0);
-       Object *sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
+       Object *sync_object(BL::Depsgraph& b_depsgraph,
+                           BL::Depsgraph::duplis_iterator& b_dupli_iter,
                            uint layer_flag,
                            float motion_time,
                            bool hide_tris,
@@ -139,7 +141,8 @@ private:
                        Transform& tfm,
                        bool *use_portal);
        void sync_background_light(bool use_portal);
-       void sync_mesh_motion(BL::Object& b_ob,
+       void sync_mesh_motion(BL::Depsgraph& b_depsgraph,
+                             BL::Object& b_ob,
                              Object *object,
                              float motion_time);
        void sync_camera_motion(BL::RenderSettings& b_render,
@@ -164,9 +167,7 @@ private:
        /* variables */
        BL::RenderEngine b_engine;
        BL::BlendData b_data;
-       BL::Depsgraph b_depsgraph;
        BL::Scene b_scene;
-       BL::ViewLayer b_view_layer;
 
        id_map<void*, Shader> shader_map;
        id_map<ObjectKey, Object> object_map;
index 99567872103f320578c7f0190241172867572c7d..6afcc73e16dfd5ad3b70bf9280d01679481e4a7c 100644 (file)
@@ -182,7 +182,7 @@ static void engine_render_to_image(RenderEngine *engine, Depsgraph *depsgraph)
        RNA_parameter_list_free(&list);
 }
 
-static void engine_bake(RenderEngine *engine, struct Scene *scene,
+static void engine_bake(RenderEngine *engine, struct Depsgraph *depsgraph, struct Scene *scene,
                         struct Object *object, const int pass_type, const int pass_filter,
                         const int object_id, const struct BakePixel *pixel_array,
                         const int num_pixels, const int depth, void *result)
@@ -196,6 +196,7 @@ static void engine_bake(RenderEngine *engine, struct Scene *scene,
        func = &rna_RenderEngine_bake_func;
 
        RNA_parameter_list_create(&list, &ptr, func);
+       RNA_parameter_set_lookup(&list, "depsgraph", &depsgraph);
        RNA_parameter_set_lookup(&list, "scene", &scene);
        RNA_parameter_set_lookup(&list, "object", &object);
        RNA_parameter_set_lookup(&list, "pass_type", &pass_type);
@@ -501,17 +502,19 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_function_ui_description(func, "Export scene data for render");
        RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
        RNA_def_pointer(func, "data", "BlendData", "", "");
-       RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
        RNA_def_pointer(func, "scene", "Scene", "", "");
 
        func = RNA_def_function(srna, "render_to_image", NULL);
        RNA_def_function_ui_description(func, "Render scene into an image");
        RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
-       RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
+       parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 
        func = RNA_def_function(srna, "bake", NULL);
        RNA_def_function_ui_description(func, "Bake passes");
        RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+       parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
        parm = RNA_def_pointer(func, "scene", "Scene", "", "");
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
        parm = RNA_def_pointer(func, "object", "Object", "", "");
index b1e5ff9890b3ec713878a8e557dc108c41200d40..ad0cb34d3821e86a1fec04ddd1fba1dea3fb32a2 100644 (file)
@@ -94,7 +94,8 @@ typedef struct RenderEngineType {
 
        void (*update)(struct RenderEngine *engine, struct Main *bmain, struct Scene *scene);
        void (*render_to_image)(struct RenderEngine *engine, struct Depsgraph *depsgraph);
-       void (*bake)(struct RenderEngine *engine, struct Scene *scene, struct Object *object, const int pass_type,
+       void (*bake)(struct RenderEngine *engine, struct Depsgraph *depsgraph,
+                    struct Scene *scene, struct Object *object, const int pass_type,
                     const int pass_filter, const int object_id, const struct BakePixel *pixel_array, const int num_pixels,
                     const int depth, void *result);
 
index 61ed19a1c9aa36560d1bc2c227816e49dbc13dec..1b8ab4d81219e10b5d68342cae61739fecb1e752 100644 (file)
@@ -584,17 +584,32 @@ bool RE_bake_engine(
                type->update(engine, re->main, re->scene);
 
        if (type->bake) {
-               type->bake(
-                           engine,
-                           re->scene,
-                           object,
-                           pass_type,
-                           pass_filter,
-                           object_id,
-                           pixel_array,
-                           num_pixels,
-                           depth,
-                           result);
+               EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
+               Depsgraph *depsgraph = DEG_graph_new();
+               ViewLayer *view_layer = BLI_findlink(&re->scene->view_layers, re->scene->active_view_layer);
+
+               DEG_evaluation_context_init_from_view_layer_for_render(
+                                       eval_ctx,
+                                       depsgraph,
+                                       re->scene,
+                                       view_layer);
+
+               BKE_scene_graph_update_tagged(eval_ctx, depsgraph, re->main, re->scene, view_layer);
+
+               type->bake(engine,
+                          depsgraph,
+                          re->scene,
+                          object,
+                          pass_type,
+                          pass_filter,
+                          object_id,
+                          pixel_array,
+                          num_pixels,
+                          depth,
+                          result);
+
+               DEG_graph_free(depsgraph);
+               DEG_evaluation_context_free(eval_ctx);
        }
 
        engine->tile_x = 0;