From f60b95b5320f8d6abe6a629fe8fc4f1b94d0d91c Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Mon, 6 Dec 2021 14:47:11 -0500 Subject: Shader Nodes: Split each node into own file This improves both code finding, for example "color ramp" now has its own file. And now each node has its own namespace so function names can be simplified similar to rBfab39440e94 This commit also makes all file names use snake case instead of camel case. Reviewed By: HooglyBoogly Differential Revision: https://developer.blender.org/D13482 --- source/blender/nodes/NOD_shader.h | 2 +- source/blender/nodes/shader/CMakeLists.txt | 20 +- .../nodes/shader/nodes/node_shader_color_ramp.cc | 189 +++++++++++++++++ .../nodes/shader/nodes/node_shader_combine_hsv.cc | 77 +++++++ .../nodes/shader/nodes/node_shader_combine_rgb.cc | 86 ++++++++ .../nodes/shader/nodes/node_shader_combine_xyz.cc | 67 ++++++ .../nodes/shader/nodes/node_shader_mixRgb.cc | 200 ------------------ .../nodes/shader/nodes/node_shader_mix_rgb.cc | 200 ++++++++++++++++++ .../nodes/shader/nodes/node_shader_rgb_to_bw.cc | 74 +++++++ .../nodes/shader/nodes/node_shader_separate_hsv.cc | 75 +++++++ .../nodes/shader/nodes/node_shader_separate_rgb.cc | 119 +++++++++++ .../nodes/shader/nodes/node_shader_separate_xyz.cc | 103 +++++++++ .../nodes/shader/nodes/node_shader_sepcombHSV.cc | 128 ----------- .../nodes/shader/nodes/node_shader_sepcombRGB.cc | 177 ---------------- .../nodes/shader/nodes/node_shader_sepcombXYZ.cc | 142 ------------- .../nodes/shader/nodes/node_shader_shaderToRgb.cc | 67 ------ .../shader/nodes/node_shader_shader_to_rgb.cc | 67 ++++++ .../shader/nodes/node_shader_uvAlongStroke.cc | 45 ---- .../shader/nodes/node_shader_uv_along_stroke.cc | 45 ++++ .../nodes/shader/nodes/node_shader_valToRgb.cc | 235 --------------------- .../shader/nodes/node_shader_vectTransform.cc | 161 -------------- .../shader/nodes/node_shader_vector_transform.cc | 161 ++++++++++++++ 22 files changed, 1276 insertions(+), 1164 deletions(-) create mode 100644 source/blender/nodes/shader/nodes/node_shader_color_ramp.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_combine_hsv.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_combine_rgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_combine_xyz.cc 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 create mode 100644 source/blender/nodes/shader/nodes/node_shader_separate_hsv.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_separate_rgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_separate_xyz.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombHSV.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_shaderToRgb.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_valToRgb.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_vectTransform.cc create mode 100644 source/blender/nodes/shader/nodes/node_shader_vector_transform.cc (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 76c174201e8..74933e69ab2 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -42,7 +42,7 @@ void register_node_type_sh_camera(void); void register_node_type_sh_value(void); void register_node_type_sh_rgb(void); void register_node_type_sh_mix_rgb(void); -void register_node_type_sh_valtorgb(void); +void register_node_type_sh_color_ramp(void); void register_node_type_sh_rgbtobw(void); void register_node_type_sh_shadertorgb(void); void register_node_type_sh_normal(void); diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index b582960f03f..bdbdef6e9ec 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -59,6 +59,10 @@ set(SRC nodes/node_shader_bump.cc nodes/node_shader_camera.cc nodes/node_shader_clamp.cc + nodes/node_shader_color_ramp.cc + nodes/node_shader_combine_hsv.cc + nodes/node_shader_combine_rgb.cc + nodes/node_shader_combine_xyz.cc nodes/node_shader_common.cc nodes/node_shader_curves.cc nodes/node_shader_displacement.cc @@ -78,7 +82,7 @@ set(SRC nodes/node_shader_map_range.cc nodes/node_shader_mapping.cc nodes/node_shader_math.cc - nodes/node_shader_mixRgb.cc + nodes/node_shader_mix_rgb.cc nodes/node_shader_mix_shader.cc nodes/node_shader_normal.cc nodes/node_shader_normal_map.cc @@ -90,11 +94,12 @@ set(SRC nodes/node_shader_output_world.cc nodes/node_shader_particle_info.cc nodes/node_shader_rgb.cc + nodes/node_shader_rgb_to_bw.cc nodes/node_shader_script.cc - nodes/node_shader_sepcombHSV.cc - nodes/node_shader_sepcombRGB.cc - nodes/node_shader_sepcombXYZ.cc - nodes/node_shader_shaderToRgb.cc + nodes/node_shader_separate_hsv.cc + nodes/node_shader_separate_rgb.cc + nodes/node_shader_separate_xyz.cc + nodes/node_shader_shader_to_rgb.cc nodes/node_shader_squeeze.cc nodes/node_shader_subsurface_scattering.cc nodes/node_shader_tangent.cc @@ -112,14 +117,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.cc + nodes/node_shader_uv_along_stroke.cc nodes/node_shader_uvmap.cc - nodes/node_shader_valToRgb.cc nodes/node_shader_value.cc - nodes/node_shader_vectTransform.cc nodes/node_shader_vector_displacement.cc nodes/node_shader_vector_math.cc nodes/node_shader_vector_rotate.cc + nodes/node_shader_vector_transform.cc nodes/node_shader_vertex_color.cc nodes/node_shader_volume_absorption.cc nodes/node_shader_volume_info.cc diff --git a/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc b/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc new file mode 100644 index 00000000000..2bb3f2e08cf --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc @@ -0,0 +1,189 @@ +/* + * 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) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "DNA_texture_types.h" + +#include "BLI_color.hh" + +#include "node_shader_util.hh" + +namespace blender::nodes::node_shader_color_ramp_cc { + +static void sh_node_color_ramp_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")); +}; + +static void node_shader_exec_color_ramp(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_color_ramp(bNodeTree *UNUSED(ntree), bNode *node) +{ + node->storage = BKE_colorband_add(true); +} + +static int gpu_shader_color_ramp(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_color_ramp_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); +} + +} // namespace blender::nodes::node_shader_color_ramp_cc + +void register_node_type_sh_color_ramp() +{ + namespace file_ns = blender::nodes::node_shader_color_ramp_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_color_ramp_declare; + node_type_init(&ntype, file_ns::node_shader_init_color_ramp); + 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, file_ns::node_shader_exec_color_ramp); + node_type_gpu(&ntype, file_ns::gpu_shader_color_ramp); + ntype.build_multi_function = file_ns::sh_node_color_ramp_build_multi_function; + + nodeRegisterType(&ntype); +} \ No newline at end of file diff --git a/source/blender/nodes/shader/nodes/node_shader_combine_hsv.cc b/source/blender/nodes/shader/nodes/node_shader_combine_hsv.cc new file mode 100644 index 00000000000..4d4879fd060 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_combine_hsv.cc @@ -0,0 +1,77 @@ +/* + * 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.hh" + +namespace blender::nodes::node_shader_combine_hsv_cc { + +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); +} + +} // namespace blender::nodes::node_shader_combine_hsv_cc + +void register_node_type_sh_combhsv() +{ + namespace file_ns = blender::nodes::node_shader_combine_hsv_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates(&ntype, file_ns::sh_node_combhsv_in, file_ns::sh_node_combhsv_out); + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_combhsv); + node_type_gpu(&ntype, file_ns::gpu_shader_combhsv); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_combine_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_combine_rgb.cc new file mode 100644 index 00000000000..f5d401a5044 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_combine_rgb.cc @@ -0,0 +1,86 @@ +/* + * 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.hh" + +namespace blender::nodes::node_shader_combine_rgb_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_combine_rgb_cc + +void register_node_type_sh_combrgb() +{ + namespace file_ns = blender::nodes::node_shader_combine_rgb_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_combrgb_declare; + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_combrgb); + node_type_gpu(&ntype, file_ns::gpu_shader_combrgb); + ntype.build_multi_function = file_ns::sh_node_combrgb_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_combine_xyz.cc b/source/blender/nodes/shader/nodes/node_shader_combine_xyz.cc new file mode 100644 index 00000000000..ff5b333a459 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_combine_xyz.cc @@ -0,0 +1,67 @@ +/* + * 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.hh" + +namespace blender::nodes::node_shader_combine_xyz_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_combine_xyz_cc + +void register_node_type_sh_combxyz() +{ + namespace file_ns = blender::nodes::node_shader_combine_xyz_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_combxyz_declare; + node_type_gpu(&ntype, file_ns::gpu_shader_combxyz); + ntype.build_multi_function = file_ns::sh_node_combxyz_build_multi_function; + + nodeRegisterType(&ntype); +} 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 c41bd438084..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc +++ /dev/null @@ -1,200 +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.hh" - -namespace blender::nodes::node_shader_mixRgb_cc { - -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")); -}; - -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); -} - -} // namespace blender::nodes::node_shader_mixRgb_cc - -void register_node_type_sh_mix_rgb() -{ - namespace file_ns = blender::nodes::node_shader_mixRgb_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - ntype.declare = file_ns::sh_node_mix_rgb_declare; - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_mix_rgb); - node_type_gpu(&ntype, file_ns::gpu_shader_mix_rgb); - ntype.build_multi_function = file_ns::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..288161d1463 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc @@ -0,0 +1,200 @@ +/* + * 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.hh" + +namespace blender::nodes::node_shader_mix_rgb_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_mix_rgb_cc + +void register_node_type_sh_mix_rgb() +{ + namespace file_ns = blender::nodes::node_shader_mix_rgb_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); + ntype.declare = file_ns::sh_node_mix_rgb_declare; + node_type_label(&ntype, node_blend_label); + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_mix_rgb); + node_type_gpu(&ntype, file_ns::gpu_shader_mix_rgb); + ntype.build_multi_function = file_ns::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..7d6fec4b7c5 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc @@ -0,0 +1,74 @@ +/* + * 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 "node_shader_util.hh" + +namespace blender::nodes::node_shader_rgb_to_bw_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_rgb_to_bw_cc + +void register_node_type_sh_rgbtobw() +{ + namespace file_ns = blender::nodes::node_shader_rgb_to_bw_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_rgbtobw_declare; + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_rgbtobw); + node_type_gpu(&ntype, file_ns::gpu_shader_rgbtobw); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_separate_hsv.cc b/source/blender/nodes/shader/nodes/node_shader_separate_hsv.cc new file mode 100644 index 00000000000..242bc5f9781 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_separate_hsv.cc @@ -0,0 +1,75 @@ +/* + * 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) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.hh" + +namespace blender::nodes::node_shader_separate_hsv_cc { + +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); +} + +} // namespace blender::nodes::node_shader_separate_hsv_cc + +void register_node_type_sh_sephsv() +{ + namespace file_ns = blender::nodes::node_shader_separate_hsv_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates(&ntype, file_ns::sh_node_sephsv_in, file_ns::sh_node_sephsv_out); + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_sephsv); + node_type_gpu(&ntype, file_ns::gpu_shader_sephsv); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_separate_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_separate_rgb.cc new file mode 100644 index 00000000000..2f57fe31f47 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_separate_rgb.cc @@ -0,0 +1,119 @@ +/* + * 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) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.hh" + +namespace blender::nodes::node_shader_separate_rgb_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_separate_rgb_cc + +void register_node_type_sh_seprgb() +{ + namespace file_ns = blender::nodes::node_shader_separate_rgb_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_seprgb_declare; + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_seprgb); + node_type_gpu(&ntype, file_ns::gpu_shader_seprgb); + ntype.build_multi_function = file_ns::sh_node_seprgb_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_separate_xyz.cc b/source/blender/nodes/shader/nodes/node_shader_separate_xyz.cc new file mode 100644 index 00000000000..ee2335978a3 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_separate_xyz.cc @@ -0,0 +1,103 @@ +/* + * 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) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "node_shader_util.hh" + +namespace blender::nodes::node_shader_separate_xyz_cc { + +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")); +}; + +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); +} + +} // namespace blender::nodes::node_shader_separate_xyz_cc + +void register_node_type_sh_sepxyz() +{ + namespace file_ns = blender::nodes::node_shader_separate_xyz_cc; + + static bNodeType ntype; + + sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0); + ntype.declare = file_ns::sh_node_sepxyz_declare; + node_type_gpu(&ntype, file_ns::gpu_shader_sepxyz); + ntype.build_multi_function = file_ns::sh_node_sepxyz_build_multi_function; + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.cc deleted file mode 100644 index b47c98fadec..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.cc +++ /dev/null @@ -1,128 +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.hh" - -/* **************** SEPARATE HSV ******************** */ - -namespace blender::nodes::node_shader_sepcombHSV_cc { - -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); -} - -/* **************** 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); -} - -} // namespace blender::nodes::node_shader_sepcombHSV_cc - -void register_node_type_sh_sephsv() -{ - namespace file_ns = blender::nodes::node_shader_sepcombHSV_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, file_ns::sh_node_sephsv_in, file_ns::sh_node_sephsv_out); - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_sephsv); - node_type_gpu(&ntype, file_ns::gpu_shader_sephsv); - - nodeRegisterType(&ntype); -} - -void register_node_type_sh_combhsv() -{ - namespace file_ns = blender::nodes::node_shader_sepcombHSV_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates(&ntype, file_ns::sh_node_combhsv_in, file_ns::sh_node_combhsv_out); - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_combhsv); - node_type_gpu(&ntype, file_ns::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 0b8c8ad443d..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.hh" - -namespace blender::nodes::node_shader_sepcombRGB_cc { - -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")); -}; - -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); -} - -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")); -}; - -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); -} - -} // namespace blender::nodes::node_shader_sepcombRGB_cc - -void register_node_type_sh_seprgb() -{ - namespace file_ns = blender::nodes::node_shader_sepcombRGB_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_seprgb_declare; - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_seprgb); - node_type_gpu(&ntype, file_ns::gpu_shader_seprgb); - ntype.build_multi_function = file_ns::sh_node_seprgb_build_multi_function; - - nodeRegisterType(&ntype); -} - -void register_node_type_sh_combrgb() -{ - namespace file_ns = blender::nodes::node_shader_sepcombRGB_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_combrgb_declare; - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_combrgb); - node_type_gpu(&ntype, file_ns::gpu_shader_combrgb); - ntype.build_multi_function = file_ns::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 c5e83789a8e..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.hh" - -namespace blender::nodes::node_shader_sepcombXYZ_cc { - -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")); -}; - -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); -} - -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")); -}; - -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); -} - -} // namespace blender::nodes::node_shader_sepcombXYZ_cc - -void register_node_type_sh_sepxyz() -{ - namespace file_ns = blender::nodes::node_shader_sepcombXYZ_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_sepxyz_declare; - node_type_gpu(&ntype, file_ns::gpu_shader_sepxyz); - ntype.build_multi_function = file_ns::sh_node_sepxyz_build_multi_function; - - nodeRegisterType(&ntype); -} - -void register_node_type_sh_combxyz() -{ - namespace file_ns = blender::nodes::node_shader_sepcombXYZ_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_combxyz_declare; - node_type_gpu(&ntype, file_ns::gpu_shader_combxyz); - ntype.build_multi_function = file_ns::sh_node_combxyz_build_multi_function; - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.cc b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.cc deleted file mode 100644 index 69b1099a76a..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.cc +++ /dev/null @@ -1,67 +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.hh" - -/* **************** OUTPUT ******************** */ - -namespace blender::nodes::node_shader_shaderToRgb_cc { - -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); -} - -} // namespace blender::nodes::node_shader_shaderToRgb_cc - -/* node type definition */ -void register_node_type_sh_shadertorgb() -{ - namespace file_ns = blender::nodes::node_shader_shaderToRgb_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTER, 0); - node_type_socket_templates( - &ntype, file_ns::sh_node_shadertorgb_in, file_ns::sh_node_shadertorgb_out); - node_type_init(&ntype, nullptr); - node_type_storage(&ntype, "", nullptr, nullptr); - node_type_gpu(&ntype, file_ns::node_shader_gpu_shadertorgb); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc new file mode 100644 index 00000000000..3791eb9449f --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc @@ -0,0 +1,67 @@ +/* + * 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.hh" + +/* **************** OUTPUT ******************** */ + +namespace blender::nodes::node_shader_shader_to_rgb_cc { + +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); +} + +} // namespace blender::nodes::node_shader_shader_to_rgb_cc + +/* node type definition */ +void register_node_type_sh_shadertorgb() +{ + namespace file_ns = blender::nodes::node_shader_shader_to_rgb_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTER, 0); + node_type_socket_templates( + &ntype, file_ns::sh_node_shadertorgb_in, file_ns::sh_node_shadertorgb_out); + node_type_init(&ntype, nullptr); + node_type_storage(&ntype, "", nullptr, nullptr); + node_type_gpu(&ntype, file_ns::node_shader_gpu_shadertorgb); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.cc b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.cc deleted file mode 100644 index cdcb5f34bb9..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.cc +++ /dev/null @@ -1,45 +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.hh" - -/* **************** OUTPUT ******************** */ - -namespace blender::nodes::node_shader_uvAlongStroke_cc { - -static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { - {SOCK_VECTOR, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - {-1, ""}, -}; - -} // namespace blender::nodes::node_shader_uvAlongStroke_cc - -/* node type definition */ -void register_node_type_sh_uvalongstroke() -{ - namespace file_ns = blender::nodes::node_shader_uvAlongStroke_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, nullptr, file_ns::sh_node_uvalongstroke_out); - node_type_init(&ntype, nullptr); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc new file mode 100644 index 00000000000..8cb60199581 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc @@ -0,0 +1,45 @@ +/* + * 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.hh" + +/* **************** OUTPUT ******************** */ + +namespace blender::nodes::node_shader_uv_along_stroke_cc { + +static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { + {SOCK_VECTOR, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, ""}, +}; + +} // namespace blender::nodes::node_shader_uv_along_stroke_cc + +/* node type definition */ +void register_node_type_sh_uvalongstroke() +{ + namespace file_ns = blender::nodes::node_shader_uv_along_stroke_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, nullptr, file_ns::sh_node_uvalongstroke_out); + node_type_init(&ntype, nullptr); + + 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 b65269f8e35..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.hh" - -namespace blender::nodes::node_shader_valToRgb_cc { - -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")); -}; - -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); -} - -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")); -}; - -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); -} - -} // namespace blender::nodes::node_shader_valToRgb_cc - -void register_node_type_sh_valtorgb() -{ - namespace file_ns = blender::nodes::node_shader_valToRgb_cc; - - static bNodeType ntype; - - sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_valtorgb_declare; - node_type_init(&ntype, file_ns::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, file_ns::node_shader_exec_valtorgb); - node_type_gpu(&ntype, file_ns::gpu_shader_valtorgb); - ntype.build_multi_function = file_ns::sh_node_valtorgb_build_multi_function; - - nodeRegisterType(&ntype); -} - -void register_node_type_sh_rgbtobw() -{ - namespace file_ns = blender::nodes::node_shader_valToRgb_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); - ntype.declare = file_ns::sh_node_rgbtobw_declare; - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_rgbtobw); - node_type_gpu(&ntype, file_ns::gpu_shader_rgbtobw); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.cc b/source/blender/nodes/shader/nodes/node_shader_vectTransform.cc deleted file mode 100644 index bfaca357c5c..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.cc +++ /dev/null @@ -1,161 +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.hh" - -/* **************** Vector Transform ******************** */ - -namespace blender::nodes::node_shader_vectTransform_cc { - -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 = (NodeShaderVectTransform *)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 nullptr; - 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 nullptr; - 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 nullptr; - 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 nullptr; -} -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 = nullptr; - - 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; -} - -} // namespace blender::nodes::node_shader_vectTransform_cc - -void register_node_type_sh_vect_transform() -{ - namespace file_ns = blender::nodes::node_shader_vectTransform_cc; - - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); - node_type_init(&ntype, file_ns::node_shader_init_vect_transform); - node_type_socket_templates( - &ntype, file_ns::sh_node_vect_transform_in, file_ns::sh_node_vect_transform_out); - node_type_storage( - &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_vect_transform); - node_type_gpu(&ntype, file_ns::gpu_shader_vect_transform); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc b/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc new file mode 100644 index 00000000000..d354b579c36 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc @@ -0,0 +1,161 @@ +/* + * 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.hh" + +/* **************** Vector Transform ******************** */ + +namespace blender::nodes::node_shader_vector_transform_cc { + +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 = (NodeShaderVectTransform *)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 nullptr; + 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 nullptr; + 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 nullptr; + 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 nullptr; +} +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 = nullptr; + + 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; +} + +} // namespace blender::nodes::node_shader_vector_transform_cc + +void register_node_type_sh_vect_transform() +{ + namespace file_ns = blender::nodes::node_shader_vector_transform_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); + node_type_init(&ntype, file_ns::node_shader_init_vect_transform); + node_type_socket_templates( + &ntype, file_ns::sh_node_vect_transform_in, file_ns::sh_node_vect_transform_out); + node_type_storage( + &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_vect_transform); + node_type_gpu(&ntype, file_ns::gpu_shader_vect_transform); + + nodeRegisterType(&ntype); +} -- cgit v1.2.3