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