From 0d8c479225d754ba376e442d56ffa935956427cf Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Tue, 7 Dec 2021 16:24:09 -0500 Subject: Shader Nodes: Use camel case for file names Recommits part of rBf60b95b5320f8d6abe6a629fe8fc4f1b94d0d91c --- source/blender/nodes/shader/CMakeLists.txt | 16 +- .../nodes/shader/nodes/node_shader_mixRgb.cc | 198 ----------------- .../nodes/shader/nodes/node_shader_mix_rgb.cc | 198 +++++++++++++++++ .../nodes/shader/nodes/node_shader_rgb_to_bw.cc | 235 +++++++++++++++++++++ .../nodes/shader/nodes/node_shader_sepcombHSV.c | 118 ----------- .../nodes/shader/nodes/node_shader_sepcombRGB.cc | 177 ---------------- .../nodes/shader/nodes/node_shader_sepcombXYZ.cc | 142 ------------- .../nodes/shader/nodes/node_shader_sepcomb_hsv.c | 118 +++++++++++ .../nodes/shader/nodes/node_shader_sepcomb_rgb.cc | 177 ++++++++++++++++ .../nodes/shader/nodes/node_shader_sepcomb_xyz.cc | 142 +++++++++++++ .../nodes/shader/nodes/node_shader_shaderToRgb.c | 60 ------ .../nodes/shader/nodes/node_shader_shader_to_rgb.c | 60 ++++++ .../nodes/shader/nodes/node_shader_uvAlongStroke.c | 39 ---- .../shader/nodes/node_shader_uv_along_stroke.c | 39 ++++ .../nodes/shader/nodes/node_shader_valToRgb.cc | 235 --------------------- .../nodes/shader/nodes/node_shader_vectTransform.c | 153 -------------- .../shader/nodes/node_shader_vector_transform.c | 153 ++++++++++++++ 17 files changed, 1130 insertions(+), 1130 deletions(-) delete mode 100644 source/blender/nodes/shader/nodes/node_shader_mixRgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.c delete mode 100644 source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.c delete mode 100644 source/blender/nodes/shader/nodes/node_shader_valToRgb.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_vectTransform.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_vector_transform.c (limited to 'source/blender') diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 4343424a5d5..7d99c233197 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -80,7 +80,7 @@ set(SRC nodes/node_shader_map_range.cc nodes/node_shader_mapping.c nodes/node_shader_math.cc - nodes/node_shader_mixRgb.cc + nodes/node_shader_mix_rgb.cc nodes/node_shader_mix_shader.c nodes/node_shader_normal.c nodes/node_shader_normal_map.c @@ -91,12 +91,13 @@ set(SRC nodes/node_shader_output_material.c nodes/node_shader_output_world.c nodes/node_shader_particle_info.c + nodes/node_shader_rgb_to_bw.cc nodes/node_shader_rgb.c nodes/node_shader_script.c - nodes/node_shader_sepcombHSV.c - nodes/node_shader_sepcombRGB.cc - nodes/node_shader_sepcombXYZ.cc - nodes/node_shader_shaderToRgb.c + nodes/node_shader_sepcomb_hsv.c + nodes/node_shader_sepcomb_rgb.cc + nodes/node_shader_sepcomb_xyz.cc + nodes/node_shader_shader_to_rgb.c nodes/node_shader_squeeze.c nodes/node_shader_subsurface_scattering.c nodes/node_shader_tangent.c @@ -114,14 +115,13 @@ set(SRC nodes/node_shader_tex_voronoi.cc nodes/node_shader_tex_wave.cc nodes/node_shader_tex_white_noise.cc - nodes/node_shader_uvAlongStroke.c + nodes/node_shader_uv_along_stroke.c nodes/node_shader_uvmap.c - nodes/node_shader_valToRgb.cc nodes/node_shader_value.cc - nodes/node_shader_vectTransform.c nodes/node_shader_vector_displacement.c nodes/node_shader_vector_math.cc nodes/node_shader_vector_rotate.cc + nodes/node_shader_vector_transform.c nodes/node_shader_vertex_color.c nodes/node_shader_volume_absorption.c nodes/node_shader_volume_info.c diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc deleted file mode 100644 index 06fafff578e..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc +++ /dev/null @@ -1,198 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "node_shader_util.h" - -namespace blender::nodes { - -static void sh_node_mix_rgb_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); - b.add_input(N_("Color1")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); - b.add_input(N_("Color2")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); - b.add_output(N_("Color")); -}; - -} // namespace blender::nodes - -static void node_shader_exec_mix_rgb(void *UNUSED(data), - int UNUSED(thread), - bNode *node, - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - /* stack order in: fac, col1, col2 */ - /* stack order out: col */ - float col[3]; - float fac; - float vec[3]; - - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - CLAMP(fac, 0.0f, 1.0f); - - nodestack_get_vec(col, SOCK_VECTOR, in[1]); - nodestack_get_vec(vec, SOCK_VECTOR, in[2]); - - ramp_blend(node->custom1, col, fac, vec); - if (node->custom2 & SHD_MIXRGB_CLAMP) { - CLAMP3(col, 0.0f, 1.0f); - } - copy_v3_v3(out[0]->vec, col); -} - -static const char *gpu_shader_get_name(int mode) -{ - switch (mode) { - case MA_RAMP_BLEND: - return "mix_blend"; - case MA_RAMP_ADD: - return "mix_add"; - case MA_RAMP_MULT: - return "mix_mult"; - case MA_RAMP_SUB: - return "mix_sub"; - case MA_RAMP_SCREEN: - return "mix_screen"; - case MA_RAMP_DIV: - return "mix_div"; - case MA_RAMP_DIFF: - return "mix_diff"; - case MA_RAMP_DARK: - return "mix_dark"; - case MA_RAMP_LIGHT: - return "mix_light"; - case MA_RAMP_OVERLAY: - return "mix_overlay"; - case MA_RAMP_DODGE: - return "mix_dodge"; - case MA_RAMP_BURN: - return "mix_burn"; - case MA_RAMP_HUE: - return "mix_hue"; - case MA_RAMP_SAT: - return "mix_sat"; - case MA_RAMP_VAL: - return "mix_val"; - case MA_RAMP_COLOR: - return "mix_color"; - case MA_RAMP_SOFT: - return "mix_soft"; - case MA_RAMP_LINEAR: - return "mix_linear"; - } - - return nullptr; -} - -static int gpu_shader_mix_rgb(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - const char *name = gpu_shader_get_name(node->custom1); - - if (name != nullptr) { - int ret = GPU_stack_link(mat, node, name, in, out); - if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { - const float min[3] = {0.0f, 0.0f, 0.0f}; - const float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link( - mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); - } - return ret; - } - - 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("Fac"); - signature.single_input("Color1"); - signature.single_input("Color2"); - signature.single_output("Color"); - return signature.build(); - } - - void call(blender::IndexMask mask, - blender::fn::MFParams params, - blender::fn::MFContext UNUSED(context)) const override - { - const blender::VArray &fac = params.readonly_single_input(0, "Fac"); - const blender::VArray &col1 = - params.readonly_single_input(1, "Color1"); - const blender::VArray &col2 = - params.readonly_single_input(2, "Color2"); - blender::MutableSpan results = - params.uninitialized_single_output(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_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) -{ - bNode &node = builder.node(); - bool clamp = node.custom2 & SHD_MIXRGB_CLAMP; - int mix_type = node.custom1; - builder.construct_and_set_matching_fn(clamp, mix_type); -} - -void register_node_type_sh_mix_rgb(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - ntype.declare = blender::nodes::sh_node_mix_rgb_declare; - 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.build_multi_function = sh_node_mix_rgb_build_multi_function; - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc new file mode 100644 index 00000000000..06fafff578e --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc @@ -0,0 +1,198 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.h" + +namespace blender::nodes { + +static void sh_node_mix_rgb_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_input(N_("Color1")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_input(N_("Color2")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_output(N_("Color")); +}; + +} // namespace blender::nodes + +static void node_shader_exec_mix_rgb(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + /* stack order in: fac, col1, col2 */ + /* stack order out: col */ + float col[3]; + float fac; + float vec[3]; + + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + CLAMP(fac, 0.0f, 1.0f); + + nodestack_get_vec(col, SOCK_VECTOR, in[1]); + nodestack_get_vec(vec, SOCK_VECTOR, in[2]); + + ramp_blend(node->custom1, col, fac, vec); + if (node->custom2 & SHD_MIXRGB_CLAMP) { + CLAMP3(col, 0.0f, 1.0f); + } + copy_v3_v3(out[0]->vec, col); +} + +static const char *gpu_shader_get_name(int mode) +{ + switch (mode) { + case MA_RAMP_BLEND: + return "mix_blend"; + case MA_RAMP_ADD: + return "mix_add"; + case MA_RAMP_MULT: + return "mix_mult"; + case MA_RAMP_SUB: + return "mix_sub"; + case MA_RAMP_SCREEN: + return "mix_screen"; + case MA_RAMP_DIV: + return "mix_div"; + case MA_RAMP_DIFF: + return "mix_diff"; + case MA_RAMP_DARK: + return "mix_dark"; + case MA_RAMP_LIGHT: + return "mix_light"; + case MA_RAMP_OVERLAY: + return "mix_overlay"; + case MA_RAMP_DODGE: + return "mix_dodge"; + case MA_RAMP_BURN: + return "mix_burn"; + case MA_RAMP_HUE: + return "mix_hue"; + case MA_RAMP_SAT: + return "mix_sat"; + case MA_RAMP_VAL: + return "mix_val"; + case MA_RAMP_COLOR: + return "mix_color"; + case MA_RAMP_SOFT: + return "mix_soft"; + case MA_RAMP_LINEAR: + return "mix_linear"; + } + + return nullptr; +} + +static int gpu_shader_mix_rgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + const char *name = gpu_shader_get_name(node->custom1); + + if (name != nullptr) { + int ret = GPU_stack_link(mat, node, name, in, out); + if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { + const float min[3] = {0.0f, 0.0f, 0.0f}; + const float max[3] = {1.0f, 1.0f, 1.0f}; + GPU_link( + mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + } + return ret; + } + + 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("Fac"); + signature.single_input("Color1"); + signature.single_input("Color2"); + signature.single_output("Color"); + return signature.build(); + } + + void call(blender::IndexMask mask, + blender::fn::MFParams params, + blender::fn::MFContext UNUSED(context)) const override + { + const blender::VArray &fac = params.readonly_single_input(0, "Fac"); + const blender::VArray &col1 = + params.readonly_single_input(1, "Color1"); + const blender::VArray &col2 = + params.readonly_single_input(2, "Color2"); + blender::MutableSpan results = + params.uninitialized_single_output(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_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) +{ + bNode &node = builder.node(); + bool clamp = node.custom2 & SHD_MIXRGB_CLAMP; + int mix_type = node.custom1; + builder.construct_and_set_matching_fn(clamp, mix_type); +} + +void register_node_type_sh_mix_rgb(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); + ntype.declare = blender::nodes::sh_node_mix_rgb_declare; + 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.build_multi_function = sh_node_mix_rgb_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc b/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc new file mode 100644 index 00000000000..e4f1b2c76f0 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc @@ -0,0 +1,235 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "IMB_colormanagement.h" + +#include "DNA_texture_types.h" + +#include "BLI_color.hh" + +#include "node_shader_util.h" + +namespace blender::nodes { + +static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_output(N_("Color")); + b.add_output(N_("Alpha")); +}; + +} // namespace blender::nodes + +static void node_shader_exec_valtorgb(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + /* stack order in: fac */ + /* stack order out: col, alpha */ + + if (node->storage) { + float fac; + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + + BKE_colorband_evaluate((ColorBand *)node->storage, fac, out[0]->vec); + out[1]->vec[0] = out[0]->vec[3]; + } +} + +static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node) +{ + node->storage = BKE_colorband_add(true); +} + +static int gpu_shader_valtorgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + struct ColorBand *coba = (ColorBand *)node->storage; + float *array, layer; + int size; + + /* Common / easy case optimization. */ + if ((coba->tot <= 2) && (coba->color_mode == COLBAND_BLEND_RGB)) { + float mul_bias[2]; + switch (coba->ipotype) { + case COLBAND_INTERP_LINEAR: + mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); + mul_bias[1] = -mul_bias[0] * coba->data[0].pos; + return GPU_stack_link(mat, + node, + "valtorgb_opti_linear", + in, + out, + GPU_uniform(mul_bias), + GPU_uniform(&coba->data[0].r), + GPU_uniform(&coba->data[1].r)); + case COLBAND_INTERP_CONSTANT: + mul_bias[1] = max_ff(coba->data[0].pos, coba->data[1].pos); + return GPU_stack_link(mat, + node, + "valtorgb_opti_constant", + in, + out, + GPU_uniform(&mul_bias[1]), + GPU_uniform(&coba->data[0].r), + GPU_uniform(&coba->data[1].r)); + case COLBAND_INTERP_EASE: + mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); + mul_bias[1] = -mul_bias[0] * coba->data[0].pos; + return GPU_stack_link(mat, + node, + "valtorgb_opti_ease", + in, + out, + GPU_uniform(mul_bias), + GPU_uniform(&coba->data[0].r), + GPU_uniform(&coba->data[1].r)); + default: + break; + } + } + + BKE_colorband_evaluate_table_rgba(coba, &array, &size); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + if (coba->ipotype == COLBAND_INTERP_CONSTANT) { + return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_constant(&layer)); + } + + return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_constant(&layer)); +} + +class ColorBandFunction : public blender::fn::MultiFunction { + private: + const ColorBand &color_band_; + + public: + ColorBandFunction(const ColorBand &color_band) : color_band_(color_band) + { + static blender::fn::MFSignature signature = create_signature(); + this->set_signature(&signature); + } + + static blender::fn::MFSignature create_signature() + { + blender::fn::MFSignatureBuilder signature{"Color Band"}; + signature.single_input("Value"); + signature.single_output("Color"); + signature.single_output("Alpha"); + return signature.build(); + } + + void call(blender::IndexMask mask, + blender::fn::MFParams params, + blender::fn::MFContext UNUSED(context)) const override + { + const blender::VArray &values = params.readonly_single_input(0, "Value"); + blender::MutableSpan colors = + params.uninitialized_single_output(1, "Color"); + blender::MutableSpan alphas = params.uninitialized_single_output(2, "Alpha"); + + for (int64_t i : mask) { + blender::ColorGeometry4f color; + BKE_colorband_evaluate(&color_band_, values[i], color); + colors[i] = color; + alphas[i] = color.a; + } + } +}; + +static void sh_node_valtorgb_build_multi_function( + blender::nodes::NodeMultiFunctionBuilder &builder) +{ + bNode &bnode = builder.node(); + const ColorBand *color_band = (const ColorBand *)bnode.storage; + builder.construct_and_set_matching_fn(*color_band); +} + +void register_node_type_sh_valtorgb(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_valtorgb_declare; + node_type_init(&ntype, node_shader_init_valtorgb); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_valtorgb); + node_type_gpu(&ntype, gpu_shader_valtorgb); + ntype.build_multi_function = sh_node_valtorgb_build_multi_function; + + nodeRegisterType(&ntype); +} + +namespace blender::nodes { + +static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b) +{ + b.add_input(N_("Color")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); + b.add_output(N_("Val")); +}; + +} // namespace blender::nodes + +static void node_shader_exec_rgbtobw(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + /* Stack order out: BW. */ + /* Stack order in: COL. */ + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); + + out[0]->vec[0] = IMB_colormanagement_get_luminance(col); +} + +static int gpu_shader_rgbtobw(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "rgbtobw", in, out); +} + +void register_node_type_sh_rgbtobw(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_rgbtobw_declare; + node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_rgbtobw); + node_type_gpu(&ntype, gpu_shader_rgbtobw); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c deleted file mode 100644 index dfecb830b35..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2013 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "node_shader_util.h" - -/* **************** SEPARATE HSV ******************** */ -static bNodeSocketTemplate sh_node_sephsv_in[] = { - {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_sephsv_out[] = { - {SOCK_FLOAT, N_("H")}, - {SOCK_FLOAT, N_("S")}, - {SOCK_FLOAT, N_("V")}, - {-1, ""}, -}; - -static void node_shader_exec_sephsv(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - - rgb_to_hsv(col[0], col[1], col[2], &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); -} - -static int gpu_shader_sephsv(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "separate_hsv", in, out); -} - -void register_node_type_sh_sephsv(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv); - node_type_gpu(&ntype, gpu_shader_sephsv); - - nodeRegisterType(&ntype); -} - -/* **************** COMBINE HSV ******************** */ -static bNodeSocketTemplate sh_node_combhsv_in[] = { - {SOCK_FLOAT, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {SOCK_FLOAT, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {SOCK_FLOAT, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - {-1, ""}, -}; -static bNodeSocketTemplate sh_node_combhsv_out[] = { - {SOCK_RGBA, N_("Color")}, - {-1, ""}, -}; - -static void node_shader_exec_combhsv(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - float h, s, v; - nodestack_get_vec(&h, SOCK_FLOAT, in[0]); - nodestack_get_vec(&s, SOCK_FLOAT, in[1]); - nodestack_get_vec(&v, SOCK_FLOAT, in[2]); - - hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); -} - -static int gpu_shader_combhsv(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "combine_hsv", in, out); -} - -void register_node_type_sh_combhsv(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv); - node_type_gpu(&ntype, gpu_shader_combhsv); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc deleted file mode 100644 index 08a9e01786e..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "node_shader_util.h" - -namespace blender::nodes { - -static void sh_node_seprgb_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 1.0f}); - b.add_output(N_("R")); - b.add_output(N_("G")); - b.add_output(N_("B")); -}; - -} // namespace blender::nodes - -static void node_shader_exec_seprgb(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - - out[0]->vec[0] = col[0]; - out[1]->vec[0] = col[1]; - out[2]->vec[0] = col[2]; -} - -static int gpu_shader_seprgb(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "separate_rgb", in, out); -} - -class SeparateRGBFunction : public blender::fn::MultiFunction { - public: - SeparateRGBFunction() - { - static blender::fn::MFSignature signature = create_signature(); - this->set_signature(&signature); - } - - static blender::fn::MFSignature create_signature() - { - blender::fn::MFSignatureBuilder signature{"Separate RGB"}; - signature.single_input("Color"); - signature.single_output("R"); - signature.single_output("G"); - signature.single_output("B"); - return signature.build(); - } - - void call(blender::IndexMask mask, - blender::fn::MFParams params, - blender::fn::MFContext UNUSED(context)) const override - { - const blender::VArray &colors = - params.readonly_single_input(0, "Color"); - blender::MutableSpan rs = params.uninitialized_single_output(1, "R"); - blender::MutableSpan gs = params.uninitialized_single_output(2, "G"); - blender::MutableSpan bs = params.uninitialized_single_output(3, "B"); - - for (int64_t i : mask) { - blender::ColorGeometry4f color = colors[i]; - rs[i] = color.r; - gs[i] = color.g; - bs[i] = color.b; - } - } -}; - -static void sh_node_seprgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) -{ - static SeparateRGBFunction fn; - builder.set_matching_fn(fn); -} - -void register_node_type_sh_seprgb(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_seprgb_declare; - node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_seprgb); - node_type_gpu(&ntype, gpu_shader_seprgb); - ntype.build_multi_function = sh_node_seprgb_build_multi_function; - - nodeRegisterType(&ntype); -} - -namespace blender::nodes { - -static void sh_node_combrgb_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("R")).min(0.0f).max(1.0f); - b.add_input(N_("G")).min(0.0f).max(1.0f); - b.add_input(N_("B")).min(0.0f).max(1.0f); - b.add_output(N_("Image")); -}; - -} // namespace blender::nodes - -static void node_shader_exec_combrgb(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - float r, g, b; - nodestack_get_vec(&r, SOCK_FLOAT, in[0]); - nodestack_get_vec(&g, SOCK_FLOAT, in[1]); - nodestack_get_vec(&b, SOCK_FLOAT, in[2]); - - out[0]->vec[0] = r; - out[0]->vec[1] = g; - out[0]->vec[2] = b; -} - -static int gpu_shader_combrgb(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "combine_rgb", in, out); -} - -static void sh_node_combrgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) -{ - static blender::fn::CustomMF_SI_SI_SI_SO fn{ - "Combine RGB", - [](float r, float g, float b) { return blender::ColorGeometry4f(r, g, b, 1.0f); }}; - builder.set_matching_fn(fn); -} - -void register_node_type_sh_combrgb(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_combrgb_declare; - node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_combrgb); - node_type_gpu(&ntype, gpu_shader_combrgb); - ntype.build_multi_function = sh_node_combrgb_build_multi_function; - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc deleted file mode 100644 index 1bbfa629462..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2014 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "node_shader_util.h" - -namespace blender::nodes { - -static void sh_node_sepxyz_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("Vector")).min(-10000.0f).max(10000.0f); - b.add_output(N_("X")); - b.add_output(N_("Y")); - b.add_output(N_("Z")); -}; - -} // namespace blender::nodes - -static int gpu_shader_sepxyz(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "separate_xyz", in, out); -} - -class MF_SeparateXYZ : public blender::fn::MultiFunction { - public: - MF_SeparateXYZ() - { - static blender::fn::MFSignature signature = create_signature(); - this->set_signature(&signature); - } - - static blender::fn::MFSignature create_signature() - { - blender::fn::MFSignatureBuilder signature{"Separate XYZ"}; - signature.single_input("XYZ"); - signature.single_output("X"); - signature.single_output("Y"); - signature.single_output("Z"); - return signature.build(); - } - - void call(blender::IndexMask mask, - blender::fn::MFParams params, - blender::fn::MFContext UNUSED(context)) const override - { - const blender::VArray &vectors = - params.readonly_single_input(0, "XYZ"); - blender::MutableSpan xs = params.uninitialized_single_output(1, "X"); - blender::MutableSpan ys = params.uninitialized_single_output(2, "Y"); - blender::MutableSpan zs = params.uninitialized_single_output(3, "Z"); - - for (int64_t i : mask) { - blender::float3 xyz = vectors[i]; - xs[i] = xyz.x; - ys[i] = xyz.y; - zs[i] = xyz.z; - } - } -}; - -static void sh_node_sepxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) -{ - static MF_SeparateXYZ separate_fn; - builder.set_matching_fn(separate_fn); -} - -void register_node_type_sh_sepxyz(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_sepxyz_declare; - node_type_gpu(&ntype, gpu_shader_sepxyz); - ntype.build_multi_function = sh_node_sepxyz_build_multi_function; - - nodeRegisterType(&ntype); -} - -namespace blender::nodes { - -static void sh_node_combxyz_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("X")).min(-10000.0f).max(10000.0f); - b.add_input(N_("Y")).min(-10000.0f).max(10000.0f); - b.add_input(N_("Z")).min(-10000.0f).max(10000.0f); - b.add_output(N_("Vector")); -}; - -} // namespace blender::nodes - -static int gpu_shader_combxyz(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "combine_xyz", in, out); -} - -static void sh_node_combxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) -{ - static blender::fn::CustomMF_SI_SI_SI_SO fn{ - "Combine Vector", [](float x, float y, float z) { return blender::float3(x, y, z); }}; - builder.set_matching_fn(fn); -} - -void register_node_type_sh_combxyz(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_combxyz_declare; - node_type_gpu(&ntype, gpu_shader_combxyz); - ntype.build_multi_function = sh_node_combxyz_build_multi_function; - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.c b/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.c new file mode 100644 index 00000000000..dfecb830b35 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.c @@ -0,0 +1,118 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.h" + +/* **************** SEPARATE HSV ******************** */ +static bNodeSocketTemplate sh_node_sephsv_in[] = { + {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + {-1, ""}, +}; +static bNodeSocketTemplate sh_node_sephsv_out[] = { + {SOCK_FLOAT, N_("H")}, + {SOCK_FLOAT, N_("S")}, + {SOCK_FLOAT, N_("V")}, + {-1, ""}, +}; + +static void node_shader_exec_sephsv(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); + + rgb_to_hsv(col[0], col[1], col[2], &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); +} + +static int gpu_shader_sephsv(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "separate_hsv", in, out); +} + +void register_node_type_sh_sephsv(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv); + node_type_gpu(&ntype, gpu_shader_sephsv); + + nodeRegisterType(&ntype); +} + +/* **************** COMBINE HSV ******************** */ +static bNodeSocketTemplate sh_node_combhsv_in[] = { + {SOCK_FLOAT, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {-1, ""}, +}; +static bNodeSocketTemplate sh_node_combhsv_out[] = { + {SOCK_RGBA, N_("Color")}, + {-1, ""}, +}; + +static void node_shader_exec_combhsv(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + float h, s, v; + nodestack_get_vec(&h, SOCK_FLOAT, in[0]); + nodestack_get_vec(&s, SOCK_FLOAT, in[1]); + nodestack_get_vec(&v, SOCK_FLOAT, in[2]); + + hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); +} + +static int gpu_shader_combhsv(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "combine_hsv", in, out); +} + +void register_node_type_sh_combhsv(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv); + node_type_gpu(&ntype, gpu_shader_combhsv); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc new file mode 100644 index 00000000000..08a9e01786e --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc @@ -0,0 +1,177 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2006 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.h" + +namespace blender::nodes { + +static void sh_node_seprgb_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 1.0f}); + b.add_output(N_("R")); + b.add_output(N_("G")); + b.add_output(N_("B")); +}; + +} // namespace blender::nodes + +static void node_shader_exec_seprgb(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); + + out[0]->vec[0] = col[0]; + out[1]->vec[0] = col[1]; + out[2]->vec[0] = col[2]; +} + +static int gpu_shader_seprgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "separate_rgb", in, out); +} + +class SeparateRGBFunction : public blender::fn::MultiFunction { + public: + SeparateRGBFunction() + { + static blender::fn::MFSignature signature = create_signature(); + this->set_signature(&signature); + } + + static blender::fn::MFSignature create_signature() + { + blender::fn::MFSignatureBuilder signature{"Separate RGB"}; + signature.single_input("Color"); + signature.single_output("R"); + signature.single_output("G"); + signature.single_output("B"); + return signature.build(); + } + + void call(blender::IndexMask mask, + blender::fn::MFParams params, + blender::fn::MFContext UNUSED(context)) const override + { + const blender::VArray &colors = + params.readonly_single_input(0, "Color"); + blender::MutableSpan rs = params.uninitialized_single_output(1, "R"); + blender::MutableSpan gs = params.uninitialized_single_output(2, "G"); + blender::MutableSpan bs = params.uninitialized_single_output(3, "B"); + + for (int64_t i : mask) { + blender::ColorGeometry4f color = colors[i]; + rs[i] = color.r; + gs[i] = color.g; + bs[i] = color.b; + } + } +}; + +static void sh_node_seprgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) +{ + static SeparateRGBFunction fn; + builder.set_matching_fn(fn); +} + +void register_node_type_sh_seprgb(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_seprgb_declare; + node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_seprgb); + node_type_gpu(&ntype, gpu_shader_seprgb); + ntype.build_multi_function = sh_node_seprgb_build_multi_function; + + nodeRegisterType(&ntype); +} + +namespace blender::nodes { + +static void sh_node_combrgb_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("R")).min(0.0f).max(1.0f); + b.add_input(N_("G")).min(0.0f).max(1.0f); + b.add_input(N_("B")).min(0.0f).max(1.0f); + b.add_output(N_("Image")); +}; + +} // namespace blender::nodes + +static void node_shader_exec_combrgb(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) +{ + float r, g, b; + nodestack_get_vec(&r, SOCK_FLOAT, in[0]); + nodestack_get_vec(&g, SOCK_FLOAT, in[1]); + nodestack_get_vec(&b, SOCK_FLOAT, in[2]); + + out[0]->vec[0] = r; + out[0]->vec[1] = g; + out[0]->vec[2] = b; +} + +static int gpu_shader_combrgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "combine_rgb", in, out); +} + +static void sh_node_combrgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) +{ + static blender::fn::CustomMF_SI_SI_SI_SO fn{ + "Combine RGB", + [](float r, float g, float b) { return blender::ColorGeometry4f(r, g, b, 1.0f); }}; + builder.set_matching_fn(fn); +} + +void register_node_type_sh_combrgb(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_combrgb_declare; + node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_combrgb); + node_type_gpu(&ntype, gpu_shader_combrgb); + ntype.build_multi_function = sh_node_combrgb_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc new file mode 100644 index 00000000000..1bbfa629462 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc @@ -0,0 +1,142 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2014 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.h" + +namespace blender::nodes { + +static void sh_node_sepxyz_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("Vector")).min(-10000.0f).max(10000.0f); + b.add_output(N_("X")); + b.add_output(N_("Y")); + b.add_output(N_("Z")); +}; + +} // namespace blender::nodes + +static int gpu_shader_sepxyz(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "separate_xyz", in, out); +} + +class MF_SeparateXYZ : public blender::fn::MultiFunction { + public: + MF_SeparateXYZ() + { + static blender::fn::MFSignature signature = create_signature(); + this->set_signature(&signature); + } + + static blender::fn::MFSignature create_signature() + { + blender::fn::MFSignatureBuilder signature{"Separate XYZ"}; + signature.single_input("XYZ"); + signature.single_output("X"); + signature.single_output("Y"); + signature.single_output("Z"); + return signature.build(); + } + + void call(blender::IndexMask mask, + blender::fn::MFParams params, + blender::fn::MFContext UNUSED(context)) const override + { + const blender::VArray &vectors = + params.readonly_single_input(0, "XYZ"); + blender::MutableSpan xs = params.uninitialized_single_output(1, "X"); + blender::MutableSpan ys = params.uninitialized_single_output(2, "Y"); + blender::MutableSpan zs = params.uninitialized_single_output(3, "Z"); + + for (int64_t i : mask) { + blender::float3 xyz = vectors[i]; + xs[i] = xyz.x; + ys[i] = xyz.y; + zs[i] = xyz.z; + } + } +}; + +static void sh_node_sepxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) +{ + static MF_SeparateXYZ separate_fn; + builder.set_matching_fn(separate_fn); +} + +void register_node_type_sh_sepxyz(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_sepxyz_declare; + node_type_gpu(&ntype, gpu_shader_sepxyz); + ntype.build_multi_function = sh_node_sepxyz_build_multi_function; + + nodeRegisterType(&ntype); +} + +namespace blender::nodes { + +static void sh_node_combxyz_declare(NodeDeclarationBuilder &b) +{ + b.is_function_node(); + b.add_input(N_("X")).min(-10000.0f).max(10000.0f); + b.add_input(N_("Y")).min(-10000.0f).max(10000.0f); + b.add_input(N_("Z")).min(-10000.0f).max(10000.0f); + b.add_output(N_("Vector")); +}; + +} // namespace blender::nodes + +static int gpu_shader_combxyz(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "combine_xyz", in, out); +} + +static void sh_node_combxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) +{ + static blender::fn::CustomMF_SI_SI_SI_SO fn{ + "Combine Vector", [](float x, float y, float z) { return blender::float3(x, y, z); }}; + builder.set_matching_fn(fn); +} + +void register_node_type_sh_combxyz(void) +{ + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::sh_node_combxyz_declare; + node_type_gpu(&ntype, gpu_shader_combxyz); + ntype.build_multi_function = sh_node_combxyz_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c deleted file mode 100644 index 25c30aa4081..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_shadertorgb_in[] = { - {SOCK_SHADER, N_("Shader")}, - {-1, ""}, -}; - -static bNodeSocketTemplate sh_node_shadertorgb_out[] = { - {SOCK_RGBA, N_("Color")}, - {SOCK_FLOAT, N_("Alpha")}, - {-1, ""}, -}; - -static int node_shader_gpu_shadertorgb(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - /* Because node_shader_to_rgba is using fallback_cubemap() - * we need to tag material as glossy. */ - GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); - - return GPU_stack_link(mat, node, "node_shader_to_rgba", in, out); -} - -/* node type definition */ -void register_node_type_sh_shadertorgb(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_shadertorgb); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.c b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.c new file mode 100644 index 00000000000..25c30aa4081 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.c @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_shadertorgb_in[] = { + {SOCK_SHADER, N_("Shader")}, + {-1, ""}, +}; + +static bNodeSocketTemplate sh_node_shadertorgb_out[] = { + {SOCK_RGBA, N_("Color")}, + {SOCK_FLOAT, N_("Alpha")}, + {-1, ""}, +}; + +static int node_shader_gpu_shadertorgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + /* Because node_shader_to_rgba is using fallback_cubemap() + * we need to tag material as glossy. */ + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); + + return GPU_stack_link(mat, node, "node_shader_to_rgba", in, out); +} + +/* node type definition */ +void register_node_type_sh_shadertorgb(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_shadertorgb); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c deleted file mode 100644 index 05c3248af65..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { - {SOCK_VECTOR, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - {-1, ""}, -}; - -/* node type definition */ -void register_node_type_sh_uvalongstroke(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_uvalongstroke_out); - node_type_init(&ntype, NULL); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.c b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.c new file mode 100644 index 00000000000..05c3248af65 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.c @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { + {SOCK_VECTOR, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, ""}, +}; + +/* node type definition */ +void register_node_type_sh_uvalongstroke(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_uvalongstroke_out); + node_type_init(&ntype, NULL); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc deleted file mode 100644 index e4f1b2c76f0..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc +++ /dev/null @@ -1,235 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "IMB_colormanagement.h" - -#include "DNA_texture_types.h" - -#include "BLI_color.hh" - -#include "node_shader_util.h" - -namespace blender::nodes { - -static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b) -{ - b.is_function_node(); - b.add_input(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); - b.add_output(N_("Color")); - b.add_output(N_("Alpha")); -}; - -} // namespace blender::nodes - -static void node_shader_exec_valtorgb(void *UNUSED(data), - int UNUSED(thread), - bNode *node, - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - /* stack order in: fac */ - /* stack order out: col, alpha */ - - if (node->storage) { - float fac; - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - - BKE_colorband_evaluate((ColorBand *)node->storage, fac, out[0]->vec); - out[1]->vec[0] = out[0]->vec[3]; - } -} - -static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node) -{ - node->storage = BKE_colorband_add(true); -} - -static int gpu_shader_valtorgb(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - struct ColorBand *coba = (ColorBand *)node->storage; - float *array, layer; - int size; - - /* Common / easy case optimization. */ - if ((coba->tot <= 2) && (coba->color_mode == COLBAND_BLEND_RGB)) { - float mul_bias[2]; - switch (coba->ipotype) { - case COLBAND_INTERP_LINEAR: - mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); - mul_bias[1] = -mul_bias[0] * coba->data[0].pos; - return GPU_stack_link(mat, - node, - "valtorgb_opti_linear", - in, - out, - GPU_uniform(mul_bias), - GPU_uniform(&coba->data[0].r), - GPU_uniform(&coba->data[1].r)); - case COLBAND_INTERP_CONSTANT: - mul_bias[1] = max_ff(coba->data[0].pos, coba->data[1].pos); - return GPU_stack_link(mat, - node, - "valtorgb_opti_constant", - in, - out, - GPU_uniform(&mul_bias[1]), - GPU_uniform(&coba->data[0].r), - GPU_uniform(&coba->data[1].r)); - case COLBAND_INTERP_EASE: - mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); - mul_bias[1] = -mul_bias[0] * coba->data[0].pos; - return GPU_stack_link(mat, - node, - "valtorgb_opti_ease", - in, - out, - GPU_uniform(mul_bias), - GPU_uniform(&coba->data[0].r), - GPU_uniform(&coba->data[1].r)); - default: - break; - } - } - - BKE_colorband_evaluate_table_rgba(coba, &array, &size); - GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); - - if (coba->ipotype == COLBAND_INTERP_CONSTANT) { - return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_constant(&layer)); - } - - return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_constant(&layer)); -} - -class ColorBandFunction : public blender::fn::MultiFunction { - private: - const ColorBand &color_band_; - - public: - ColorBandFunction(const ColorBand &color_band) : color_band_(color_band) - { - static blender::fn::MFSignature signature = create_signature(); - this->set_signature(&signature); - } - - static blender::fn::MFSignature create_signature() - { - blender::fn::MFSignatureBuilder signature{"Color Band"}; - signature.single_input("Value"); - signature.single_output("Color"); - signature.single_output("Alpha"); - return signature.build(); - } - - void call(blender::IndexMask mask, - blender::fn::MFParams params, - blender::fn::MFContext UNUSED(context)) const override - { - const blender::VArray &values = params.readonly_single_input(0, "Value"); - blender::MutableSpan colors = - params.uninitialized_single_output(1, "Color"); - blender::MutableSpan alphas = params.uninitialized_single_output(2, "Alpha"); - - for (int64_t i : mask) { - blender::ColorGeometry4f color; - BKE_colorband_evaluate(&color_band_, values[i], color); - colors[i] = color; - alphas[i] = color.a; - } - } -}; - -static void sh_node_valtorgb_build_multi_function( - blender::nodes::NodeMultiFunctionBuilder &builder) -{ - bNode &bnode = builder.node(); - const ColorBand *color_band = (const ColorBand *)bnode.storage; - builder.construct_and_set_matching_fn(*color_band); -} - -void register_node_type_sh_valtorgb(void) -{ - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_valtorgb_declare; - node_type_init(&ntype, node_shader_init_valtorgb); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_valtorgb); - node_type_gpu(&ntype, gpu_shader_valtorgb); - ntype.build_multi_function = sh_node_valtorgb_build_multi_function; - - nodeRegisterType(&ntype); -} - -namespace blender::nodes { - -static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b) -{ - b.add_input(N_("Color")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); - b.add_output(N_("Val")); -}; - -} // namespace blender::nodes - -static void node_shader_exec_rgbtobw(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - /* Stack order out: BW. */ - /* Stack order in: COL. */ - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - - out[0]->vec[0] = IMB_colormanagement_get_luminance(col); -} - -static int gpu_shader_rgbtobw(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - return GPU_stack_link(mat, node, "rgbtobw", in, out); -} - -void register_node_type_sh_rgbtobw(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::sh_node_rgbtobw_declare; - node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_rgbtobw); - node_type_gpu(&ntype, gpu_shader_rgbtobw); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c deleted file mode 100644 index 7b08178f874..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2013 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup shdnodes - */ - -#include "../node_shader_util.h" - -/* **************** Vector Transform ******************** */ -static bNodeSocketTemplate sh_node_vect_transform_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {-1, ""}}; - -static bNodeSocketTemplate sh_node_vect_transform_out[] = { - {SOCK_VECTOR, N_("Vector")}, - {-1, ""}, -}; - -static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), - "NodeShaderVectTransform"); - - /* Convert World into Object Space per default */ - vect->convert_to = 1; - - node->storage = vect; -} - -static void node_shader_exec_vect_transform(void *UNUSED(data), - int UNUSED(thread), - bNode *UNUSED(node), - bNodeExecData *UNUSED(execdata), - bNodeStack **UNUSED(in), - bNodeStack **UNUSED(out)) -{ -} - -static GPUNodeLink *get_gpulink_matrix_from_to(short from, short to) -{ - switch (from) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return GPU_builtin(GPU_OBJECT_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return GPU_builtin(GPU_LOC_TO_VIEW_MATRIX); - } - break; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return GPU_builtin(GPU_VIEW_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); - } - break; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return GPU_builtin(GPU_INVERSE_VIEW_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return GPU_builtin(GPU_INVERSE_LOC_TO_VIEW_MATRIX); - } - break; - } - return NULL; -} -static int gpu_shader_vect_transform(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - struct GPUNodeLink *inputlink; - struct GPUNodeLink *fromto; - - const char *vtransform = "direction_transform_m4v3"; - const char *ptransform = "point_transform_m4v3"; - const char *func_name = 0; - - NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; - - if (in[0].hasinput) { - inputlink = in[0].link; - } - else { - inputlink = GPU_constant(in[0].vec); - } - - fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); - - func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform; - if (fromto) { - /* For cycles we have inverted Z */ - /* TODO: pass here the correct matrices */ - if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && - nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", inputlink, &inputlink); - } - GPU_link(mat, func_name, inputlink, fromto, &out[0].link); - if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && - nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", out[0].link, &out[0].link); - } - } - else { - GPU_link(mat, "set_rgb", inputlink, &out[0].link); - } - - if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) { - GPU_link(mat, "vector_normalize", out[0].link, &out[0].link); - } - - return true; -} - -void register_node_type_sh_vect_transform(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); - node_type_init(&ntype, node_shader_init_vect_transform); - node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out); - node_type_storage( - &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_transform); - node_type_gpu(&ntype, gpu_shader_vect_transform); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_transform.c b/source/blender/nodes/shader/nodes/node_shader_vector_transform.c new file mode 100644 index 00000000000..7b08178f874 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_vector_transform.c @@ -0,0 +1,153 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "../node_shader_util.h" + +/* **************** Vector Transform ******************** */ +static bNodeSocketTemplate sh_node_vect_transform_in[] = { + {SOCK_VECTOR, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {-1, ""}}; + +static bNodeSocketTemplate sh_node_vect_transform_out[] = { + {SOCK_VECTOR, N_("Vector")}, + {-1, ""}, +}; + +static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), + "NodeShaderVectTransform"); + + /* Convert World into Object Space per default */ + vect->convert_to = 1; + + node->storage = vect; +} + +static void node_shader_exec_vect_transform(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) +{ +} + +static GPUNodeLink *get_gpulink_matrix_from_to(short from, short to) +{ + switch (from) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return GPU_builtin(GPU_OBJECT_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return GPU_builtin(GPU_LOC_TO_VIEW_MATRIX); + } + break; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return GPU_builtin(GPU_VIEW_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); + } + break; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return GPU_builtin(GPU_INVERSE_VIEW_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return GPU_builtin(GPU_INVERSE_LOC_TO_VIEW_MATRIX); + } + break; + } + return NULL; +} +static int gpu_shader_vect_transform(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + struct GPUNodeLink *inputlink; + struct GPUNodeLink *fromto; + + const char *vtransform = "direction_transform_m4v3"; + const char *ptransform = "point_transform_m4v3"; + const char *func_name = 0; + + NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; + + if (in[0].hasinput) { + inputlink = in[0].link; + } + else { + inputlink = GPU_constant(in[0].vec); + } + + fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); + + func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform; + if (fromto) { + /* For cycles we have inverted Z */ + /* TODO: pass here the correct matrices */ + if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && + nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", inputlink, &inputlink); + } + GPU_link(mat, func_name, inputlink, fromto, &out[0].link); + if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && + nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", out[0].link, &out[0].link); + } + } + else { + GPU_link(mat, "set_rgb", inputlink, &out[0].link); + } + + if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) { + GPU_link(mat, "vector_normalize", out[0].link, &out[0].link); + } + + return true; +} + +void register_node_type_sh_vect_transform(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); + node_type_init(&ntype, node_shader_init_vect_transform); + node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out); + node_type_storage( + &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_transform); + node_type_gpu(&ntype, gpu_shader_vect_transform); + + nodeRegisterType(&ntype); +} -- cgit v1.2.3