From 1eeb846e781dac3f55d6c108d0fc4c3cfe88f4cc Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 24 Jan 2018 20:19:48 +0100 Subject: 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 --- intern/cycles/graph/node.cpp | 20 ++++++++++++++++++++ intern/cycles/graph/node.h | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'intern/cycles/graph') diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp index 10d91a1e4ef..c71221746ad 100644 --- a/intern/cycles/graph/node.cpp +++ b/intern/cycles/graph/node.cpp @@ -18,6 +18,7 @@ #include "graph/node_type.h" #include "util/util_foreach.h" +#include "util/util_md5.h" #include "util/util_param.h" #include "util/util_transform.h" @@ -403,5 +404,24 @@ bool Node::equals(const Node& other) const return true; } +/* Hash */ + +void Node::hash(MD5Hash& md5) +{ + md5.append(type->name.string()); + + foreach(const SocketType& socket, type->inputs) { + md5.append(socket.name.string()); + + if(socket.is_array()) { + const array* a = (const array*)(((char*)this) + socket.struct_offset); + md5.append((uint8_t*)a->data(), socket.size() * a->size()); + } + else { + md5.append(((uint8_t*)this) + socket.struct_offset, socket.size()); + } + } +} + CCL_NAMESPACE_END diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h index 53425f5faf1..d198c38be32 100644 --- a/intern/cycles/graph/node.h +++ b/intern/cycles/graph/node.h @@ -24,6 +24,7 @@ CCL_NAMESPACE_BEGIN +class MD5Hash; struct Node; struct NodeType; struct Transform; @@ -88,6 +89,9 @@ struct Node /* equals */ bool equals(const Node& other) const; + /* compute hash of node and its socket values */ + void hash(MD5Hash& md5); + ustring name; const NodeType *type; }; -- cgit v1.2.3