Shader Nodes: Convert bump node to use new socket builder

This node is a bit special in that it uses two internal sockets
for a hack for Eevee; see rBffd5e1e6acd296a187e7af016f9d7f8a9f209f87

As a result, the `SOCK_UNAVAIL` flag is exposed to socket builder API.

Reviewed By: JacquesLucke, fclem

Differential Revision: https://developer.blender.org/D13496
This commit is contained in:
Aaron Carlisle 2021-12-25 11:12:43 -05:00 committed by Aaron Carlisle
parent c5862da5ad
commit fbd01624e3
3 changed files with 42 additions and 14 deletions

View File

@ -95,6 +95,7 @@ class SocketDeclaration {
bool compact_ = false;
bool is_multi_input_ = false;
bool no_mute_links_ = false;
bool is_unavailable_ = false;
bool is_attribute_name_ = false;
bool is_default_link_socket_ = false;
@ -185,12 +186,23 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
decl_->description_ = std::move(value);
return *(Self *)this;
}
Self &no_muted_links(bool value = true)
{
decl_->no_mute_links_ = value;
return *(Self *)this;
}
/**
* Used for sockets that are always unavailable and should not be seen by the user.
* Ideally, no new calls to this method should be added over time.
*/
Self &unavailable(bool value = true)
{
decl_->is_unavailable_ = value;
return *(Self *)this;
}
Self &is_attribute_name(bool value = true)
{
decl_->is_attribute_name_ = value;

View File

@ -63,6 +63,7 @@ void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
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);
SET_FLAG_FROM_TEST(socket.flag, is_unavailable_, SOCK_UNAVAIL);
}
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_NO_INTERNAL_LINK) != 0) != no_mute_links_) {
return false;
}
if (((socket.flag & SOCK_UNAVAIL) != 0) != is_unavailable_) {
return false;
}
return true;
}

View File

@ -24,19 +24,27 @@
#include "node_shader_util.h"
/* **************** BUMP ******************** */
/* clang-format off */
static bNodeSocketTemplate sh_node_bump_in[] = {
{SOCK_FLOAT, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
{SOCK_FLOAT, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
{SOCK_FLOAT, N_("Height"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE},
{SOCK_FLOAT, N_("Height_dx"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
{SOCK_FLOAT, N_("Height_dy"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
{SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{-1, ""}
};
/* clang-format on */
static bNodeSocketTemplate sh_node_bump_out[] = {{SOCK_VECTOR, "Normal"}, {-1, ""}};
namespace blender::nodes::node_shader_bump_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Float>(N_("Strength"))
.default_value(1.0f)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
b.add_input<decl::Float>(N_("Distance")).default_value(1.0f).min(0.0f).max(1000.0f);
b.add_input<decl::Float>(N_("Height"))
.default_value(1.0f)
.min(-1000.0f)
.max(1000.0f)
.hide_value();
b.add_input<decl::Float>(N_("Height_dx")).default_value(1.0f).unavailable();
b.add_input<decl::Float>(N_("Height_dy")).default_value(1.0f).unavailable();
b.add_input<decl::Vector>(N_("Normal")).min(-1.0f).max(1.0f).hide_value();
b.add_output<decl::Vector>(N_("Normal"));
}
static int gpu_shader_bump(GPUMaterial *mat,
bNode *node,
@ -54,15 +62,19 @@ static int gpu_shader_bump(GPUMaterial *mat,
mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert));
}
} // namespace blender::nodes::node_shader_bump_cc
/* node type definition */
void register_node_type_sh_bump()
{
namespace file_ns = blender::nodes::node_shader_bump_cc;
static bNodeType ntype;
sh_node_type_base(&ntype, SH_NODE_BUMP, "Bump", NODE_CLASS_OP_VECTOR, 0);
node_type_socket_templates(&ntype, sh_node_bump_in, sh_node_bump_out);
ntype.declare = file_ns::node_declare;
node_type_storage(&ntype, "", nullptr, nullptr);
node_type_gpu(&ntype, gpu_shader_bump);
node_type_gpu(&ntype, file_ns::gpu_shader_bump);
nodeRegisterType(&ntype);
}