Merge branch 'master' into blender2.8
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 8 Nov 2018 14:13:43 +0000 (15:13 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 8 Nov 2018 14:15:29 +0000 (15:15 +0100)
1  2 
build_files/cmake/platform/platform_win32.cmake
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_util.h
intern/cycles/render/shader.cpp
intern/cycles/render/shader.h
source/blender/blenkernel/intern/image.c
source/blender/makesrna/intern/rna_render.c

index 22a64df0c846a7d7b0a694763df4390c44b3b4fe,75c7dcee05e9a023b9886e45a69045b70713912d..b639dcc4b008637a99f34fa24087b2d6d8d9f0d0
@@@ -382,10 -371,19 +383,21 @@@ void BlenderSession::update_render_tile
                do_write_update_render_tile(rtile, false, false);
  }
  
 -void BlenderSession::render()
+ static void add_cryptomatte_layer(BL::RenderResult& b_rr, string name, string manifest)
+ {
+       string identifier = string_printf("%08x", util_murmur_hash3(name.c_str(), name.length(), 0));
+       string prefix = "cryptomatte/" + identifier.substr(0, 7) + "/";
+       render_add_metadata(b_rr, prefix+"name", name);
+       render_add_metadata(b_rr, prefix+"hash", "MurmurHash3_32");
+       render_add_metadata(b_rr, prefix+"conversion", "uint32_to_float32");
+       render_add_metadata(b_rr, prefix+"manifest", manifest);
+ }
 +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);
        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
  
        /* render each layer */
 -      BL::RenderSettings r = b_scene.render();
 -      BL::RenderSettings::layers_iterator b_layer_iter;
 -      BL::RenderResult::views_iterator b_view_iter;
 +      BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
  
        /* We do some special meta attributes when we only have single layer. */
 -      const bool is_single_layer = (r.layers.length() == 1);
 -
 -      for(r.layers.begin(b_layer_iter); b_layer_iter != r.layers.end(); ++b_layer_iter) {
 -              b_rlay_name = b_layer_iter->name();
 +      const bool is_single_layer = (b_scene.view_layers.length() == 1);
  
 -              /* 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);
 -
 -              /* 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;
 -              }
 -
 -              BL::RenderLayer b_rlay = *b_single_rlay;
 -
 -              /* add passes */
 -              vector<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");
 -              bool denoising_passes = use_denoising || get_boolean(crl, "denoising_store_passes");
 -
 -              session->tile_manager.schedule_denoising = use_denoising;
 -              buffer_params.denoising_data_pass = denoising_passes;
 -              buffer_params.denoising_clean_pass = (scene->film->denoising_flags & DENOISING_CLEAN_ALL_PASSES);
 -
 -              session->params.use_denoising = use_denoising;
 -              session->params.denoising_passes = denoising_passes;
 -              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->denoising_data_pass = buffer_params.denoising_data_pass;
 -              scene->film->denoising_clean_pass = buffer_params.denoising_clean_pass;
 -              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);
 -                      }
 -
 -                      /* Update number of samples per layer. */
 -                      int samples = sync->get_layer_samples();
 -                      bool bound_samples = sync->get_layer_bound_samples();
 -                      int effective_layer_samples;
 +      /* 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;
++      b_rlay_name = b_view_layer.name();
 +
 +      /* add passes */
 +      vector<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");
 +      bool denoising_passes = use_denoising || get_boolean(crl, "denoising_store_passes");
 +
 +      session->tile_manager.schedule_denoising = use_denoising;
 +      buffer_params.denoising_data_pass = denoising_passes;
 +      buffer_params.denoising_clean_pass = (scene->film->denoising_flags & DENOISING_CLEAN_ALL_PASSES);
 +
 +      session->params.use_denoising = use_denoising;
 +      session->params.denoising_passes = denoising_passes;
 +      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->denoising_data_pass = buffer_params.denoising_data_pass;
 +      scene->film->denoising_clean_pass = buffer_params.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);
  
 -                      if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
 -                              effective_layer_samples = samples;
 -                      else
 -                              effective_layer_samples = session_params.samples;
 +      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 tile manager if we're doing resumable render. */
 -                      update_resumable_tile_manager(effective_layer_samples);
 +              /* set the current view */
 +              b_engine.active_view_set(b_rview_name.c_str());
  
 -                      /* Update session itself. */
 -                      session->reset(buffer_params, effective_layer_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);
 +              builtin_images_load();
 +
 +              /* 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);
 +              }
  
 -                      /* render */
 -                      session->start();
 -                      session->wait();
 +              int effective_layer_samples = session_params.samples;
  
 -                      if(session->progress.get_cancel())
 -                              break;
 -              }
 +              /* TODO: Update number of samples per layer. */
 +#if 0
 +              if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
 +                      effective_layer_samples = samples;
 +#endif
  
 -              BL::RenderResult b_full_rr = b_engine.get_result();
 -              if(is_single_layer) {
 -                      string num_aa_samples = string_printf("%d", session->params.samples);
 -                      render_add_metadata(b_full_rr, "Cycles Samples", num_aa_samples);
 -                      /* TODO(sergey): Report whether we're doing resumable render
 -                       * and also start/end sample if so.
 -                       */
 -              }
 +              /* Update tile manager if we're doing resumable render. */
 +              update_resumable_tile_manager(effective_layer_samples);
  
 -              if(scene->film->cryptomatte_passes & CRYPT_OBJECT) {
 -                      add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoObject",
 -                                            scene->object_manager->get_cryptomatte_objects(scene));
 -              }
 -              if(scene->film->cryptomatte_passes & CRYPT_MATERIAL) {
 -                      add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoMaterial",
 -                                            scene->shader_manager->get_cryptomatte_materials(scene));
 -              }
 -              if(scene->film->cryptomatte_passes & CRYPT_ASSET) {
 -                      add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoAsset",
 -                                            scene->object_manager->get_cryptomatte_assets(scene));
 -              }
 +              /* 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(!b_engine.is_preview() && background && print_render_stats) {
                        RenderStats stats;
                        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.
 +               */
 +      }
 +
++      /* Write cryptomatte metadata. */
++      if(scene->film->cryptomatte_passes & CRYPT_OBJECT) {
++              add_cryptomatte_layer(b_rr, b_rlay_name+".CryptoObject",
++                                                        scene->object_manager->get_cryptomatte_objects(scene));
++      }
++      if(scene->film->cryptomatte_passes & CRYPT_MATERIAL) {
++              add_cryptomatte_layer(b_rr, b_rlay_name+".CryptoMaterial",
++                                                        scene->shader_manager->get_cryptomatte_materials(scene));
++      }
++      if(scene->film->cryptomatte_passes & CRYPT_ASSET) {
++              add_cryptomatte_layer(b_rr, b_rlay_name+".CryptoAsset",
++                                                        scene->object_manager->get_cryptomatte_assets(scene));
++      }
++
 +      /* 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;
Simple merge
Simple merge
Simple merge