Cycles: restore old sample and material override settings for view layers.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 28 Dec 2018 17:37:05 +0000 (18:37 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 28 Dec 2018 17:59:33 +0000 (18:59 +0100)
Since there will be no view layer overrides in 2.80, this is needed still.

17 files changed:
intern/cycles/blender/addon/properties.py
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_mesh.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h
source/blender/blenkernel/BKE_layer.h
source/blender/blenkernel/intern/layer.c
source/blender/blenkernel/intern/library_query.c
source/blender/blenloader/intern/versioning_280.c
source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
source/blender/makesdna/DNA_layer_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_scene.c
source/blender/render/intern/source/render_result.c

index 243e0571a97fd1760b79c6a23f1e699f5c50e948..3f6c6de5c5e67da306270a72ce25ae240f58d7cd 100644 (file)
@@ -272,7 +272,7 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
 
     use_layer_samples: EnumProperty(
         name="Layer Samples",
-        description="How to use per render layer sample settings",
+        description="How to use per view layer sample settings",
         items=enum_use_layer_samples,
         default='USE',
     )
index f5e7e98b40eb76b64d5fc83d622478353c38153b..667547633b46bc214abe607614aee94700c1c59a 100644 (file)
@@ -244,6 +244,12 @@ class CYCLES_RENDER_PT_sampling_advanced(CyclesButtonsPanel, Panel):
             col.prop(cscene, "sample_all_lights_direct")
             col.prop(cscene, "sample_all_lights_indirect")
 
+        for view_layer in scene.view_layers:
+            if view_layer.samples > 0:
+                layout.separator()
+                layout.row().prop(cscene, "use_layer_samples")
+                break
+
 
 class CYCLES_RENDER_PT_sampling_total(CyclesButtonsPanel, Panel):
     bl_label = "Total Samples"
@@ -720,6 +726,22 @@ class CYCLES_RENDER_PT_filter(CyclesButtonsPanel, Panel):
             col.active = rd.use_freestyle
 
 
+class CYCLES_RENDER_PT_override(CyclesButtonsPanel, Panel):
+    bl_label = "Override"
+    bl_options = {'DEFAULT_CLOSED'}
+    bl_context = "view_layer"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.use_property_split = True
+        layout.use_property_decorate = False
+
+        view_layer = context.view_layer
+
+        layout.prop(view_layer, "material_override")
+        layout.prop(view_layer, "samples")
+
+
 class CYCLES_RENDER_PT_passes(CyclesButtonsPanel, Panel):
     bl_label = "Passes"
     bl_context = "view_layer"
@@ -2098,6 +2120,7 @@ classes = (
     CYCLES_RENDER_PT_performance_final_render,
     CYCLES_RENDER_PT_performance_viewport,
     CYCLES_RENDER_PT_filter,
+    CYCLES_RENDER_PT_override,
     CYCLES_RENDER_PT_passes,
     CYCLES_RENDER_PT_passes_data,
     CYCLES_RENDER_PT_passes_light,
index 701dba61b5077e57e1b7c93c6fd16f461c60850a..7a85ff27e53e91b55930beb6802729e4df4bfa0c 100644 (file)
@@ -985,18 +985,27 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph& b_depsgraph,
        /* test if we can instance or if the object is modified */
        BL::ID b_ob_data = b_ob.data();
        BL::ID key = (BKE_object_is_modified(b_ob))? b_ob_instance: b_ob_data;
+       BL::Material material_override = view_layer.material_override;
 
        /* find shader indices */
        vector<Shader*> used_shaders;
 
        BL::Object::material_slots_iterator slot;
        for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
-               BL::ID b_material(slot->material());
-               find_shader(b_material, used_shaders, scene->default_surface);
+               if(material_override) {
+                       find_shader(material_override, used_shaders, scene->default_surface);
+               }
+               else {
+                       BL::ID b_material(slot->material());
+                       find_shader(b_material, used_shaders, scene->default_surface);
+               }
        }
 
        if(used_shaders.size() == 0) {
-               used_shaders.push_back(scene->default_surface);
+               if(material_override)
+                       find_shader(material_override, used_shaders, scene->default_surface);
+               else
+                       used_shaders.push_back(scene->default_surface);
        }
 
        /* test if we need to sync */
index 58d3b57a67eea78ef4ce8abac955ac14b15f1578..f84eefd0233d5b30225618d35083f7c7a585d294 100644 (file)
@@ -481,13 +481,15 @@ void BlenderSession::render(BL::Depsgraph& b_depsgraph_)
                        scene->integrator->tag_update(scene);
                }
 
-               int effective_layer_samples = session_params.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;
 
-               /* TODO: Update number of samples per layer. */
-#if 0
                if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
                        effective_layer_samples = samples;
-#endif
+               else
+                       effective_layer_samples = session_params.samples;
 
                /* Update tile manager if we're doing resumable render. */
                update_resumable_tile_manager(effective_layer_samples);
index 38e0e66b91bb65040492901c8944dc3c899696ff..60192bfa8f890b1ec3184a5e67152daf522604bd 100644 (file)
@@ -372,6 +372,25 @@ void BlenderSync::sync_view_layer(BL::SpaceView3D& /*b_v3d*/, BL::ViewLayer& b_v
        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();
+
+       /* Material override. */
+       view_layer.material_override = b_view_layer.material_override();
+
+       /* Sample override. */
+       PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
+       int use_layer_samples = get_enum(cscene, "use_layer_samples");
+
+       view_layer.bound_samples = (use_layer_samples == 1);
+       view_layer.samples = 0;
+
+       if(use_layer_samples != 2) {
+               int samples = b_view_layer.samples();
+               if(get_boolean(cscene, "use_square_samples"))
+                       view_layer.samples = samples * samples;
+               else
+                       view_layer.samples = samples;
+       }
+
 }
 
 /* Images */
index 7290ea0cee0e66b9b73da51f78bdddf47b383adb..bf16de4a9c97fb9ba77e3bcfb6b4860694fe2e92 100644 (file)
@@ -78,6 +78,8 @@ public:
        void sync_view(BL::SpaceView3D& b_v3d,
                       BL::RegionView3D& b_rv3d,
                       int width, int height);
+       inline int get_layer_samples() { return view_layer.samples; }
+       inline int get_layer_bound_samples() { return view_layer.bound_samples; }
 
        /* get parameters */
        static SceneParams get_scene_params(BL::Scene& b_scene,
@@ -191,18 +193,23 @@ private:
 
        struct RenderLayerInfo {
                RenderLayerInfo()
-               : use_background_shader(true),
+               : material_override(PointerRNA_NULL),
+                 use_background_shader(true),
                  use_background_ao(true),
                  use_surfaces(true),
-                 use_hair(true)
+                 use_hair(true),
+                 samples(0),
+                 bound_samples(false)
                {}
 
                string name;
-               uint view_layer;
+               BL::Material material_override;
                bool use_background_shader;
                bool use_background_ao;
                bool use_surfaces;
                bool use_hair;
+               int samples;
+               bool bound_samples;
        } view_layer;
 
        Progress &progress;
index 2abdaf103f95082819023732b468df00b1b739b8..9ac0c56d93f126dbcde06db5c0125e9151c8b6ba 100644 (file)
@@ -117,16 +117,6 @@ bool BKE_layer_collection_has_selected_objects(
 void BKE_base_set_visible(struct Scene *scene, struct ViewLayer *view_layer, struct Base *base, bool extend);
 void BKE_layer_collection_set_visible(struct Scene *scene, struct ViewLayer *view_layer, struct LayerCollection *lc, bool extend);
 
-/* override */
-
-void BKE_override_view_layer_datablock_add(
-        struct ViewLayer *view_layer, int id_type, const char *data_path, const struct ID *owner_id);
-void BKE_override_view_layer_int_add(
-        struct ViewLayer *view_layer, int id_type, const char *data_path, const int value);
-
-void BKE_override_layer_collection_boolean_add(
-        struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value);
-
 /* evaluation */
 
 void BKE_layer_eval_view_layer(
index 3fedd380f729b6a819715b7257358f8e9f2b8cd1..572dba4d83baba955cfeb3b5f1bc5bb69756fbd3 100644 (file)
@@ -1057,39 +1057,6 @@ bool BKE_scene_has_object(Scene *scene, Object *ob)
        return false;
 }
 
-/* ---------------------------------------------------------------------- */
-/* Override */
-
-/**
- * Add a new datablock override
- */
-void BKE_override_view_layer_datablock_add(
-        ViewLayer *view_layer, int id_type, const char *data_path, const ID *owner_id)
-{
-       UNUSED_VARS(view_layer, id_type, data_path, owner_id);
-       TODO_LAYER_OVERRIDE;
-}
-
-/**
- * Add a new int override
- */
-void BKE_override_view_layer_int_add(
-        ViewLayer *view_layer, int id_type, const char *data_path, const int value)
-{
-       UNUSED_VARS(view_layer, id_type, data_path, value);
-       TODO_LAYER_OVERRIDE;
-}
-
-/**
- * Add a new boolean override
- */
-void BKE_override_layer_collection_boolean_add(
-        struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value)
-{
-       UNUSED_VARS(layer_collection, id_type, data_path, value);
-       TODO_LAYER_OVERRIDE;
-}
-
 /** \} */
 
 /* Iterators */
index ab50cf8b0a8c1987574a61f07b76b2ec6360d446..2134c02b63d4b8ef5a56262ea86b726851db7a99 100644 (file)
@@ -438,6 +438,8 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 
                                ViewLayer *view_layer;
                                for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+                                       CALLBACK_INVOKE(view_layer->mat_override, IDWALK_CB_USER);
+
                                        for (Base *base = view_layer->object_bases.first; base; base = base->next) {
                                                CALLBACK_INVOKE(base->object, IDWALK_CB_NOP);
                                        }
index 1529e6693fb241a776a18c11b08996216c887fec..ab5f1a30d04e55fd01a70e5f482344f83745e3ab 100644 (file)
@@ -460,28 +460,6 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
        for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
                ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
 
-               if (srl->samples != 0) {
-                       have_override = true;
-
-                       /* It is up to the external engine to handle
-                        * its own doversion in this case. */
-                       BKE_override_view_layer_int_add(
-                               view_layer,
-                               ID_SCE,
-                               "samples",
-                               srl->samples);
-               }
-
-               if (srl->mat_override) {
-                       have_override = true;
-
-                       BKE_override_view_layer_datablock_add(
-                               view_layer,
-                               ID_MA,
-                               "self",
-                               (ID *)srl->mat_override);
-               }
-
                if (srl->layflag & SCE_LAY_DISABLE) {
                        view_layer->flag &= ~VIEW_LAYER_RENDER;
                }
@@ -490,12 +468,11 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
                        view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
                }
 
-               /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
                view_layer->layflag = srl->layflag;
-               /* XXX Not sure if we should keep the passes (dfelinto). */
                view_layer->passflag = srl->passflag;
-               view_layer->pass_xor = srl->pass_xor;
                view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
+               view_layer->samples = srl->samples;
+               view_layer->mat_override = srl->mat_override;
 
                BKE_freestyle_config_free(&view_layer->freestyle_config, true);
                view_layer->freestyle_config = srl->freestyleConfig;
index 70bd533647caf6a72c31ef28dc8250744e9219cc..ce3b2538274dec74944a06e7d4e4664c1444b415 100644 (file)
@@ -151,6 +151,10 @@ void DepsgraphNodeBuilder::build_view_layer(
        LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
                build_movieclip(clip);
        }
+       /* Material override. */
+       if (view_layer->mat_override != NULL) {
+               build_material(view_layer->mat_override);
+       }
        /* Collections. */
        add_operation_node(&scene->id,
                           DEG_NODE_TYPE_LAYER_COLLECTIONS,
index 866b5e6303176521bc71a6e079745f1ab34a42f6..f77d47874a2e986b9cc2531ff73e0fa8705ee514 100644 (file)
@@ -132,6 +132,10 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la
        LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
                build_movieclip(clip);
        }
+       /* Material override. */
+       if (view_layer->mat_override != NULL) {
+               build_material(view_layer->mat_override);
+       }
        /* Build all set scenes. */
        if (scene->set != NULL) {
                ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
index c3e819c55385d50c2520e76861d3f45ddac5d4a3..d959d54b07fa5db72815cf978c0c116bdfef9100 100644 (file)
@@ -76,9 +76,10 @@ typedef struct ViewLayer {
        /* Old SceneRenderLayer data. */
        int layflag;
        int passflag;                   /* pass_xor has to be after passflag */
-       int pass_xor;
        float pass_alpha_threshold;
+       int samples;
 
+       struct Material *mat_override;
        struct IDProperty *id_properties; /* Equivalent to datablocks ID properties. */
 
        struct FreestyleConfig freestyle_config;
index 2d0838a04c5fbbfe4b6c0112a7f05feac5915af8..d100449c3536dfd44ab93e499e477bf6fa9af58f 100644 (file)
@@ -194,7 +194,7 @@ typedef struct SceneRenderLayer {
 
        char name[64] DNA_DEPRECATED;   /* MAX_NAME */
 
-       struct Material *mat_override DNA_DEPRECATED; /* Converted to ViewLayer override. */
+       struct Material *mat_override DNA_DEPRECATED; /* Converted to ViewLayer setting. */
 
        unsigned int lay DNA_DEPRECATED; /* Converted to LayerCollection cycles camera visibility override. */
        unsigned int lay_zmask DNA_DEPRECATED; /* Converted to LayerCollection cycles holdout override. */
@@ -205,7 +205,7 @@ typedef struct SceneRenderLayer {
        int passflag DNA_DEPRECATED; /* pass_xor has to be after passflag */
        int pass_xor DNA_DEPRECATED; /* Converted to ViewLayer passflag and flag. */
 
-       int samples DNA_DEPRECATED; /* Converted to ViewLayer override. */
+       int samples DNA_DEPRECATED; /* Converted to ViewLayer setting. */
        float pass_alpha_threshold DNA_DEPRECATED; /* Converted to ViewLayer pass_alpha_threshold. */
 
        IDProperty *prop DNA_DEPRECATED; /* Converted to ViewLayer id_properties. */
index 155c030587dff3bfde0654591dca4d1a03ea3a94..6e69de774e95147e51f0a26c7eddc9fe900c0575 100644 (file)
@@ -274,6 +274,7 @@ void rna_Scene_use_view_map_cache_update(struct Main *bmain, struct Scene *scene
 void rna_Scene_glsl_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
 void rna_Scene_freestyle_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
 void rna_ViewLayer_name_set(struct PointerRNA *ptr, const char *value);
+void rna_ViewLayer_material_override_update(struct Main *bmain, struct Scene *activescene, struct PointerRNA *ptr);
 void rna_ViewLayer_pass_update(struct Main *bmain, struct Scene *activescene, struct PointerRNA *ptr);
 
 /* named internal so as not to conflict with obj.update() rna func */
index 9389dcf81ef0e668b49532c0659cb766b2016912..f3f5371b45894e8c64470c0a52454fd1c329d11f 100644 (file)
@@ -1424,6 +1424,13 @@ static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
        BLI_uniquename(&scene->r.views, rv, DATA_("RenderView"), '.', offsetof(SceneRenderView, name), sizeof(rv->name));
 }
 
+void rna_ViewLayer_material_override_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       Scene *scene = (Scene *)ptr->id.data;
+       rna_Scene_glsl_update(bmain, scene, ptr);
+       DEG_relations_tag_update(bmain);
+}
+
 void rna_ViewLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
 {
        Scene *scene = (Scene *)ptr->id.data;
@@ -3227,6 +3234,19 @@ void rna_def_view_layer_common(StructRNA *srna, int scene)
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
        if (scene) {
+               prop = RNA_def_property(srna, "material_override", PROP_POINTER, PROP_NONE);
+               RNA_def_property_pointer_sdna(prop, NULL, "mat_override");
+               RNA_def_property_struct_type(prop, "Material");
+               RNA_def_property_flag(prop, PROP_EDITABLE);
+               RNA_def_property_ui_text(prop, "Material Override",
+                                                                "Material to override all other materials in this view layer");
+               RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_material_override_update");
+
+               prop = RNA_def_property(srna, "samples", PROP_INT, PROP_UNSIGNED);
+               RNA_def_property_ui_text(prop, "Samples", "Override number of render samples for this view layer, "
+                                                         "0 will use the scene setting");
+               RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
+
                prop = RNA_def_property(srna, "pass_alpha_threshold", PROP_FLOAT, PROP_FACTOR);
                RNA_def_property_ui_text(prop, "Alpha Threshold",
                                         "Z, Index, normal, UV and vector passes are only affected by surfaces with "
index fc99be81ba3aa8d83ccbd4275b5d82ef7c4c1c0f..7efe0a5da607891ef8047762d53ef772a98f4e3c 100644 (file)
@@ -307,7 +307,6 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
                BLI_strncpy(rl->name, view_layer->name, sizeof(rl->name));
                rl->layflag = view_layer->layflag;
                rl->passflag = view_layer->passflag; /* for debugging: view_layer->passflag | SCE_PASS_RAYHITS; */
-               rl->pass_xor = view_layer->pass_xor;
                rl->rectx = rectx;
                rl->recty = recty;