[Bf-blender-cvs] [bbd33b3] master: Cycles: Create proper sockets for OSL script nodes

Sergey Sharybin noreply at git.blender.org
Wed Nov 25 16:26:19 CET 2015


Commit: bbd33b3a8ec563372bf230204290f7338a35eb29
Author: Sergey Sharybin
Date:   Wed Nov 25 20:21:06 2015 +0500
Branches: master
https://developer.blender.org/rBbbd33b3a8ec563372bf230204290f7338a35eb29

Cycles: Create proper sockets for OSL script nodes

Previously render nodes will be always created with just a VECTOR socket
type and then those sockets will try to be set as all point, vector and
normal to work around lack of such a subtype distinguishing in blender.

This change makes it so subtype is being queried from OSL itself and
proper subtupe is being used for socket.

It's still not in use for the official builds because it requires changes
applied recently on the 1.7 branch of OSL:

  https://github.com/imageworks/OpenShadingLanguage/commit/f70e58f

This solves artists confusion reported in T46117.

Reviewers: #cycles, juicyfruit

Reviewed By: #cycles, juicyfruit

Subscribers: juicyfruit

Differential Revision: https://developer.blender.org/D1627

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

M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 3f4f1bb..38e019e 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -107,6 +107,32 @@ static ShaderSocketType convert_socket_type(BL::NodeSocket b_socket)
 	}
 }
 
+#ifdef WITH_OSL
+static ShaderSocketType convert_osl_socket_type(OSL::OSLQuery& query,
+                                                BL::NodeSocket b_socket)
+{
+	ShaderSocketType socket_type = convert_socket_type(b_socket);
+#if OSL_LIBRARY_VERSION_CODE < 10701
+	(void) query;
+#else
+	if(socket_type == SHADER_SOCKET_VECTOR) {
+		/* TODO(sergey): Do we need compatible_name() here? */
+		const OSL::OSLQuery::Parameter *param = query.getparam(b_socket.name());
+		assert(param != NULL);
+		if(param != NULL) {
+			if(param->type.vecsemantics == TypeDesc::POINT) {
+				socket_type = SHADER_SOCKET_POINT;
+			}
+			else if(param->type.vecsemantics == TypeDesc::NORMAL) {
+				socket_type = SHADER_SOCKET_NORMAL;
+			}
+		}
+	}
+#endif
+	return socket_type;
+}
+#endif  /* WITH_OSL */
+
 static void set_default_value(ShaderInput *input, BL::NodeSocket b_sock, BL::BlendData b_data, BL::ID b_id)
 {
 	/* copy values for non linked inputs */
@@ -508,6 +534,23 @@ static ShaderNode *add_node(Scene *scene,
 			BL::ShaderNodeScript b_script_node(b_node);
 			OSLScriptNode *script_node = new OSLScriptNode();
 
+			OSLShaderManager *manager = (OSLShaderManager*)scene->shader_manager;
+			string bytecode_hash = b_script_node.bytecode_hash();
+
+			/* Gather additional information from the shader, such as
+			 * input/output type info needed for proper node construction.
+			 */
+			OSL::OSLQuery query;
+#if OSL_LIBRARY_VERSION_CODE >= 10701
+			if(!bytecode_hash.empty()) {
+				query.open_bytecode(b_script_node.bytecode());
+			}
+			else {
+				!OSLShaderManager::osl_query(query, b_script_node.filepath());
+			}
+			/* TODO(sergey): Add proper query info error parsing. */
+#endif
+
 			/* Generate inputs/outputs from node sockets
 			 *
 			 * Note: the node sockets are generated from OSL parameters,
@@ -520,7 +563,7 @@ static ShaderNode *add_node(Scene *scene,
 			for(b_script_node.inputs.begin(b_input); b_input != b_script_node.inputs.end(); ++b_input) {
 				script_node->input_names.push_back(ustring(b_input->name()));
 				ShaderInput *input = script_node->add_input(script_node->input_names.back().c_str(),
-				                                            convert_socket_type(*b_input));
+				                                            convert_osl_socket_type(query, *b_input));
 				set_default_value(input, *b_input, b_data, b_ntree);
 			}
 
@@ -529,13 +572,10 @@ static ShaderNode *add_node(Scene *scene,
 			for(b_script_node.outputs.begin(b_output); b_output != b_script_node.outputs.end(); ++b_output) {
 				script_node->output_names.push_back(ustring(b_output->name()));
 				script_node->add_output(script_node->output_names.back().c_str(),
-				                        convert_socket_type(*b_output));
+				                        convert_osl_socket_type(query, *b_output));
 			}
 
 			/* load bytecode or filepath */
-			OSLShaderManager *manager = (OSLShaderManager*)scene->shader_manager;
-			string bytecode_hash = b_script_node.bytecode_hash();
-
 			if(!bytecode_hash.empty()) {
 				/* loaded bytecode if not already done */
 				if(!manager->shader_test_loaded(bytecode_hash))
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 1594e88..e661b0b 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -4478,6 +4478,7 @@ void OSLScriptNode::compile(SVMCompiler& /*compiler*/)
 
 void OSLScriptNode::compile(OSLCompiler& compiler)
 {
+#if OSL_LIBRARY_VERSION_CODE < 10701
 	/* XXX fix for #36790:
 	 * point and normal parameters are reflected as generic SOCK_VECTOR sockets
 	 * on the node. Socket fixed input values need to be copied explicitly here for
@@ -4497,6 +4498,7 @@ void OSLScriptNode::compile(OSLCompiler& compiler)
 			}
 		}
 	}
+#endif
 
 	if(!filepath.empty())
 		compiler.add(this, filepath.c_str(), true);




More information about the Bf-blender-cvs mailing list