Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/graph.cpp
| Show All 12 Lines | |||||
| * 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 244 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(this, node, output).process_fold(); | ||||
| /* Apply optimized value to other connected sockets and disconnect. */ | |||||
| 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 | |||||