Nodes: Add Shader Socket to new decleration API

This commit adds the shader socket type to the new socket builder api.

As a test, this commit also converts the Add Shader node to the new API

Reviewed By: JacquesLucke

Differential Revision: https://developer.blender.org/D13485
This commit is contained in:
Aaron Carlisle 2021-12-06 11:59:26 -05:00 committed by Aaron Carlisle
parent f72cc47d8e
commit 0bd3cad04e
Notes: blender-bot 2023-02-14 06:37:09 +01:00
Referenced by commit 333dc7b5c4, Nodes: Add Shader Socket to new decleration API
Referenced by commit 0f48b37aae, Revert moving all shader nodes to c++
3 changed files with 47 additions and 12 deletions

View File

@ -212,6 +212,21 @@ class Image : public IDSocketDeclaration {
Image();
};
class ShaderBuilder;
class Shader : public SocketDeclaration {
private:
friend ShaderBuilder;
public:
using Builder = ShaderBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class ShaderBuilder : public SocketDeclarationBuilder<Shader> {};
/* -------------------------------------------------------------------- */
/** \name #FloatBuilder Inline Methods
* \{ */

View File

@ -376,4 +376,29 @@ GeometryBuilder &GeometryBuilder::only_instances(bool value)
/** \} */
/* -------------------------------------------------------------------- */
/** \name #Shader
* \{ */
bNodeSocket &Shader::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out, "NodeSocketShader", identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
return socket;
}
bool Shader::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_SHADER) {
return false;
}
return true;
}
/** \} */
} // namespace blender::nodes::decl

View File

@ -23,16 +23,12 @@
namespace blender::nodes::node_shader_add_shader_cc {
static bNodeSocketTemplate sh_node_add_shader_in[] = {
{SOCK_SHADER, N_("Shader")},
{SOCK_SHADER, N_("Shader")},
{-1, ""},
};
static bNodeSocketTemplate sh_node_add_shader_out[] = {
{SOCK_SHADER, N_("Shader")},
{-1, ""},
};
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Shader>(N_("Shader"));
b.add_input<decl::Shader>(N_("Shader"), "Shader_001");
b.add_output<decl::Shader>(N_("Shader"));
}
static int node_shader_gpu_add_shader(GPUMaterial *mat,
bNode *node,
@ -53,8 +49,7 @@ void register_node_type_sh_add_shader()
static bNodeType ntype;
sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER, 0);
node_type_socket_templates(
&ntype, file_ns::sh_node_add_shader_in, file_ns::sh_node_add_shader_out);
ntype.declare = file_ns::node_declare;
node_type_init(&ntype, nullptr);
node_type_storage(&ntype, "", nullptr, nullptr);
node_type_gpu(&ntype, file_ns::node_shader_gpu_add_shader);