Blender V4.3
node_composite_val_to_rgb.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_assert.h"
10
12
13#include "BKE_colorband.hh"
14
15#include "GPU_material.hh"
16
17#include "COM_shader_node.hh"
18
20
21/* **************** VALTORGB ******************** */
22
24
26{
27 b.add_input<decl::Float>("Fac")
28 .default_value(0.5f)
29 .min(0.0f)
30 .max(1.0f)
32 .compositor_domain_priority(1);
33 b.add_output<decl::Color>("Image").compositor_domain_priority(0);
34 b.add_output<decl::Float>("Alpha");
35}
36
37static void node_composit_init_valtorgb(bNodeTree * /*ntree*/, bNode *node)
38{
39 node->storage = BKE_colorband_add(true);
40}
41
42using namespace blender::realtime_compositor;
43
45 public:
47
48 void compile(GPUMaterial *material) override
49 {
52
53 ColorBand *color_band = get_color_band();
54
55 /* Common / easy case optimization. */
56 if ((color_band->tot <= 2) && (color_band->color_mode == COLBAND_BLEND_RGB)) {
57 float mul_bias[2];
58 switch (color_band->ipotype) {
60 mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos);
61 mul_bias[1] = -mul_bias[0] * color_band->data[0].pos;
62 GPU_stack_link(material,
63 &bnode(),
64 "valtorgb_opti_linear",
65 inputs,
66 outputs,
67 GPU_uniform(mul_bias),
68 GPU_uniform(&color_band->data[0].r),
69 GPU_uniform(&color_band->data[1].r));
70 return;
72 mul_bias[1] = max_ff(color_band->data[0].pos, color_band->data[1].pos);
73 GPU_stack_link(material,
74 &bnode(),
75 "valtorgb_opti_constant",
76 inputs,
77 outputs,
78 GPU_uniform(&mul_bias[1]),
79 GPU_uniform(&color_band->data[0].r),
80 GPU_uniform(&color_band->data[1].r));
81 return;
83 mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos);
84 mul_bias[1] = -mul_bias[0] * color_band->data[0].pos;
85 GPU_stack_link(material,
86 &bnode(),
87 "valtorgb_opti_ease",
88 inputs,
89 outputs,
90 GPU_uniform(mul_bias),
91 GPU_uniform(&color_band->data[0].r),
92 GPU_uniform(&color_band->data[1].r));
93 return;
96 /* Not optimized yet. Fallback to gradient texture. */
97 break;
98 default:
100 return;
101 }
102 }
103
104 float *array, layer;
105 int size;
106 BKE_colorband_evaluate_table_rgba(color_band, &array, &size);
107 GPUNodeLink *tex = GPU_color_band(material, size, array, &layer);
108
109 if (color_band->ipotype == COLBAND_INTERP_CONSTANT) {
111 material, &bnode(), "valtorgb_nearest", inputs, outputs, tex, GPU_constant(&layer));
112 return;
113 }
114
115 GPU_stack_link(material, &bnode(), "valtorgb", inputs, outputs, tex, GPU_constant(&layer));
116 }
117
119 {
120 return static_cast<ColorBand *>(bnode().storage);
121 }
122};
123
125{
126 return new ColorRampShaderNode(node);
127}
128
129} // namespace blender::nodes::node_composite_color_ramp_cc
130
132{
134
135 static blender::bke::bNodeType ntype;
136
137 cmp_node_type_base(&ntype, CMP_NODE_VALTORGB, "Color Ramp", NODE_CLASS_CONVERTER);
138 ntype.declare = file_ns::cmp_node_valtorgb_declare;
139 blender::bke::node_type_size(&ntype, 240, 200, 320);
140 ntype.initfunc = file_ns::node_composit_init_valtorgb;
143 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
144
146}
147
148/* **************** RGBTOBW ******************** */
149
151
153{
154 b.add_input<decl::Color>("Image")
155 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
156 .compositor_domain_priority(0);
157 b.add_output<decl::Float>("Val");
158}
159
160using namespace blender::realtime_compositor;
161
163 public:
165
166 void compile(GPUMaterial *material) override
167 {
168 GPUNodeStack *inputs = get_inputs_array();
169 GPUNodeStack *outputs = get_outputs_array();
170
171 float luminance_coefficients[3];
173
174 GPU_stack_link(material,
175 &bnode(),
176 "color_to_luminance",
177 inputs,
178 outputs,
179 GPU_constant(luminance_coefficients));
180 }
181};
182
184{
185 return new RGBToBWShaderNode(node);
186}
187
188} // namespace blender::nodes::node_composite_rgb_to_bw_cc
189
191{
193
194 static blender::bke::bNodeType ntype;
195
196 cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER);
197 ntype.declare = file_ns::cmp_node_rgbtobw_declare;
199 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
200
202}
void BKE_colorband_evaluate_table_rgba(const ColorBand *coba, float **array, int *size)
Definition colorband.cc:559
ColorBand * BKE_colorband_add(bool rangetype)
Definition colorband.cc:298
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
MINLINE float max_ff(float a, float b)
@ COLBAND_BLEND_RGB
@ COLBAND_INTERP_LINEAR
@ COLBAND_INTERP_CONSTANT
@ COLBAND_INTERP_B_SPLINE
@ COLBAND_INTERP_EASE
@ COLBAND_INTERP_CARDINAL
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)
GPUNodeLink * GPU_uniform(const float *num)
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
@ PROP_FACTOR
Definition RNA_types.hh:154
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
local_group_size(16, 16) .push_constant(Type b
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
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 void cmp_node_valtorgb_declare(NodeDeclarationBuilder &b)
static void node_composit_init_valtorgb(bNodeTree *, bNode *node)
static void cmp_node_rgbtobw_declare(NodeDeclarationBuilder &b)
static ShaderNode * get_compositor_shader_node(DNode node)
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void register_node_type_cmp_valtorgb()
void register_node_type_cmp_rgbtobw()
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
CBData data[32]
void * storage
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328