Particles: support Separate/Combine RGB nodes

This commit is contained in:
2020-07-16 16:08:18 +02:00
parent ada173ebfd
commit 4249d6f58e
3 changed files with 47 additions and 1 deletions

View File

@@ -193,7 +193,7 @@ set(SRC
shader/nodes/node_shader_rgb.c
shader/nodes/node_shader_script.c
shader/nodes/node_shader_sepcombHSV.c
shader/nodes/node_shader_sepcombRGB.c
shader/nodes/node_shader_sepcombRGB.cc
shader/nodes/node_shader_sepcombXYZ.cc
shader/nodes/node_shader_shaderToRgb.c
shader/nodes/node_shader_squeeze.c

View File

@@ -75,6 +75,7 @@
# include "BKE_node_tree_multi_function.hh"
# include "BLI_color.hh"
# include "BLI_float3.hh"
extern "C" {

View File

@@ -59,6 +59,42 @@ static int gpu_shader_seprgb(GPUMaterial *mat,
return GPU_stack_link(mat, node, "separate_rgb", in, out);
}
class SeparateRGBFunction : public blender::fn::MultiFunction {
public:
SeparateRGBFunction()
{
blender::fn::MFSignatureBuilder signature = this->get_builder("Separate RGB");
signature.single_input<blender::Color4f>("Color");
signature.single_output<float>("R");
signature.single_output<float>("G");
signature.single_output<float>("B");
}
void call(blender::IndexMask mask,
blender::fn::MFParams params,
blender::fn::MFContext UNUSED(context)) const override
{
blender::fn::VSpan<blender::Color4f> colors = params.readonly_single_input<blender::Color4f>(
0, "Color");
blender::MutableSpan<float> rs = params.uninitialized_single_output<float>(1, "R");
blender::MutableSpan<float> gs = params.uninitialized_single_output<float>(2, "G");
blender::MutableSpan<float> bs = params.uninitialized_single_output<float>(3, "B");
for (uint i : mask) {
blender::Color4f color = colors[i];
rs[i] = color.r;
gs[i] = color.g;
bs[i] = color.b;
}
}
};
static void sh_node_seprgb_expand_in_mf_network(blender::bke::NodeMFNetworkBuilder &builder)
{
static SeparateRGBFunction fn;
builder.set_matching_fn(fn);
}
void register_node_type_sh_seprgb(void)
{
static bNodeType ntype;
@@ -67,6 +103,7 @@ void register_node_type_sh_seprgb(void)
node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out);
node_type_exec(&ntype, NULL, NULL, node_shader_exec_seprgb);
node_type_gpu(&ntype, gpu_shader_seprgb);
ntype.expand_in_mf_network = sh_node_seprgb_expand_in_mf_network;
nodeRegisterType(&ntype);
}
@@ -109,6 +146,13 @@ static int gpu_shader_combrgb(GPUMaterial *mat,
return GPU_stack_link(mat, node, "combine_rgb", in, out);
}
static void sh_node_combrgb_expand_in_mf_network(blender::bke::NodeMFNetworkBuilder &builder)
{
static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, blender::Color4f> fn{
"Combine RGB", [](float r, float g, float b) { return blender::Color4f(r, g, b, 1.0f); }};
builder.set_matching_fn(fn);
}
void register_node_type_sh_combrgb(void)
{
static bNodeType ntype;
@@ -117,6 +161,7 @@ void register_node_type_sh_combrgb(void)
node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out);
node_type_exec(&ntype, NULL, NULL, node_shader_exec_combrgb);
node_type_gpu(&ntype, gpu_shader_combrgb);
ntype.expand_in_mf_network = sh_node_combrgb_expand_in_mf_network;
nodeRegisterType(&ntype);
}