diff options
author | Hans Goudey <h.goudey@me.com> | 2021-09-23 01:34:09 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-23 01:34:09 +0300 |
commit | 79bcc19240258fe697b583376f59902c3235691c (patch) | |
tree | ebb15ffda6a3381435551924ae6dadeca1bd80d3 /source/blender/nodes/shader | |
parent | 6fb4c8f040f87bed4d6c69e3a718114eef91b7e1 (diff) |
Cleanup: Move more shader nodes to socket declaration API
I had to add `no_muted_links` to the declaration API. The name could
change there, but I think it's more obvious than "internal"
Diffstat (limited to 'source/blender/nodes/shader')
4 files changed, 65 insertions, 115 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 0c0d75179a9..e0520ee49d3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -19,27 +19,16 @@ #include "../node_shader_util.h" -/* **************** BLEND ******************** */ +namespace blender::nodes { -static bNodeSocketTemplate sh_node_tex_gradient_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {-1, ""}, +static void sh_node_tex_gradient_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").hide_value(); + b.add_output<decl::Color>("Color").no_muted_links(); + b.add_output<decl::Float>("Fac").no_muted_links(); }; -static bNodeSocketTemplate sh_node_tex_gradient_out[] = { - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {SOCK_FLOAT, - N_("Fac"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_FACTOR, - SOCK_NO_INTERNAL_LINK}, - {-1, ""}, -}; +} // namespace blender::nodes static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node) { @@ -72,7 +61,7 @@ void register_node_type_sh_tex_gradient(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out); + ntype.declare = blender::nodes::sh_node_tex_gradient_declare; node_type_init(&ntype, node_shader_init_tex_gradient); node_type_storage( &ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc index f5e9aef3aad..d33d92f25fd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc @@ -19,34 +19,23 @@ #include "../node_shader_util.h" -/* **************** MUSGRAVE ******************** */ - -static bNodeSocketTemplate sh_node_tex_musgrave_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, - {SOCK_FLOAT, N_("Dimension"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - {SOCK_FLOAT, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - {SOCK_FLOAT, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Gain"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - {-1, ""}, -}; +namespace blender::nodes { -static bNodeSocketTemplate sh_node_tex_musgrave_out[] = { - {SOCK_FLOAT, - N_("Fac"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_FACTOR, - SOCK_NO_INTERNAL_LINK}, - {-1, ""}, +static void sh_node_tex_musgrave_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").hide_value(); + b.add_input<decl::Float>("W").min(-1000.0f).max(1000.0f); + b.add_input<decl::Float>("Scale").min(-1000.0f).max(1000.0f).default_value(5.0f); + b.add_input<decl::Float>("Detail").min(0.0f).max(16.0f).default_value(2.0f); + b.add_input<decl::Float>("Dimension").min(0.0f).max(1000.0f).default_value(2.0f); + b.add_input<decl::Float>("Lacunarity").min(0.0f).max(1000.0f).default_value(2.0f); + b.add_input<decl::Float>("Offset").min(-1000.0f).max(1000.0f); + b.add_input<decl::Float>("Gain").min(0.0f).max(1000.0f).default_value(1.0f); + b.add_output<decl::Float>("Fac").no_muted_links(); }; +} // namespace blender::nodes + static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node) { NodeTexMusgrave *tex = (NodeTexMusgrave *)MEM_callocN(sizeof(NodeTexMusgrave), @@ -139,7 +128,7 @@ void register_node_type_sh_tex_musgrave(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_MUSGRAVE, "Musgrave Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_musgrave_in, sh_node_tex_musgrave_out); + ntype.declare = blender::nodes::sh_node_tex_musgrave_declare; node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tex_musgrave); node_type_storage( diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index c0deb232b2d..1ae6b3a616c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -21,32 +21,25 @@ #include "BLI_noise.hh" -/* **************** NOISE ******************** */ +namespace blender::nodes { -static bNodeSocketTemplate sh_node_tex_noise_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, - {SOCK_FLOAT, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_FLOAT, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {-1, ""}, +static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").hide_value(); + b.add_input<decl::Float>("W").min(-1000.0f).max(1000.0f); + b.add_input<decl::Float>("Scale").min(-1000.0f).max(1000.0f).default_value(5.0f); + b.add_input<decl::Float>("Detail").min(0.0f).max(16.0f).default_value(2.0f); + b.add_input<decl::Float>("Roughness") + .min(0.0f) + .max(1.0f) + .default_value(0.5f) + .subtype(PROP_FACTOR); + b.add_input<decl::Float>("Distortion").min(-1000.0f).max(1000.0f).default_value(0.0f); + b.add_output<decl::Float>("Fac").no_muted_links(); + b.add_output<decl::Color>("Color").no_muted_links(); }; -static bNodeSocketTemplate sh_node_tex_noise_out[] = { - {SOCK_FLOAT, - N_("Fac"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_FACTOR, - SOCK_NO_INTERNAL_LINK}, - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {-1, ""}, -}; +} // namespace blender::nodes static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node) { @@ -252,7 +245,7 @@ void register_node_type_sh_tex_noise(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out); + ntype.declare = blender::nodes::sh_node_tex_noise_declare; node_type_init(&ntype, node_shader_init_tex_noise); node_type_storage( &ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 1cc715d99ea..cea7af247c1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -19,54 +19,33 @@ #include "../node_shader_util.h" -/* **************** VORONOI ******************** */ - -static bNodeSocketTemplate sh_node_tex_voronoi_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - {SOCK_FLOAT, N_("Smoothness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_FLOAT, N_("Exponent"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 32.0f}, - {SOCK_FLOAT, N_("Randomness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {-1, ""}, -}; +namespace blender::nodes { -static bNodeSocketTemplate sh_node_tex_voronoi_out[] = { - {SOCK_FLOAT, - N_("Distance"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_NONE, - SOCK_NO_INTERNAL_LINK}, - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {SOCK_VECTOR, - N_("Position"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_NONE, - SOCK_NO_INTERNAL_LINK}, - {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {SOCK_FLOAT, - N_("Radius"), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - PROP_NONE, - SOCK_NO_INTERNAL_LINK}, - {-1, ""}, +static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").hide_value(); + b.add_input<decl::Float>("W").min(-1000.0f).max(1000.0f); + b.add_input<decl::Float>("Scale").min(-1000.0f).max(1000.0f).default_value(5.0f); + b.add_input<decl::Float>("Smoothness") + .min(0.0f) + .max(1.0f) + .default_value(1.0f) + .subtype(PROP_FACTOR); + b.add_input<decl::Float>("Exponent").min(0.0f).max(32.0f).default_value(0.5f); + b.add_input<decl::Float>("Randomness") + .min(0.0f) + .max(1.0f) + .default_value(1.0f) + .subtype(PROP_FACTOR); + b.add_output<decl::Float>("Distance").no_muted_links(); + b.add_output<decl::Color>("Color").no_muted_links(); + b.add_output<decl::Vector>("Position").no_muted_links(); + b.add_output<decl::Float>("W").no_muted_links(); + b.add_output<decl::Float>("Radius").no_muted_links(); }; +} // namespace blender::nodes + static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) { NodeTexVoronoi *tex = (NodeTexVoronoi *)MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); @@ -183,7 +162,7 @@ void register_node_type_sh_tex_voronoi(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_voronoi_in, sh_node_tex_voronoi_out); + ntype.declare = blender::nodes::sh_node_tex_voronoi_declare; node_type_init(&ntype, node_shader_init_tex_voronoi); node_type_storage( &ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); |