Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/graph.h
| Show All 16 Lines | |||||
| #ifndef __GRAPH_H__ | #ifndef __GRAPH_H__ | ||||
| #define __GRAPH_H__ | #define __GRAPH_H__ | ||||
| #include "graph/node.h" | #include "graph/node.h" | ||||
| #include "graph/node_type.h" | #include "graph/node_type.h" | ||||
| #include "kernel/kernel_types.h" | #include "kernel/kernel_types.h" | ||||
| #include "util/util_api.h" | |||||
| #include "util/util_list.h" | #include "util/util_list.h" | ||||
| #include "util/util_map.h" | #include "util/util_map.h" | ||||
| #include "util/util_param.h" | #include "util/util_param.h" | ||||
| #include "util/util_set.h" | #include "util/util_set.h" | ||||
| #include "util/util_types.h" | #include "util/util_types.h" | ||||
| #include "util/util_vector.h" | #include "util/util_vector.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| public: | public: | ||||
| ShaderInput(const SocketType &socket_type_, ShaderNode *parent_) | ShaderInput(const SocketType &socket_type_, ShaderNode *parent_) | ||||
| : socket_type(socket_type_), parent(parent_), link(NULL), stack_offset(SVM_STACK_INVALID) | : socket_type(socket_type_), parent(parent_), link(NULL), stack_offset(SVM_STACK_INVALID) | ||||
| { | { | ||||
| } | } | ||||
| ustring name() | ustring name() | ||||
| { | { | ||||
| return socket_type.ui_name; | return socket_type.get_ui_name(); | ||||
| } | } | ||||
| int flags() | int flags() | ||||
| { | { | ||||
| return socket_type.flags; | return socket_type.get_flags(); | ||||
| } | } | ||||
| SocketType::Type type() | SocketType::Type type() | ||||
| { | { | ||||
| return socket_type.type; | return socket_type.get_type(); | ||||
| } | } | ||||
| void set(float f) | void set(float f) | ||||
| { | { | ||||
| ((Node *)parent)->set(socket_type, f); | ((Node *)parent)->set(socket_type, f); | ||||
| } | } | ||||
| void set(float3 f) | void set(float3 f) | ||||
| { | { | ||||
| ((Node *)parent)->set(socket_type, f); | ((Node *)parent)->set(socket_type, f); | ||||
| } | } | ||||
| void disconnect(); | void disconnect(); | ||||
| const SocketType &get_socket_type() | |||||
| { | |||||
| return socket_type; | |||||
| } | |||||
| protected: | |||||
| const SocketType &socket_type; | const SocketType &socket_type; | ||||
| ShaderNode *parent; | GET(ShaderNode *, parent) | ||||
| ShaderOutput *link; | GET(ShaderOutput *, link) | ||||
| int stack_offset; /* for SVM compiler */ | GET(int, stack_offset) /* for SVM compiler */ | ||||
| }; | }; | ||||
| /* Output | /* Output | ||||
| * | * | ||||
| * Output socket for a shader node. */ | * Output socket for a shader node. */ | ||||
| class ShaderOutput { | class ShaderOutput { | ||||
| public: | public: | ||||
| ShaderOutput(const SocketType &socket_type_, ShaderNode *parent_) | ShaderOutput(const SocketType &socket_type_, ShaderNode *parent_) | ||||
| : socket_type(socket_type_), parent(parent_), stack_offset(SVM_STACK_INVALID) | : socket_type(socket_type_), parent(parent_), stack_offset(SVM_STACK_INVALID) | ||||
| { | { | ||||
| } | } | ||||
| ustring name() | ustring name() | ||||
| { | { | ||||
| return socket_type.ui_name; | return socket_type.get_ui_name(); | ||||
| } | } | ||||
| SocketType::Type type() | SocketType::Type type() | ||||
| { | { | ||||
| return socket_type.type; | return socket_type.get_type(); | ||||
| } | } | ||||
| void disconnect(); | void disconnect(); | ||||
| bool is_linked() const | |||||
| { | |||||
| return !links.empty(); | |||||
| } | |||||
| protected: | |||||
| const SocketType &socket_type; | const SocketType &socket_type; | ||||
| ShaderNode *parent; | GET(ShaderNode *, parent) | ||||
| vector<ShaderInput *> links; | GET(vector<ShaderInput *>, links) | ||||
| int stack_offset; /* for SVM compiler */ | GET(int, stack_offset) /* for SVM compiler */ | ||||
| }; | }; | ||||
| /* Node | /* Node | ||||
| * | * | ||||
| * Shader node in graph, with input and output sockets. This is the virtual | * Shader node in graph, with input and output sockets. This is the virtual | ||||
| * base class for all node types. */ | * base class for all node types. */ | ||||
| class ShaderNode : public Node { | class ShaderNode : public Node { | ||||
| GET(vector<ShaderInput *>, inputs) | |||||
| GET(vector<ShaderOutput *>, outputs) | |||||
| GET_SET(int, id) /* index in graph node array */ | |||||
| GET(ShaderBump, bump) /* for bump mapping utility */ | |||||
| GET(ShaderNodeSpecialType, special_type) /* special node type */ | |||||
| public: | public: | ||||
| explicit ShaderNode(const NodeType *type); | explicit ShaderNode(const NodeType *type); | ||||
| virtual ~ShaderNode(); | virtual ~ShaderNode(); | ||||
| void create_inputs_outputs(const NodeType *type); | void create_inputs_outputs(const NodeType *type); | ||||
| void remove_input(ShaderInput *input); | void remove_input(ShaderInput *input); | ||||
| ShaderInput *input(const char *name); | ShaderInput *input(const char *name); | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public: | ||||
| virtual bool has_volume_support() | virtual bool has_volume_support() | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| virtual bool has_raytrace() | virtual bool has_raytrace() | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| vector<ShaderInput *> inputs; | |||||
| vector<ShaderOutput *> outputs; | |||||
| int id; /* index in graph node array */ | |||||
| ShaderBump bump; /* for bump mapping utility */ | |||||
| ShaderNodeSpecialType special_type; /* special node type */ | |||||
| /* ** Selective nodes compilation ** */ | /* ** Selective nodes compilation ** */ | ||||
| /* TODO(sergey): More explicitly mention in the function names | /* TODO(sergey): More explicitly mention in the function names | ||||
| * that those functions are for selective compilation only? | * that those functions are for selective compilation only? | ||||
| */ | */ | ||||
| /* Nodes are split into several groups, group of level 0 contains | /* Nodes are split into several groups, group of level 0 contains | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | #define SHADER_NODE_BASE_CLASS(type) \ | ||||
| } \ | } \ | ||||
| virtual void compile(SVMCompiler &compiler); \ | virtual void compile(SVMCompiler &compiler); \ | ||||
| virtual void compile(OSLCompiler &compiler); | virtual void compile(OSLCompiler &compiler); | ||||
| class ShaderNodeIDComparator { | class ShaderNodeIDComparator { | ||||
| public: | public: | ||||
| bool operator()(const ShaderNode *n1, const ShaderNode *n2) const | bool operator()(const ShaderNode *n1, const ShaderNode *n2) const | ||||
| { | { | ||||
| return n1->id < n2->id; | return n1->get_id() < n2->get_id(); | ||||
| } | } | ||||
| }; | }; | ||||
| typedef set<ShaderNode *, ShaderNodeIDComparator> ShaderNodeSet; | typedef set<ShaderNode *, ShaderNodeIDComparator> ShaderNodeSet; | ||||
| typedef map<ShaderNode *, ShaderNode *, ShaderNodeIDComparator> ShaderNodeMap; | typedef map<ShaderNode *, ShaderNode *, ShaderNodeIDComparator> ShaderNodeMap; | ||||
| /* Graph | /* Graph | ||||
| * | * | ||||
| * Shader graph of nodes. Also does graph manipulations for default inputs, | * Shader graph of nodes. Also does graph manipulations for default inputs, | ||||
| * bump mapping from displacement, and possibly other things in the future. */ | * bump mapping from displacement, and possibly other things in the future. */ | ||||
| class ShaderGraph : public NodeOwner { | class ShaderGraph : public NodeOwner { | ||||
| public: | GET(list<ShaderNode *>, nodes) | ||||
| list<ShaderNode *> nodes; | |||||
| size_t num_node_ids; | size_t num_node_ids; | ||||
| bool finalized; | bool finalized; | ||||
| bool simplified; | bool simplified; | ||||
| string displacement_hash; | string displacement_hash; | ||||
| public: | |||||
| ShaderGraph(); | ShaderGraph(); | ||||
| ~ShaderGraph(); | ~ShaderGraph(); | ||||
| ShaderNode *add(ShaderNode *node); | ShaderNode *add(ShaderNode *node); | ||||
| OutputNode *output(); | OutputNode *output(); | ||||
| void connect(ShaderOutput *from, ShaderInput *to); | void connect(ShaderOutput *from, ShaderInput *to); | ||||
| void disconnect(ShaderOutput *from); | void disconnect(ShaderOutput *from); | ||||
| ▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines | |||||