Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/graph.cpp
| Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | OutputNode *ShaderGraph::output() | ||||
| return (OutputNode*)nodes.front(); | return (OutputNode*)nodes.front(); | ||||
| } | } | ||||
| ShaderGraph *ShaderGraph::copy() | ShaderGraph *ShaderGraph::copy() | ||||
| { | { | ||||
| ShaderGraph *newgraph = new ShaderGraph(); | ShaderGraph *newgraph = new ShaderGraph(); | ||||
| /* copy nodes */ | /* copy nodes */ | ||||
| set<ShaderNode*> nodes_all; | ShaderNodeSet nodes_all; | ||||
| foreach(ShaderNode *node, nodes) | foreach(ShaderNode *node, nodes) | ||||
| nodes_all.insert(node); | nodes_all.insert(node); | ||||
| map<ShaderNode*, ShaderNode*> nodes_copy; | ShaderNodeMap nodes_copy; | ||||
| copy_nodes(nodes_all, nodes_copy); | copy_nodes(nodes_all, nodes_copy); | ||||
| /* add nodes (in same order, so output is still first) */ | /* add nodes (in same order, so output is still first) */ | ||||
| newgraph->nodes.clear(); | newgraph->nodes.clear(); | ||||
| foreach(ShaderNode *node, nodes) | foreach(ShaderNode *node, nodes) | ||||
| newgraph->add(nodes_copy[node]); | newgraph->add(nodes_copy[node]); | ||||
| return newgraph; | return newgraph; | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if(!finalized) { | ||||
| finalized = true; | finalized = true; | ||||
| } | } | ||||
| else if(do_simplify) { | else if(do_simplify) { | ||||
| simplify_nodes(scene); | simplify_nodes(scene); | ||||
| } | } | ||||
| } | } | ||||
| void ShaderGraph::find_dependencies(set<ShaderNode*>& dependencies, ShaderInput *input) | void ShaderGraph::find_dependencies(ShaderNodeSet& dependencies, ShaderInput *input) | ||||
| { | { | ||||
| /* find all nodes that this input depends on directly and indirectly */ | /* find all nodes that this input depends on directly and indirectly */ | ||||
| ShaderNode *node = (input->link)? input->link->parent: NULL; | ShaderNode *node = (input->link)? input->link->parent: NULL; | ||||
| if(node) { | if(node) { | ||||
| foreach(ShaderInput *in, node->inputs) | foreach(ShaderInput *in, node->inputs) | ||||
| find_dependencies(dependencies, in); | find_dependencies(dependencies, in); | ||||
| dependencies.insert(node); | dependencies.insert(node); | ||||
| } | } | ||||
| } | } | ||||
| void ShaderGraph::copy_nodes(set<ShaderNode*>& nodes, map<ShaderNode*, ShaderNode*>& nnodemap) | void ShaderGraph::copy_nodes(ShaderNodeSet& nodes, ShaderNodeMap& nnodemap) | ||||
| { | { | ||||
| /* copy a set of nodes, and the links between them. the assumption is | /* copy a set of nodes, and the links between them. the assumption is | ||||
| * made that all nodes that inputs are linked to are in the set too. */ | * made that all nodes that inputs are linked to are in the set too. */ | ||||
| /* copy nodes */ | /* copy nodes */ | ||||
| foreach(ShaderNode *node, nodes) { | foreach(ShaderNode *node, nodes) { | ||||
| ShaderNode *nnode = node->clone(); | ShaderNode *nnode = node->clone(); | ||||
| nnodemap[node] = nnode; | nnodemap[node] = nnode; | ||||
| ▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | void ShaderGraph::refine_bump_nodes() | ||||
| /* we transverse the node graph looking for bump nodes, when we find them, | /* we transverse the node graph looking for bump nodes, when we find them, | ||||
| * like in bump_from_displacement(), we copy the sub-graph defined from "bump" | * like in bump_from_displacement(), we copy the sub-graph defined from "bump" | ||||
| * input to the inputs "center","dx" and "dy" What is in "bump" input is moved | * input to the inputs "center","dx" and "dy" What is in "bump" input is moved | ||||
| * to "center" input. */ | * to "center" input. */ | ||||
| foreach(ShaderNode *node, nodes) { | foreach(ShaderNode *node, nodes) { | ||||
| if(node->name == ustring("bump") && node->input("Height")->link) { | if(node->name == ustring("bump") && node->input("Height")->link) { | ||||
| ShaderInput *bump_input = node->input("Height"); | ShaderInput *bump_input = node->input("Height"); | ||||
| set<ShaderNode*> nodes_bump; | ShaderNodeSet nodes_bump; | ||||
| /* make 2 extra copies of the subgraph defined in Bump input */ | /* make 2 extra copies of the subgraph defined in Bump input */ | ||||
| map<ShaderNode*, ShaderNode*> nodes_dx; | ShaderNodeMap nodes_dx; | ||||
| map<ShaderNode*, ShaderNode*> nodes_dy; | ShaderNodeMap nodes_dy; | ||||
| /* find dependencies for the given input */ | /* find dependencies for the given input */ | ||||
| find_dependencies(nodes_bump, bump_input ); | find_dependencies(nodes_bump, bump_input); | ||||
| copy_nodes(nodes_bump, nodes_dx); | copy_nodes(nodes_bump, nodes_dx); | ||||
| copy_nodes(nodes_bump, nodes_dy); | copy_nodes(nodes_bump, nodes_dy); | ||||
| /* mark nodes to indicate they are use for bump computation, so | /* mark nodes to indicate they are use for bump computation, so | ||||
| that any texture coordinates are shifted by dx/dy when sampling */ | that any texture coordinates are shifted by dx/dy when sampling */ | ||||
| foreach(ShaderNode *node, nodes_bump) | foreach(ShaderNode *node, nodes_bump) | ||||
| node->bump = SHADER_BUMP_CENTER; | node->bump = SHADER_BUMP_CENTER; | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void ShaderGraph::bump_from_displacement() | ||||
| * output the perturbed normal. */ | * output the perturbed normal. */ | ||||
| ShaderInput *displacement_in = output()->input("Displacement"); | ShaderInput *displacement_in = output()->input("Displacement"); | ||||
| if(!displacement_in->link) | if(!displacement_in->link) | ||||
| return; | return; | ||||
| /* find dependencies for the given input */ | /* find dependencies for the given input */ | ||||
| set<ShaderNode*> nodes_displace; | ShaderNodeSet nodes_displace; | ||||
| find_dependencies(nodes_displace, displacement_in); | find_dependencies(nodes_displace, displacement_in); | ||||
| /* copy nodes for 3 bump samples */ | /* copy nodes for 3 bump samples */ | ||||
| map<ShaderNode*, ShaderNode*> nodes_center; | ShaderNodeMap nodes_center; | ||||
| map<ShaderNode*, ShaderNode*> nodes_dx; | ShaderNodeMap nodes_dx; | ||||
| map<ShaderNode*, ShaderNode*> nodes_dy; | ShaderNodeMap nodes_dy; | ||||
| copy_nodes(nodes_displace, nodes_center); | copy_nodes(nodes_displace, nodes_center); | ||||
| copy_nodes(nodes_displace, nodes_dx); | copy_nodes(nodes_displace, nodes_dx); | ||||
| copy_nodes(nodes_displace, nodes_dy); | copy_nodes(nodes_displace, nodes_dy); | ||||
| /* mark nodes to indicate they are use for bump computation, so | /* mark nodes to indicate they are use for bump computation, so | ||||
| * that any texture coordinates are shifted by dx/dy when sampling */ | * that any texture coordinates are shifted by dx/dy when sampling */ | ||||
| foreach(NodePair& pair, nodes_center) | foreach(NodePair& pair, nodes_center) | ||||
| ▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines | |||||