Blender V5.0
node_shader_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
5#include "node_shader_util.hh"
6
7#include "BLI_math_vector.hh"
9
11
12#include "NOD_multi_function.hh"
14
16{
17 b.use_custom_socket_order();
18 b.allow_any_socket_order();
19 b.is_function_node();
20 b.add_input<decl::Color>("Color")
21 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
22 .hide_value()
23 .description("Color input on which correction will be applied");
24 b.add_output<decl::Color>("Color").align_with_previous();
25
26 b.add_input<decl::Float>("Gamma")
27 .default_value(1.0f)
28 .min(0.001f)
29 .max(10.0f)
31 .description(
32 "Gamma correction value, applied as color^gamma.\n"
33 "Gamma controls the relative intensity of the mid-tones compared to the full black and "
34 "full white");
35}
36
38 bNode *node,
39 bNodeExecData * /*execdata*/,
42{
43 return GPU_stack_link(mat, node, "node_gamma", in, out);
44}
45
46using namespace blender::math;
47
49{
50 static auto fn = mf::build::SI2_SO<ColorGeometry4f, float, ColorGeometry4f>(
51 "Gamma",
52 [](const ColorGeometry4f &color, const float gamma) -> ColorGeometry4f {
53 const float3 rgb = float3(color.r, color.g, color.b);
54 const float3 rgb_gamma = math::safe_pow(rgb, gamma);
55 return ColorGeometry4f(rgb_gamma.x, rgb_gamma.y, rgb_gamma.z, color.a);
56 },
57 mf::build::exec_presets::SomeSpanOrSingle<0>());
58 builder.set_matching_fn(fn);
59}
60
62#ifdef WITH_MATERIALX
63{
64 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
65 NodeItem gamma = get_input_value("Gamma", NodeItem::Type::Float);
66 return color ^ gamma;
67}
68#endif
70
71} // namespace blender::nodes::node_shader_gamma_cc
72
74{
75 namespace file_ns = blender::nodes::node_shader_gamma_cc;
76
77 static blender::bke::bNodeType ntype;
78
79 common_node_type_base(&ntype, "ShaderNodeGamma", SH_NODE_GAMMA);
80 ntype.ui_name = "Gamma";
81 ntype.ui_description = "Apply a gamma correction";
82 ntype.enum_name_legacy = "GAMMA";
84 ntype.declare = file_ns::node_declare;
85 ntype.gpu_fn = file_ns::node_shader_gpu_gamma;
86 ntype.build_multi_function = file_ns::node_build_multi_function;
87 ntype.materialx_fn = file_ns::node_shader_materialx;
88
90}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define SH_NODE_GAMMA
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_NONE
Definition RNA_types.hh:233
void set_matching_fn(const mf::MultiFunction *fn)
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
T safe_pow(const T &x, const T &power)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_gamma()
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362