2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "BLI_string_ref.hh"
|
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
2024-02-01 10:40:24 -05:00
|
|
|
#include "GPU_material.hh"
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
#include "NOD_derived_node_tree.hh"
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
namespace blender::compositor {
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
using namespace nodes::derived_node_tree_types;
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
|
* Shader Node
|
|
|
|
|
*
|
|
|
|
|
* A shader node encapsulates a compositor node tree that is capable of being used together with
|
|
|
|
|
* other shader nodes to construct a Shader Operation using the GPU material compiler. A GPU node
|
|
|
|
|
* stack for each of the node inputs and outputs is stored and populated during construction in
|
2024-02-01 10:40:24 -05:00
|
|
|
* order to represent the node as a GPU node inside the GPU material graph, see GPU_material.hh for
|
2025-03-18 11:23:43 +02:00
|
|
|
* more information. The compiler is expected to initialize the input links of the node inputs
|
|
|
|
|
* before invoking the compile method. See the discussion in COM_shader_operation.hh for more
|
|
|
|
|
* information. */
|
2022-08-10 09:14:22 +02:00
|
|
|
class ShaderNode {
|
|
|
|
|
private:
|
|
|
|
|
/* The node that this operation represents. */
|
|
|
|
|
DNode node_;
|
|
|
|
|
/* The GPU node stacks of the inputs of the node. Those are populated during construction in the
|
|
|
|
|
* populate_inputs method. The links of the inputs are initialized by the GPU material compiler
|
|
|
|
|
* prior to calling the compile method. There is an extra stack at the end to mark the end of the
|
|
|
|
|
* array, as this is what the GPU module functions expect. */
|
|
|
|
|
Vector<GPUNodeStack> inputs_;
|
|
|
|
|
/* The GPU node stacks of the outputs of the node. Those are populated during construction in the
|
|
|
|
|
* populate_outputs method. There is an extra stack at the end to mark the end of the array, as
|
|
|
|
|
* this is what the GPU module functions expect. */
|
|
|
|
|
Vector<GPUNodeStack> outputs_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/* Construct the node by populating both its inputs and outputs. */
|
|
|
|
|
ShaderNode(DNode node);
|
|
|
|
|
|
|
|
|
|
/* Compile the node by adding the appropriate GPU material graph nodes and linking the
|
|
|
|
|
* appropriate resources. */
|
2025-02-10 11:51:57 +01:00
|
|
|
void compile(GPUMaterial *material);
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
/* Returns the GPU node stack of the input with the given identifier. */
|
2025-02-14 14:32:57 -05:00
|
|
|
GPUNodeStack &get_input(StringRef identifier);
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
/* Returns the GPU node stack of the output with the given identifier. */
|
2025-02-14 14:32:57 -05:00
|
|
|
GPUNodeStack &get_output(StringRef identifier);
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* Populate the inputs of the node. The input link is set to nullptr and is expected to be
|
|
|
|
|
* initialized by the GPU material compiler before calling the compile method. */
|
|
|
|
|
void populate_inputs();
|
|
|
|
|
/* Populate the outputs of the node. The output link is set to nullptr and is expected to be
|
|
|
|
|
* initialized by the compile method. */
|
|
|
|
|
void populate_outputs();
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
} // namespace blender::compositor
|