Depsgraph and collection enable/visibility

Iterate over invisible objects too, so lamps can still lit the scene.
Also, now you can use a collection to set an object to invisible, not
only to visible.

For example:
Scene > Master collection > bedroom > furniture
Scene > View Layer > bedroom    (visible)
                   > furniture  (invisible)

The View Layer has two linked collections, bedroom and furniture.
This setup will make the furniture collection invisible.

Note: Unlike what was suggested on D2849, this does not make collection
visibility influence camera visibility. I will keep this as a separate
patch.

Reviewers: sergey

Subscribers: sergey, brecht, fclem

Differential Revision: https://developer.blender.org/D2849
This commit is contained in:
Dalai Felinto 2017-09-21 12:55:14 +02:00
parent 77377f0ea8
commit 9ad2c0b615
Notes: blender-bot 2023-02-14 06:30:02 +01:00
Referenced by commit 7553523af7, Collections: Bring back simple visibility behaviour
Referenced by commit fdeb125c7a, Fix T53014: Cycles material preview not working
Referenced by commit 8a1d787b89, Initial fix for T53014: Cycles material preview no light
Referenced by issue #53014, Cycles material preview no light
12 changed files with 73 additions and 39 deletions

View File

@ -519,6 +519,10 @@ void BlenderSync::sync_objects(float motion_time)
++b_dupli_iter)
{
BL::Object b_ob = b_dupli_iter->object();
if(!b_ob.is_visible()) {
continue;
}
progress.set_sync_status("Synchronizing object", b_ob.name());
/* load per-object culling data */

View File

@ -83,6 +83,7 @@ bool BKE_object_exists_check(struct Object *obtest);
bool BKE_object_is_in_editmode(struct Object *ob);
bool BKE_object_is_in_editmode_vgroup(struct Object *ob);
bool BKE_object_is_in_wpaint_select_vert(struct Object *ob);
bool BKE_object_is_visible(struct Object *ob);
void BKE_object_init(struct Object *ob);
struct Object *BKE_object_add_only_object(

View File

@ -1860,6 +1860,9 @@ void BKE_layer_eval_layer_collection(const struct EvaluationContext *UNUSED(eval
IDP_MergeGroup(base->collection_properties, layer_collection->properties_evaluated, true);
base->flag |= BASE_VISIBLED;
}
else {
base->flag &= ~BASE_VISIBLED;
}
if (is_selectable) {
base->flag |= BASE_SELECTABLED;

View File

@ -562,6 +562,15 @@ bool BKE_object_is_in_wpaint_select_vert(Object *ob)
return false;
}
/**
* Return if the object is visible, as evaluated by depsgraph
* Keep in sync with rna_object.c (object.is_visible).
*/
bool BKE_object_is_visible(Object *ob)
{
return (ob->base_flag & BASE_VISIBLED) != 0;
}
bool BKE_object_exists_check(Object *obtest)
{
Object *ob;

View File

@ -211,33 +211,30 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
}
base = data->base->next;
while (base != NULL) {
if ((base->flag & BASE_VISIBLED) != 0) {
// Object *ob = DEG_get_evaluated_object(data->graph, base->object);
Object *ob = base->object;
iter->current = ob;
data->base = base;
if (base != NULL) {
// Object *ob = DEG_get_evaluated_object(data->graph, base->object);
Object *ob = base->object;
iter->current = ob;
data->base = base;
BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
/* Make sure we have the base collection settings is already populated.
* This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
* Which usually means a missing call to DEG_id_tag_update(). */
BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
/* Make sure we have the base collection settings is already populated.
* This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
* Which usually means a missing call to DEG_id_tag_update(). */
BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
/* Flushing depsgraph data. */
deg_flush_base_flags_and_settings(ob,
base,
data->base_flag);
/* Flushing depsgraph data. */
deg_flush_base_flags_and_settings(ob,
base,
data->base_flag);
if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
data->dupli_parent = ob;
data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
data->dupli_object_next = (DupliObject *)data->dupli_list->first;
}
return;
if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
data->dupli_parent = ob;
data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
data->dupli_object_next = (DupliObject *)data->dupli_list->first;
}
base = base->next;
return;
}
/* Look for an object in the next set. */

View File

@ -29,6 +29,8 @@
#include "BLI_dynstr.h"
#include "BLI_rand.h"
#include "BKE_object.h"
#include "GPU_material.h"
#include "GPU_glew.h"
@ -93,6 +95,10 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
}
if (ELEM(ob->type, OB_MESH)) {
if (!BKE_object_is_visible(ob)) {
return;
}
EEVEE_materials_cache_populate(vedata, sldata, ob);
const bool cast_shadow = true;

View File

@ -590,7 +590,10 @@ static void EEVEE_planar_reflections_updates(EEVEE_SceneLayerData *sldata, EEVEE
eplanar->attenuation_bias = max_dist * -eplanar->attenuation_scale;
/* Debug Display */
if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
if (BKE_object_is_visible(ob) &&
DRW_state_draw_support() &&
(probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
{
DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_planar_display_sh, psl->probe_display);
DRW_shgroup_uniform_int(grp, "probeIdx", &ped->probe_id, 1);
@ -643,8 +646,12 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
invert_m4(eprobe->parallaxmat);
/* Debug Display */
if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
DRW_shgroup_call_dynamic_add(stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &probe->data_draw_size);
if (BKE_object_is_visible(ob) &&
DRW_state_draw_support() &&
(probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
{
DRW_shgroup_call_dynamic_add(
stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &probe->data_draw_size);
}
}
@ -701,7 +708,10 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
copy_v3_v3_int(egrid->resolution, &probe->grid_resolution_x);
/* Debug Display */
if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
if (BKE_object_is_visible(ob) &&
DRW_state_draw_support() &&
(probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
{
struct Gwn_Batch *geom = DRW_cache_sphere_get();
DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.probe_grid_display_sh, psl->probe_display, geom);
DRW_shgroup_set_instance_count(grp, ped->num_cell);

View File

@ -2164,6 +2164,10 @@ bool DRW_object_is_renderable(Object *ob)
Scene *scene = DST.draw_ctx.scene;
Object *obedit = scene->obedit;
if (!BKE_object_is_visible(ob)) {
return false;
}
if (ob->type == OB_MESH) {
if (ob == obedit) {
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_EDIT, "");

View File

@ -43,6 +43,7 @@
#include "BKE_camera.h"
#include "BKE_curve.h"
#include "BKE_global.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_image.h"
#include "BKE_texture.h"
@ -1562,7 +1563,7 @@ static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, Object *ob, SceneLay
static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
{
if (ob->parent && ((ob->parent->base_flag & BASE_VISIBLED) != 0)) {
if (ob->parent && BKE_object_is_visible(ob->parent)) {
DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->obmat[3]);
DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->parent->obmat[3]);
}
@ -1677,6 +1678,10 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
View3D *v3d = draw_ctx->v3d;
int theme_id = TH_UNDEFINED;
if (!BKE_object_is_visible(ob)) {
return;
}
//CollectionEngineSettings *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, "");
//bool do_wire = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_wire");

View File

@ -9217,7 +9217,7 @@ afterdraw:
/* help lines and so */
if (ob != scene->obedit && ob->parent) {
if ((ob->parent->base_flag & BASE_VISIBLED) != 0) {
if (BKE_object_is_visible(ob->parent)) {
setlinestyle(3);
immBegin(GWN_PRIM_LINES, 2);
immVertex3fv(pos, ob->obmat[3]);

View File

@ -2897,6 +2897,12 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
/* Keep it in sync with BKE_object_is_visible. */
prop = RNA_def_property(srna, "is_visible", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_VISIBLED);
RNA_def_property_ui_text(prop, "Visible", "Visible to camera rays, set only on objects evaluated by depsgraph");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "collection_properties", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "base_collection_properties->data.group", NULL);
RNA_def_property_struct_type(prop, "LayerCollectionSettings");

View File

@ -329,11 +329,6 @@ static void rna_Object_shape_key_remove(
RNA_POINTER_INVALIDATE(kb_ptr);
}
static int rna_Object_is_visible(Object *ob, Scene *sce)
{
return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
}
#if 0
static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
float weight, int assignmode)
@ -754,12 +749,6 @@ void RNA_api_object(StructRNA *srna)
RNA_def_function_output(func, parm);
/* View */
func = RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
parm = RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
RNA_def_function_return(func, parm);
/* utility function for checking if the object is modified */
func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");