I want to add a new node to the shader editor. my build environment is ready and updated:
Windows 64 Bit
Cmake
VSCode
Visual Studio 2022 installed
Python 3 installed
This are stpest that I did to add the shader:
D:\WIP\Test_018_Blender\blender\source\blender\nodes\shader\nodes\node_shader_mehdi.cc
#include "node_shader_util.hh"
#include "node_shader_register.hh"
namespace blender::nodes::node_shader_mehdi_cc
{
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Shader>("In");
b.add_output<decl::Shader>("Out");
}
static int gpu_shader_mehdi(GPUMaterial *mat,
bNode *node,
bNodeExecData *,
GPUNodeStack *in,
GPUNodeStack *out)
{
return GPU_stack_link(mat, node, "node_mehdi", in, out);
}
}
void register_node_type_sh_mehdi()
{
namespace file_ns = blender::nodes::node_shader_mehdi_cc;
static blender::bke::bNodeType ntype;
sh_node_type_base(&ntype, "ShaderNodeMehdi", SH_NODE_MEHDI);
ntype.ui_name = "Mehdi";
ntype.ui_description = "Minimal pass-through example.";
ntype.nclass = NODE_CLASS_SHADER;
ntype.add_ui_poll = object_shader_nodes_poll;
ntype.declare = file_ns::node_declare;
ntype.gpu_fn = file_ns::gpu_shader_mehdi;
blender::bke::node_register_type(ntype);
}
D:\WIP\Test_018_Blender\blender\source\blender\nodes\shader\CMakeLists.txt
set(SRC
nodes/node_shader_mehdi.cc
D:\WIP\Test_018_Blender\blender\source\blender\nodes\shader\node_shader_register.cc
register_node_type_sh_mehdi();
D:\WIP\Test_018_Blender\blender\source\blender\nodes\shader\node_shader_register.hh
void register_node_type_sh_mehdi();
D:\WIP\Test_018_Blender\blender\source\blender\gpu\shaders\material\gpu_shader_material_mehdi.glsl
/* SPDX-FileCopyrightText: 2019 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
void node_mehdi(float val, float width, float center, out float outval)
{
outval = 1.0 / (1.0 + pow(2.71828183, -((val - center) * width)));
}
D:\WIP\Test_018_Blender\blender\source\blender\gpu\CMakeLists.txt
shaders/material/gpu_shader_material_mehdi.glsl
and then build/make the entire project, but when I open Blender, shader node is not created.
In general what is the correct pipeline to add a shader node in Blender?
The functionality of the node is, it hasa shader socket input and will output metallic as rgb.