Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2022-04-02 01:11:11 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2022-04-02 07:14:27 +0300
commitad35453cd19b3db779b0b3a90feac2e93c7a73cf (patch)
tree3ad7893815bda3e34e18302422ad1f978e828603 /intern/cycles/scene
parent5387d33e5f954c4cecdb7ffd3d1042d8632d6c15 (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 'intern/cycles/scene')
-rw-r--r--intern/cycles/scene/background.cpp11
-rw-r--r--intern/cycles/scene/background.h2
-rw-r--r--intern/cycles/scene/film.cpp41
-rw-r--r--intern/cycles/scene/film.h2
-rw-r--r--intern/cycles/scene/light.cpp10
-rw-r--r--intern/cycles/scene/light.h2
-rw-r--r--intern/cycles/scene/object.cpp16
-rw-r--r--intern/cycles/scene/object.h5
-rw-r--r--intern/cycles/scene/pass.cpp18
-rw-r--r--intern/cycles/scene/pass.h8
-rw-r--r--intern/cycles/scene/scene.cpp5
-rw-r--r--intern/cycles/scene/scene.h3
12 files changed, 110 insertions, 13 deletions
diff --git a/intern/cycles/scene/background.cpp b/intern/cycles/scene/background.cpp
index 1c3a9f9358d..bffc8895bfd 100644
--- a/intern/cycles/scene/background.cpp
+++ b/intern/cycles/scene/background.cpp
@@ -32,6 +32,8 @@ NODE_DEFINE(Background)
SOCKET_NODE(shader, "Shader", Shader::get_node_type());
+ SOCKET_STRING(lightgroup, "Light Group", ustring());
+
return type;
}
@@ -101,6 +103,15 @@ void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene
kbackground->surface_shader |= SHADER_EXCLUDE_CAMERA;
}
+ /* Light group. */
+ auto it = scene->lightgroups.find(lightgroup);
+ if (it != scene->lightgroups.end()) {
+ kbackground->lightgroup = it->second;
+ }
+ else {
+ kbackground->lightgroup = LIGHTGROUP_NONE;
+ }
+
clear_modified();
}
diff --git a/intern/cycles/scene/background.h b/intern/cycles/scene/background.h
index bbffce6e30a..50b4368d708 100644
--- a/intern/cycles/scene/background.h
+++ b/intern/cycles/scene/background.h
@@ -30,6 +30,8 @@ class Background : public Node {
NODE_SOCKET_API(float, volume_step_size)
+ NODE_SOCKET_API(ustring, lightgroup)
+
Background();
~Background();
diff --git a/intern/cycles/scene/film.cpp b/intern/cycles/scene/film.cpp
index e17c839d60b..c3b126544c4 100644
--- a/intern/cycles/scene/film.cpp
+++ b/intern/cycles/scene/film.cpp
@@ -175,6 +175,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
kfilm->pass_volume_direct = PASS_UNUSED;
kfilm->pass_volume_indirect = PASS_UNUSED;
kfilm->pass_shadow = PASS_UNUSED;
+ kfilm->pass_lightgroup = PASS_UNUSED;
/* Mark passes as unused so that the kernel knows the pass is inaccessible. */
kfilm->pass_denoising_normal = PASS_UNUSED;
@@ -189,6 +190,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
bool have_cryptomatte = false;
bool have_aov_color = false;
bool have_aov_value = false;
+ bool have_lightgroup = false;
for (size_t i = 0; i < scene->passes.size(); i++) {
const Pass *pass = scene->passes[i];
@@ -223,6 +225,15 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
assert(pass->get_type() <= PASS_CATEGORY_BAKE_END);
}
+ if (pass->get_lightgroup() != ustring()) {
+ if (!have_lightgroup) {
+ kfilm->pass_lightgroup = kfilm->pass_stride;
+ have_lightgroup = true;
+ }
+ kfilm->pass_stride += pass->get_info().num_components;
+ continue;
+ }
+
switch (pass->get_type()) {
case PASS_COMBINED:
kfilm->pass_combined = kfilm->pass_stride;
@@ -414,6 +425,26 @@ int Film::get_aov_offset(Scene *scene, string name, bool &is_color)
return -1;
}
+bool Film::update_lightgroups(Scene *scene)
+{
+ map<ustring, int> lightgroups;
+ int i = 0;
+ foreach (const Pass *pass, scene->passes) {
+ ustring lightgroup = pass->get_lightgroup();
+ if (!lightgroup.empty()) {
+ if (!lightgroups.count(lightgroup)) {
+ lightgroups[lightgroup] = i++;
+ }
+ }
+ }
+ if (scene->lightgroups != lightgroups) {
+ scene->lightgroups = lightgroups;
+ return true;
+ }
+
+ return false;
+}
+
void Film::update_passes(Scene *scene, bool add_sample_count_pass)
{
const Background *background = scene->background;
@@ -580,11 +611,19 @@ void Film::remove_auto_passes(Scene *scene)
static bool compare_pass_order(const Pass *a, const Pass *b)
{
+ /* On the highest level, sort by number of components.
+ * Within passes of the same component count, sort so that all non-lightgroup passes come first.
+ * Within that group, sort by type. */
const int num_components_a = a->get_info().num_components;
const int num_components_b = b->get_info().num_components;
if (num_components_a == num_components_b) {
- return (a->get_type() < b->get_type());
+ const int is_lightgroup_a = !a->get_lightgroup().empty();
+ const int is_lightgroup_b = !b->get_lightgroup().empty();
+ if (is_lightgroup_a == is_lightgroup_b) {
+ return (a->get_type() < b->get_type());
+ }
+ return is_lightgroup_b;
}
return num_components_a > num_components_b;
diff --git a/intern/cycles/scene/film.h b/intern/cycles/scene/film.h
index 43597b0fc79..f1e3237eb9e 100644
--- a/intern/cycles/scene/film.h
+++ b/intern/cycles/scene/film.h
@@ -68,6 +68,8 @@ class Film : public Node {
int get_aov_offset(Scene *scene, string name, bool &is_color);
+ bool update_lightgroups(Scene *scene);
+
/* Update passes so that they contain all passes required for the configured functionality.
*
* If `add_sample_count_pass` is true then the SAMPLE_COUNT pass is ensured to be added. */
diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp
index 85a7f37994c..5e311d3051f 100644
--- a/intern/cycles/scene/light.cpp
+++ b/intern/cycles/scene/light.cpp
@@ -134,6 +134,8 @@ NODE_DEFINE(Light)
SOCKET_NODE(shader, "Shader", Shader::get_node_type());
+ SOCKET_STRING(lightgroup, "Light Group", ustring());
+
return type;
}
@@ -902,6 +904,14 @@ void LightManager::device_update_points(Device *, DeviceScene *dscene, Scene *sc
klights[light_index].tfm = light->tfm;
klights[light_index].itfm = transform_inverse(light->tfm);
+ auto it = scene->lightgroups.find(light->lightgroup);
+ if (it != scene->lightgroups.end()) {
+ klights[light_index].lightgroup = it->second;
+ }
+ else {
+ klights[light_index].lightgroup = LIGHTGROUP_NONE;
+ }
+
light_index++;
}
diff --git a/intern/cycles/scene/light.h b/intern/cycles/scene/light.h
index 25190f6fb63..5b852f210fc 100644
--- a/intern/cycles/scene/light.h
+++ b/intern/cycles/scene/light.h
@@ -71,6 +71,8 @@ class Light : public Node {
NODE_SOCKET_API(int, max_bounces)
NODE_SOCKET_API(uint, random_id)
+ NODE_SOCKET_API(ustring, lightgroup)
+
void tag_update(Scene *scene);
/* Check whether the light has contribution the scene. */
diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp
index 9b19169880a..55d89fc3673 100644
--- a/intern/cycles/scene/object.cpp
+++ b/intern/cycles/scene/object.cpp
@@ -98,6 +98,8 @@ NODE_DEFINE(Object)
SOCKET_FLOAT(ao_distance, "AO Distance", 0.0f);
+ SOCKET_STRING(lightgroup, "Light Group", ustring());
+
return type;
}
@@ -393,7 +395,8 @@ static float object_volume_density(const Transform &tfm, Geometry *geom)
void ObjectManager::device_update_object_transform(UpdateObjectTransformState *state,
Object *ob,
- bool update_all)
+ bool update_all,
+ const Scene *scene)
{
KernelObject &kobject = state->objects[ob->index];
Transform *object_motion_pass = state->object_motion_pass;
@@ -532,6 +535,15 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
if (geom->geometry_type == Geometry::HAIR) {
state->have_curves = true;
}
+
+ /* Light group. */
+ auto it = scene->lightgroups.find(ob->lightgroup);
+ if (it != scene->lightgroups.end()) {
+ kobject.lightgroup = it->second;
+ }
+ else {
+ kobject.lightgroup = LIGHTGROUP_NONE;
+ }
}
void ObjectManager::device_update_prim_offsets(Device *device, DeviceScene *dscene, Scene *scene)
@@ -618,7 +630,7 @@ void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene,
[&](const blocked_range<size_t> &r) {
for (size_t i = r.begin(); i != r.end(); i++) {
Object *ob = state.scene->objects[i];
- device_update_object_transform(&state, ob, update_all);
+ device_update_object_transform(&state, ob, update_all, scene);
}
});
diff --git a/intern/cycles/scene/object.h b/intern/cycles/scene/object.h
index 561ecd4e7e9..c41f1416180 100644
--- a/intern/cycles/scene/object.h
+++ b/intern/cycles/scene/object.h
@@ -66,6 +66,8 @@ class Object : public Node {
NODE_SOCKET_API(float, ao_distance)
+ NODE_SOCKET_API(ustring, lightgroup)
+
/* Set during device update. */
bool intersects_volume;
@@ -169,7 +171,8 @@ class ObjectManager {
protected:
void device_update_object_transform(UpdateObjectTransformState *state,
Object *ob,
- bool update_all);
+ bool update_all,
+ const Scene *scene);
void device_update_object_transform_task(UpdateObjectTransformState *state);
bool device_update_object_transform_pop_work(UpdateObjectTransformState *state,
int *start_index,
diff --git a/intern/cycles/scene/pass.cpp b/intern/cycles/scene/pass.cpp
index 41730cb189d..5f5b19e710d 100644
--- a/intern/cycles/scene/pass.cpp
+++ b/intern/cycles/scene/pass.cpp
@@ -124,6 +124,7 @@ NODE_DEFINE(Pass)
SOCKET_ENUM(mode, "Mode", *pass_mode_enum, static_cast<int>(PassMode::DENOISED));
SOCKET_STRING(name, "Name", ustring());
SOCKET_BOOLEAN(include_albedo, "Include Albedo", false);
+ SOCKET_STRING(lightgroup, "Light Group", ustring());
return type;
}
@@ -134,7 +135,7 @@ Pass::Pass() : Node(get_node_type()), is_auto_(false)
PassInfo Pass::get_info() const
{
- return get_info(type, include_albedo);
+ return get_info(type, include_albedo, !lightgroup.empty());
}
bool Pass::is_written() const
@@ -142,7 +143,7 @@ bool Pass::is_written() const
return get_info().is_written;
}
-PassInfo Pass::get_info(const PassType type, const bool include_albedo)
+PassInfo Pass::get_info(const PassType type, const bool include_albedo, const bool is_lightgroup)
{
PassInfo pass_info;
@@ -157,9 +158,9 @@ PassInfo Pass::get_info(const PassType type, const bool include_albedo)
pass_info.num_components = 0;
break;
case PASS_COMBINED:
- pass_info.num_components = 4;
+ pass_info.num_components = is_lightgroup ? 3 : 4;
pass_info.use_exposure = true;
- pass_info.support_denoise = true;
+ pass_info.support_denoise = !is_lightgroup;
break;
case PASS_DEPTH:
pass_info.num_components = 1;
@@ -369,13 +370,16 @@ const Pass *Pass::find(const vector<Pass *> &passes, const string &name)
return nullptr;
}
-const Pass *Pass::find(const vector<Pass *> &passes, PassType type, PassMode mode)
+const Pass *Pass::find(const vector<Pass *> &passes,
+ PassType type,
+ PassMode mode,
+ const ustring &lightgroup)
{
for (const Pass *pass : passes) {
- if (pass->get_type() != type || pass->get_mode() != mode) {
+ if (pass->get_type() != type || pass->get_mode() != mode ||
+ pass->get_lightgroup() != lightgroup) {
continue;
}
-
return pass;
}
diff --git a/intern/cycles/scene/pass.h b/intern/cycles/scene/pass.h
index c12df007b5d..e0689eba688 100644
--- a/intern/cycles/scene/pass.h
+++ b/intern/cycles/scene/pass.h
@@ -53,6 +53,7 @@ class Pass : public Node {
NODE_SOCKET_API(PassMode, mode)
NODE_SOCKET_API(ustring, name)
NODE_SOCKET_API(bool, include_albedo)
+ NODE_SOCKET_API(ustring, lightgroup)
Pass();
@@ -72,7 +73,9 @@ class Pass : public Node {
static const NodeEnum *get_type_enum();
static const NodeEnum *get_mode_enum();
- static PassInfo get_info(PassType type, const bool include_albedo = false);
+ static PassInfo get_info(PassType type,
+ const bool include_albedo = false,
+ const bool is_lightgroup = false);
static bool contains(const vector<Pass *> &passes, PassType type);
@@ -80,7 +83,8 @@ class Pass : public Node {
static const Pass *find(const vector<Pass *> &passes, const string &name);
static const Pass *find(const vector<Pass *> &passes,
PassType type,
- PassMode mode = PassMode::NOISY);
+ PassMode mode = PassMode::NOISY,
+ const ustring &lightgroup = ustring());
/* Returns PASS_UNUSED if there is no corresponding pass. */
static int get_offset(const vector<Pass *> &passes, const Pass *pass);
diff --git a/intern/cycles/scene/scene.cpp b/intern/cycles/scene/scene.cpp
index 359e2d8e2c3..b6b53004816 100644
--- a/intern/cycles/scene/scene.cpp
+++ b/intern/cycles/scene/scene.cpp
@@ -251,6 +251,11 @@ void Scene::device_update(Device *device_, Progress &progress)
* - Lookup tables are done a second time to handle film tables
*/
+ if (film->update_lightgroups(this)) {
+ light_manager->tag_update(this, ccl::LightManager::LIGHT_MODIFIED);
+ object_manager->tag_update(this, ccl::ObjectManager::OBJECT_MODIFIED);
+ }
+
progress.set_status("Updating Shaders");
shader_manager->device_update(device, &dscene, this, progress);
diff --git a/intern/cycles/scene/scene.h b/intern/cycles/scene/scene.h
index e1b36899302..9e3e8d61b80 100644
--- a/intern/cycles/scene/scene.h
+++ b/intern/cycles/scene/scene.h
@@ -197,6 +197,9 @@ class Scene : public NodeOwner {
/* Optional name. Is used for logging and reporting. */
string name;
+ /* Maps from Light group names to their pass ID. */
+ map<ustring, int> lightgroups;
+
/* data */
BVH *bvh;
Camera *camera;