Fix #35847: cycles group nodes did not work well exposing inputs like normal or
texture coordinate that should automatically use the default normal or texture coordinate appropriate for that node, rather than some fixed value specified by the user.
This commit is contained in:
@@ -199,7 +199,7 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add automatic conversion node in case of type mismatch */
|
/* add automatic conversion node in case of type mismatch */
|
||||||
ShaderNode *convert = add(new ConvertNode(from->type, to->type));
|
ShaderNode *convert = add(new ConvertNode(from->type, to->type, true));
|
||||||
|
|
||||||
connect(from, convert->inputs[0]);
|
connect(from, convert->inputs[0]);
|
||||||
connect(convert->outputs[0], to);
|
connect(convert->outputs[0], to);
|
||||||
@@ -341,6 +341,24 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach(ShaderInput *to, links) {
|
foreach(ShaderInput *to, links) {
|
||||||
|
/* remove any autoconvert nodes too if they lead to
|
||||||
|
* sockets with an automatically set default value */
|
||||||
|
ShaderNode *tonode = to->parent;
|
||||||
|
|
||||||
|
if(tonode->special_type == SHADER_SPECIAL_TYPE_AUTOCONVERT) {
|
||||||
|
bool all_links_removed = true;
|
||||||
|
|
||||||
|
foreach(ShaderInput *autoin, tonode->outputs[0]->links) {
|
||||||
|
if(autoin->default_value == ShaderInput::NONE)
|
||||||
|
all_links_removed = false;
|
||||||
|
else
|
||||||
|
disconnect(autoin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(all_links_removed)
|
||||||
|
removed[tonode->id] = true;
|
||||||
|
}
|
||||||
|
|
||||||
disconnect(to);
|
disconnect(to);
|
||||||
|
|
||||||
/* transfer the default input value to the target socket */
|
/* transfer the default input value to the target socket */
|
||||||
@@ -352,10 +370,10 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
removed[proxy->id] = true;
|
removed[proxy->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
|
else if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) {
|
||||||
/* remove useless mix closures nodes */
|
|
||||||
if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) {
|
|
||||||
MixClosureNode *mix = static_cast<MixClosureNode*>(node);
|
MixClosureNode *mix = static_cast<MixClosureNode*>(node);
|
||||||
|
|
||||||
|
/* remove useless mix closures nodes */
|
||||||
if(mix->outputs[0]->links.size() && mix->inputs[1]->link == mix->inputs[2]->link) {
|
if(mix->outputs[0]->links.size() && mix->inputs[1]->link == mix->inputs[2]->link) {
|
||||||
ShaderOutput *output = mix->inputs[1]->link;
|
ShaderOutput *output = mix->inputs[1]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
@@ -370,15 +388,11 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
connect(output, input);
|
connect(output, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* remove unused mix closure input when factor is 0.0 or 1.0 */
|
/* remove unused mix closure input when factor is 0.0 or 1.0 */
|
||||||
if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) {
|
/* check for closure links and make sure factor link is disconnected */
|
||||||
MixClosureNode *mix = static_cast<MixClosureNode*>(node);
|
|
||||||
/* Check for closure links and make sure factor link is disconnected */
|
|
||||||
if(mix->outputs[0]->links.size() && mix->inputs[1]->link && mix->inputs[2]->link && !mix->inputs[0]->link) {
|
if(mix->outputs[0]->links.size() && mix->inputs[1]->link && mix->inputs[2]->link && !mix->inputs[0]->link) {
|
||||||
|
/* factor 0.0 */
|
||||||
/* Factor 0.0 */
|
|
||||||
if(mix->inputs[0]->value.x == 0.0f) {
|
if(mix->inputs[0]->value.x == 0.0f) {
|
||||||
ShaderOutput *output = mix->inputs[1]->link;
|
ShaderOutput *output = mix->inputs[1]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
@@ -393,7 +407,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
connect(output, input);
|
connect(output, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Factor 1.0 */
|
/* factor 1.0 */
|
||||||
else if(mix->inputs[0]->value.x == 1.0f) {
|
else if(mix->inputs[0]->value.x == 1.0f) {
|
||||||
ShaderOutput *output = mix->inputs[2]->link;
|
ShaderOutput *output = mix->inputs[2]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
@@ -75,7 +75,8 @@ enum ShaderBump {
|
|||||||
enum ShaderNodeSpecialType {
|
enum ShaderNodeSpecialType {
|
||||||
SHADER_SPECIAL_TYPE_NONE,
|
SHADER_SPECIAL_TYPE_NONE,
|
||||||
SHADER_SPECIAL_TYPE_PROXY,
|
SHADER_SPECIAL_TYPE_PROXY,
|
||||||
SHADER_SPECIAL_TYPE_MIX_CLOSURE
|
SHADER_SPECIAL_TYPE_MIX_CLOSURE,
|
||||||
|
SHADER_SPECIAL_TYPE_AUTOCONVERT
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Enum
|
/* Enum
|
||||||
|
@@ -1121,12 +1121,15 @@ void MappingNode::compile(OSLCompiler& compiler)
|
|||||||
|
|
||||||
/* Convert */
|
/* Convert */
|
||||||
|
|
||||||
ConvertNode::ConvertNode(ShaderSocketType from_, ShaderSocketType to_)
|
ConvertNode::ConvertNode(ShaderSocketType from_, ShaderSocketType to_, bool autoconvert)
|
||||||
: ShaderNode("convert")
|
: ShaderNode("convert")
|
||||||
{
|
{
|
||||||
from = from_;
|
from = from_;
|
||||||
to = to_;
|
to = to_;
|
||||||
|
|
||||||
|
if(autoconvert)
|
||||||
|
special_type = SHADER_SPECIAL_TYPE_AUTOCONVERT;
|
||||||
|
|
||||||
assert(from != to);
|
assert(from != to);
|
||||||
|
|
||||||
if(from == SHADER_SOCKET_FLOAT)
|
if(from == SHADER_SOCKET_FLOAT)
|
||||||
@@ -1271,7 +1274,7 @@ void ProxyNode::compile(OSLCompiler& compiler)
|
|||||||
/* BSDF Closure */
|
/* BSDF Closure */
|
||||||
|
|
||||||
BsdfNode::BsdfNode(bool scattering_)
|
BsdfNode::BsdfNode(bool scattering_)
|
||||||
: ShaderNode("subsurface_scattering"), scattering(scattering_)
|
: ShaderNode("bsdf"), scattering(scattering_)
|
||||||
{
|
{
|
||||||
closure = ccl::CLOSURE_BSSRDF_ID;
|
closure = ccl::CLOSURE_BSSRDF_ID;
|
||||||
|
|
||||||
|
@@ -182,7 +182,7 @@ public:
|
|||||||
|
|
||||||
class ConvertNode : public ShaderNode {
|
class ConvertNode : public ShaderNode {
|
||||||
public:
|
public:
|
||||||
ConvertNode(ShaderSocketType from, ShaderSocketType to);
|
ConvertNode(ShaderSocketType from, ShaderSocketType to, bool autoconvert = false);
|
||||||
SHADER_NODE_BASE_CLASS(ConvertNode)
|
SHADER_NODE_BASE_CLASS(ConvertNode)
|
||||||
|
|
||||||
ShaderSocketType from, to;
|
ShaderSocketType from, to;
|
||||||
|
@@ -308,6 +308,8 @@ void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
to->flag |= (from->flag & SOCK_HIDE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path))
|
static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path))
|
||||||
|
Reference in New Issue
Block a user