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/rna_scene.c | |
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/rna_scene.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 104 |
1 files changed, 104 insertions, 0 deletions
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); |