diff options
author | Charlie Jolly <charlie> | 2021-08-18 15:16:14 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-08-18 16:50:52 +0300 |
commit | 04376c3bac796c9fb4bc2e33150484e357a65eab (patch) | |
tree | b2d670aa2d8bbc057469c4d146a7bbfaa2b5d936 /source/blender/nodes | |
parent | 787350dde8aec3caf8660c749e1847ff406974c8 (diff) |
Geometry Nodes: Add shader Color Mix node
Port color mix shader node to Geometry Nodes.
Differential Revision: https://developer.blender.org/D10585
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_mixRgb.cc | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc index 6baaa17f956..47011caeeb6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc @@ -127,15 +127,71 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, return 0; } +class MixRGBFunction : public blender::fn::MultiFunction { + private: + bool clamp_; + int type_; + + public: + MixRGBFunction(bool clamp, int type) : clamp_(clamp), type_(type) + { + static blender::fn::MFSignature signature = create_signature(); + this->set_signature(&signature); + } + + static blender::fn::MFSignature create_signature() + { + blender::fn::MFSignatureBuilder signature{"MixRGB"}; + signature.single_input<float>("Fac"); + signature.single_input<blender::ColorGeometry4f>("Color1"); + signature.single_input<blender::ColorGeometry4f>("Color2"); + signature.single_output<blender::ColorGeometry4f>("Color"); + return signature.build(); + } + + void call(blender::IndexMask mask, + blender::fn::MFParams params, + blender::fn::MFContext UNUSED(context)) const override + { + const blender::VArray<float> &fac = params.readonly_single_input<float>(0, "Fac"); + const blender::VArray<blender::ColorGeometry4f> &col1 = + params.readonly_single_input<blender::ColorGeometry4f>(1, "Color1"); + const blender::VArray<blender::ColorGeometry4f> &col2 = + params.readonly_single_input<blender::ColorGeometry4f>(2, "Color2"); + blender::MutableSpan<blender::ColorGeometry4f> results = + params.uninitialized_single_output<blender::ColorGeometry4f>(3, "Color"); + + for (int64_t i : mask) { + results[i] = col1[i]; + ramp_blend(type_, results[i], clamp_f(fac[i], 0.0f, 1.0f), col2[i]); + } + + if (clamp_) { + for (int64_t i : mask) { + clamp_v3(results[i], 0.0f, 1.0f); + } + } + } +}; + +static void sh_node_mix_rgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder) +{ + bNode &node = builder.bnode(); + bool clamp = node.custom2 & SHD_MIXRGB_CLAMP; + int mix_type = node.custom1; + builder.construct_and_set_matching_fn<MixRGBFunction>(clamp, mix_type); +} + void register_node_type_sh_mix_rgb(void) { static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); + sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); node_type_label(&ntype, node_blend_label); node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_mix_rgb); node_type_gpu(&ntype, gpu_shader_mix_rgb); + ntype.expand_in_mf_network = sh_node_mix_rgb_expand_in_mf_network; nodeRegisterType(&ntype); } |