Blender V4.5
node_composite_gamma.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_vector.hh"
11
12#include "NOD_multi_function.hh"
13
15
16#include "GPU_material.hh"
17
19
20/* **************** Gamma Tools ******************** */
21
23
25{
26 b.add_input<decl::Color>("Image")
27 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .compositor_domain_priority(0);
29 b.add_input<decl::Float>("Gamma")
30 .default_value(1.0f)
31 .min(0.001f)
32 .max(10.0f)
34 .compositor_domain_priority(1)
35 .description(
36 "Gamma correction value, applied as color^gamma.\n"
37 "Typically used to convert from gamma encoded to linear color space, or in the reverse "
38 "direction with 1/gamma");
39 b.add_output<decl::Color>("Image");
40}
41
42using namespace blender::compositor;
43
44static int node_gpu_material(GPUMaterial *material,
45 bNode *node,
46 bNodeExecData * /*execdata*/,
49{
50 return GPU_stack_link(material, node, "node_composite_gamma", inputs, outputs);
51}
52
54{
55 static auto gamma_function = mf::build::SI2_SO<float4, float, float4>(
56 "Gamma",
57 [](const float4 &color, const float gamma) -> float4 {
58 return float4(math::safe_pow(color.xyz(), gamma), color.w);
59 },
60 mf::build::exec_presets::SomeSpanOrSingle<0>());
61 builder.set_matching_fn(gamma_function);
62}
63
64} // namespace blender::nodes::node_composite_gamma_cc
65
67{
69
70 static blender::bke::bNodeType ntype;
71
72 cmp_node_type_base(&ntype, "CompositorNodeGamma", CMP_NODE_GAMMA);
73 ntype.ui_name = "Gamma";
74 ntype.ui_description = "Apply gamma correction";
75 ntype.enum_name_legacy = "GAMMA";
77 ntype.declare = file_ns::cmp_node_gamma_declare;
78 ntype.gpu_fn = file_ns::node_gpu_material;
79 ntype.build_multi_function = file_ns::node_build_multi_function;
80
82}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:435
#define CMP_NODE_GAMMA
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_UNSIGNED
Definition RNA_types.hh:237
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
T safe_pow(const T &x, const T &power)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_gamma_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
VecBase< float, 4 > float4
static void register_node_type_cmp_gamma()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355