diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-11-25 18:21:06 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-11-25 18:23:52 +0300 |
commit | bbd33b3a8ec563372bf230204290f7338a35eb29 (patch) | |
tree | 13cb58870530f6e4208bcb435ded59f42bbc7d72 /intern/cycles/blender/blender_shader.cpp | |
parent | 50c08bdc0ec312afbd948121d9a072728ae54015 (diff) |
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
Diffstat (limited to 'intern/cycles/blender/blender_shader.cpp')
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 3f4f1bb206b..38e019eb0c1 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)) |