From 4fba59c55defdde69838bc8a8e9bcf933d8e8f4c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 16 Mar 2023 14:44:50 +0100 Subject: [PATCH] Fix #105803: Cycles slow light tree build when previewing shader nodes When linking a texture directly to the material output, it's likely being done for the purpose of previewing. In that case, bias the heuristic towards not building a light tree, as it's likely not needed and slow on dense meshes. --- intern/cycles/scene/shader.cpp | 10 ++++++++++ intern/cycles/scene/shader_graph.cpp | 1 + intern/cycles/scene/shader_nodes.h | 2 ++ 3 files changed, 13 insertions(+) diff --git a/intern/cycles/scene/shader.cpp b/intern/cycles/scene/shader.cpp index dfd86f82bb6..da8c5719fa2 100644 --- a/intern/cycles/scene/shader.cpp +++ b/intern/cycles/scene/shader.cpp @@ -153,6 +153,16 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant) estimate *= node->get_float(strength_in->socket_type); } + /* Lower importance of emission nodes from automatic value/color to shader + * conversion, as these are likely used for previewing and can be slow to + * build a light tree for on dense meshes. */ + if (node->type == EmissionNode::get_node_type()) { + EmissionNode *emission_node = static_cast(node); + if (emission_node->from_auto_conversion) { + estimate *= 0.1f; + } + } + return estimate; } else if (node->type == LightFalloffNode::get_node_type() || diff --git a/intern/cycles/scene/shader_graph.cpp b/intern/cycles/scene/shader_graph.cpp index ef3f142ed4e..f86385b5b04 100644 --- a/intern/cycles/scene/shader_graph.cpp +++ b/intern/cycles/scene/shader_graph.cpp @@ -260,6 +260,7 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to) if (to->type() == SocketType::CLOSURE) { EmissionNode *emission = create_node(); + emission->from_auto_conversion = true; emission->set_color(one_float3()); emission->set_strength(1.0f); convert = add(emission); diff --git a/intern/cycles/scene/shader_nodes.h b/intern/cycles/scene/shader_nodes.h index 35c5a7a61ac..0c36d17107c 100644 --- a/intern/cycles/scene/shader_nodes.h +++ b/intern/cycles/scene/shader_nodes.h @@ -723,6 +723,8 @@ class EmissionNode : public ShaderNode { NODE_SOCKET_API(float3, color) NODE_SOCKET_API(float, strength) NODE_SOCKET_API(float, surface_mix_weight) + + bool from_auto_conversion = false; }; class BackgroundNode : public ShaderNode {