48 if (done.find(in->link->parent) == done.end()) {
192 for (
int i = 0; i <
inputs.size(); ++i) {
200 else if (input_a->
link !=
NULL && input_b->link !=
NULL) {
202 if (input_a->
link != input_b->link) {
224 add(create_node<OutputNode>());
253 fprintf(stderr,
"Cycles shader graph connect: input already connected.\n");
261 "Cycles shader graph connect: can only connect closure to closure "
262 "(%s.%s to %s.%s).\n",
263 from->parent->name.c_str(),
264 from->name().c_str(),
277 emission->set_strength(1.0f);
281 convert_in =
convert->input(
"Strength");
284 convert_in =
convert->input(
"Color");
289 convert_in =
convert->inputs[0];
298 from->links.push_back(to);
391 if (surface_in->
link)
398 else if (do_simplify) {
408 if (
node !=
NULL && dependencies.find(
node) == dependencies.end()) {
412 dependencies.insert(
node);
432 nnodemap[
node] = nnode;
470 bool any_node_removed =
false;
492 bool all_links_removed =
true;
499 all_links_removed =
false;
502 if (all_links_removed)
503 removed[tonode->
id] =
true;
513 removed[proxy->
id] =
true;
514 any_node_removed =
true;
519 if (any_node_removed) {
520 list<ShaderNode *> newnodes;
523 if (!removed[
node->id])
524 newnodes.push_back(
node);
541 queue<ShaderNode *> traverse_queue;
548 traverse_queue.push(
node);
549 scheduled.insert(
node);
553 while (!traverse_queue.empty()) {
555 traverse_queue.pop();
558 if (
output->links.size() == 0) {
565 if (scheduled.find(input->
parent) != scheduled.end()) {
573 traverse_queue.push(input->
parent);
574 scheduled.insert(input->
parent);
579 node->constant_fold(folder);
587 if (has_displacement && !
output()->input(
"Displacement")->link) {
616 map<ustring, ShaderNodeSet> candidates;
617 queue<ShaderNode *> traverse_queue;
618 int num_deduplicated = 0;
623 traverse_queue.push(
node);
624 scheduled.insert(
node);
628 while (!traverse_queue.empty()) {
630 traverse_queue.pop();
633 bool has_output_links =
false;
636 has_output_links =
true;
637 if (scheduled.find(input->
parent) != scheduled.end()) {
645 traverse_queue.push(input->
parent);
646 scheduled.insert(input->
parent);
651 if (!has_output_links) {
657 if (
node != other_node &&
node->equals(*other_node)) {
658 merge_with = other_node;
663 if (merge_with !=
NULL) {
664 for (
int i = 0; i <
node->outputs.size(); ++i) {
670 candidates[
node->type->name].insert(
node);
674 if (num_deduplicated > 0) {
675 VLOG(1) <<
"Deduplicated " << num_deduplicated <<
" nodes.";
689 bool has_valid_volume =
false;
691 queue<ShaderNode *> traverse_queue;
696 while (!traverse_queue.empty()) {
698 traverse_queue.pop();
700 if (
node->has_volume_support()) {
701 has_valid_volume =
true;
708 if (scheduled.find(input->
link->
parent) != scheduled.end()) {
715 if (!has_valid_volume) {
716 VLOG(1) <<
"Disconnect meaningless volume output.";
724 on_stack[
node->id] =
true;
730 if (on_stack[depnode->
id]) {
733 fprintf(stderr,
"Cycles shader graph: detected cycle in graph, connection removed.\n");
742 on_stack[
node->id] =
false;
751 if (!displacement_in->
link) {
812 from->links.erase(remove(
from->links.begin(),
from->links.end(), to),
from->links.end());
819 list<ShaderNode *> newnodes;
823 newnodes.push_back(
node);
852 texco = create_node<TextureCoordinateNode>();
858 texco = create_node<TextureCoordinateNode>();
864 texco = create_node<TextureCoordinateNode>();
870 geom = create_node<GeometryNode>();
876 geom = create_node<GeometryNode>();
882 geom = create_node<GeometryNode>();
888 geom = create_node<GeometryNode>();
974 if (!displacement_in->
link)
992 foreach (
NodePair &pair, nodes_center)
1007 bump->set_use_object_space(use_object_space);
1008 bump->set_distance(1.0f);
1045 foreach (
NodePair &pair, nodes_center)
1079 connect(weight_out, weight_in);
1081 weight1_out = mix_node->
output(
"Weight1");
1082 weight2_out = mix_node->
output(
"Weight2");
1086 weight1_out = weight_out;
1087 weight2_out = weight_out;
1096 ShaderInput *weight_in =
node->input((volume) ?
"VolumeMixWeight" :
"SurfaceMixWeight");
1104 if (weight_in->
link || weight_value != 0.0f) {
1105 MathNode *math_node = create_node<MathNode>();
1108 if (weight_in->
link)
1111 math_node->set_value1(weight_value);
1116 math_node->set_value2(1.0f);
1118 weight_out = math_node->
output(
"Value");
1119 if (weight_in->
link)
1125 connect(weight_out, weight_in);
1133 int num_closures = 0;
1161 return num_closures;
1166 FILE *fd = fopen(filename,
"w");
1169 printf(
"Error opening file for dumping the graph: %s\n", filename);
1173 fprintf(fd,
"digraph shader_graph {\n");
1174 fprintf(fd,
"ranksep=1.5\n");
1175 fprintf(fd,
"rankdir=LR\n");
1176 fprintf(fd,
"splines=false\n");
1179 fprintf(fd,
"// NODE: %p\n",
node);
1180 fprintf(fd,
"\"%p\" [shape=record,label=\"{",
node);
1181 if (
node->inputs.size()) {
1184 if (socket !=
node->inputs[0]) {
1187 fprintf(fd,
"<IN_%p>%s", socket, socket->
name().c_str());
1191 fprintf(fd,
"%s",
node->name.c_str());
1193 fprintf(fd,
" (bump:center)");
1196 fprintf(fd,
" (bump:dx)");
1199 fprintf(fd,
" (bump:dy)");
1201 if (
node->outputs.size()) {
1204 if (socket !=
node->outputs[0]) {
1207 fprintf(fd,
"<OUT_%p>%s", socket, socket->
name().c_str());
1211 fprintf(fd,
"}\"]");
1218 "// CONNECTION: OUT_%p->IN_%p (%s:%s)\n",
1222 input->
name().c_str());
1224 "\"%p\":\"OUT_%p\":e -> \"%p\":\"IN_%p\":w [label=\"\"]\n",
@ NODE_VECTOR_MATH_DOT_PRODUCT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void append(const uint8_t *data, int size)
void find_dependencies(ShaderNodeSet &dependencies, ShaderInput *input)
list< ShaderNode * > nodes
void verify_volume_output()
void simplify(Scene *scene)
void disconnect(ShaderOutput *from)
void delete_node(T *node)
void break_cycles(ShaderNode *node, vector< bool > &visited, vector< bool > &on_stack)
void copy_nodes(ShaderNodeSet &nodes, ShaderNodeMap &nnodemap)
pair< ShaderNode *const, ShaderNode * > NodePair
void compute_displacement_hash()
void default_inputs(bool do_osl)
void connect(ShaderOutput *from, ShaderInput *to)
void relink(ShaderInput *from, ShaderInput *to)
void constant_fold(Scene *scene)
void transform_multi_closure(ShaderNode *node, ShaderOutput *weight_out, bool volume)
void remove_proxy_nodes()
void simplify_settings(Scene *scene)
void bump_from_displacement(bool use_object_space)
void finalize(Scene *scene, bool do_bump=false, bool do_simplify=false, bool bump_in_object_space=false)
ShaderNode * add(ShaderNode *node)
void dump_graph(const char *filename)
ShaderInput * input(const char *name)
vector< ShaderOutput * > outputs
void remove_input(ShaderInput *input)
ShaderNodeSpecialType special_type
vector< ShaderInput * > inputs
virtual bool equals(const ShaderNode &other)
ShaderNode(const NodeType *type)
void create_inputs_outputs(const NodeType *type)
ShaderOutput * output(const char *name)
virtual void attributes(Shader *shader, AttributeRequestSet *attributes)
vector< ShaderInput * > links
Set< ComponentNode * > visited
@ SHADER_SPECIAL_TYPE_PROXY
@ SHADER_SPECIAL_TYPE_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_COMBINE_CLOSURE
@ SHADER_SPECIAL_TYPE_BUMP
@ SHADER_SPECIAL_TYPE_AUTOCONVERT
@ SHADER_SPECIAL_TYPE_NONE
@ SHADER_SPECIAL_TYPE_OSL
set< ShaderNode *, ShaderNodeIDComparator > ShaderNodeSet
map< ShaderNode *, ShaderNode *, ShaderNodeIDComparator > ShaderNodeMap
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
@ ATTR_STD_GENERATED_TRANSFORM
#define VOLUME_STACK_SIZE
bool check_node_inputs_traversed(const ShaderNode *node, const ShaderNodeSet &done)
bool check_node_inputs_has_links(const ShaderNode *node)
struct blender::gpu::ShaderInput ShaderInput
static bNodeSocketTemplate outputs[]
vector< SocketType, std::allocator< SocketType > > inputs
vector< SocketType, std::allocator< SocketType > > outputs
void set_value(const SocketType &input, const Node &other, const SocketType &other_input)
void copy_value(const SocketType &input, const Node &other, const SocketType &other_input)
bool equals_value(const Node &other, const SocketType &input) const
ShaderManager * shader_manager
#define CLOSURE_IS_GLASS(type)
#define CLOSURE_IS_VOLUME(type)
#define CLOSURE_IS_PRINCIPLED(type)
@ CLOSURE_BSDF_HAIR_PRINCIPLED_ID
#define CLOSURE_IS_BSSRDF(type)
#define CLOSURE_IS_BSDF_MULTISCATTER(type)
ccl_device_inline float3 one_float3()