Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/graph.cpp
| /* | /* | ||||
| * Copyright 2011-2013 Blender Foundation | * Copyright 2011-2016 Blender Foundation | ||||
| * | * | ||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| * You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
| * | * | ||||
| * http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "attribute.h" | #include "attribute.h" | ||||
| #include "graph.h" | #include "graph.h" | ||||
| #include "nodes.h" | #include "nodes.h" | ||||
| #include "shader.h" | #include "shader.h" | ||||
| #include "constant_fold.h" | |||||
| #include "util_algorithm.h" | #include "util_algorithm.h" | ||||
| #include "util_debug.h" | #include "util_debug.h" | ||||
| #include "util_foreach.h" | #include "util_foreach.h" | ||||
| #include "util_queue.h" | #include "util_queue.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| foreach(ShaderOutput *socket, outputs) | foreach(ShaderOutput *socket, outputs) | ||||
| if(socket->name() == name) | if(socket->name() == name) | ||||
| return socket; | return socket; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| bool ShaderNode::all_inputs_constant() const | |||||
| { | |||||
| foreach(ShaderInput *input, inputs) { | |||||
| if(input->link) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes) | void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes) | ||||
| { | { | ||||
| foreach(ShaderInput *input, inputs) { | foreach(ShaderInput *input, inputs) { | ||||
| if(!input->link) { | if(!input->link) { | ||||
| if(input->flags() & SocketType::LINK_TEXTURE_GENERATED) { | if(input->flags() & SocketType::LINK_TEXTURE_GENERATED) { | ||||
| if(shader->has_surface) | if(shader->has_surface) | ||||
| attributes->add(ATTR_STD_GENERATED); | attributes->add(ATTR_STD_GENERATED); | ||||
| if(shader->has_volume) | if(shader->has_volume) | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to) | ||||
| } | } | ||||
| else { | else { | ||||
| /* types match, just connect */ | /* types match, just connect */ | ||||
| to->link = from; | to->link = from; | ||||
| from->links.push_back(to); | from->links.push_back(to); | ||||
| } | } | ||||
| } | } | ||||
| void ShaderGraph::disconnect(ShaderOutput *from) | |||||
| { | |||||
| assert(!finalized); | |||||
| foreach(ShaderInput *sock, from->links) { | |||||
| sock->link = NULL; | |||||
| } | |||||
| from->links.clear(); | |||||
| } | |||||
| void ShaderGraph::disconnect(ShaderInput *to) | void ShaderGraph::disconnect(ShaderInput *to) | ||||
| { | { | ||||
| assert(!finalized); | assert(!finalized); | ||||
| assert(to->link); | assert(to->link); | ||||
| ShaderOutput *from = to->link; | ShaderOutput *from = to->link; | ||||
| to->link = NULL; | to->link = NULL; | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | foreach(ShaderOutput *output, node->outputs) { | ||||
| } | } | ||||
| /* Schedule node if its inputs are fully done. */ | /* Schedule node if its inputs are fully done. */ | ||||
| if(check_node_inputs_traversed(input->parent, done)) { | if(check_node_inputs_traversed(input->parent, done)) { | ||||
| traverse_queue.push(input->parent); | traverse_queue.push(input->parent); | ||||
| scheduled.insert(input->parent); | scheduled.insert(input->parent); | ||||
| } | } | ||||
| } | } | ||||
| /* Optimize current node. */ | /* Optimize current node. */ | ||||
| if(node->constant_fold(this, output, output->links[0])) { | ConstantFolder folder(this, node, output); | ||||
| /* Apply optimized value to other connected sockets and disconnect. */ | node->constant_fold(folder); | ||||
| vector<ShaderInput*> links(output->links); | |||||
| for(size_t i = 0; i < links.size(); i++) { | |||||
| if(i > 0) | |||||
| links[i]->parent->copy_value(links[i]->socket_type, *links[0]->parent, links[0]->socket_type); | |||||
| disconnect(links[i]); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Step 3: Simplification. */ | /* Step 3: Simplification. */ | ||||
| void ShaderGraph::simplify_settings(Scene *scene) | void ShaderGraph::simplify_settings(Scene *scene) | ||||
| { | { | ||||
| foreach(ShaderNode *node, nodes) { | foreach(ShaderNode *node, nodes) { | ||||
| ▲ Show 20 Lines • Show All 524 Lines • Show Last 20 Lines | |||||