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"
This commit is contained in:
Hans Goudey 2021-09-22 17:34:09 -05:00
parent 6fb4c8f040
commit 79bcc19240
6 changed files with 74 additions and 113 deletions

View File

@ -37,6 +37,7 @@ class SocketDeclaration {
bool hide_label_ = false;
bool hide_value_ = false;
bool is_multi_input_ = false;
bool no_mute_links_ = false;
friend NodeDeclarationBuilder;
template<typename SocketDecl> friend class SocketDeclarationBuilder;
@ -93,6 +94,12 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
decl_->is_multi_input_ = value;
return *(Self *)this;
}
Self &no_muted_links(bool value = true)
{
decl_->no_mute_links_ = value;
return *(Self *)this;
}
};
using SocketDeclarationPtr = std::unique_ptr<SocketDeclaration>;

View File

@ -69,6 +69,7 @@ void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
SET_FLAG_FROM_TEST(socket.flag, hide_value_, SOCK_HIDE_VALUE);
SET_FLAG_FROM_TEST(socket.flag, hide_label_, SOCK_HIDE_LABEL);
SET_FLAG_FROM_TEST(socket.flag, is_multi_input_, SOCK_MULTI_INPUT);
SET_FLAG_FROM_TEST(socket.flag, no_mute_links_, SOCK_NO_INTERNAL_LINK);
}
bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
@ -88,6 +89,9 @@ bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
if (((socket.flag & SOCK_MULTI_INPUT) != 0) != is_multi_input_) {
return false;
}
if (((socket.flag & SOCK_NO_INTERNAL_LINK) != 0) != no_mute_links_) {
return false;
}
return true;
}

View File

@ -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);

View File

@ -19,33 +19,22 @@
#include "../node_shader_util.h"
/* **************** MUSGRAVE ******************** */
namespace blender::nodes {
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, ""},
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();
};
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, ""},
};
} // namespace blender::nodes
static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)
{
@ -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(

View File

@ -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);

View File

@ -19,53 +19,32 @@
#include "../node_shader_util.h"
/* **************** VORONOI ******************** */
namespace blender::nodes {
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, ""},
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();
};
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, ""},
};
} // namespace blender::nodes
static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
{
@ -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);