diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2022-04-02 01:11:11 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2022-04-02 07:14:27 +0300 |
commit | ad35453cd19b3db779b0b3a90feac2e93c7a73cf (patch) | |
tree | 3ad7893815bda3e34e18302422ad1f978e828603 /source/blender/makesrna/intern | |
parent | 5387d33e5f954c4cecdb7ffd3d1042d8632d6c15 (diff) |
Cycles: Add support for light groups
Light groups are a type of pass that only contains lighting from a subset of light sources.
They are created in the View layer, and light sources (lamps, objects with emissive materials
and/or the environment) can be assigned to a group.
Currently, each light group ends up generating its own version of the Combined pass.
In the future, additional types of passes (e.g. shadowcatcher) might be getting their own
per-lightgroup versions.
The lightgroup creation and assignment is not Cycles-specific, so Eevee or external render
engines could make use of it in the future.
Note that Lightgroups are identified by their name - therefore, the name of the Lightgroup
in the View Layer and the name that's set in an object's settings must match for it to be
included.
Currently, changing a Lightgroup's name does not update objects - this is planned for the
future, along with other features such as denoising for light groups and viewing them in
preview renders.
Original patch by Alex Fuller (@mistaed), with some polishing by Lukas Stockner (@lukasstockner97).
Differential Revision: https://developer.blender.org/D12871
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 24 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 104 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_world.c | 23 |
4 files changed, 155 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 84f083cb37a..0df0be07fee 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -355,6 +355,10 @@ void rna_ViewLayer_active_aov_index_range( PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax); int rna_ViewLayer_active_aov_index_get(PointerRNA *ptr); void rna_ViewLayer_active_aov_index_set(PointerRNA *ptr, int value); +void rna_ViewLayer_active_lightgroup_index_range( + PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax); +int rna_ViewLayer_active_lightgroup_index_get(PointerRNA *ptr); +void rna_ViewLayer_active_lightgroup_index_set(PointerRNA *ptr, int value); /** * Set `r_rna_path` with the base view-layer path. * `rna_path_buffer_size` should be at least `sizeof(ViewLayer.name) * 3`. diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index e4495df36f1..f995ee3383e 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -2292,6 +2292,21 @@ static int rna_Object_mesh_symmetry_yz_editable(PointerRNA *ptr, const char **UN return PROP_EDITABLE; } +void rna_Object_lightgroup_get(PointerRNA *ptr, char *value) +{ + BKE_lightgroup_membership_get(((Object *)ptr->owner_id)->lightgroup, value); +} + +int rna_Object_lightgroup_length(PointerRNA *ptr) +{ + return BKE_lightgroup_membership_length(((Object *)ptr->owner_id)->lightgroup); +} + +void rna_Object_lightgroup_set(PointerRNA *ptr, const char *value) +{ + BKE_lightgroup_membership_set(&((Object *)ptr->owner_id)->lightgroup, value); +} + #else static void rna_def_vertex_group(BlenderRNA *brna) @@ -3775,6 +3790,15 @@ static void rna_def_object(BlenderRNA *brna) RNA_def_property_editable_func(prop, "rna_Object_mesh_symmetry_yz_editable"); RNA_def_property_ui_text(prop, "Z", "Enable mesh symmetry in the Z axis"); + /* Lightgroup Membership */ + prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs(prop, + "rna_Object_lightgroup_get", + "rna_Object_lightgroup_length", + "rna_Object_lightgroup_set"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the object belongs to"); + RNA_define_lib_overridable(false); /* anim */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 8d5d93e10ac..0960d246257 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1767,6 +1767,10 @@ void rna_ViewLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr) ViewLayerAOV *aov = (ViewLayerAOV *)ptr->data; view_layer = BKE_view_layer_find_with_aov(scene, aov); } + else if (ptr->type == &RNA_Lightgroup) { + ViewLayerLightgroup *lightgroup = (ViewLayerLightgroup *)ptr->data; + view_layer = BKE_view_layer_find_with_lightgroup(scene, lightgroup); + } if (view_layer) { RenderEngineType *engine_type = RE_engines_find(scene->r.engine); @@ -2447,6 +2451,49 @@ void rna_ViewLayer_active_aov_index_set(PointerRNA *ptr, int value) view_layer->active_aov = aov; } +void rna_ViewLayer_active_lightgroup_index_range( + PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) +{ + ViewLayer *view_layer = (ViewLayer *)ptr->data; + + *min = 0; + *max = max_ii(0, BLI_listbase_count(&view_layer->lightgroups) - 1); +} + +int rna_ViewLayer_active_lightgroup_index_get(PointerRNA *ptr) +{ + ViewLayer *view_layer = (ViewLayer *)ptr->data; + return BLI_findindex(&view_layer->lightgroups, view_layer->active_lightgroup); +} + +void rna_ViewLayer_active_lightgroup_index_set(PointerRNA *ptr, int value) +{ + ViewLayer *view_layer = (ViewLayer *)ptr->data; + ViewLayerLightgroup *lightgroup = BLI_findlink(&view_layer->lightgroups, value); + view_layer->active_lightgroup = lightgroup; +} + +static void rna_ViewLayerLightgroup_name_get(PointerRNA *ptr, char *value) +{ + ViewLayerLightgroup *lightgroup = (ViewLayerLightgroup *)ptr->data; + BLI_strncpy(value, lightgroup->name, sizeof(lightgroup->name)); +} + +static int rna_ViewLayerLightgroup_name_length(PointerRNA *ptr) +{ + ViewLayerLightgroup *lightgroup = (ViewLayerLightgroup *)ptr->data; + return strlen(lightgroup->name); +} + +static void rna_ViewLayerLightgroup_name_set(PointerRNA *ptr, const char *value) +{ + ViewLayerLightgroup *lightgroup = (ViewLayerLightgroup *)ptr->data; + Scene *scene = (Scene *)ptr->owner_id; + ViewLayer *view_layer = BKE_view_layer_find_with_lightgroup(scene, lightgroup); + + BKE_view_layer_rename_lightgroup(view_layer, lightgroup, value); +} + /* Fake value, used internally (not saved to DNA). */ # define V3D_ORIENT_DEFAULT -1 @@ -4156,6 +4203,43 @@ static void rna_def_view_layer_aov(BlenderRNA *brna) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update"); } +static void rna_def_view_layer_lightgroups(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + /* PropertyRNA *prop; */ + + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "Lightgroups"); + srna = RNA_def_struct(brna, "Lightgroups", NULL); + RNA_def_struct_sdna(srna, "ViewLayer"); + RNA_def_struct_ui_text(srna, "List of Lightgroups", "Collection of Lightgroups"); + + func = RNA_def_function(srna, "add", "BKE_view_layer_add_lightgroup"); + parm = RNA_def_pointer(func, "lightgroup", "Lightgroup", "", "Newly created Lightgroup"); + RNA_def_function_return(func, parm); +} + +static void rna_def_view_layer_lightgroup(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + srna = RNA_def_struct(brna, "Lightgroup", NULL); + RNA_def_struct_sdna(srna, "ViewLayerLightgroup"); + RNA_def_struct_ui_text(srna, "Light Group", ""); + + prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_string_funcs(prop, + "rna_ViewLayerLightgroup_name_get", + "rna_ViewLayerLightgroup_name_length", + "rna_ViewLayerLightgroup_name_set"); + RNA_def_property_ui_text(prop, "Name", "Name of the Lightgroup"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update"); + RNA_def_struct_name_property(srna, prop); +} + void rna_def_view_layer_common(BlenderRNA *brna, StructRNA *srna, const bool scene) { PropertyRNA *prop; @@ -4226,6 +4310,25 @@ void rna_def_view_layer_common(BlenderRNA *brna, StructRNA *srna, const bool sce RNA_def_property_ui_text(prop, "Active AOV Index", "Index of active aov"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); + prop = RNA_def_property(srna, "lightgroups", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "lightgroups", NULL); + RNA_def_property_struct_type(prop, "Lightgroup"); + RNA_def_property_ui_text(prop, "Light Groups", ""); + rna_def_view_layer_lightgroups(brna, prop); + + prop = RNA_def_property(srna, "active_lightgroup", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Lightgroup"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Light Groups", "Active Lightgroup"); + + prop = RNA_def_property(srna, "active_lightgroup_index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_funcs(prop, + "rna_ViewLayer_active_lightgroup_index_get", + "rna_ViewLayer_active_lightgroup_index_set", + "rna_ViewLayer_active_lightgroup_index_range"); + RNA_def_property_ui_text(prop, "Active Lightgroup Index", "Index of active lightgroup"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); + prop = RNA_def_property(srna, "use_pass_cryptomatte_object", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "cryptomatte_flag", VIEW_LAYER_CRYPTOMATTE_OBJECT); RNA_def_property_ui_text( @@ -8088,6 +8191,7 @@ void RNA_def_scene(BlenderRNA *brna) rna_def_scene_display(brna); rna_def_scene_eevee(brna); rna_def_view_layer_aov(brna); + rna_def_view_layer_lightgroup(brna); rna_def_view_layer_eevee(brna); rna_def_scene_gpencil(brna); RNA_define_animate_sdna(true); diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index 04008665342..d1049eef2c7 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -22,6 +22,7 @@ # include "MEM_guardedalloc.h" # include "BKE_context.h" +# include "BKE_layer.h" # include "BKE_main.h" # include "BKE_texture.h" @@ -84,6 +85,21 @@ static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr) rna_World_draw_update(bmain, scene, ptr); } +void rna_World_lightgroup_get(PointerRNA *ptr, char *value) +{ + BKE_lightgroup_membership_get(((World *)ptr->owner_id)->lightgroup, value); +} + +int rna_World_lightgroup_length(PointerRNA *ptr) +{ + return BKE_lightgroup_membership_length(((World *)ptr->owner_id)->lightgroup); +} + +void rna_World_lightgroup_set(PointerRNA *ptr, const char *value) +{ + BKE_lightgroup_membership_set(&((World *)ptr->owner_id)->lightgroup, value); +} + #else static void rna_def_lighting(BlenderRNA *brna) @@ -234,6 +250,13 @@ void RNA_def_world(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world"); RNA_def_property_update(prop, 0, "rna_World_use_nodes_update"); + /* Lightgroup Membership */ + prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs( + prop, "rna_World_lightgroup_get", "rna_World_lightgroup_length", "rna_World_lightgroup_set"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the world belongs to"); + rna_def_lighting(brna); rna_def_world_mist(brna); } |