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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-12 14:41:23 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-13 16:56:10 +0300
commit21854575a4ede7d0c16fbe31ac90e66493f607fe (patch)
tree1a196b314cbd7f5eedd16caef6d1de43b0cd2837 /source/blender/blenloader/intern/versioning_cycles.c
parent7ad802cf3ae500bc72863b6dba0f28a488fce3d1 (diff)
Cycles/Eevee: unify light strength and color
Cycles lights now use strength and color properties of the light outside of the shading nodes, just like Eevee. The shading nodes then act as a multiplier on this, and become optional unless textures, fallof or other effects are desired. Backwards compatibility is not exact, as we can't be sure which renderer the .blend was designed for or even if it was designed for a single one. If the render engine in the active scene is set to Cycles, lights are converted to ensure overall light strength remains the same, and removing unnecessary shader node setups that only included a single emission node. If the engine is set to Eevee, we increase strength to remove the automatic 100x multiplier that was there to match Cycles. Differential Revision: https://developer.blender.org/D4588
Diffstat (limited to 'source/blender/blenloader/intern/versioning_cycles.c')
-rw-r--r--source/blender/blenloader/intern/versioning_cycles.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c
index 2bd379c6f19..7616e62af9f 100644
--- a/source/blender/blenloader/intern/versioning_cycles.c
+++ b/source/blender/blenloader/intern/versioning_cycles.c
@@ -49,6 +49,12 @@ static float *cycles_node_socket_float_value(bNodeSocket *socket)
return &socket_data->value;
}
+static float *cycles_node_socket_rgba_value(bNodeSocket *socket)
+{
+ bNodeSocketValueRGBA *socket_data = socket->default_value;
+ return socket_data->value;
+}
+
static IDProperty *cycles_properties_from_ID(ID *id)
{
IDProperty *idprop = IDP_GetProperties(id, false);
@@ -291,6 +297,87 @@ static void image_node_colorspace(bNode *node)
}
}
+static void light_emission_node_to_energy(Light *light, float *energy, float color[3])
+{
+ *energy = 1.0;
+ copy_v3_fl(color, 1.0f);
+
+ /* If nodetree has animation or drivers, don't try to convert. */
+ bNodeTree *ntree = light->nodetree;
+ if (ntree == NULL || ntree->adt) {
+ return;
+ }
+
+ /* Find emission node */
+ bNode *output_node = ntreeShaderOutputNode(ntree, SHD_OUTPUT_CYCLES);
+ if (output_node == NULL) {
+ return;
+ }
+
+ bNode *emission_node = NULL;
+ for (bNodeLink *link = ntree->links.first; link; link = link->next) {
+ if (link->tonode == output_node && link->fromnode->type == SH_NODE_EMISSION) {
+ emission_node = link->fromnode;
+ break;
+ }
+ }
+
+ if (emission_node == NULL) {
+ return;
+ }
+
+ /* Don't convert if anything is linked */
+ bNodeSocket *strength_socket = nodeFindSocket(emission_node, SOCK_IN, "Strength");
+ bNodeSocket *color_socket = nodeFindSocket(emission_node, SOCK_IN, "Color");
+
+ if ((strength_socket->flag & SOCK_IN_USE) || (color_socket->flag & SOCK_IN_USE)) {
+ return;
+ }
+
+ float *strength_value = cycles_node_socket_float_value(strength_socket);
+ float *color_value = cycles_node_socket_rgba_value(color_socket);
+
+ *energy = *strength_value;
+ copy_v3_v3(color, color_value);
+
+ *strength_value = 1.0f;
+ copy_v4_fl(color_value, 1.0f);
+ light->use_nodes = false;
+}
+
+static void light_emission_unify(Light *light, const char *engine)
+{
+ if (light->type != LA_SUN) {
+ light->energy *= 100.0f;
+ }
+
+ /* Attempt to extract constant energy and color from nodes. */
+ bool use_nodes = light->use_nodes;
+ float energy, color[3];
+ light_emission_node_to_energy(light, &energy, color);
+
+ if (STREQ(engine, "CYCLES")) {
+ if (use_nodes) {
+ /* Energy extracted from nodes */
+ light->energy = energy;
+ copy_v3_v3(&light->r, color);
+ }
+ else {
+ /* Default cycles multipliers if there are no nodes */
+ if (light->type == LA_SUN) {
+ light->energy = 1.0f;
+ }
+ else {
+ light->energy = 100.0f;
+ }
+ }
+ }
+ else {
+ /* Disable nodes if scene was configured for Eevee */
+ light->use_nodes = false;
+ }
+}
+
void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bmain)
{
/* Particle shape shared with Eevee. */
@@ -364,4 +451,14 @@ void do_versions_after_linking_cycles(Main *bmain)
}
FOREACH_NODETREE_END;
}
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 280, 64)) {
+ /* Unfiy Cycles and Eevee settings. */
+ Scene *scene = bmain->scenes.first;
+ const char *engine = (scene) ? scene->r.engine : "CYCLES";
+
+ for (Light *light = bmain->lights.first; light; light = light->id.next) {
+ light_emission_unify(light, engine);
+ }
+ }
}