diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-09-15 20:31:07 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-09-15 20:31:07 +0400 |
commit | 41081b3e8cd0f5f80f7753ad600db64b93a4d9b5 (patch) | |
tree | 1b3be00d4d58bdffc6ded86b0a633572818771c9 /intern | |
parent | 21964e65380131324dcb50567e913cf6e4a29102 (diff) |
Generate compatible OSL shader parameter names in cases where the node has and input and output with the same name. In that case the convention is to add suffixes "In" and "Out" respectively.
Example:
Blender node has one input "Color" and one output "Color"
-> OSL parameter names should be "ColorIn" and "ColorOut"
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/render/osl.cpp | 52 | ||||
-rw-r--r-- | intern/cycles/render/osl.h | 4 |
2 files changed, 42 insertions, 14 deletions
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 75a10d38c5d..39d04814d33 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -154,14 +154,43 @@ string OSLCompiler::id(ShaderNode *node) return stream.str(); } -string OSLCompiler::compatible_name(const char *name) +string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input) { - string sname = name; + string sname(input->name); size_t i; + /* strip whitespace */ while((i = sname.find(" ")) != string::npos) sname.replace(i, 1, ""); + /* if output exists with the same name, add "In" suffix */ + foreach(ShaderOutput *output, node->outputs) { + if (strcmp(input->name, output->name)==0) { + sname += "In"; + break; + } + } + + return sname; +} + +string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output) +{ + string sname(output->name); + size_t i; + + /* strip whitespace */ + while((i = sname.find(" ")) != string::npos) + sname.replace(i, 1, ""); + + /* if output exists with the same name, add "In" suffix */ + foreach(ShaderInput *input, node->inputs) { + if (strcmp(input->name, output->name)==0) { + sname += "Out"; + break; + } + } + return sname; } @@ -198,21 +227,22 @@ void OSLCompiler::add(ShaderNode *node, const char *name) else if(input->default_value != ShaderInput::NONE) continue; + string param_name = compatible_name(node, input); switch(input->type) { case SHADER_SOCKET_COLOR: - parameter_color(compatible_name(input->name).c_str(), input->value); + parameter_color(param_name.c_str(), input->value); break; case SHADER_SOCKET_POINT: - parameter_point(compatible_name(input->name).c_str(), input->value); + parameter_point(param_name.c_str(), input->value); break; case SHADER_SOCKET_VECTOR: - parameter_vector(compatible_name(input->name).c_str(), input->value); + parameter_vector(param_name.c_str(), input->value); break; case SHADER_SOCKET_NORMAL: - parameter_normal(compatible_name(input->name).c_str(), input->value); + parameter_normal(param_name.c_str(), input->value); break; case SHADER_SOCKET_FLOAT: - parameter(compatible_name(input->name).c_str(), input->value.x); + parameter(param_name.c_str(), input->value.x); break; case SHADER_SOCKET_CLOSURE: break; @@ -242,12 +272,8 @@ void OSLCompiler::add(ShaderNode *node, const char *name) /* connect shaders */ string id_from = id(input->link->parent); string id_to = id(node); - string param_from = compatible_name(input->link->name); - string param_to = compatible_name(input->name); - - /* avoid name conflict with same input/output socket name */ - if(input->link->parent->input(input->link->name)) - param_from += "_"; + string param_from = compatible_name(input->link->parent, input->link); + string param_to = compatible_name(node, input); ss->ConnectShaders(id_from.c_str(), param_from.c_str(), id_to.c_str(), param_to.c_str()); } diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h index 2da951ab3d2..90107a34a98 100644 --- a/intern/cycles/render/osl.h +++ b/intern/cycles/render/osl.h @@ -37,6 +37,7 @@ class OSLGlobals; class Scene; class ShaderGraph; class ShaderNode; +class ShaderInput; class ShaderOutput; #ifdef WITH_OSL @@ -96,7 +97,8 @@ private: string id(ShaderNode *node); void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type); bool node_skip_input(ShaderNode *node, ShaderInput *input); - string compatible_name(const char *name); + string compatible_name(ShaderNode *node, ShaderInput *input); + string compatible_name(ShaderNode *node, ShaderOutput *output); void find_dependencies(set<ShaderNode*>& dependencies, ShaderInput *input); void generate_nodes(const set<ShaderNode*>& nodes); |