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/render/shader.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'intern/cycles/render/shader.cpp') diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index abb9e19a074..51b7f76b9d5 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -200,7 +200,7 @@ Shader::Shader() used = false; need_update = true; - need_update_attributes = true; + need_update_mesh = true; } Shader::~Shader() @@ -235,9 +235,24 @@ void Shader::set_graph(ShaderGraph *graph_) /* do this here already so that we can detect if mesh or object attributes * are needed, since the node attribute callbacks check if their sockets * are connected but proxy nodes should not count */ - if(graph_) + if(graph_) { graph_->remove_proxy_nodes(); + if(displacement_method != DISPLACE_BUMP) { + graph_->compute_displacement_hash(); + } + } + + /* update geometry if displacement changed */ + if(displacement_method != DISPLACE_BUMP) { + const char *old_hash = (graph)? graph->displacement_hash.c_str() : ""; + const char *new_hash = (graph_)? graph_->displacement_hash.c_str() : ""; + + if(strcmp(old_hash, new_hash) != 0) { + need_update_mesh = true; + } + } + /* assign graph */ delete graph; graph = graph_; @@ -294,9 +309,9 @@ void Shader::tag_update(Scene *scene) } /* compare if the attributes changed, mesh manager will check - * need_update_attributes, update the relevant meshes and clear it. */ + * need_update_mesh, update the relevant meshes and clear it. */ if(attributes.modified(prev_attributes)) { - need_update_attributes = true; + need_update_mesh = true; scene->mesh_manager->need_update = true; } -- cgit v1.2.3