diff options
author | Hans Goudey <h.goudey@me.com> | 2021-09-22 22:39:09 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-22 22:39:09 +0300 |
commit | c99cb814520480379276192f044c673ef857447b (patch) | |
tree | f8786da60252f0bbb9e0fbed2c8c80bb197e146a | |
parent | bd01f4761cf983e411b9c3fd52dd83a3fd9103f8 (diff) |
Cleanup: Use new node socket declaration API for some shader nodes
This converts socket declarations for most shader nodes that had already
been converted to C++, but skips those that needed a special flag.
13 files changed, 176 insertions, 161 deletions
diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h index a75354d3381..c647b86a19a 100644 --- a/source/blender/nodes/shader/node_shader_util.h +++ b/source/blender/nodes/shader/node_shader_util.h @@ -73,6 +73,7 @@ # include "FN_multi_function_builder.hh" # include "NOD_multi_function.hh" +# include "NOD_socket_declarations.hh" # include "BLI_color.hh" # include "BLI_float3.hh" diff --git a/source/blender/nodes/shader/nodes/node_shader_clamp.cc b/source/blender/nodes/shader/nodes/node_shader_clamp.cc index b90397e4892..31d8f8ef15c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_clamp.cc +++ b/source/blender/nodes/shader/nodes/node_shader_clamp.cc @@ -23,18 +23,18 @@ #include "node_shader_util.h" -/* **************** Clamp ******************** */ -static bNodeSocketTemplate sh_node_clamp_in[] = { - {SOCK_FLOAT, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_clamp_out[] = { - {SOCK_FLOAT, N_("Result")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_clamp_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Value").min(0.0f).max(1.0f).default_value(1.0f); + b.add_input<decl::Float>("Min").default_value(0.0f).min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Max").default_value(1.0f).min(-10000.0f).max(10000.0f); + b.add_output<decl::Float>("Result"); }; +} // namespace blender::nodes + static void node_shader_init_clamp(bNodeTree *UNUSED(ntree), bNode *node) { node->custom1 = NODE_CLAMP_MINMAX; /* clamp type */ @@ -79,7 +79,7 @@ void register_node_type_sh_clamp(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_CLAMP, "Clamp", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_clamp_in, sh_node_clamp_out); + ntype.declare = blender::nodes::sh_node_clamp_declare; node_type_init(&ntype, node_shader_init_clamp); node_type_gpu(&ntype, gpu_shader_clamp); ntype.build_multi_function = sh_node_clamp_build_multi_function; diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.cc b/source/blender/nodes/shader/nodes/node_shader_curves.cc index df075d6e973..e4ada06133e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.cc +++ b/source/blender/nodes/shader/nodes/node_shader_curves.cc @@ -23,18 +23,17 @@ #include "node_shader_util.h" -/* **************** CURVE VEC ******************** */ -static bNodeSocketTemplate sh_node_curve_vec_in[] = { - {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, - {-1, ""}, -}; +namespace blender::nodes { -static bNodeSocketTemplate sh_node_curve_vec_out[] = { - {SOCK_VECTOR, N_("Vector")}, - {-1, ""}, +static void sh_node_curve_vec_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Fac").min(0.0f).max(1.0f).default_value(1.0f).subtype(PROP_FACTOR); + b.add_input<decl::Vector>("Vector").min(-1.0f).max(1.0f); + b.add_output<decl::Vector>("Vector"); }; +} // namespace blender::nodes + static void node_shader_exec_curve_vec(void *UNUSED(data), int UNUSED(thread), bNode *node, @@ -157,7 +156,7 @@ void register_node_type_sh_curve_vec(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_curve_vec_in, sh_node_curve_vec_out); + ntype.declare = blender::nodes::sh_node_curve_vec_declare; node_type_init(&ntype, node_shader_init_curve_vec); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); @@ -169,17 +168,18 @@ void register_node_type_sh_curve_vec(void) } /* **************** CURVE RGB ******************** */ -static bNodeSocketTemplate sh_node_curve_rgb_in[] = { - {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR}, - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_curve_rgb_out[] = { - {SOCK_RGBA, N_("Color")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_curve_rgb_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Fac").min(0.0f).max(1.0f).default_value(1.0f).subtype(PROP_FACTOR); + b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f}); + b.add_output<decl::Color>("Color"); }; +} // namespace blender::nodes + static void node_shader_exec_curve_rgb(void *UNUSED(data), int UNUSED(thread), bNode *node, @@ -332,7 +332,7 @@ void register_node_type_sh_curve_rgb(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_curve_rgb_in, sh_node_curve_rgb_out); + ntype.declare = blender::nodes::sh_node_curve_rgb_declare; node_type_init(&ntype, node_shader_init_curve_rgb); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index f48e824ccb5..a5f9a24a728 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -25,21 +25,21 @@ #include "BLI_math_base_safe.h" -/* **************** Map Range ******************** */ -static bNodeSocketTemplate sh_node_map_range_in[] = { - {SOCK_FLOAT, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - {SOCK_FLOAT, N_("From Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("From Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("To Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("To Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Steps"), 4.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_NONE}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_map_range_out[] = { - {SOCK_FLOAT, N_("Result")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_map_range_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Value").min(-10000.0f).max(10000.0f).default_value(1.0f); + b.add_input<decl::Float>("From Min").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("From Max").min(-10000.0f).max(10000.0f).default_value(1.0f); + b.add_input<decl::Float>("To Min").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("To Max").min(-10000.0f).max(10000.0f).default_value(1.0f); + b.add_input<decl::Float>("Steps").min(-10000.0f).max(10000.0f).default_value(4.0f); + b.add_output<decl::Float>("Result"); }; +} // namespace blender::nodes + static void node_shader_update_map_range(bNodeTree *UNUSED(ntree), bNode *node) { bNodeSocket *sockSteps = nodeFindSocket(node, SOCK_IN, "Steps"); @@ -311,7 +311,7 @@ void register_node_type_sh_map_range(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_MAP_RANGE, "Map Range", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_map_range_in, sh_node_map_range_out); + ntype.declare = blender::nodes::sh_node_map_range_declare; node_type_init(&ntype, node_shader_init_map_range); node_type_update(&ntype, node_shader_update_map_range); node_type_gpu(&ntype, gpu_shader_map_range); diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc index 66c50b6de46..80a27b8e6a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.cc +++ b/source/blender/nodes/shader/nodes/node_shader_math.cc @@ -26,13 +26,18 @@ #include "NOD_math_functions.hh" /* **************** SCALAR MATH ******************** */ -static bNodeSocketTemplate sh_node_math_in[] = { - {SOCK_FLOAT, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Value"), 0.0f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {-1, ""}}; -static bNodeSocketTemplate sh_node_math_out[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}}; +namespace blender::nodes { + +static void sh_node_math_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Value").default_value(0.5f).min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Value", "Value_001").default_value(0.5f).min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Value", "Value_002").default_value(0.5f).min(-10000.0f).max(10000.0f); + b.add_output<decl::Float>("Value"); +}; + +} // namespace blender::nodes static const char *gpu_shader_get_name(int mode) { @@ -153,7 +158,7 @@ void register_node_type_sh_math(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out); + ntype.declare = blender::nodes::sh_node_math_declare; node_type_label(&ntype, node_math_label); node_type_gpu(&ntype, gpu_shader_math); node_type_update(&ntype, node_math_update); diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc index ade35a40366..860cc260d5d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc @@ -23,18 +23,18 @@ #include "node_shader_util.h" -/* **************** MIX RGB ******************** */ -static bNodeSocketTemplate sh_node_mix_rgb_in[] = { - {SOCK_FLOAT, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_RGBA, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f}, - {SOCK_RGBA, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_mix_rgb_out[] = { - {SOCK_RGBA, N_("Color")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_mix_rgb_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Fac").default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_input<decl::Color>("Color1").default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_input<decl::Color>("Color2").default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_output<decl::Color>("Color"); }; +} // namespace blender::nodes + static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNode *node, @@ -187,7 +187,7 @@ void register_node_type_sh_mix_rgb(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); + ntype.declare = blender::nodes::sh_node_mix_rgb_declare; node_type_label(&ntype, node_blend_label); node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_mix_rgb); node_type_gpu(&ntype, gpu_shader_mix_rgb); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc index d9cbee33c0f..38f66547379 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc @@ -23,18 +23,18 @@ #include "node_shader_util.h" -/* **************** SEPARATE RGBA ******************** */ -static bNodeSocketTemplate sh_node_seprgb_in[] = { - {SOCK_RGBA, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_seprgb_out[] = { - {SOCK_FLOAT, N_("R")}, - {SOCK_FLOAT, N_("G")}, - {SOCK_FLOAT, N_("B")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_seprgb_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Color>("Image").default_value({0.8f, 0.8f, 0.8f, 1.0f}); + b.add_output<decl::Float>("X"); + b.add_output<decl::Float>("Y"); + b.add_output<decl::Float>("Z"); }; +} // namespace blender::nodes + static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), @@ -107,7 +107,7 @@ void register_node_type_sh_seprgb(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out); + ntype.declare = blender::nodes::sh_node_seprgb_declare; node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_seprgb); node_type_gpu(&ntype, gpu_shader_seprgb); ntype.build_multi_function = sh_node_seprgb_build_multi_function; @@ -115,18 +115,18 @@ void register_node_type_sh_seprgb(void) nodeRegisterType(&ntype); } -/* **************** COMBINE RGB ******************** */ -static bNodeSocketTemplate sh_node_combrgb_in[] = { - {SOCK_FLOAT, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {SOCK_FLOAT, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {SOCK_FLOAT, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_combrgb_out[] = { - {SOCK_RGBA, N_("Image")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_combrgb_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("R").min(0.0f).max(1.0f); + b.add_input<decl::Float>("G").min(0.0f).max(1.0f); + b.add_input<decl::Float>("B").min(0.0f).max(1.0f); + b.add_output<decl::Color>("Image"); }; +} // namespace blender::nodes + static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), @@ -166,7 +166,7 @@ void register_node_type_sh_combrgb(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out); + ntype.declare = blender::nodes::sh_node_combrgb_declare; node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_combrgb); node_type_gpu(&ntype, gpu_shader_combrgb); ntype.build_multi_function = sh_node_combrgb_build_multi_function; diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc index 3048ed1e9fc..b4b3c48482f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc @@ -23,18 +23,18 @@ #include "node_shader_util.h" -/* **************** SEPARATE XYZ ******************** */ -static bNodeSocketTemplate sh_node_sepxyz_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_sepxyz_out[] = { - {SOCK_FLOAT, N_("X")}, - {SOCK_FLOAT, N_("Y")}, - {SOCK_FLOAT, N_("Z")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_sepxyz_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").min(-10000.0f).max(10000.0f); + b.add_output<decl::Float>("X"); + b.add_output<decl::Float>("Y"); + b.add_output<decl::Float>("Z"); }; +} // namespace blender::nodes + static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), @@ -92,25 +92,25 @@ void register_node_type_sh_sepxyz(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out); + ntype.declare = blender::nodes::sh_node_sepxyz_declare; node_type_gpu(&ntype, gpu_shader_sepxyz); ntype.build_multi_function = sh_node_sepxyz_build_multi_function; nodeRegisterType(&ntype); } -/* **************** COMBINE XYZ ******************** */ -static bNodeSocketTemplate sh_node_combxyz_in[] = { - {SOCK_FLOAT, N_("X"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - {SOCK_FLOAT, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - {SOCK_FLOAT, N_("Z"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_combxyz_out[] = { - {SOCK_VECTOR, N_("Vector")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_combxyz_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("X").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Y").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Z").min(-10000.0f).max(10000.0f); + b.add_output<decl::Vector>("Vector"); }; +} // namespace blender::nodes + static int gpu_shader_combxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), @@ -132,7 +132,7 @@ void register_node_type_sh_combxyz(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out); + ntype.declare = blender::nodes::sh_node_combxyz_declare; node_type_gpu(&ntype, gpu_shader_combxyz); ntype.build_multi_function = sh_node_combxyz_build_multi_function; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc index 6e973189065..bae16e10120 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc @@ -19,19 +19,18 @@ #include "../node_shader_util.h" -/* **************** WHITE NOISE **************** */ +namespace blender::nodes { -static bNodeSocketTemplate sh_node_tex_white_noise_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, - {-1, ""}}; - -static bNodeSocketTemplate sh_node_tex_white_noise_out[] = { - {SOCK_FLOAT, N_("Value")}, - {SOCK_RGBA, N_("Color")}, - {-1, ""}, +static void sh_node_tex_white_noise_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("W").min(-10000.0f).max(10000.0f); + b.add_output<decl::Float>("Value"); + b.add_output<decl::Color>("Color"); }; +} // namespace blender::nodes + static void node_shader_init_tex_white_noise(bNodeTree *UNUSED(ntree), bNode *node) { node->custom1 = 3; @@ -70,7 +69,7 @@ void register_node_type_sh_tex_white_noise(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_WHITE_NOISE, "White Noise Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_white_noise_in, sh_node_tex_white_noise_out); + ntype.declare = blender::nodes::sh_node_tex_white_noise_declare; node_type_init(&ntype, node_shader_init_tex_white_noise); node_type_gpu(&ntype, gpu_shader_tex_white_noise); node_type_update(&ntype, node_shader_update_tex_white_noise); diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc index 62f6b38c79f..1870caffbb1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc +++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc @@ -29,17 +29,17 @@ #include "node_shader_util.h" -/* **************** VALTORGB ******************** */ -static bNodeSocketTemplate sh_node_valtorgb_in[] = { - {SOCK_FLOAT, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_valtorgb_out[] = { - {SOCK_RGBA, N_("Color")}, - {SOCK_FLOAT, N_("Alpha")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Float>("Fac").default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_output<decl::Color>("Color"); + b.add_output<decl::Float>("Alpha"); }; +} // namespace blender::nodes + static void node_shader_exec_valtorgb(void *UNUSED(data), int UNUSED(thread), bNode *node, @@ -176,7 +176,7 @@ void register_node_type_sh_valtorgb(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_valtorgb_in, sh_node_valtorgb_out); + ntype.declare = blender::nodes::sh_node_valtorgb_declare; node_type_init(&ntype, node_shader_init_valtorgb); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); @@ -187,11 +187,15 @@ void register_node_type_sh_valtorgb(void) nodeRegisterType(&ntype); } -/* **************** RGBTOBW ******************** */ -static bNodeSocketTemplate sh_node_rgbtobw_in[] = { - {SOCK_RGBA, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, {-1, ""}}; -static bNodeSocketTemplate sh_node_rgbtobw_out[] = { - {SOCK_FLOAT, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-1, ""}}; +namespace blender::nodes { + +static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Color>("Color").default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_output<decl::Float>("Val"); +}; + +} // namespace blender::nodes static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), @@ -222,7 +226,7 @@ void register_node_type_sh_rgbtobw(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_rgbtobw_in, sh_node_rgbtobw_out); + ntype.declare = blender::nodes::sh_node_rgbtobw_declare; node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_rgbtobw); node_type_gpu(&ntype, gpu_shader_rgbtobw); diff --git a/source/blender/nodes/shader/nodes/node_shader_value.cc b/source/blender/nodes/shader/nodes/node_shader_value.cc index 602d5a1cf56..74197ff8218 100644 --- a/source/blender/nodes/shader/nodes/node_shader_value.cc +++ b/source/blender/nodes/shader/nodes/node_shader_value.cc @@ -23,12 +23,15 @@ #include "node_shader_util.h" -/* **************** VALUE ******************** */ -static bNodeSocketTemplate sh_node_value_out[] = { - {SOCK_FLOAT, N_("Value"), 0.5f, 0, 0, 0, -FLT_MAX, FLT_MAX, PROP_NONE}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_value_declare(NodeDeclarationBuilder &b) +{ + b.add_output<decl::Float>("Vector"); }; +} // namespace blender::nodes + static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), @@ -51,7 +54,7 @@ void register_node_type_sh_value(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, nullptr, sh_node_value_out); + ntype.declare = blender::nodes::sh_node_value_declare; node_type_gpu(&ntype, gpu_shader_value); ntype.build_multi_function = sh_node_value_build_multi_function; diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc index 4424db6aed1..5b24e8bb72d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc +++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc @@ -25,16 +25,19 @@ #include "NOD_math_functions.hh" -/* **************** VECTOR MATH ******************** */ -static bNodeSocketTemplate sh_node_vector_math_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {SOCK_FLOAT, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - {-1, ""}}; +namespace blender::nodes { -static bNodeSocketTemplate sh_node_vector_math_out[] = { - {SOCK_VECTOR, N_("Vector")}, {SOCK_FLOAT, N_("Value")}, {-1, ""}}; +static void sh_node_vector_math_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").min(-10000.0f).max(10000.0f); + b.add_input<decl::Vector>("Vector", "Vector_001").min(-10000.0f).max(10000.0f); + b.add_input<decl::Vector>("Vector", "Vector_002").min(-10000.0f).max(10000.0f); + b.add_input<decl::Float>("Scale").default_value(1.0f).min(-10000.0f).max(10000.0f); + b.add_output<decl::Vector>("Vector"); + b.add_output<decl::Float>("Value"); +}; + +} // namespace blender::nodes static const char *gpu_shader_get_name(int mode) { @@ -274,7 +277,7 @@ void register_node_type_sh_vect_math(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_VECTOR_MATH, "Vector Math", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_vector_math_in, sh_node_vector_math_out); + ntype.declare = blender::nodes::sh_node_vector_math_declare; node_type_label(&ntype, node_vector_math_label); node_type_gpu(&ntype, gpu_shader_vector_math); node_type_update(&ntype, node_shader_update_vector_math); diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc index bc51b7e29ea..e9fd6c4f31e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc +++ b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc @@ -23,20 +23,20 @@ #include "../node_shader_util.h" -/* **************** Vector Rotate ******************** */ -static bNodeSocketTemplate sh_node_vector_rotate_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {SOCK_VECTOR, N_("Center"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_NONE}, - {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_NONE, PROP_NONE}, - {SOCK_FLOAT, N_("Angle"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_ANGLE, PROP_NONE}, - {SOCK_VECTOR, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER}, - {-1, ""}}; - -static bNodeSocketTemplate sh_node_vector_rotate_out[] = { - {SOCK_VECTOR, N_("Vector")}, - {-1, ""}, +namespace blender::nodes { + +static void sh_node_vector_rotate_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Vector>("Vector").min(0.0f).max(1.0f).hide_value(); + b.add_input<decl::Vector>("Vector"); + b.add_input<decl::Vector>("Axis").min(-1.0f).max(1.0f).default_value({0.0f, 0.0f, 1.0f}); + b.add_input<decl::Float>("Angle").subtype(PROP_ANGLE); + b.add_input<decl::Vector>("Rotation").subtype(PROP_EULER); + b.add_output<decl::Vector>("Value"); }; +} // namespace blender::nodes + static const char *gpu_shader_get_name(int mode) { switch (mode) { @@ -207,7 +207,7 @@ void register_node_type_sh_vector_rotate(void) static bNodeType ntype; sh_fn_node_type_base(&ntype, SH_NODE_VECTOR_ROTATE, "Vector Rotate", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_vector_rotate_in, sh_node_vector_rotate_out); + ntype.declare = blender::nodes::sh_node_vector_rotate_declare; node_type_gpu(&ntype, gpu_shader_vector_rotate); node_type_update(&ntype, node_shader_update_vector_rotate); ntype.build_multi_function = sh_node_vector_rotate_build_multi_function; |