Blender V4.3
node_composite_curves.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
9#include "BLI_math_base.h"
10
11#include "BKE_colortools.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "GPU_material.hh"
17
18#include "COM_node_operation.hh"
19#include "COM_shader_node.hh"
20
22
23/* **************** CURVE Time ******************** */
24
26
28{
29 b.add_output<decl::Float>("Fac");
30}
31
32/* custom1 = start_frame, custom2 = end_frame */
33static void node_composit_init_curves_time(bNodeTree * /*ntree*/, bNode *node)
34{
35 node->custom1 = 1;
36 node->custom2 = 250;
37 node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
38}
39
40using namespace blender::realtime_compositor;
41
43 public:
45
46 void execute() override
47 {
48 Result &result = get_result("Fac");
49 result.allocate_single_value();
50
51 CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
52 BKE_curvemapping_init(curve_mapping);
53 const float time = BKE_curvemapping_evaluateF(curve_mapping, 0, compute_normalized_time());
54 result.set_float_value(clamp_f(time, 0.0f, 1.0f));
55 }
56
58 {
59 return static_cast<const CurveMapping *>(bnode().storage);
60 }
61
63 {
64 return bnode().custom1;
65 }
66
68 {
69 return bnode().custom2;
70 }
71
73 {
74 const int frame_number = context().get_frame_number();
75 if (frame_number < get_start_time()) {
76 return 0.0f;
77 }
78 if (frame_number > get_end_time()) {
79 return 1.0f;
80 }
81 if (get_start_time() == get_end_time()) {
82 return 0.0f;
83 }
84 return float(frame_number - get_start_time()) / float(get_end_time() - get_start_time());
85 }
86};
87
89{
90 return new TimeCurveOperation(context, node);
91}
92
93} // namespace blender::nodes::node_composite_time_curves_cc
94
96{
98
99 static blender::bke::bNodeType ntype;
100
101 cmp_node_type_base(&ntype, CMP_NODE_TIME, "Time Curve", NODE_CLASS_INPUT);
102 ntype.declare = file_ns::cmp_node_time_declare;
103 blender::bke::node_type_size(&ntype, 200, 140, 320);
104 ntype.initfunc = file_ns::node_composit_init_curves_time;
106 ntype.get_compositor_operation = file_ns::get_compositor_operation;
107
109}
110
111/* **************** CURVE VEC ******************** */
112
114
116{
117 b.add_input<decl::Vector>("Vector")
118 .default_value({0.0f, 0.0f, 0.0f})
119 .min(-1.0f)
120 .max(1.0f)
122 b.add_output<decl::Vector>("Vector");
123}
124
125static void node_composit_init_curve_vec(bNodeTree * /*ntree*/, bNode *node)
126{
127 node->storage = BKE_curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
128}
129
130static void node_buts_curvevec(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
131{
132 uiTemplateCurveMapping(layout, ptr, "mapping", 'v', false, false, false, false);
133}
134
135using namespace blender::realtime_compositor;
136
138 public:
140
141 void compile(GPUMaterial *material) override
142 {
143 GPUNodeStack *inputs = get_inputs_array();
144 GPUNodeStack *outputs = get_outputs_array();
145
146 CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
147
148 BKE_curvemapping_init(curve_mapping);
149 float *band_values;
150 int band_size;
151 BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size);
152 float band_layer;
153 GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer);
154
155 float start_slopes[CM_TOT];
156 float end_slopes[CM_TOT];
157 BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes);
158 float range_minimums[CM_TOT];
159 BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums);
160 float range_dividers[CM_TOT];
161 BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers);
162
163 GPU_stack_link(material,
164 &bnode(),
165 "curves_vector",
166 inputs,
167 outputs,
168 band_texture,
169 GPU_constant(&band_layer),
170 GPU_uniform(range_minimums),
171 GPU_uniform(range_dividers),
172 GPU_uniform(start_slopes),
173 GPU_uniform(end_slopes));
174 }
175
177 {
178 return static_cast<const CurveMapping *>(bnode().storage);
179 }
180};
181
183{
184 return new VectorCurvesShaderNode(node);
185}
186
187} // namespace blender::nodes::node_composite_vector_curves_cc
188
190{
192
193 static blender::bke::bNodeType ntype;
194
195 cmp_node_type_base(&ntype, CMP_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR);
196 ntype.declare = file_ns::cmp_node_curve_vec_declare;
197 ntype.draw_buttons = file_ns::node_buts_curvevec;
198 blender::bke::node_type_size(&ntype, 200, 140, 320);
199 ntype.initfunc = file_ns::node_composit_init_curve_vec;
201 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
202
204}
205
206/* **************** CURVE RGB ******************** */
207
209
211{
212 b.add_input<decl::Float>("Fac")
213 .default_value(1.0f)
214 .min(-1.0f)
215 .max(1.0f)
217 .compositor_domain_priority(1)
218 .description("Amount of influence the node exerts on the image");
219 b.add_input<decl::Color>("Image")
220 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
221 .compositor_domain_priority(0)
222 .description("Image/Color input on which RGB color transformation will be applied");
223 b.add_input<decl::Color>("Black Level")
224 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
225 .description("Input color that should be mapped to black");
226 b.add_input<decl::Color>("White Level")
227 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
228 .description("Input color that should be mapped to white");
229 b.add_output<decl::Color>("Image");
230}
231
232static void node_composit_init_curve_rgb(bNodeTree * /*ntree*/, bNode *node)
233{
234 node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
235}
236
237using namespace blender::realtime_compositor;
238
240 public:
242
243 void compile(GPUMaterial *material) override
244 {
245 GPUNodeStack *inputs = get_inputs_array();
246 GPUNodeStack *outputs = get_outputs_array();
247
248 CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
249
250 BKE_curvemapping_init(curve_mapping);
251 float *band_values;
252 int band_size;
253 BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size);
254 float band_layer;
255 GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer);
256
257 float start_slopes[CM_TOT];
258 float end_slopes[CM_TOT];
259 BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes);
260 float range_minimums[CM_TOT];
261 BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums);
262 float range_dividers[CM_TOT];
263 BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers);
264
265 if (curve_mapping->tone == CURVE_TONE_FILMLIKE) {
266 GPU_stack_link(material,
267 &bnode(),
268 "curves_film_like",
269 inputs,
270 outputs,
271 band_texture,
272 GPU_constant(&band_layer),
273 GPU_uniform(&range_minimums[3]),
274 GPU_uniform(&range_dividers[3]),
275 GPU_uniform(&start_slopes[3]),
276 GPU_uniform(&end_slopes[3]));
277 return;
278 }
279
280 const float min = 0.0f;
281 const float max = 1.0f;
282 GPU_link(material,
283 "clamp_value",
284 get_input_link("Fac"),
286 GPU_constant(&max),
287 &get_input("Fac").link);
288
289 /* If the RGB curves do nothing, use a function that skips RGB computations. */
290 if (BKE_curvemapping_is_map_identity(curve_mapping, 0) &&
291 BKE_curvemapping_is_map_identity(curve_mapping, 1) &&
292 BKE_curvemapping_is_map_identity(curve_mapping, 2))
293 {
294 GPU_stack_link(material,
295 &bnode(),
296 "curves_combined_only",
297 inputs,
298 outputs,
299 band_texture,
300 GPU_constant(&band_layer),
301 GPU_uniform(&range_minimums[3]),
302 GPU_uniform(&range_dividers[3]),
303 GPU_uniform(&start_slopes[3]),
304 GPU_uniform(&end_slopes[3]));
305 return;
306 }
307
308 GPU_stack_link(material,
309 &bnode(),
310 "curves_combined_rgb",
311 inputs,
312 outputs,
313 band_texture,
314 GPU_constant(&band_layer),
315 GPU_uniform(range_minimums),
316 GPU_uniform(range_dividers),
317 GPU_uniform(start_slopes),
318 GPU_uniform(end_slopes));
319 }
320
322 {
323 return static_cast<const CurveMapping *>(bnode().storage);
324 }
325};
326
328{
329 return new RGBCurvesShaderNode(node);
330}
331
332} // namespace blender::nodes::node_composite_rgb_curves_cc
333
335{
337
338 static blender::bke::bNodeType ntype;
339
340 cmp_node_type_base(&ntype, CMP_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR);
341 ntype.declare = file_ns::cmp_node_rgbcurves_declare;
342 blender::bke::node_type_size(&ntype, 200, 140, 320);
343 ntype.initfunc = file_ns::node_composit_init_curve_rgb;
345 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
346
348}
void BKE_curvemapping_compute_range_dividers(const CurveMapping *curve_mapping, float dividers[4])
void BKE_curvemapping_get_range_minimums(const CurveMapping *curve_mapping, float minimums[4])
bool BKE_curvemapping_is_map_identity(const CurveMapping *curve_mapping, int index)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_init(CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:90
void BKE_curvemapping_table_RGBA(const CurveMapping *cumap, float **array, int *size)
void BKE_curvemapping_compute_slopes(const CurveMapping *curve_mapping, float start_slopes[4], float end_slopes[4])
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:407
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
MINLINE float clamp_f(float value, float min, float max)
#define CM_TOT
@ CURVE_TONE_FILMLIKE
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row)
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_uniform(const float *num)
@ PROP_FACTOR
Definition RNA_types.hh:154
void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, const char *propname, int type, bool levels, bool brush, bool neg_slope, bool tone)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:46
GPUNodeLink * get_input_link(StringRef identifier)
GPUNodeStack & get_input(StringRef identifier)
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition node.cc:4602
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static ShaderNode * get_compositor_shader_node(DNode node)
static void cmp_node_rgbcurves_declare(NodeDeclarationBuilder &b)
static void node_composit_init_curve_rgb(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_time_declare(NodeDeclarationBuilder &b)
static void node_composit_init_curves_time(bNodeTree *, bNode *node)
static ShaderNode * get_compositor_shader_node(DNode node)
static void node_buts_curvevec(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_composit_init_curve_vec(bNodeTree *, bNode *node)
static void cmp_node_curve_vec_declare(NodeDeclarationBuilder &b)
void register_node_type_cmp_curve_rgb()
void register_node_type_cmp_curve_time()
void register_node_type_cmp_curve_vec()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_curves(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:53
void node_free_curves(bNode *node)
Definition node_util.cc:41
#define min(a, b)
Definition sort.c:32
int16_t custom1
void * storage
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328
PointerRNA * ptr
Definition wm_files.cc:4126