[Bf-blender-cvs] [7e71be2] master: Cycles: Fix filter glossy being broken after recent changes

Sergey Sharybin noreply at git.blender.org
Fri Nov 20 14:44:19 CET 2015


Commit: 7e71be261bb88d0a7c1dcef7b19995317fdb51ef
Author: Sergey Sharybin
Date:   Fri Nov 20 18:18:27 2015 +0500
Branches: master
https://developer.blender.org/rB7e71be261bb88d0a7c1dcef7b19995317fdb51ef

Cycles: Fix filter glossy being broken after recent changes

Basically we can not use sharp closure as a substitude when filter glossy is
used. This is because we can not blur sharp reflection/refraction.

This is quite quick and not really clean implementation. Not really happy
with manual handling of original settings, but this is as good as we can do
in the quick patch. It's a good acknowledgment and we now can re-consider
some aspects of graph simplification to make such cases more natively
supported.

P.S. This failure would have been shown by our regression tests, so please,
bother a bit to run Cycles's test sweep before doing such optimizations.

===================================================================

M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	intern/cycles/render/osl.cpp
M	intern/cycles/render/osl.h
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h
M	intern/cycles/render/svm.cpp
M	intern/cycles/render/svm.h

===================================================================

diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 7496400..7e6e960 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -266,7 +266,10 @@ void ShaderGraph::relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outpu
 	}
 }
 
-void ShaderGraph::finalize(bool do_bump, bool do_osl)
+void ShaderGraph::finalize(Scene *scene,
+                           bool do_bump,
+                           bool do_osl,
+                           bool do_simplify)
 {
 	/* before compiling, the shader graph may undergo a number of modifications.
 	 * currently we set default geometry shader inputs, and create automatic bump
@@ -274,7 +277,7 @@ void ShaderGraph::finalize(bool do_bump, bool do_osl)
 	 * modified afterwards. */
 
 	if(!finalized) {
-		clean();
+		clean(scene);
 		default_inputs(do_osl);
 		refine_bump_nodes();
 
@@ -293,6 +296,9 @@ void ShaderGraph::finalize(bool do_bump, bool do_osl)
 
 		finalized = true;
 	}
+	else if(do_simplify) {
+		simplify_nodes(scene);
+	}
 }
 
 void ShaderGraph::find_dependencies(set<ShaderNode*>& dependencies, ShaderInput *input)
@@ -557,10 +563,10 @@ void ShaderGraph::remove_unneeded_nodes()
 }
 
 /* Step 3: Simplification.*/
-void ShaderGraph::simplify_nodes()
+void ShaderGraph::simplify_nodes(Scene *scene)
 {
 	foreach(ShaderNode *node, nodes) {
-		node->optimize();
+		node->optimize(scene);
 	}
 }
 
@@ -588,7 +594,7 @@ void ShaderGraph::break_cycles(ShaderNode *node, vector<bool>& visited, vector<b
 	on_stack[node->id] = false;
 }
 
-void ShaderGraph::clean()
+void ShaderGraph::clean(Scene *scene)
 {
 	/* Graph simplification:
 	 *  1: Remove unnecesarry nodes
@@ -604,7 +610,7 @@ void ShaderGraph::clean()
 	/* TODO(dingto): Implement */
 
 	/* 3: Simplification. */
-	simplify_nodes();
+	simplify_nodes(scene);
 
 	/* 4: De-duplication. */
 	/* TODO(dingto): Implement */
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index fa2de37..a2c210f 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -29,6 +29,7 @@
 CCL_NAMESPACE_BEGIN
 
 class AttributeRequestSet;
+class Scene;
 class Shader;
 class ShaderInput;
 class ShaderOutput;
@@ -196,7 +197,7 @@ public:
 	virtual void attributes(Shader *shader, AttributeRequestSet *attributes);
 	virtual void compile(SVMCompiler& compiler) = 0;
 	virtual void compile(OSLCompiler& compiler) = 0;
-	virtual void optimize() {};
+	virtual void optimize(Scene * /*scene*/) {};
 
 	virtual bool has_surface_emission() { return false; }
 	virtual bool has_surface_transparent() { return false; }
@@ -204,6 +205,7 @@ public:
 	virtual bool has_bssrdf_bump() { return false; }
 	virtual bool has_spatial_varying() { return false; }
 	virtual bool has_object_dependency() { return false; }
+	virtual bool has_integrator_dependency() { return false; }
 
 	vector<ShaderInput*> inputs;
 	vector<ShaderOutput*> outputs;
@@ -276,8 +278,10 @@ public:
 	void relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outputs, ShaderOutput *output);
 
 	void remove_unneeded_nodes();
-	void simplify_nodes();
-	void finalize(bool do_bump = false, bool do_osl = false);
+	void finalize(Scene *scene,
+	              bool do_bump = false,
+	              bool do_osl = false,
+	              bool do_simplify = false);
 
 	int get_num_closures();
 
@@ -290,7 +294,8 @@ protected:
 	void copy_nodes(set<ShaderNode*>& nodes, map<ShaderNode*, ShaderNode*>& nnodemap);
 
 	void break_cycles(ShaderNode *node, vector<bool>& visited, vector<bool>& on_stack);
-	void clean();
+	void clean(Scene *scene);
+	void simplify_nodes(Scene *scene);
 	void bump_from_displacement();
 	void refine_bump_nodes();
 	void default_inputs(bool do_osl);
diff --git a/intern/cycles/render/integrator.cpp b/intern/cycles/render/integrator.cpp
index 9f8d5b5..47489f6 100644
--- a/intern/cycles/render/integrator.cpp
+++ b/intern/cycles/render/integrator.cpp
@@ -18,6 +18,7 @@
 #include "integrator.h"
 #include "light.h"
 #include "scene.h"
+#include "shader.h"
 #include "sobol.h"
 
 #include "util_foreach.h"
@@ -217,8 +218,14 @@ bool Integrator::modified(const Integrator& integrator)
 		sample_all_lights_indirect == integrator.sample_all_lights_indirect);
 }
 
-void Integrator::tag_update(Scene * /*scene*/)
+void Integrator::tag_update(Scene *scene)
 {
+	foreach(Shader *shader, scene->shaders) {
+		if(shader->has_integrator_dependency) {
+			scene->shader_manager->need_update = true;
+			break;
+		}
+	}
 	need_update = true;
 }
 
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index d8d88b4..d89e748 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -15,7 +15,9 @@
  */
 
 #include "image.h"
+#include "integrator.h"
 #include "nodes.h"
+#include "scene.h"
 #include "svm.h"
 #include "svm_math_util.h"
 #include "osl.h"
@@ -1874,20 +1876,37 @@ GlossyBsdfNode::GlossyBsdfNode()
 {
 	closure = CLOSURE_BSDF_MICROFACET_GGX_ID;
 	distribution = ustring("GGX");
+	distribution_orig = ustring("");
 
 	add_input("Roughness", SHADER_SOCKET_FLOAT, 0.2f);
 }
 
-void GlossyBsdfNode::optimize()
+void GlossyBsdfNode::optimize(Scene *scene)
 {
-	/* Fallback to Sharp closure for Roughness close to 0.
-	 * Note: Keep the epsilon in sync with kernel!
-	 */
-	ShaderInput *roughness_input = get_input("Roughness");
-	if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
-		closure = CLOSURE_BSDF_REFLECTION_ID;
-		distribution = ustring("Sharp");
+	if(distribution_orig == "") {
+		distribution_orig = distribution;
+	}
+	Integrator *integrator = scene->integrator;
+	if(integrator->filter_glossy == 0.0f) {
+		/* Fallback to Sharp closure for Roughness close to 0.
+		 * Note: Keep the epsilon in sync with kernel!
+		 */
+		ShaderInput *roughness_input = get_input("Roughness");
+		if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
+			distribution = ustring("Sharp");
+		}
 	}
+	else {
+		/* Rollback to original distribution when filter glossy is used. */
+		distribution = distribution_orig;
+	}
+	closure = (ClosureType)distribution_enum[distribution];
+}
+
+bool GlossyBsdfNode::has_integrator_dependency()
+{
+	ShaderInput *roughness_input = get_input("Roughness");
+	return !roughness_input->link && roughness_input->value.x <= 1e-4f;
 }
 
 void GlossyBsdfNode::compile(SVMCompiler& compiler)
@@ -1925,21 +1944,38 @@ GlassBsdfNode::GlassBsdfNode()
 {
 	closure = CLOSURE_BSDF_SHARP_GLASS_ID;
 	distribution = ustring("Sharp");
+	distribution_orig = ustring("");
 
 	add_input("Roughness", SHADER_SOCKET_FLOAT, 0.0f);
 	add_input("IOR", SHADER_SOCKET_FLOAT, 0.3f);
 }
 
-void GlassBsdfNode::optimize()
+void GlassBsdfNode::optimize(Scene *scene)
 {
-	/* Fallback to Sharp closure for Roughness close to 0.
-	 * Note: Keep the epsilon in sync with kernel!
-	 */
-	ShaderInput *roughness_input = get_input("Roughness");
-	if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
-		closure = CLOSURE_BSDF_SHARP_GLASS_ID;
-		distribution = ustring("Sharp");
+	if(distribution_orig == "") {
+		distribution_orig = distribution;
+	}
+	Integrator *integrator = scene->integrator;
+	if(integrator->filter_glossy == 0.0f) {
+		/* Fallback to Sharp closure for Roughness close to 0.
+		 * Note: Keep the epsilon in sync with kernel!
+		 */
+		ShaderInput *roughness_input = get_input("Roughness");
+		if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
+			distribution = ustring("Sharp");
+		}
+	}
+	else {
+		/* Rollback to original distribution when filter glossy is used. */
+		distribution = distribution_orig;
 	}
+	closure = (ClosureType)distribution_enum[distribution];
+}
+
+bool GlassBsdfNode::has_integrator_dependency()
+{
+	ShaderInput *roughness_input = get_input("Roughness");
+	return !roughness_input->link && roughness_input->value.x <= 1e-4f;
 }
 
 void GlassBsdfNode::compile(SVMCompiler& compiler)
@@ -1977,21 +2013,38 @@ RefractionBsdfNode::RefractionBsdfNode()
 {
 	closure = CLOSURE_BSDF_REFRACTION_ID;
 	distribution = ustring("Sharp");
+	distribution_orig = ustring("");
 
 	add_input("Roughness", SHADER_SOCKET_FLOAT, 0.0f);
 	add_input("IOR", SHADER_SOCKET_FLOAT, 0.3f);
 }
 
-void RefractionBsdfNode::optimize()
+void RefractionBsdfNode::optimize(Scene *scene)
 {
-	/* Fallback to Sharp closure for Roughness close to 0.
-	 * Note: Keep the epsilon in sync with kernel!
-	 */
-	ShaderInput *roughness_input = get_input("Roughness");
-	if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
-		closure = CLOSURE_BSDF_REFRACTION_ID;
-		distribution = ustring("Sharp");
+	if(distribution_orig == "") {
+		distribution_orig = distribution;
+	}
+	Integrator *integrator = scene->integrator;
+	if(integrator->filter_glossy == 0.0f) {
+		/* Fallback to Sharp closure for Roughness close to 0.
+		 * Note: Keep the epsilon in sync with kernel!
+		 */
+		ShaderInput *roughness_input = get_input("Roughness");
+		if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
+			distribution = ustring("Sharp");
+		}
 	}
+	else {
+		/* Rollback to original distribution when filter glossy is used. */
+		distribution = distribution_orig;
+	}
+	closure = (ClosureType)distribution_enum[distribution];
+}
+
+bool RefractionBsdfNode::has_integrator_dependency()
+{
+	ShaderInput *roughness_input = get_input("Roughness");
+	return !roughness_input->link && roughness_input->value.x <= 1e-4f;
 }
 
 void RefractionBsdfNode::compile(SVMCompiler& compiler)
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 2b205c4..4f40612 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -24,6 +24,7 @@
 CCL_NAMESPACE_BEGIN
 
 class ImageManager;
+class Scene;
 class Shader;
 
 /* Texture Mapping */
@@ -310,9 +311,10 @@ class GlossyBsdfNode : public BsdfNode {
 public:
 	SHADER_NODE_CLASS(GlossyBsdfNode)
 
-	void optimize();
+	void optimize(Scene *scene);
+	bool has_integrator_dependency();
 
-	ustring distribution;
+	ustring distribution, distribution_orig;
 	static ShaderEnum distribution_enum;
 };
 
@@ -320,9 +322,10 @@ class GlassBsdfNode : public BsdfNode {
 public:
 	SHADER_NODE_CLASS(GlassBsdfNode)
 
-	void optimize();
+	void optimize(Scene *scene);
+	bool has_int

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list