diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-24 22:19:48 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-29 19:07:08 +0300 |
commit | 1eeb846e781dac3f55d6c108d0fc4c3cfe88f4cc (patch) | |
tree | c80b01eb79df21ad995cb22831ac6012dc0fd1c1 /intern/cycles/render/graph.cpp | |
parent | fb941679bb6e537a8fb1e1de69b5a446490e761b (diff) |
Fix Cycles viewport render not updating when tweaking displacement shader.
This was disabled to avoid updating the geometry every time when the
material includes displacement, because there was no way to distinguish
between surface shader and displacement updates.
As a solution, we now compute an MD5 hash of the nodes linked to the
displacement socket, and only update the mesh if that changes.
Differential Revision: https://developer.blender.org/D3018
Diffstat (limited to 'intern/cycles/render/graph.cpp')
-rw-r--r-- | intern/cycles/render/graph.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index fb2e34c2fc7..096de878e51 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -23,8 +23,9 @@ #include "util/util_algorithm.h" #include "util/util_foreach.h" -#include "util/util_queue.h" #include "util/util_logging.h" +#include "util/util_md5.h" +#include "util/util_queue.h" CCL_NAMESPACE_BEGIN @@ -683,6 +684,32 @@ void ShaderGraph::break_cycles(ShaderNode *node, vector<bool>& visited, vector<b on_stack[node->id] = false; } +void ShaderGraph::compute_displacement_hash() +{ + /* Compute hash of all nodes linked to displacement, to detect if we need + * to recompute displacement when shader nodes change. */ + ShaderInput *displacement_in = output()->input("Displacement"); + + if(!displacement_in->link) { + displacement_hash = ""; + return; + } + + ShaderNodeSet nodes_displace; + find_dependencies(nodes_displace, displacement_in); + + MD5Hash md5; + foreach(ShaderNode *node, nodes_displace) { + node->hash(md5); + foreach(ShaderInput *input, node->inputs) { + int link_id = (input->link) ? input->link->parent->id : 0; + md5.append((uint8_t*)&link_id, sizeof(link_id)); + } + } + + displacement_hash = md5.get_hex(); +} + void ShaderGraph::clean(Scene *scene) { /* Graph simplification */ |