42#include "RNA_prototypes.hh"
58 const char *engine_id = scene->
r.
engine;
84 *r_ntree = (id_cast<Light *>(ob->
data))->nodetree;
90 *r_ntree = ma->nodetree;
100 *r_id = &linestyle->
id;
108 *r_id = &scene->
world->id;
109 *r_ntree = scene->
world->nodetree;
133 if (
node.is_muted() ||
node.is_reroute()) {
193 tt->
idname =
"ShaderNodeTree"_ustr;
196 tt->
ui_icon = ICON_NODE_MATERIAL;
197 tt->
ui_description =
N_(
"Edit materials, lights, and world shading using nodes");
222 bNode *output_node =
nullptr;
232 if (output_node ==
nullptr) {
241 else if (
node.custom1 == target) {
242 if (output_node ==
nullptr) {
259 const char *identifier)
262 if (
STREQ(sock.identifier, identifier)) {
336 auto gather_branch_nodes = [](
bNode *fromnode,
bNode * ,
void *userdata) {
346 node.runtime->tmp_flag = -1;
358 if (
node.runtime->tmp_flag >= 0) {
359 int id =
node.runtime->tmp_flag;
387 bool from_copy = link.fromnode->runtime->tmp_flag >= 0;
388 bool to_copy = link.tonode->runtime->tmp_flag >= 0;
389 if (from_copy && to_copy) {
390 bNode *from_node = nodes_copy[link.fromnode->runtime->tmp_flag];
391 bNode *to_node = nodes_copy[link.tonode->runtime->tmp_flag];
399 bNode *to_node = nodes_copy[link.tonode->runtime->tmp_flag];
406 else if (from_copy && branch_nodes.
contains(link.tonode)) {
407 bNode *from_node = nodes_copy[link.fromnode->runtime->tmp_flag];
423 bool modified =
false;
464 *tosock = addsock_out;
469 int *node_count =
static_cast<int *
>(userdata);
497 if (displace_output && displace_output->
link) {
499 displace_link = displace_output->
link;
500 displace_output->
link =
nullptr;
504 if (thickness_output && thickness_output->
link) {
506 thickness_link = thickness_output->
link;
507 thickness_output->
link =
nullptr;
511 node.runtime->tmp_flag = -1;
521 if (
node.runtime->tmp_flag >= 0) {
522 int id =
node.runtime->tmp_flag;
524 switch (
node.type_legacy) {
531 nodes_copy[
id]->runtime->tmp_flag = -2;
541 nodes_copy[
id]->runtime->tmp_flag = -2;
548 bNode *fromnode, *tonode;
554 nodes_copy[
id]->runtime->tmp_flag = -2;
559 nodes_copy[
id]->runtime->tmp_flag = -2;
565 nodes_copy[
id]->runtime->tmp_flag = -2;
570 if (!fac_sock->
link) {
580 nodes_copy[
id]->runtime->tmp_flag = -2;
585 fromnode = nodes_copy[id_start];
586 tonode = nodes_copy[id_start + 1];
591 fromnode = nodes_copy[id_start + 2];
592 tonode = nodes_copy[id_start];
597 fromnode = nodes_copy[id_start + 3];
599 tonode = nodes_copy[id_start];
602 tonode = nodes_copy[id_start + 1];
615 if (
node.runtime->tmp_flag >= 0) {
619 for (
const auto [socket_index, sock] :
node.inputs.enumerate()) {
623 switch (
node.type_legacy) {
629 tonode = nodes_copy[
node.runtime->tmp_flag];
634 if (socket_index == 0) {
636 tonode = nodes_copy[
node.runtime->tmp_flag + 2];
639 else if (socket_index == 1) {
641 tonode = nodes_copy[
node.runtime->tmp_flag + 1];
646 tonode = nodes_copy[
node.runtime->tmp_flag];
658 bNode *fromnode = sock.link->fromnode;
664 if (fromsock->
link) {
672 if (fromsock->
link) {
701 if (fromsock->
link) {
725 if (thickness_link) {
737 switch (
node->type_legacy) {
778 for (
bNode *shader_to_rgba : shader_to_rgba_nodes) {
780 if (closure_input->
link ==
nullptr) {
801 stack.
push({node_start, 0});
804 StackNode s_node = !stack.
is_empty() ? stack.
pop() : zone_stack.
pop();
807 int16_t depth_level = s_node.depth;
809 if (
node->runtime->tmp_flag >= depth_level) {
816 max_depth = std::max(max_depth, depth_level);
819 node->runtime->tmp_flag = std::max(
node->runtime->tmp_flag, depth_level);
823 if (link ==
nullptr) {
836 if (zone_type->output_type ==
node->type_legacy) {
837 if (
bNode *zone_input_node = zone_type->get_corresponding_input(*ntree, *
node)) {
838 zone_stack.
push({zone_input_node, depth_level});
855 int factor_socket_index,
861 if (factor_socket->
link ==
nullptr) {
867 factor =
clamp_f(factor, 0.0f, 1.0f);
872 float vfactor_copy[3];
873 for (
int i = 0; i < 3; i++) {
875 vfactor_copy[i] =
clamp_f(vfactor[i], 0.0f, 1.0f);
878 vfactor_copy[i] = vfactor[i];
881 if (vfactor_copy[0] == vfactor_copy[1] && vfactor_copy[0] == vfactor_copy[2]) {
882 factor = vfactor_copy[0];
886 if (factor == 1.0f && a_socket_index >= 0) {
889 else if (factor == 0.0f && b_socket_index >= 0) {
906 for (
int i : {1, 4, 5, 6, 7}) {
913 ntree, &
node, factor_socket, 4, 5,
storage->clamp_factor);
915 int unused_factor_socket = factor_socket == 0 ? 1 : 0;
916 for (
int i : {unused_factor_socket, 2, 3, 6, 7}) {
924 for (
int i : {1, 2, 3, 4, 5}) {
946 bool changed =
false;
949 node.runtime->tmp_flag = 0;
960 node.runtime->tmp_flag = 1;
966 if (
node.runtime->tmp_flag == 0) {
982 bool has_light_accumulation =
false;
985 has_light_accumulation =
true;
990 if (!has_light_accumulation) {
994 bNode *zone_input =
nullptr;
995 bNode *zone_output =
nullptr;
997 auto ensure_nodes = [&]() {
1047 accumulation_out_to_zone_out.
add(&accumulation_out, socket_out);
1062 links_to_remove.
append(&link);
1066 for (
bNodeLink *link : links_to_remove) {
1095 node.runtime->tmp_flag = -1;
1105 for (
int depth = max_depth; depth >= 0; depth--) {
1128 "thread stack array");
1131 node.runtime->need_exec = 1;
1165 MEM_delete(nts.stack);
Blender kernel freestyle line style functionality.
General operations, lookup, etc. for materials.
#define NODE_CLASS_OUTPUT
#define NODE_CLASS_INTERFACE
#define NODE_CLASS_CONVERTER
#define NODE_CLASS_OP_VECTOR
#define NODE_CLASS_LAYOUT
#define NODE_CLASS_OP_COLOR
#define NODE_CLASS_TEXTURE
#define NODE_CLASS_SHADER
#define NODE_CLASS_SCRIPT
#define SH_NODE_LIGHT_ITER_INTERNAL_OUTPUT
#define SH_NODE_MIX_SHADER
#define SH_NODE_LIGHT_ACCUMULATION
#define SH_NODE_BSDF_METALLIC
#define SH_NODE_LIGHT_EVALUATION
#define SH_NODE_VOLUME_COEFFICIENTS
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_SHADOW_RAYCAST
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_BSDF_SHEEN
#define SH_NODE_ADD_SHADER
#define SH_NODE_SUBSURFACE_SCATTERING
#define SH_NODE_VOLUME_ABSORPTION
#define SH_NODE_LIGHT_INFO
#define SH_NODE_BSDF_TOON
#define SH_NODE_BSDF_TRANSPARENT
#define SH_NODE_BSDF_DIFFUSE
#define SH_NODE_VECT_TRANSFORM
#define SH_NODE_SHADERTORGB
#define SH_NODE_OUTPUT_MATERIAL
#define SH_NODE_BSDF_TRANSLUCENT
#define SH_NODE_BSDF_HAIR_PRINCIPLED
#define SH_NODE_BSDF_HAIR
#define SH_NODE_BACKGROUND
#define SH_NODE_BSDF_RAY_PORTAL
#define SH_NODE_BSDF_GLOSSY
#define SH_NODE_EEVEE_SPECULAR
#define SH_NODE_BSDF_GLASS
#define SH_NODE_LIGHT_ITER_INTERNAL_INPUT
#define SH_NODE_VOLUME_PRINCIPLED
#define SH_NODE_BSDF_REFRACTION
#define SH_NODE_OUTPUT_LIGHT
#define SH_NODE_VOLUME_SCATTER
#define SH_NODE_OUTPUT_AOV
#define SH_NODE_ATTRIBUTE
#define BLENDER_MAX_THREADS
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
bool contains(const Key &key) const
void push(const T &value)
void append(const T &value)
#define storage(slot, qualifiers)
void node_chain_iterator_backwards(const bNodeTree *ntree, bNode *node_start, bool(*callback)(bNode *, bNode *, void *), void *userdata, int recursion_lvl)
void node_tree_free_local_node(bNodeTree &ntree, bNode &node)
void node_tree_set_output(bNodeTree &ntree)
const bNodeZoneType * zone_type_by_node_type(const int node_type)
void node_unlink_node(bNodeTree &ntree, bNode &node)
void node_tree_free_tree(bNodeTree &ntree)
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
void node_tree_type_add(bNodeTreeType &nt)
void node_internal_relink(bNodeTree &ntree, bNode &node)
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE
void node_free_node(bNodeTree *tree, bNode &node)
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
bNodeSocket * node_add_static_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out, int type, int subtype, StringRefNull identifier, StringRefNull name)
bNode * node_copy_with_mapping(bNodeTree *dst_tree, const bNode &node_src, int flag, std::optional< StringRefNull > dst_unique_name, std::optional< int > dst_unique_identifier, Map< const bNodeSocket *, bNodeSocket * > &new_socket_map, bool allow_duplicate_names=false)
bool node_is_static_socket_type(const bNodeSocketType &stype)
static bNodeSocket * ntree_shader_node_output_get(bNode *node, int n)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void ntree_weight_tree_merge_weight(bNodeTree *ntree, bNode *, bNodeSocket *fromsock, bNode **tonode, bNodeSocket **tosock)
struct bNode * ntreeShaderOutputNode(struct bNodeTree *ntree, int target)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
static bool ntree_weight_tree_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
static void shader_node_disconnect_input(bNodeTree *ntree, bNode *node, int index)
Material * BKE_object_material_get(Object *ob, short act)
static void localize(bNodeTree *localtree, bNodeTree *)
static bool shader_node_tree_socket_type_valid(bke::bNodeTreeType *, bke::bNodeSocketType *socket_type)
static bool ntree_shader_implicit_closure_cast(bNodeTree *ntree)
static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node)
const char * RE_engine_id_CYCLES
void ntreeGPUMaterialNodes(struct bNodeTree *localtree, struct GPUMaterial *mat)
static bool shader_tree_poll(const bContext *C, bke::bNodeTreeType *)
bool BKE_scene_use_shading_nodes_custom(Scene *scene)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
ViewLayer * CTX_data_view_layer(const bContext *C)
static bool ntree_branch_count_and_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
void ntree_exec_end(bNodeTreeExec *exec)
static void ntree_shader_disconnect_inactive_mix_branches(bNodeTree *ntree)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
static void ntree_shader_shader_to_rgba_branches(bNodeTree *ntree)
static void ntree_shader_setup_custom_lighting_zone(bNodeTree *ntree)
static void shader_node_disconnect_inactive_mix_branch(bNodeTree *ntree, bNode *node, int factor_socket_index, int a_socket_index, int b_socket_index, bool clamp_factor)
struct bNodeTreeExec * ntreeShaderBeginExecTree(struct bNodeTree *ntree)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
SpaceNode * CTX_wm_space_node(const bContext *C)
static void iter_shader_to_rgba_depth_count(bNodeTree *ntree, bNode *node_start, int16_t &max_depth)
static void ntree_shader_pruned_unused(bNodeTree *ntree, bNode *output_node)
bNodeTreeExec * ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
void ntreeShaderEndExecTree_internal(bNodeTreeExec *exec)
bNodeTreeExec * ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
static void shader_get_from_context(const bContext *C, bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
void BKE_ntree_update_without_main(bNodeTree &tree)
static bool ntree_branch_node_tag(bNode *fromnode, bNode *tonode, void *)
static void update(bNodeTree *ntree)
@ SHD_VECT_TRANSFORM_SPACE_LIGHT
struct bke::bNodeTreeType * ntreeType_Shader
static void ntree_shader_unlink_script_nodes(bNodeTree *ntree)
static bNodeSocket * ntree_shader_node_find_input(bNode *node, const char *identifier)
static bool shader_validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Main * CTX_data_main(const bContext *C)
static bNodeSocket * ntree_shader_node_input_get(bNode *node, int n)
void ntree_update_reroute_nodes(bNodeTree *ntree)
static void ntree_shader_copy_branch(bNodeTree *ntree, bNode *start_node, bool(*node_filter)(const bNode *node))
void register_node_tree_type_sh()
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
static bNodeSocket * ntree_shader_node_find_socket(ListBaseT< bNodeSocket > *sockets, const char *identifier)
Scene * CTX_data_scene(const bContext *C)
void ntreeShaderEndExecTree(struct bNodeTreeExec *exec)
static bool closure_node_filter(const bNode *node)
static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node, const int *depth_level)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE float clamp_f(float value, float min, float max)
static bNodeSocket * ntree_shader_node_find_output(bNode *node, const char *identifier)
struct bNodeTree * nodetree
eSpaceNode_ShaderFrom shaderfrom
bke::motionpath::Runtime * runtime
ListBaseT< bNodeThreadStack > * threadstack
ListBaseT< bNodeLink > links
bke::bNodeTreeRuntime * runtime
bke::bNodeRuntime * runtime
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
void(*) get_from_context(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
void(*) update(bNodeTree *ntree)
std::string ui_description
void(*) foreach_nodeclass(void *calldata, bNodeClassCallback func)
void(*) localize(bNodeTree *localtree, bNodeTree *ntree)
std::optional< std::string > asset_catalog_path_prefix
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
bool(*) poll(const bContext *C, bNodeTreeType *ntreetype)
bool(*) node_filter(const bNode *node)