Fix point density rendering in Cycles.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 21 Apr 2018 17:35:12 +0000 (19:35 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 21 Apr 2018 17:43:41 +0000 (19:43 +0200)
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_shader.cpp
source/blender/render/intern/source/pointdensity.c

index 95582b15d63f324e838e19c1c0a02d2728d2b999..e6aabb5fe36280d59a71300804d6e60949189ac2 100644 (file)
@@ -57,6 +57,7 @@ BlenderSession::BlenderSession(BL::RenderEngine& b_engine,
   b_userpref(b_userpref),
   b_data(b_data),
   b_render(b_engine.render()),
+  b_depsgraph(PointerRNA_NULL),
   b_scene(b_scene),
   b_v3d(PointerRNA_NULL),
   b_rv3d(PointerRNA_NULL),
@@ -84,6 +85,7 @@ BlenderSession::BlenderSession(BL::RenderEngine& b_engine,
   b_userpref(b_userpref),
   b_data(b_data),
   b_render(b_scene.render()),
+  b_depsgraph(PointerRNA_NULL),
   b_scene(b_scene),
   b_v3d(b_v3d),
   b_rv3d(b_rv3d),
@@ -357,8 +359,10 @@ void BlenderSession::update_render_tile(RenderTile& rtile, bool highlight)
                do_write_update_render_tile(rtile, false, false);
 }
 
-void BlenderSession::render(BL::Depsgraph& b_depsgraph)
+void BlenderSession::render(BL::Depsgraph& b_depsgraph_)
 {
+       b_depsgraph = b_depsgraph_;
+
        /* set callback to write out render results */
        session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
        session->update_render_tile_cb = function_bind(&BlenderSession::update_render_tile, this, _1, _2);
@@ -539,7 +543,7 @@ static int bake_pass_filter_get(const int pass_filter)
        return flag;
 }
 
-void BlenderSession::bake(BL::Depsgraph& b_depsgraph,
+void BlenderSession::bake(BL::Depsgraph& b_depsgraph_,
                           BL::Object& b_object,
                           const string& pass_type,
                           const int pass_filter,
@@ -549,6 +553,8 @@ void BlenderSession::bake(BL::Depsgraph& b_depsgraph,
                           const int /*depth*/,
                           float result[])
 {
+       b_depsgraph = b_depsgraph_;
+
        ShaderEvalType shader_type = get_shader_type(pass_type);
 
        /* Set baking flag in advance, so kernel loading can check if we need
@@ -719,7 +725,7 @@ void BlenderSession::update_render_result(BL::RenderResult& b_rr,
        do_write_update_render_result(b_rr, b_rlay, rtile, true);
 }
 
-void BlenderSession::synchronize(BL::Depsgraph& b_depsgraph)
+void BlenderSession::synchronize(BL::Depsgraph& b_depsgraph_)
 {
        /* only used for viewport render */
        if(!b_v3d)
@@ -760,6 +766,8 @@ void BlenderSession::synchronize(BL::Depsgraph& b_depsgraph)
        }
 
        /* data and camera synchronize */
+       b_depsgraph = b_depsgraph_;
+
        BL::Object b_camera_override(b_engine.camera_override());
        sync->sync_data(b_render,
                        b_depsgraph,
@@ -1280,8 +1288,6 @@ 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
                 * a depsgraph to pass to the RE_point_density_minmax() function.
                 */
@@ -1292,10 +1298,8 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
                if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
                        BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
                        int length;
-                       int settings = background ? 1 : 0;  /* 1 - render settings, 0 - vewport settings. */
-                       b_point_density_node.calc_point_density(b_depsgraph, settings, &length, &pixels);
+                       b_point_density_node.calc_point_density(b_depsgraph, &length, &pixels);
                }
-#endif
        }
 
        return false;
index 77a64031da1d80585f224a2c204d79c41e095de0..030b542d0dd3d4af4f0f856dda34f3a9b3b4d793 100644 (file)
@@ -106,6 +106,7 @@ public:
        BL::UserPreferences b_userpref;
        BL::BlendData b_data;
        BL::RenderSettings b_render;
+       BL::Depsgraph b_depsgraph;
        BL::Scene b_scene;
        BL::SpaceView3D b_v3d;
        BL::RegionView3D b_rv3d;
index 211375621524817c6e2f2c3c8d5c2a250a094618..ddf18e9f3c72313d99d216351d522009beb31d29 100644 (file)
@@ -834,7 +834,6 @@ 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 */
                BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
                PointDensityTextureNode *point_density = new PointDensityTextureNode();
                point_density->filename = b_point_density_node.name();
index 86f31f79c49310a9660d3a1a85e95ccfb6bea902..a6350e3c4485cde2461302f78067436d6327de4a 100644 (file)
@@ -933,15 +933,11 @@ static void point_density_sample_func(
                        texvec[1] += dim[1] * (float)y / (float)resolution;
                        texvec[2] += dim[2] * (float)z / (float)resolution;
 
-                       if (pointdensity(pd, texvec, &texres, vec, &age, col)) {
-                               pointdensity_color(pd, &texres, age, vec, col);
+                       pointdensity(pd, texvec, &texres, vec, &age, col);
+                       pointdensity_color(pd, &texres, age, vec, col);
 
-                               copy_v3_v3(&values[index*4 + 0], &texres.tr);
-                               values[index*4 + 3] = texres.tin;
-                       }
-                       else {
-                               zero_v4(&values[index*4]);
-                       }
+                       copy_v3_v3(&values[index*4 + 0], &texres.tr);
+                       values[index*4 + 3] = texres.tin;
                }
        }
 }