diff --git a/source/blender/blenkernel/BKE_node.hh b/source/blender/blenkernel/BKE_node.hh index dabdaba7f7a..1281813c3be 100644 --- a/source/blender/blenkernel/BKE_node.hh +++ b/source/blender/blenkernel/BKE_node.hh @@ -77,7 +77,6 @@ class InverseEvalParams; namespace compositor { class Context; class NodeOperation; -class ShaderNode; } // namespace compositor } // namespace blender @@ -133,8 +132,6 @@ using NodeGatherAddOperationsFunction = using NodeGetCompositorOperationFunction = blender::compositor::NodeOperation *(*)(blender::compositor::Context &context, blender::nodes::DNode node); -using NodeGetCompositorShaderNodeFunction = - blender::compositor::ShaderNode *(*)(blender::nodes::DNode node); using NodeExtraInfoFunction = void (*)(blender::nodes::NodeExtraInfoParams ¶ms); using NodeInverseElemEvalFunction = void (*)(blender::nodes::value_elem::InverseElemEvalParams ¶ms); @@ -333,10 +330,6 @@ struct bNodeType { * responsibility of the caller. */ NodeGetCompositorOperationFunction get_compositor_operation = nullptr; - /* Get an instance of this node's compositor shader node. Freeing the instance is the - * responsibility of the caller. */ - NodeGetCompositorShaderNodeFunction get_compositor_shader_node = nullptr; - /* A message to display in the node header for unsupported compositor nodes. The message * is assumed to be static and thus require no memory handling. This field is to be removed when * all nodes are supported. */ diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index cdad91ee758..6b9f622d416 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -139,7 +139,10 @@ set(SRC derived_resources/COM_denoised_auxiliary_pass.hh + utilities/intern/gpu_material.cc + utilities/COM_utilities_diagonals.hh + utilities/COM_utilities_gpu_material.hh utilities/COM_utilities_type_conversion.hh ) diff --git a/source/blender/compositor/COM_shader_node.hh b/source/blender/compositor/COM_shader_node.hh index 94bb7dccbe6..2ec9d90bb60 100644 --- a/source/blender/compositor/COM_shader_node.hh +++ b/source/blender/compositor/COM_shader_node.hh @@ -46,36 +46,15 @@ class ShaderNode { /* Construct the node by populating both its inputs and outputs. */ ShaderNode(DNode node); - virtual ~ShaderNode() = default; - /* Compile the node by adding the appropriate GPU material graph nodes and linking the * appropriate resources. */ - virtual void compile(GPUMaterial *material) = 0; - - /* Returns a contiguous array containing the GPU node stacks of each input. */ - GPUNodeStack *get_inputs_array(); - - /* Returns a contiguous array containing the GPU node stacks of each output. */ - GPUNodeStack *get_outputs_array(); + void compile(GPUMaterial *material); /* Returns the GPU node stack of the input with the given identifier. */ - GPUNodeStack &get_input(StringRef identifier); + GPUNodeStack &get_input(const StringRef identifier); /* Returns the GPU node stack of the output with the given identifier. */ - GPUNodeStack &get_output(StringRef identifier); - - /* Returns the GPU node link of the input with the given identifier, if the input is not linked, - * a uniform link carrying the value of the input will be created a returned. It is expected that - * the caller will use the returned link in a GPU material, otherwise, the link may not be - * properly freed. */ - GPUNodeLink *get_input_link(StringRef identifier); - - protected: - /* Returns a reference to the derived node that this operation represents. */ - const DNode &node() const; - - /* Returns a reference to the node this operations represents. */ - const bNode &bnode() const; + GPUNodeStack &get_output(const StringRef identifier); private: /* Populate the inputs of the node. The input link is set to nullptr and is expected to be diff --git a/source/blender/compositor/COM_shader_operation.hh b/source/blender/compositor/COM_shader_operation.hh index 9d0fe78c329..398fe32336c 100644 --- a/source/blender/compositor/COM_shader_operation.hh +++ b/source/blender/compositor/COM_shader_operation.hh @@ -18,6 +18,7 @@ #include "COM_context.hh" #include "COM_pixel_operation.hh" #include "COM_scheduler.hh" +#include "COM_shader_node.hh" namespace blender::compositor { diff --git a/source/blender/compositor/COM_utilities.hh b/source/blender/compositor/COM_utilities.hh index dae1e77de5b..6b991afc0b8 100644 --- a/source/blender/compositor/COM_utilities.hh +++ b/source/blender/compositor/COM_utilities.hh @@ -47,7 +47,7 @@ bool is_output_linked_to_node_conditioned(DOutputSocket output, int number_of_inputs_linked_to_output_conditioned(DOutputSocket output, FunctionRef condition); -/** A node is a pixel node if it defines a method to get a shader node operation. */ +/** A node is a pixel node if it defines a method to get a pixel node operation. */ bool is_pixel_node(DNode node); /** Get the input descriptor of the given input socket. */ diff --git a/source/blender/compositor/intern/shader_node.cc b/source/blender/compositor/intern/shader_node.cc index 0598a52a308..940666572bd 100644 --- a/source/blender/compositor/intern/shader_node.cc +++ b/source/blender/compositor/intern/shader_node.cc @@ -14,6 +14,7 @@ #include "COM_shader_node.hh" #include "COM_utilities.hh" +#include "COM_utilities_gpu_material.hh" #include "COM_utilities_type_conversion.hh" namespace blender::compositor { @@ -26,43 +27,20 @@ ShaderNode::ShaderNode(DNode node) : node_(node) populate_outputs(); } -GPUNodeStack *ShaderNode::get_inputs_array() +void ShaderNode::compile(GPUMaterial *material) { - return inputs_.data(); + node_->typeinfo->gpu_fn( + material, const_cast(node_.bnode()), nullptr, inputs_.data(), outputs_.data()); } -GPUNodeStack *ShaderNode::get_outputs_array() +GPUNodeStack &ShaderNode::get_input(const StringRef identifier) { - return outputs_.data(); + return get_shader_node_input(*node_, inputs_.data(), identifier); } -GPUNodeStack &ShaderNode::get_input(StringRef identifier) +GPUNodeStack &ShaderNode::get_output(const StringRef identifier) { - return inputs_[node_.input_by_identifier(identifier)->index()]; -} - -GPUNodeStack &ShaderNode::get_output(StringRef identifier) -{ - return outputs_[node_.output_by_identifier(identifier)->index()]; -} - -GPUNodeLink *ShaderNode::get_input_link(StringRef identifier) -{ - GPUNodeStack &input = get_input(identifier); - if (input.link) { - return input.link; - } - return GPU_uniform(input.vec); -} - -const DNode &ShaderNode::node() const -{ - return node_; -} - -const bNode &ShaderNode::bnode() const -{ - return *node_; + return get_shader_node_output(*node_, outputs_.data(), identifier); } static eGPUType gpu_type_from_socket_type(eNodeSocketDatatype type) diff --git a/source/blender/compositor/intern/shader_operation.cc b/source/blender/compositor/intern/shader_operation.cc index 53d9ef0fdd2..cc9ba74b95e 100644 --- a/source/blender/compositor/intern/shader_operation.cc +++ b/source/blender/compositor/intern/shader_operation.cc @@ -116,12 +116,11 @@ void ShaderOperation::construct_material(void *thunk, GPUMaterial *material) ShaderOperation *operation = static_cast(thunk); operation->material_ = material; for (DNode node : operation->compile_unit_) { - ShaderNode *shader_node = node->typeinfo->get_compositor_shader_node(node); - operation->shader_nodes_.add_new(node, std::unique_ptr(shader_node)); + operation->shader_nodes_.add_new(node, std::make_unique(node)); operation->link_node_inputs(node); - shader_node->compile(material); + operation->shader_nodes_.lookup(node)->compile(material); operation->populate_results_for_node(node); } diff --git a/source/blender/compositor/intern/utilities.cc b/source/blender/compositor/intern/utilities.cc index 78721de824a..4b587b8634a 100644 --- a/source/blender/compositor/intern/utilities.cc +++ b/source/blender/compositor/intern/utilities.cc @@ -100,7 +100,8 @@ int number_of_inputs_linked_to_output_conditioned(DOutputSocket output, bool is_pixel_node(DNode node) { - return node->typeinfo->get_compositor_shader_node; + BLI_assert(bool(node->typeinfo->gpu_fn) == bool(node->typeinfo->build_multi_function)); + return node->typeinfo->gpu_fn && node->typeinfo->build_multi_function; } InputDescriptor input_descriptor_from_input_socket(const bNodeSocket *socket) diff --git a/source/blender/compositor/utilities/COM_utilities_gpu_material.hh b/source/blender/compositor/utilities/COM_utilities_gpu_material.hh new file mode 100644 index 00000000000..7d195560412 --- /dev/null +++ b/source/blender/compositor/utilities/COM_utilities_gpu_material.hh @@ -0,0 +1,36 @@ +/* SPDX-FileCopyrightText: 2025 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#include "BLI_string_ref.hh" + +#include "DNA_node_types.h" + +#include "GPU_material.hh" + +namespace blender::compositor { + +/* Returns the GPU node stack of the input with the given identifier in the given node within the + * given inputs stack array. See the ShaderNode class for more information. */ +GPUNodeStack &get_shader_node_input(const bNode &node, + GPUNodeStack inputs[], + const StringRef identifier); + +/* Returns the GPU node stack of the output with the given identifier in the given node within the + * given output stack array. See the ShaderNode class for more information. */ +GPUNodeStack &get_shader_node_output(const bNode &node, + GPUNodeStack outputs[], + const StringRef identifier); + +/* Returns the GPU node link of the input with the given identifier in the given node within the + * given inputs stack array, if the input is not linked, a uniform link carrying the value of the + * input will be created and returned. It is expected that the caller will use the returned link in + * a GPU material, otherwise, the link may not be properly freed. See the ShaderNode class for more + * information. */ +GPUNodeLink *get_shader_node_input_link(const bNode &node, + GPUNodeStack inputs[], + const StringRef identifier); + +} // namespace blender::compositor diff --git a/source/blender/compositor/utilities/intern/gpu_material.cc b/source/blender/compositor/utilities/intern/gpu_material.cc new file mode 100644 index 00000000000..bb1580106bc --- /dev/null +++ b/source/blender/compositor/utilities/intern/gpu_material.cc @@ -0,0 +1,42 @@ +/* SPDX-FileCopyrightText: 2025 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BLI_string_ref.hh" + +#include "DNA_node_types.h" + +#include "BKE_node_runtime.hh" + +#include "GPU_material.hh" + +#include "COM_utilities_gpu_material.hh" + +namespace blender::compositor { + +GPUNodeStack &get_shader_node_input(const bNode &node, + GPUNodeStack inputs[], + const StringRef identifier) +{ + return inputs[node.input_by_identifier(identifier).index()]; +} + +GPUNodeStack &get_shader_node_output(const bNode &node, + GPUNodeStack outputs[], + const StringRef identifier) +{ + return outputs[node.output_by_identifier(identifier).index()]; +} + +GPUNodeLink *get_shader_node_input_link(const bNode &node, + GPUNodeStack inputs[], + const StringRef identifier) +{ + GPUNodeStack &input = get_shader_node_input(node, inputs, identifier); + if (input.link) { + return input.link; + } + return GPU_uniform(input.vec); +} + +} // namespace blender::compositor diff --git a/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc b/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc index 5db2b7e9405..a7337a05dd3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc +++ b/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc @@ -18,8 +18,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** ALPHAOVER ******************** */ @@ -71,38 +69,27 @@ static float get_premultiply_factor(const bNode &node) return node_storage(node).x; } -class AlphaOverShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float premultiply_factor = get_premultiply_factor(bnode()); - if (premultiply_factor != 0.0f) { - GPU_stack_link(material, - &bnode(), - "node_composite_alpha_over_mixed", - inputs, - outputs, - GPU_uniform(&premultiply_factor)); - return; - } - - if (get_use_premultiply(bnode())) { - GPU_stack_link(material, &bnode(), "node_composite_alpha_over_key", inputs, outputs); - return; - } - - GPU_stack_link(material, &bnode(), "node_composite_alpha_over_premultiply", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new AlphaOverShaderNode(node); + const float premultiply_factor = get_premultiply_factor(*node); + if (premultiply_factor != 0.0f) { + return GPU_stack_link(material, + node, + "node_composite_alpha_over_mixed", + inputs, + outputs, + GPU_uniform(&premultiply_factor)); + } + + if (get_use_premultiply(*node)) { + return GPU_stack_link(material, node, "node_composite_alpha_over_key", inputs, outputs); + } + + return GPU_stack_link(material, node, "node_composite_alpha_over_premultiply", inputs, outputs); } static float4 alpha_over_mixed(const float factor, @@ -207,7 +194,7 @@ void register_node_type_cmp_alphaover() ntype.initfunc = file_ns::node_alphaover_init; blender::bke::node_type_storage( &ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_brightness.cc b/source/blender/nodes/composite/nodes/node_composite_brightness.cc index 0303467fb33..20df5eaee77 100644 --- a/source/blender/nodes/composite/nodes/node_composite_brightness.cc +++ b/source/blender/nodes/composite/nodes/node_composite_brightness.cc @@ -20,8 +20,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Brightness and Contrast ******************** */ @@ -55,29 +53,19 @@ static bool get_use_premultiply(const bNode &node) return node.custom1; } -class BrightContrastShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float use_premultiply = get_use_premultiply(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_bright_contrast", - inputs, - outputs, - GPU_constant(&use_premultiply)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new BrightContrastShaderNode(node); + const float use_premultiply = get_use_premultiply(*node); + return GPU_stack_link(material, + node, + "node_composite_bright_contrast", + inputs, + outputs, + GPU_constant(&use_premultiply)); } /* The algorithm is by Werner D. Streidt, extracted of OpenCV `demhist.c`: @@ -156,7 +144,7 @@ void register_node_type_cmp_brightcontrast() ntype.declare = file_ns::cmp_node_brightcontrast_declare; ntype.draw_buttons = file_ns::node_composit_buts_brightcontrast; ntype.initfunc = file_ns::node_composit_init_brightcontrast; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc b/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc index d055870dc03..7237ffcf161 100644 --- a/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc @@ -22,8 +22,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Channel Matte Node ********************************* */ @@ -157,37 +155,28 @@ static float get_min_limit(const bNode &node) return node_storage(node).t2; } -class ChannelMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float color_space = int(get_color_space(bnode())); - const float matte_channel = get_matte_channel(bnode()); - const float2 limit_channels = float2(get_limit_channels(bnode())); - const float max_limit = get_max_limit(bnode()); - const float min_limit = get_min_limit(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_channel_matte", - inputs, - outputs, - GPU_constant(&color_space), - GPU_constant(&matte_channel), - GPU_constant(limit_channels), - GPU_uniform(&max_limit), - GPU_uniform(&min_limit)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ChannelMatteShaderNode(node); + const float color_space = int(get_color_space(*node)); + const float matte_channel = get_matte_channel(*node); + const float2 limit_channels = float2(get_limit_channels(*node)); + const float max_limit = get_max_limit(*node); + const float min_limit = get_min_limit(*node); + + return GPU_stack_link(material, + node, + "node_composite_channel_matte", + inputs, + outputs, + GPU_constant(&color_space), + GPU_constant(&matte_channel), + GPU_constant(limit_channels), + GPU_uniform(&max_limit), + GPU_uniform(&min_limit)); } template @@ -309,7 +298,7 @@ void register_node_type_cmp_channel_matte() ntype.initfunc = file_ns::node_composit_init_channel_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc b/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc index 32f04b9bd7f..7a1edef9d72 100644 --- a/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc @@ -23,8 +23,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Chroma Key ********************************************************** */ @@ -90,33 +88,24 @@ static float get_falloff(const bNode &node) return node_storage(node).fstrength; } -class ChromaMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float acceptance = get_acceptance(bnode()); - const float cutoff = get_cutoff(bnode()); - const float falloff = get_falloff(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_chroma_matte", - inputs, - outputs, - GPU_uniform(&acceptance), - GPU_uniform(&cutoff), - GPU_uniform(&falloff)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ChromaMatteShaderNode(node); + const float acceptance = get_acceptance(*node); + const float cutoff = get_cutoff(*node); + const float falloff = get_falloff(*node); + + return GPU_stack_link(material, + node, + "node_composite_chroma_matte", + inputs, + outputs, + GPU_uniform(&acceptance), + GPU_uniform(&cutoff), + GPU_uniform(&falloff)); } /* Algorithm from the book Video Demystified. Chapter 7. Chroma Keying. */ @@ -199,7 +188,7 @@ void register_node_type_cmp_chroma_matte() ntype.initfunc = file_ns::node_composit_init_chroma_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_color_matte.cc b/source/blender/nodes/composite/nodes/node_composite_color_matte.cc index 0ad9d95e6d2..3f5e3cd250a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_color_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_color_matte.cc @@ -20,8 +20,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Color Matte ********************************************************** */ @@ -96,33 +94,24 @@ static float get_value_epsilon(const bNode &node) return node_storage(node).t3; } -class ColorMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float hue_epsilon = get_hue_epsilon(bnode()); - const float saturation_epsilon = get_saturation_epsilon(bnode()); - const float value_epsilon = get_value_epsilon(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_color_matte", - inputs, - outputs, - GPU_uniform(&hue_epsilon), - GPU_uniform(&saturation_epsilon), - GPU_uniform(&value_epsilon)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ColorMatteShaderNode(node); + const float hue_epsilon = get_hue_epsilon(*node); + const float saturation_epsilon = get_saturation_epsilon(*node); + const float value_epsilon = get_value_epsilon(*node); + + return GPU_stack_link(material, + node, + "node_composite_color_matte", + inputs, + outputs, + GPU_uniform(&hue_epsilon), + GPU_uniform(&saturation_epsilon), + GPU_uniform(&value_epsilon)); } static void color_matte(const float4 color, @@ -192,7 +181,7 @@ void register_node_type_cmp_color_matte() ntype.initfunc = file_ns::node_composit_init_color_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_color_spill.cc b/source/blender/nodes/composite/nodes/node_composite_color_spill.cc index a581904af7b..c629b1b9f05 100644 --- a/source/blender/nodes/composite/nodes/node_composite_color_spill.cc +++ b/source/blender/nodes/composite/nodes/node_composite_color_spill.cc @@ -19,8 +19,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Color Spill Suppression ********************************* */ @@ -167,35 +165,26 @@ static float get_limit_scale(const bNode &node) return node_storage(node).limscale; } -class ColorSpillShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float spill_channel = get_spill_channel(bnode()); - const float3 spill_scale = get_spill_scale(bnode()); - const float2 limit_channels = float2(get_limit_channels(bnode())); - const float limit_scale = get_limit_scale(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_color_spill", - inputs, - outputs, - GPU_constant(&spill_channel), - GPU_uniform(spill_scale), - GPU_constant(limit_channels), - GPU_uniform(&limit_scale)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ColorSpillShaderNode(node); + const float spill_channel = get_spill_channel(*node); + const float3 spill_scale = get_spill_scale(*node); + const float2 limit_channels = float2(get_limit_channels(*node)); + const float limit_scale = get_limit_scale(*node); + + return GPU_stack_link(material, + node, + "node_composite_color_spill", + inputs, + outputs, + GPU_constant(&spill_channel), + GPU_uniform(spill_scale), + GPU_constant(limit_channels), + GPU_uniform(&limit_scale)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -237,7 +226,7 @@ void register_node_type_cmp_color_spill() ntype.initfunc = file_ns::node_composit_init_color_spill; blender::bke::node_type_storage( &ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc index 2f17b382dc0..efb5d637f36 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc +++ b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc @@ -24,8 +24,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "IMB_colormanagement.hh" #include "BLI_math_color.hh" @@ -237,62 +235,57 @@ static float3x3 get_white_point_matrix(const bNode &node) return xyz_to_scene * adaption * scene_to_xyz; } -class ColorBalanceShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) +{ + const NodeColorBalance &node_color_balance = node_storage(*node); - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const NodeColorBalance &node_color_balance = node_storage(bnode()); - - if (get_color_balance_method(bnode()) == CMP_NODE_COLOR_BALANCE_LGG) { + switch (get_color_balance_method(*node)) { + case CMP_NODE_COLOR_BALANCE_LGG: { const float3 lift = node_color_balance.lift; const float3 gamma = node_color_balance.gamma; const float3 gain = node_color_balance.gain; const float3 sanitized_gamma = get_sanitized_gamma(gamma); - GPU_stack_link(material, - &bnode(), - "node_composite_color_balance_lgg", - inputs, - outputs, - GPU_uniform(lift), - GPU_uniform(sanitized_gamma), - GPU_uniform(gain)); + return GPU_stack_link(material, + node, + "node_composite_color_balance_lgg", + inputs, + outputs, + GPU_uniform(lift), + GPU_uniform(sanitized_gamma), + GPU_uniform(gain)); } - else if (get_color_balance_method(bnode()) == CMP_NODE_COLOR_BALANCE_ASC_CDL) { + case CMP_NODE_COLOR_BALANCE_ASC_CDL: { const float3 offset = node_color_balance.offset; const float3 power = node_color_balance.power; const float3 slope = node_color_balance.slope; const float3 full_offset = node_color_balance.offset_basis + offset; - GPU_stack_link(material, - &bnode(), - "node_composite_color_balance_asc_cdl", - inputs, - outputs, - GPU_uniform(full_offset), - GPU_uniform(power), - GPU_uniform(slope)); + return GPU_stack_link(material, + node, + "node_composite_color_balance_asc_cdl", + inputs, + outputs, + GPU_uniform(full_offset), + GPU_uniform(power), + GPU_uniform(slope)); } - else if (get_color_balance_method(bnode()) == CMP_NODE_COLOR_BALANCE_WHITEPOINT) { - const float3x3 matrix = get_white_point_matrix(bnode()); - GPU_stack_link(material, - &bnode(), - "node_composite_color_balance_whitepoint", - inputs, - outputs, - GPU_uniform(blender::float4x4(matrix).base_ptr())); + case CMP_NODE_COLOR_BALANCE_WHITEPOINT: { + const float3x3 matrix = get_white_point_matrix(*node); + return GPU_stack_link(material, + node, + "node_composite_color_balance_whitepoint", + inputs, + outputs, + GPU_uniform(blender::float4x4(matrix).base_ptr())); } } -}; -static ShaderNode *get_compositor_shader_node(DNode node) -{ - return new ColorBalanceShaderNode(node); + return false; } static float4 color_balance_lgg(const float factor, @@ -399,7 +392,7 @@ void register_node_type_cmp_colorbalance() ntype.initfunc = file_ns::node_composit_init_colorbalance; blender::bke::node_type_storage( &ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc index 6e669e81c42..79faa6fbadd 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc +++ b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc @@ -21,8 +21,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Color Correction ********************************* */ @@ -313,64 +311,55 @@ static void node_composit_buts_colorcorrection_ex(uiLayout *layout, using namespace blender::compositor; -class ColorCorrectionShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - float enabled_channels[3]; - get_enabled_channels(enabled_channels); - float luminance_coefficients[3]; - IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); - - const NodeColorCorrection &node_color_correction = node_storage(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_color_correction", - inputs, - outputs, - GPU_constant(enabled_channels), - GPU_uniform(&node_color_correction.startmidtones), - GPU_uniform(&node_color_correction.endmidtones), - GPU_uniform(&node_color_correction.master.saturation), - GPU_uniform(&node_color_correction.master.contrast), - GPU_uniform(&node_color_correction.master.gamma), - GPU_uniform(&node_color_correction.master.gain), - GPU_uniform(&node_color_correction.master.lift), - GPU_uniform(&node_color_correction.shadows.saturation), - GPU_uniform(&node_color_correction.shadows.contrast), - GPU_uniform(&node_color_correction.shadows.gamma), - GPU_uniform(&node_color_correction.shadows.gain), - GPU_uniform(&node_color_correction.shadows.lift), - GPU_uniform(&node_color_correction.midtones.saturation), - GPU_uniform(&node_color_correction.midtones.contrast), - GPU_uniform(&node_color_correction.midtones.gamma), - GPU_uniform(&node_color_correction.midtones.gain), - GPU_uniform(&node_color_correction.midtones.lift), - GPU_uniform(&node_color_correction.highlights.saturation), - GPU_uniform(&node_color_correction.highlights.contrast), - GPU_uniform(&node_color_correction.highlights.gamma), - GPU_uniform(&node_color_correction.highlights.gain), - GPU_uniform(&node_color_correction.highlights.lift), - GPU_constant(luminance_coefficients)); - } - - void get_enabled_channels(float enabled_channels[3]) - { - for (int i = 0; i < 3; i++) { - enabled_channels[i] = (bnode().custom1 & (1 << i)) ? 1.0f : 0.0f; - } - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static void get_enabled_channels(const bNode &node, float enabled_channels[3]) { - return new ColorCorrectionShaderNode(node); + for (int i = 0; i < 3; i++) { + enabled_channels[i] = (node.custom1 & (1 << i)) ? 1.0f : 0.0f; + } +} + +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) +{ + float enabled_channels[3]; + get_enabled_channels(*node, enabled_channels); + float luminance_coefficients[3]; + IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); + + const NodeColorCorrection &node_color_correction = node_storage(*node); + + return GPU_stack_link(material, + node, + "node_composite_color_correction", + inputs, + outputs, + GPU_constant(enabled_channels), + GPU_uniform(&node_color_correction.startmidtones), + GPU_uniform(&node_color_correction.endmidtones), + GPU_uniform(&node_color_correction.master.saturation), + GPU_uniform(&node_color_correction.master.contrast), + GPU_uniform(&node_color_correction.master.gamma), + GPU_uniform(&node_color_correction.master.gain), + GPU_uniform(&node_color_correction.master.lift), + GPU_uniform(&node_color_correction.shadows.saturation), + GPU_uniform(&node_color_correction.shadows.contrast), + GPU_uniform(&node_color_correction.shadows.gamma), + GPU_uniform(&node_color_correction.shadows.gain), + GPU_uniform(&node_color_correction.shadows.lift), + GPU_uniform(&node_color_correction.midtones.saturation), + GPU_uniform(&node_color_correction.midtones.contrast), + GPU_uniform(&node_color_correction.midtones.gamma), + GPU_uniform(&node_color_correction.midtones.gain), + GPU_uniform(&node_color_correction.midtones.lift), + GPU_uniform(&node_color_correction.highlights.saturation), + GPU_uniform(&node_color_correction.highlights.contrast), + GPU_uniform(&node_color_correction.highlights.gamma), + GPU_uniform(&node_color_correction.highlights.gain), + GPU_uniform(&node_color_correction.highlights.lift), + GPU_constant(luminance_coefficients)); } static float4 color_correction(const float4 &color, @@ -524,7 +513,7 @@ void register_node_type_cmp_colorcorrection() ntype.initfunc = file_ns::node_composit_init_colorcorrection; blender::bke::node_type_storage( &ntype, "NodeColorCorrection", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_curves.cc b/source/blender/nodes/composite/nodes/node_composite_curves.cc index 8b471552524..e91999f9281 100644 --- a/source/blender/nodes/composite/nodes/node_composite_curves.cc +++ b/source/blender/nodes/composite/nodes/node_composite_curves.cc @@ -24,7 +24,7 @@ #include "GPU_material.hh" #include "COM_node_operation.hh" -#include "COM_shader_node.hh" +#include "COM_utilities_gpu_material.hh" #include "node_composite_util.hh" @@ -153,49 +153,40 @@ static CurveMapping *get_curve_mapping(const bNode &node) return static_cast(node.storage); } -class VectorCurvesShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - CurveMapping *curve_mapping = get_curve_mapping(bnode()); - - BKE_curvemapping_init(curve_mapping); - float *band_values; - int band_size; - BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); - float band_layer; - GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); - - float start_slopes[CM_TOT]; - float end_slopes[CM_TOT]; - BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes); - float range_minimums[CM_TOT]; - BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); - float range_dividers[CM_TOT]; - BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); - - GPU_stack_link(material, - &bnode(), - "curves_vector", - inputs, - outputs, - band_texture, - GPU_constant(&band_layer), - GPU_uniform(range_minimums), - GPU_uniform(range_dividers), - GPU_uniform(start_slopes), - GPU_uniform(end_slopes)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new VectorCurvesShaderNode(node); + CurveMapping *curve_mapping = get_curve_mapping(*node); + + BKE_curvemapping_init(curve_mapping); + float *band_values; + int band_size; + BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); + float band_layer; + GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); + + float start_slopes[CM_TOT]; + float end_slopes[CM_TOT]; + BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes); + float range_minimums[CM_TOT]; + BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); + float range_dividers[CM_TOT]; + BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); + + return GPU_stack_link(material, + node, + "curves_vector", + inputs, + outputs, + band_texture, + GPU_constant(&band_layer), + GPU_uniform(range_minimums), + GPU_uniform(range_dividers), + GPU_uniform(start_slopes), + GPU_uniform(end_slopes)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -233,7 +224,7 @@ void register_node_type_cmp_curve_vec() blender::bke::node_type_size(&ntype, 200, 140, 320); ntype.initfunc = file_ns::node_composit_init_curve_vec; blender::bke::node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -277,92 +268,81 @@ static CurveMapping *get_curve_mapping(const bNode &node) return static_cast(node.storage); } -class RGBCurvesShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - CurveMapping *curve_mapping = get_curve_mapping(bnode()); - - BKE_curvemapping_init(curve_mapping); - float *band_values; - int band_size; - BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); - float band_layer; - GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); - - float start_slopes[CM_TOT]; - float end_slopes[CM_TOT]; - BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes); - float range_minimums[CM_TOT]; - BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); - float range_dividers[CM_TOT]; - BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); - - if (curve_mapping->tone == CURVE_TONE_FILMLIKE) { - GPU_stack_link(material, - &bnode(), - "curves_film_like", - inputs, - outputs, - band_texture, - GPU_constant(&band_layer), - GPU_uniform(&range_minimums[3]), - GPU_uniform(&range_dividers[3]), - GPU_uniform(&start_slopes[3]), - GPU_uniform(&end_slopes[3])); - return; - } - - const float min = 0.0f; - const float max = 1.0f; - GPU_link(material, - "clamp_value", - get_input_link("Fac"), - GPU_constant(&min), - GPU_constant(&max), - &get_input("Fac").link); - - /* If the RGB curves do nothing, use a function that skips RGB computations. */ - if (BKE_curvemapping_is_map_identity(curve_mapping, 0) && - BKE_curvemapping_is_map_identity(curve_mapping, 1) && - BKE_curvemapping_is_map_identity(curve_mapping, 2)) - { - GPU_stack_link(material, - &bnode(), - "curves_combined_only", - inputs, - outputs, - band_texture, - GPU_constant(&band_layer), - GPU_uniform(&range_minimums[3]), - GPU_uniform(&range_dividers[3]), - GPU_uniform(&start_slopes[3]), - GPU_uniform(&end_slopes[3])); - return; - } - - GPU_stack_link(material, - &bnode(), - "curves_combined_rgb", - inputs, - outputs, - band_texture, - GPU_constant(&band_layer), - GPU_uniform(range_minimums), - GPU_uniform(range_dividers), - GPU_uniform(start_slopes), - GPU_uniform(end_slopes)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new RGBCurvesShaderNode(node); + CurveMapping *curve_mapping = get_curve_mapping(*node); + + BKE_curvemapping_init(curve_mapping); + float *band_values; + int band_size; + BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); + float band_layer; + GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); + + float start_slopes[CM_TOT]; + float end_slopes[CM_TOT]; + BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes); + float range_minimums[CM_TOT]; + BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); + float range_dividers[CM_TOT]; + BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); + + if (curve_mapping->tone == CURVE_TONE_FILMLIKE) { + return GPU_stack_link(material, + node, + "curves_film_like", + inputs, + outputs, + band_texture, + GPU_constant(&band_layer), + GPU_uniform(&range_minimums[3]), + GPU_uniform(&range_dividers[3]), + GPU_uniform(&start_slopes[3]), + GPU_uniform(&end_slopes[3])); + } + + const float min = 0.0f; + const float max = 1.0f; + GPU_link(material, + "clamp_value", + get_shader_node_input_link(*node, inputs, "Fac"), + GPU_constant(&min), + GPU_constant(&max), + &get_shader_node_input(*node, inputs, "Fac").link); + + /* If the RGB curves do nothing, use a function that skips RGB computations. */ + if (BKE_curvemapping_is_map_identity(curve_mapping, 0) && + BKE_curvemapping_is_map_identity(curve_mapping, 1) && + BKE_curvemapping_is_map_identity(curve_mapping, 2)) + { + return GPU_stack_link(material, + node, + "curves_combined_only", + inputs, + outputs, + band_texture, + GPU_constant(&band_layer), + GPU_uniform(&range_minimums[3]), + GPU_uniform(&range_dividers[3]), + GPU_uniform(&start_slopes[3]), + GPU_uniform(&end_slopes[3])); + } + + return GPU_stack_link(material, + node, + "curves_combined_rgb", + inputs, + outputs, + band_texture, + GPU_constant(&band_layer), + GPU_uniform(range_minimums), + GPU_uniform(range_dividers), + GPU_uniform(start_slopes), + GPU_uniform(end_slopes)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -406,7 +386,7 @@ void register_node_type_cmp_curve_rgb() blender::bke::node_type_size(&ntype, 200, 140, 320); ntype.initfunc = file_ns::node_composit_init_curve_rgb; blender::bke::node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc b/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc index e73ca8e50e0..72a7e405f85 100644 --- a/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc @@ -19,8 +19,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* channel Difference Matte ********************************* */ @@ -76,31 +74,22 @@ static float get_falloff(const bNode &node) return node_storage(node).t2; } -class DifferenceMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float tolerance = get_tolerance(bnode()); - const float falloff = get_falloff(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_difference_matte", - inputs, - outputs, - GPU_uniform(&tolerance), - GPU_uniform(&falloff)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new DifferenceMatteShaderNode(node); + const float tolerance = get_tolerance(*node); + const float falloff = get_falloff(*node); + + return GPU_stack_link(material, + node, + "node_composite_difference_matte", + inputs, + outputs, + GPU_uniform(&tolerance), + GPU_uniform(&falloff)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -147,7 +136,7 @@ void register_node_type_cmp_diff_matte() ntype.initfunc = file_ns::node_composit_init_diff_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc b/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc index 0af70020e06..02c39448566 100644 --- a/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc @@ -20,8 +20,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* channel Distance Matte ********************************* */ @@ -89,42 +87,35 @@ static float get_falloff(const bNode &node) return node_storage(node).t2; } -class DistanceMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float tolerance = get_tolerance(bnode()); - const float falloff = get_falloff(bnode()); - - if (get_color_space(bnode()) == CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA) { - GPU_stack_link(material, - &bnode(), - "node_composite_distance_matte_rgba", - inputs, - outputs, - GPU_uniform(&tolerance), - GPU_uniform(&falloff)); - return; - } - - GPU_stack_link(material, - &bnode(), - "node_composite_distance_matte_ycca", - inputs, - outputs, - GPU_uniform(&tolerance), - GPU_uniform(&falloff)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new DistanceMatteShaderNode(node); + const float tolerance = get_tolerance(*node); + const float falloff = get_falloff(*node); + + switch (get_color_space(*node)) { + case CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA: + return GPU_stack_link(material, + node, + "node_composite_distance_matte_rgba", + inputs, + outputs, + GPU_uniform(&tolerance), + GPU_uniform(&falloff)); + case CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_YCCA: + return GPU_stack_link(material, + node, + "node_composite_distance_matte_ycca", + inputs, + outputs, + GPU_uniform(&tolerance), + GPU_uniform(&falloff)); + } + + return false; } static void distance_key_rgba(const float4 &color, @@ -214,7 +205,7 @@ void register_node_type_cmp_distance_matte() ntype.initfunc = file_ns::node_composit_init_distance_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_exposure.cc b/source/blender/nodes/composite/nodes/node_composite_exposure.cc index dce6108eaad..d625636a16c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_exposure.cc +++ b/source/blender/nodes/composite/nodes/node_composite_exposure.cc @@ -16,8 +16,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Exposure ******************** */ @@ -35,22 +33,13 @@ static void cmp_node_exposure_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class ExposureShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_exposure", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ExposureShaderNode(node); + return GPU_stack_link(material, node, "node_composite_exposure", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -78,7 +67,7 @@ void register_node_type_cmp_exposure() ntype.enum_name_legacy = "EXPOSURE"; ntype.nclass = NODE_CLASS_OP_COLOR; ntype.declare = file_ns::cmp_node_exposure_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_gamma.cc b/source/blender/nodes/composite/nodes/node_composite_gamma.cc index 28fc90ea32d..243fb037842 100644 --- a/source/blender/nodes/composite/nodes/node_composite_gamma.cc +++ b/source/blender/nodes/composite/nodes/node_composite_gamma.cc @@ -15,8 +15,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Gamma Tools ******************** */ @@ -39,22 +37,13 @@ static void cmp_node_gamma_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class GammaShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_gamma", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new GammaShaderNode(node); + return GPU_stack_link(material, node, "node_composite_gamma", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -82,7 +71,7 @@ void register_node_type_cmp_gamma() ntype.enum_name_legacy = "GAMMA"; ntype.nclass = NODE_CLASS_OP_COLOR; ntype.declare = file_ns::cmp_node_gamma_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc b/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc index d1047f86362..dda3dc6d81e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc +++ b/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc @@ -17,8 +17,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Hue/Saturation/Value ******************** */ @@ -60,22 +58,13 @@ static void cmp_node_huesatval_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class HueSaturationValueShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_hue_saturation_value", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new HueSaturationValueShaderNode(node); + return GPU_stack_link(material, node, "node_composite_hue_saturation_value", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -118,7 +107,7 @@ void register_node_type_cmp_hue_sat() ntype.enum_name_legacy = "HUE_SAT"; ntype.nclass = NODE_CLASS_OP_COLOR; ntype.declare = file_ns::cmp_node_huesatval_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc index a9a85256a49..286385fac7b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc +++ b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc @@ -20,8 +20,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" namespace blender::nodes::node_composite_huecorrect_cc { @@ -65,44 +63,35 @@ static CurveMapping *get_curve_mapping(const bNode &node) return static_cast(node.storage); } -class HueCorrectShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - CurveMapping *curve_mapping = get_curve_mapping(bnode()); - - BKE_curvemapping_init(curve_mapping); - float *band_values; - int band_size; - BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); - float band_layer; - GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); - - float range_minimums[CM_TOT]; - BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); - float range_dividers[CM_TOT]; - BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); - - GPU_stack_link(material, - &bnode(), - "node_composite_hue_correct", - inputs, - outputs, - band_texture, - GPU_constant(&band_layer), - GPU_uniform(range_minimums), - GPU_uniform(range_dividers)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new HueCorrectShaderNode(node); + CurveMapping *curve_mapping = get_curve_mapping(*node); + + BKE_curvemapping_init(curve_mapping); + float *band_values; + int band_size; + BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size); + float band_layer; + GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer); + + float range_minimums[CM_TOT]; + BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums); + float range_dividers[CM_TOT]; + BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers); + + return GPU_stack_link(material, + node, + "node_composite_hue_correct", + inputs, + outputs, + band_texture, + GPU_constant(&band_layer), + GPU_uniform(range_minimums), + GPU_uniform(range_dividers)); } static float4 hue_correct(const float factor, const float4 &color, const CurveMapping *curve_map) @@ -165,7 +154,7 @@ void register_node_type_cmp_huecorrect() blender::bke::node_type_size(&ntype, 320, 140, 500); ntype.initfunc = file_ns::node_composit_init_huecorrect; blender::bke::node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_invert.cc b/source/blender/nodes/composite/nodes/node_composite_invert.cc index 33253f797a0..a47d7ab047f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_invert.cc +++ b/source/blender/nodes/composite/nodes/node_composite_invert.cc @@ -18,8 +18,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** INVERT ******************** */ @@ -66,31 +64,22 @@ static bool should_invert_alpha(const bNode &node) return node.custom1 & CMP_CHAN_A; } -class InvertShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float do_rgb = should_invert_rgb(bnode()); - const float do_alpha = should_invert_alpha(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_invert", - inputs, - outputs, - GPU_constant(&do_rgb), - GPU_constant(&do_alpha)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new InvertShaderNode(node); + const float do_rgb = should_invert_rgb(*node); + const float do_alpha = should_invert_alpha(*node); + + return GPU_stack_link(material, + node, + "node_composite_invert", + inputs, + outputs, + GPU_constant(&do_rgb), + GPU_constant(&do_alpha)); } template @@ -168,7 +157,7 @@ void register_node_type_cmp_invert() ntype.declare = file_ns::cmp_node_invert_declare; ntype.draw_buttons = file_ns::node_composit_buts_invert; ntype.initfunc = file_ns::node_composit_init_invert; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc b/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc index a26df31ca15..d7400a86765 100644 --- a/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc @@ -21,8 +21,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* ******************* Luma Matte Node ********************************* */ @@ -79,34 +77,25 @@ static float get_low(const bNode &node) return node_storage(node).t2; } -class LuminanceMatteShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float high = get_high(bnode()); - const float low = get_low(bnode()); - float luminance_coefficients[3]; - IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); - - GPU_stack_link(material, - &bnode(), - "node_composite_luminance_matte", - inputs, - outputs, - GPU_uniform(&high), - GPU_uniform(&low), - GPU_constant(luminance_coefficients)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new LuminanceMatteShaderNode(node); + const float high = get_high(*node); + const float low = get_low(*node); + float luminance_coefficients[3]; + IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); + + return GPU_stack_link(material, + node, + "node_composite_luminance_matte", + inputs, + outputs, + GPU_uniform(&high), + GPU_uniform(&low), + GPU_constant(luminance_coefficients)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -148,7 +137,7 @@ void register_node_type_cmp_luma_matte() ntype.initfunc = file_ns::node_composit_init_luma_matte; blender::bke::node_type_storage( &ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_map_range.cc b/source/blender/nodes/composite/nodes/node_composite_map_range.cc index 34e4b80e6d6..0a396841bda 100644 --- a/source/blender/nodes/composite/nodes/node_composite_map_range.cc +++ b/source/blender/nodes/composite/nodes/node_composite_map_range.cc @@ -17,8 +17,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Map Range ******************** */ @@ -70,29 +68,15 @@ static bool get_should_clamp(const bNode &node) return node.custom1; } -class MapRangeShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const float should_clamp = get_should_clamp(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_map_range", - inputs, - outputs, - GPU_constant(&should_clamp)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new MapRangeShaderNode(node); + const float should_clamp = get_should_clamp(*node); + return GPU_stack_link( + material, node, "node_composite_map_range", inputs, outputs, GPU_constant(&should_clamp)); } /* An arbitrary value determined by Blender. */ @@ -182,7 +166,7 @@ void register_node_type_cmp_map_range() ntype.nclass = NODE_CLASS_OP_VECTOR; ntype.declare = file_ns::cmp_node_map_range_declare; ntype.draw_buttons = file_ns::node_composit_buts_map_range; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_map_value.cc b/source/blender/nodes/composite/nodes/node_composite_map_value.cc index 787925ea611..be247d24e1e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_map_value.cc +++ b/source/blender/nodes/composite/nodes/node_composite_map_value.cc @@ -21,8 +21,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** MAP VALUE ******************** */ @@ -79,37 +77,28 @@ static bool get_use_max(const bNode &node) return node_storage(node).flag & TEXMAP_CLIP_MAX; } -class MapValueShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - const TexMapping &texture_mapping = node_storage(bnode()); - - const float use_min = get_use_min(bnode()); - const float use_max = get_use_max(bnode()); - - GPU_stack_link(material, - &bnode(), - "node_composite_map_value", - inputs, - outputs, - GPU_uniform(texture_mapping.loc), - GPU_uniform(texture_mapping.size), - GPU_constant(&use_min), - GPU_uniform(texture_mapping.min), - GPU_constant(&use_max), - GPU_uniform(texture_mapping.max)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new MapValueShaderNode(node); + const TexMapping &texture_mapping = node_storage(*node); + + const float use_min = get_use_min(*node); + const float use_max = get_use_max(*node); + + return GPU_stack_link(material, + node, + "node_composite_map_value", + inputs, + outputs, + GPU_uniform(texture_mapping.loc), + GPU_uniform(texture_mapping.size), + GPU_constant(&use_min), + GPU_uniform(texture_mapping.min), + GPU_constant(&use_max), + GPU_uniform(texture_mapping.max)); } template @@ -203,7 +192,7 @@ void register_node_type_cmp_map_value() ntype.initfunc = file_ns::node_composit_init_map_value; blender::bke::node_type_storage( &ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_math.cc b/source/blender/nodes/composite/nodes/node_composite_math.cc index 53306e3b4e6..cf9dfc21afd 100644 --- a/source/blender/nodes/composite/nodes/node_composite_math.cc +++ b/source/blender/nodes/composite/nodes/node_composite_math.cc @@ -6,15 +6,15 @@ * \ingroup cmpnodes */ -#include "GPU_material.hh" - -#include "COM_shader_node.hh" - #include "NOD_math_functions.hh" #include "NOD_socket_search_link.hh" #include "RNA_enum_types.hh" +#include "GPU_material.hh" + +#include "COM_utilities_gpu_material.hh" + #include "node_composite_util.hh" /* **************** SCALAR MATH ******************** */ @@ -70,50 +70,42 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) using namespace blender::compositor; -class MathShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - - if (!get_should_clamp()) { - return; - } - - const float min = 0.0f; - const float max = 1.0f; - GPU_link(material, - "clamp_value", - get_output("Value").link, - GPU_constant(&min), - GPU_constant(&max), - &get_output("Value").link); - } - - NodeMathOperation get_operation() - { - return (NodeMathOperation)bnode().custom1; - } - - const char *get_shader_function_name() - { - return get_float_math_operation_info(get_operation())->shader_name.c_str(); - } - - bool get_should_clamp() - { - return bnode().custom2 & SHD_MATH_CLAMP; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static NodeMathOperation get_operation(const bNode &node) { - return new MathShaderNode(node); + return static_cast(node.custom1); +} + +static const char *get_shader_function_name(const bNode &node) +{ + return get_float_math_operation_info(get_operation(node))->shader_name.c_str(); +} + +static bool get_should_clamp(const bNode &node) +{ + return node.custom2 & SHD_MATH_CLAMP; +} + +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) +{ + const bool is_valid = GPU_stack_link( + material, node, get_shader_function_name(*node), inputs, outputs); + + if (!is_valid || !get_should_clamp(*node)) { + return is_valid; + } + + const float min = 0.0f; + const float max = 1.0f; + return GPU_link(material, + "clamp_value", + get_shader_node_output(*node, outputs, "Value").link, + GPU_constant(&min), + GPU_constant(&max), + &get_shader_node_output(*node, outputs, "Value").link); } } // namespace blender::nodes::node_composite_math_cc @@ -132,9 +124,9 @@ void register_node_type_cmp_math() ntype.declare = file_ns::cmp_node_math_declare; ntype.labelfunc = node_math_label; ntype.updatefunc = node_math_update; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; - ntype.build_multi_function = blender::nodes::node_math_build_multi_function; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.gather_link_search_ops = file_ns::node_gather_link_searches; + ntype.build_multi_function = blender::nodes::node_math_build_multi_function; blender::bke::node_register_type(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc b/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc index 6421087045f..afdf15d099d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc +++ b/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc @@ -18,7 +18,7 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" +#include "COM_utilities_gpu_material.hh" #include "NOD_multi_function.hh" #include "NOD_socket_search_link.hh" @@ -90,90 +90,82 @@ static bool get_should_clamp(const bNode &node) return node.custom2 & SHD_MIXRGB_CLAMP; } -class MixRGBShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - if (get_use_alpha(bnode())) { - GPU_link(material, - "multiply_by_alpha", - get_input_link("Fac"), - get_input_link("Image_001"), - &get_input("Fac").link); - } - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - - if (!get_should_clamp(bnode())) { - return; - } - - const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - GPU_link(material, - "clamp_color", - get_output("Image").link, - GPU_constant(min), - GPU_constant(max), - &get_output("Image").link); - } - - const char *get_shader_function_name() - { - switch (get_mode(bnode())) { - 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_EXCLUSION: - return "mix_exclusion"; - 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"; - } - - BLI_assert_unreachable(); - return nullptr; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static const char *get_shader_function_name(const bNode &node) { - return new MixRGBShaderNode(node); + switch (get_mode(node)) { + 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_EXCLUSION: + return "mix_exclusion"; + 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"; + } + + BLI_assert_unreachable(); + return nullptr; +} + +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) +{ + if (get_use_alpha(*node)) { + GPU_link(material, + "multiply_by_alpha", + get_shader_node_input_link(*node, inputs, "Fac"), + get_shader_node_input_link(*node, inputs, "Image_001"), + &get_shader_node_input(*node, inputs, "Fac").link); + } + + const bool is_valid = GPU_stack_link( + material, node, get_shader_function_name(*node), inputs, outputs); + + if (!is_valid || !get_should_clamp(*node)) { + return is_valid; + } + + const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + return GPU_link(material, + "clamp_color", + get_shader_node_output(*node, outputs, "Image").link, + GPU_constant(min), + GPU_constant(max), + &get_shader_node_output(*node, outputs, "Image").link); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -252,8 +244,8 @@ void register_node_type_cmp_mix_rgb() ntype.flag |= NODE_PREVIEW; ntype.declare = file_ns::cmp_node_mixrgb_declare; ntype.labelfunc = node_blend_label; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; ntype.gather_link_search_ops = file_ns::node_gather_link_searches; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_normal.cc b/source/blender/nodes/composite/nodes/node_composite_normal.cc index e6655670014..0c4156ba931 100644 --- a/source/blender/nodes/composite/nodes/node_composite_normal.cc +++ b/source/blender/nodes/composite/nodes/node_composite_normal.cc @@ -11,12 +11,12 @@ #include "FN_multi_function_builder.hh" +#include "BKE_node_runtime.hh" + #include "NOD_multi_function.hh" #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** NORMAL ******************** */ @@ -49,27 +49,18 @@ static float3 get_vector_value(const bNode &node) return math::normalize(node_normal); } -class NormalShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, - &bnode(), - "node_composite_normal", - inputs, - outputs, - GPU_uniform(get_vector_value(bnode()))); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new NormalShaderNode(node); + return GPU_stack_link(material, + node, + "node_composite_normal", + inputs, + outputs, + GPU_uniform(get_vector_value(*node))); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -101,7 +92,7 @@ void register_node_type_cmp_normal() ntype.enum_name_legacy = "NORMAL"; ntype.nclass = NODE_CLASS_OP_VECTOR; ntype.declare = file_ns::cmp_node_normal_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_posterize.cc b/source/blender/nodes/composite/nodes/node_composite_posterize.cc index d821b826426..a1a3c39f998 100644 --- a/source/blender/nodes/composite/nodes/node_composite_posterize.cc +++ b/source/blender/nodes/composite/nodes/node_composite_posterize.cc @@ -16,8 +16,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Posterize ******************** */ @@ -39,22 +37,13 @@ static void cmp_node_posterize_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class PosterizeShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_posterize", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new PosterizeShaderNode(node); + return GPU_stack_link(material, node, "node_composite_posterize", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -84,7 +73,7 @@ void register_node_type_cmp_posterize() ntype.enum_name_legacy = "POSTERIZE"; ntype.nclass = NODE_CLASS_OP_COLOR; ntype.declare = file_ns::cmp_node_posterize_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_premulkey.cc b/source/blender/nodes/composite/nodes/node_composite_premulkey.cc index 9415daedf4b..c84d9ddc41e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_premulkey.cc +++ b/source/blender/nodes/composite/nodes/node_composite_premulkey.cc @@ -17,8 +17,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** Pre-multiply and Key Alpha Convert ******************** */ @@ -45,27 +43,20 @@ static CMPNodeAlphaConvertMode get_mode(const bNode &node) return static_cast(node.custom1); } -class AlphaConvertShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - if (get_mode(bnode()) == CMP_NODE_ALPHA_CONVERT_PREMULTIPLY) { - GPU_stack_link(material, &bnode(), "color_alpha_premultiply", inputs, outputs); - return; - } - - GPU_stack_link(material, &bnode(), "color_alpha_unpremultiply", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new AlphaConvertShaderNode(node); + switch (get_mode(*node)) { + case CMP_NODE_ALPHA_CONVERT_PREMULTIPLY: + return GPU_stack_link(material, node, "color_alpha_premultiply", inputs, outputs); + case CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY: + return GPU_stack_link(material, node, "color_alpha_unpremultiply", inputs, outputs); + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -110,7 +101,7 @@ void register_node_type_cmp_premulkey() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_premulkey_declare; ntype.draw_buttons = file_ns::node_composit_buts_premulkey; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc index 8d5b135d925..adb914fca57 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc @@ -12,8 +12,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" static void node_cmp_combsep_color_init(bNodeTree * /*ntree*/, bNode *node) @@ -91,48 +89,37 @@ static void cmp_node_separate_color_update(bNodeTree * /*ntree*/, bNode *node) using namespace blender::compositor; -class SeparateColorShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - } - - const char *get_shader_function_name() - { - switch (node_storage(bnode()).mode) { - case CMP_NODE_COMBSEP_COLOR_RGB: - return "node_composite_separate_rgba"; - case CMP_NODE_COMBSEP_COLOR_HSV: - return "node_composite_separate_hsva"; - case CMP_NODE_COMBSEP_COLOR_HSL: - return "node_composite_separate_hsla"; - case CMP_NODE_COMBSEP_COLOR_YUV: - return "node_composite_separate_yuva_itu_709"; - case CMP_NODE_COMBSEP_COLOR_YCC: - switch (node_storage(bnode()).ycc_mode) { - case BLI_YCC_ITU_BT601: - return "node_composite_separate_ycca_itu_601"; - case BLI_YCC_ITU_BT709: - return "node_composite_separate_ycca_itu_709"; - case BLI_YCC_JFIF_0_255: - return "node_composite_separate_ycca_jpeg"; - } - } - - BLI_assert_unreachable(); - return nullptr; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateColorShaderNode(node); + switch (node_storage(*node).mode) { + case CMP_NODE_COMBSEP_COLOR_RGB: + return GPU_stack_link(material, node, "node_composite_separate_rgba", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_HSV: + return GPU_stack_link(material, node, "node_composite_separate_hsva", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_HSL: + return GPU_stack_link(material, node, "node_composite_separate_hsla", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_YUV: + return GPU_stack_link( + material, node, "node_composite_separate_yuva_itu_709", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_YCC: + switch (node_storage(*node).ycc_mode) { + case BLI_YCC_ITU_BT601: + return GPU_stack_link( + material, node, "node_composite_separate_ycca_itu_601", inputs, outputs); + case BLI_YCC_ITU_BT709: + return GPU_stack_link( + material, node, "node_composite_separate_ycca_itu_709", inputs, outputs); + case BLI_YCC_JFIF_0_255: + return GPU_stack_link( + material, node, "node_composite_separate_ycca_jpeg", inputs, outputs); + } + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -250,7 +237,7 @@ void register_node_type_cmp_separate_color() blender::bke::node_type_storage( &ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage); ntype.updatefunc = file_ns::cmp_node_separate_color_update; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -299,48 +286,37 @@ static void cmp_node_combine_color_update(bNodeTree * /*ntree*/, bNode *node) using namespace blender::compositor; -class CombineColorShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - } - - const char *get_shader_function_name() - { - switch (node_storage(bnode()).mode) { - case CMP_NODE_COMBSEP_COLOR_RGB: - return "node_composite_combine_rgba"; - case CMP_NODE_COMBSEP_COLOR_HSV: - return "node_composite_combine_hsva"; - case CMP_NODE_COMBSEP_COLOR_HSL: - return "node_composite_combine_hsla"; - case CMP_NODE_COMBSEP_COLOR_YUV: - return "node_composite_combine_yuva_itu_709"; - case CMP_NODE_COMBSEP_COLOR_YCC: - switch (node_storage(bnode()).ycc_mode) { - case BLI_YCC_ITU_BT601: - return "node_composite_combine_ycca_itu_601"; - case BLI_YCC_ITU_BT709: - return "node_composite_combine_ycca_itu_709"; - case BLI_YCC_JFIF_0_255: - return "node_composite_combine_ycca_jpeg"; - } - } - - BLI_assert_unreachable(); - return nullptr; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineColorShaderNode(node); + switch (node_storage(*node).mode) { + case CMP_NODE_COMBSEP_COLOR_RGB: + return GPU_stack_link(material, node, "node_composite_combine_rgba", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_HSV: + return GPU_stack_link(material, node, "node_composite_combine_hsva", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_HSL: + return GPU_stack_link(material, node, "node_composite_combine_hsla", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_YUV: + return GPU_stack_link( + material, node, "node_composite_combine_yuva_itu_709", inputs, outputs); + case CMP_NODE_COMBSEP_COLOR_YCC: + switch (node_storage(*node).ycc_mode) { + case BLI_YCC_ITU_BT601: + return GPU_stack_link( + material, node, "node_composite_combine_ycca_itu_601", inputs, outputs); + case BLI_YCC_ITU_BT709: + return GPU_stack_link( + material, node, "node_composite_combine_ycca_itu_709", inputs, outputs); + case BLI_YCC_JFIF_0_255: + return GPU_stack_link( + material, node, "node_composite_combine_ycca_jpeg", inputs, outputs); + } + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -476,7 +452,7 @@ void register_node_type_cmp_combine_color() blender::bke::node_type_storage( &ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage); ntype.updatefunc = file_ns::cmp_node_combine_color_update; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc index a1c30997b00..903c7fc1137 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc @@ -15,8 +15,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SEPARATE HSVA ******************** */ @@ -36,22 +34,13 @@ static void cmp_node_sephsva_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class SeparateHSVAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_separate_hsva", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateHSVAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_separate_hsva", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -81,7 +70,7 @@ void register_node_type_cmp_sephsva() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_sephsva_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -119,22 +108,13 @@ static void cmp_node_combhsva_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class CombineHSVAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_combine_hsva", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineHSVAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_combine_hsva", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -166,7 +146,7 @@ void register_node_type_cmp_combhsva() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_combhsva_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc index 8895f611318..2961a9c07f7 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc @@ -14,8 +14,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SEPARATE RGBA ******************** */ @@ -35,22 +33,13 @@ static void cmp_node_seprgba_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class SeparateRGBAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_separate_rgba", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateRGBAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_separate_rgba", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -82,7 +71,7 @@ void register_node_type_cmp_seprgba() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_seprgba_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -120,22 +109,13 @@ static void cmp_node_combrgba_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class CombineRGBAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_combine_rgba", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineRGBAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_combine_rgba", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -164,7 +144,7 @@ void register_node_type_cmp_combrgba() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_combrgba_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc index e914823c7f4..f157a50d911 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc @@ -14,8 +14,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SEPARATE XYZ ******************** */ @@ -32,22 +30,13 @@ static void cmp_node_separate_xyz_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class SeparateXYZShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_separate_xyz", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateXYZShaderNode(node); + return GPU_stack_link(material, node, "node_composite_separate_xyz", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -77,7 +66,7 @@ void register_node_type_cmp_separate_xyz() ntype.enum_name_legacy = "SEPARATE_XYZ"; ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_separate_xyz_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -97,22 +86,13 @@ static void cmp_node_combine_xyz_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class CombineXYZShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_combine_xyz", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineXYZShaderNode(node); + return GPU_stack_link(material, node, "node_composite_combine_xyz", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -138,7 +118,7 @@ void register_node_type_cmp_combine_xyz() ntype.enum_name_legacy = "COMBINE_XYZ"; ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_combine_xyz_declare; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc index 3e989765412..aaafb2aa96c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc @@ -16,8 +16,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SEPARATE YCCA ******************** */ @@ -42,42 +40,24 @@ static void node_composit_init_mode_sepycca(bNodeTree * /*ntree*/, bNode *node) using namespace blender::compositor; -class SeparateYCCAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - } - - int get_mode() - { - return bnode().custom1; - } - - const char *get_shader_function_name() - { - switch (get_mode()) { - case BLI_YCC_ITU_BT601: - return "node_composite_separate_ycca_itu_601"; - case BLI_YCC_ITU_BT709: - return "node_composite_separate_ycca_itu_709"; - case BLI_YCC_JFIF_0_255: - return "node_composite_separate_ycca_jpeg"; - } - - BLI_assert_unreachable(); - return nullptr; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateYCCAShaderNode(node); + switch (node->custom1) { + case BLI_YCC_ITU_BT601: + return GPU_stack_link( + material, node, "node_composite_separate_ycca_itu_601", inputs, outputs); + case BLI_YCC_ITU_BT709: + return GPU_stack_link( + material, node, "node_composite_separate_ycca_itu_709", inputs, outputs); + case BLI_YCC_JFIF_0_255: + return GPU_stack_link(material, node, "node_composite_separate_ycca_jpeg", inputs, outputs); + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -144,7 +124,7 @@ void register_node_type_cmp_sepycca() ntype.declare = file_ns::cmp_node_sepycca_declare; ntype.initfunc = file_ns::node_composit_init_mode_sepycca; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -187,42 +167,24 @@ static void node_composit_init_mode_combycca(bNodeTree * /*ntree*/, bNode *node) using namespace blender::compositor; -class CombineYCCAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs); - } - - int get_mode() - { - return bnode().custom1; - } - - const char *get_shader_function_name() - { - switch (get_mode()) { - case BLI_YCC_ITU_BT601: - return "node_composite_combine_ycca_itu_601"; - case BLI_YCC_ITU_BT709: - return "node_composite_combine_ycca_itu_709"; - case BLI_YCC_JFIF_0_255: - return "node_composite_combine_ycca_jpeg"; - } - - BLI_assert_unreachable(); - return nullptr; - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineYCCAShaderNode(node); + switch (node->custom1) { + case BLI_YCC_ITU_BT601: + return GPU_stack_link( + material, node, "node_composite_combine_ycca_itu_601", inputs, outputs); + case BLI_YCC_ITU_BT709: + return GPU_stack_link( + material, node, "node_composite_combine_ycca_itu_709", inputs, outputs); + case BLI_YCC_JFIF_0_255: + return GPU_stack_link(material, node, "node_composite_combine_ycca_jpeg", inputs, outputs); + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -304,7 +266,7 @@ void register_node_type_cmp_combycca() ntype.declare = file_ns::cmp_node_combycca_declare; ntype.initfunc = file_ns::node_composit_init_mode_combycca; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc index 9b9f038d6d1..b9049814903 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc @@ -15,8 +15,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SEPARATE YUVA ******************** */ @@ -36,22 +34,13 @@ static void cmp_node_sepyuva_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class SeparateYUVAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_separate_yuva_itu_709", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SeparateYUVAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_separate_yuva_itu_709", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -81,7 +70,7 @@ void register_node_type_cmp_sepyuva() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_sepyuva_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -119,22 +108,13 @@ static void cmp_node_combyuva_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class CombineYUVAShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - GPU_stack_link(material, &bnode(), "node_composite_combine_yuva_itu_709", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new CombineYUVAShaderNode(node); + return GPU_stack_link(material, node, "node_composite_combine_yuva_itu_709", inputs, outputs); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -166,7 +146,7 @@ void register_node_type_cmp_combyuva() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_combyuva_declare; ntype.gather_link_search_ops = nullptr; - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_setalpha.cc b/source/blender/nodes/composite/nodes/node_composite_setalpha.cc index 114923944cb..97559d6bdaf 100644 --- a/source/blender/nodes/composite/nodes/node_composite_setalpha.cc +++ b/source/blender/nodes/composite/nodes/node_composite_setalpha.cc @@ -17,8 +17,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** SET ALPHA ******************** */ @@ -59,27 +57,20 @@ static CMPNodeSetAlphaMode get_mode(const bNode &node) return static_cast(node_storage(node).mode); } -class SetAlphaShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - if (get_mode(bnode()) == CMP_NODE_SETALPHA_MODE_APPLY) { - GPU_stack_link(material, &bnode(), "node_composite_set_alpha_apply", inputs, outputs); - return; - } - - GPU_stack_link(material, &bnode(), "node_composite_set_alpha_replace", inputs, outputs); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new SetAlphaShaderNode(node); + switch (get_mode(*node)) { + case CMP_NODE_SETALPHA_MODE_APPLY: + return GPU_stack_link(material, node, "node_composite_set_alpha_apply", inputs, outputs); + case CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA: + return GPU_stack_link(material, node, "node_composite_set_alpha_replace", inputs, outputs); + } + + return false; } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -122,7 +113,7 @@ void register_node_type_cmp_setalpha() ntype.initfunc = file_ns::node_composit_init_setalpha; blender::bke::node_type_storage( &ntype, "NodeSetAlpha", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); diff --git a/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc b/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc index 9fcfd22bf96..927724e7702 100644 --- a/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc +++ b/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc @@ -20,8 +20,6 @@ #include "GPU_material.hh" -#include "COM_shader_node.hh" - #include "node_composite_util.hh" /* **************** VALTORGB ******************** */ @@ -52,84 +50,68 @@ static ColorBand *get_color_band(const bNode &node) return static_cast(node.storage); } -class ColorRampShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - ColorBand *color_band = get_color_band(bnode()); - - /* Common / easy case optimization. */ - if ((color_band->tot <= 2) && (color_band->color_mode == COLBAND_BLEND_RGB)) { - float mul_bias[2]; - switch (color_band->ipotype) { - case COLBAND_INTERP_LINEAR: - mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos); - mul_bias[1] = -mul_bias[0] * color_band->data[0].pos; - GPU_stack_link(material, - &bnode(), - "valtorgb_opti_linear", - inputs, - outputs, - GPU_uniform(mul_bias), - GPU_uniform(&color_band->data[0].r), - GPU_uniform(&color_band->data[1].r)); - return; - case COLBAND_INTERP_CONSTANT: - mul_bias[1] = max_ff(color_band->data[0].pos, color_band->data[1].pos); - GPU_stack_link(material, - &bnode(), - "valtorgb_opti_constant", - inputs, - outputs, - GPU_uniform(&mul_bias[1]), - GPU_uniform(&color_band->data[0].r), - GPU_uniform(&color_band->data[1].r)); - return; - case COLBAND_INTERP_EASE: - mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos); - mul_bias[1] = -mul_bias[0] * color_band->data[0].pos; - GPU_stack_link(material, - &bnode(), - "valtorgb_opti_ease", - inputs, - outputs, - GPU_uniform(mul_bias), - GPU_uniform(&color_band->data[0].r), - GPU_uniform(&color_band->data[1].r)); - return; - case COLBAND_INTERP_B_SPLINE: - case COLBAND_INTERP_CARDINAL: - /* Not optimized yet. Fallback to gradient texture. */ - break; - default: - BLI_assert_unreachable(); - return; - } - } - - float *array, layer; - int size; - BKE_colorband_evaluate_table_rgba(color_band, &array, &size); - GPUNodeLink *tex = GPU_color_band(material, size, array, &layer); - - if (color_band->ipotype == COLBAND_INTERP_CONSTANT) { - GPU_stack_link( - material, &bnode(), "valtorgb_nearest", inputs, outputs, tex, GPU_constant(&layer)); - return; - } - - GPU_stack_link(material, &bnode(), "valtorgb", inputs, outputs, tex, GPU_constant(&layer)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new ColorRampShaderNode(node); + ColorBand *color_band = get_color_band(*node); + + /* Common / easy case optimization. */ + if ((color_band->tot <= 2) && (color_band->color_mode == COLBAND_BLEND_RGB)) { + float mul_bias[2]; + switch (color_band->ipotype) { + case COLBAND_INTERP_LINEAR: + mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos); + mul_bias[1] = -mul_bias[0] * color_band->data[0].pos; + return GPU_stack_link(material, + node, + "valtorgb_opti_linear", + inputs, + outputs, + GPU_uniform(mul_bias), + GPU_uniform(&color_band->data[0].r), + GPU_uniform(&color_band->data[1].r)); + case COLBAND_INTERP_CONSTANT: + mul_bias[1] = max_ff(color_band->data[0].pos, color_band->data[1].pos); + return GPU_stack_link(material, + node, + "valtorgb_opti_constant", + inputs, + outputs, + GPU_uniform(&mul_bias[1]), + GPU_uniform(&color_band->data[0].r), + GPU_uniform(&color_band->data[1].r)); + case COLBAND_INTERP_EASE: + mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos); + mul_bias[1] = -mul_bias[0] * color_band->data[0].pos; + return GPU_stack_link(material, + node, + "valtorgb_opti_ease", + inputs, + outputs, + GPU_uniform(mul_bias), + GPU_uniform(&color_band->data[0].r), + GPU_uniform(&color_band->data[1].r)); + case COLBAND_INTERP_B_SPLINE: + case COLBAND_INTERP_CARDINAL: + /* Not optimized yet. Fallback to gradient texture. */ + break; + } + } + + float *array, layer; + int size; + BKE_colorband_evaluate_table_rgba(color_band, &array, &size); + GPUNodeLink *tex = GPU_color_band(material, size, array, &layer); + + if (color_band->ipotype == COLBAND_INTERP_CONSTANT) { + return GPU_stack_link( + material, node, "valtorgb_nearest", inputs, outputs, tex, GPU_constant(&layer)); + } + + return GPU_stack_link(material, node, "valtorgb", inputs, outputs, tex, GPU_constant(&layer)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -164,7 +146,7 @@ void register_node_type_cmp_valtorgb() ntype.initfunc = file_ns::node_composit_init_valtorgb; blender::bke::node_type_storage( &ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype); @@ -184,30 +166,17 @@ static void cmp_node_rgbtobw_declare(NodeDeclarationBuilder &b) using namespace blender::compositor; -class RGBToBWShaderNode : public ShaderNode { - public: - using ShaderNode::ShaderNode; - - void compile(GPUMaterial *material) override - { - GPUNodeStack *inputs = get_inputs_array(); - GPUNodeStack *outputs = get_outputs_array(); - - float luminance_coefficients[3]; - IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); - - GPU_stack_link(material, - &bnode(), - "color_to_luminance", - inputs, - outputs, - GPU_constant(luminance_coefficients)); - } -}; - -static ShaderNode *get_compositor_shader_node(DNode node) +static int node_gpu_material(GPUMaterial *material, + bNode *node, + bNodeExecData * /*execdata*/, + GPUNodeStack *inputs, + GPUNodeStack *outputs) { - return new RGBToBWShaderNode(node); + float luminance_coefficients[3]; + IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); + + return GPU_stack_link( + material, node, "color_to_luminance", inputs, outputs, GPU_constant(luminance_coefficients)); } static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) @@ -240,7 +209,7 @@ void register_node_type_cmp_rgbtobw() ntype.nclass = NODE_CLASS_CONVERTER; ntype.declare = file_ns::cmp_node_rgbtobw_declare; blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::Default); - ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node; + ntype.gpu_fn = file_ns::node_gpu_material; ntype.build_multi_function = file_ns::node_build_multi_function; blender::bke::node_register_type(&ntype);