Blender V5.3
drawnode.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#include "BLI_color_types.hh"
11#include "BLI_listbase.hh"
12#include "BLI_string_utf8.hh"
13#include "BLI_threads.hh"
14
15#include "DNA_node_types.h"
16#include "DNA_screen_types.h"
17#include "DNA_space_types.h"
18#include "DNA_userdef_types.h"
19
20#include "BKE_context.hh"
21#include "BKE_curve.hh"
22#include "BKE_image.hh"
23#include "BKE_main.hh"
25#include "BKE_node.hh"
26#include "BKE_node_enum.hh"
28#include "BKE_node_runtime.hh"
30#include "BKE_scene.hh"
31
32#include "BLT_translation.hh"
33
34#include "BIF_glutil.hh"
35
36#include "GPU_batch.hh"
37#include "GPU_batch_presets.hh"
38#include "GPU_framebuffer.hh"
39#include "GPU_immediate.hh"
40#include "GPU_matrix.hh"
41#include "GPU_shader_shared.hh"
42#include "GPU_state.hh"
43#include "GPU_uniform_buffer.hh"
44#include "GPU_viewport.hh"
45
46#include "DRW_engine.hh"
47
48#include "RNA_access.hh"
49#include "RNA_define.hh"
50#include "RNA_prototypes.hh"
51
52#include "ED_node.hh"
53#include "ED_space_api.hh"
54
55#include "WM_api.hh"
56#include "WM_types.hh"
57
58#include "UI_interface.hh"
59#include "UI_resources.hh"
60#include "UI_view2d.hh"
61
63#include "IMB_imbuf_types.hh"
64
65#include "NOD_geometry.hh"
69#include "NOD_socket.hh"
71#include "node_intern.hh" /* own include */
72
73namespace blender {
74
75namespace ed::space_node {
76
77/* Default flags for Layout::prop(). Name is kept short since this is used a lot in this file. */
78#define DEFAULT_FLAGS ui::ITEM_R_SPLIT_EMPTY_NAME
79
80/* -------------------------------------------------------------------- */
83
85 ui::Layout *layout,
86 PointerRNA * /*ptr*/,
87 PointerRNA * /*node_ptr*/,
88 const StringRef text)
89{
90 layout->label(text, ICON_NONE);
91}
92
94
95/* -------------------------------------------------------------------- */
98
99static void node_buts_mix_rgb(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
100{
101 bNodeTree *ntree = id_cast<bNodeTree *>(ptr->owner_id);
102
103 ui::Layout &col = layout.column(false);
104 ui::Layout &row = col.row(true);
105 row.prop(ptr, "blend_type", DEFAULT_FLAGS, "", ICON_NONE);
106 if (ELEM(ntree->type, NTREE_COMPOSIT, NTREE_TEXTURE)) {
107 row.prop(ptr, "use_alpha", DEFAULT_FLAGS, "", ICON_IMAGE_RGB_ALPHA);
108 }
109
110 col.prop(ptr, "use_clamp", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
111}
112
113static void node_buts_time(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
114{
115 template_curve_mapping(&layout, ptr, "curve", 's', false, false, false, false, false);
116}
117
118static void node_buts_colorramp(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
119{
120 template_color_ramp(&layout, ptr, "color_ramp", false);
121}
122
123static void node_buts_curvevec(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
124{
125 template_curve_mapping(&layout, ptr, "mapping", 'v', false, false, false, false, false);
126}
127
128static void node_buts_curvefloat(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
129{
130 template_curve_mapping(&layout, ptr, "mapping", 0, false, false, false, false, false);
131}
132
133} // namespace ed::space_node
134
135#define SAMPLE_FLT_ISNONE FLT_MAX
136/* Bad! 2.5 will do better? ... no it won't! */
137static float _sample_col[4] = {SAMPLE_FLT_ISNONE};
138void ED_node_sample_set(const float col[4])
139{
140 if (col) {
142 }
143 else {
145 }
146}
147
148namespace ed::space_node {
149
150static void node_buts_curvecol(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
151{
152 bNode *node = static_cast<bNode *>(ptr->data);
153 CurveMapping *cumap = static_cast<CurveMapping *>(node->storage);
154
155 if (_sample_col[0] != SAMPLE_FLT_ISNONE) {
156 cumap->flag |= CUMA_DRAW_SAMPLE;
158 }
159 else {
160 cumap->flag &= ~CUMA_DRAW_SAMPLE;
161 }
162
163 /* "Tone" (Standard/Film-like) only used in the Compositor. */
164 bNodeTree *ntree = id_cast<bNodeTree *>(ptr->owner_id);
165 template_curve_mapping(
166 &layout, ptr, "mapping", 'c', false, false, false, (ntree->type == NTREE_COMPOSIT), false);
167}
168
169static void node_buts_normal(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
170{
171 bNode *node = static_cast<bNode *>(ptr->data);
172 /* first output stores normal */
173 bNodeSocket *output = node->outputs.first();
174 PointerRNA sockptr = RNA_pointer_create_discrete(ptr->owner_id, RNA_NodeSocket, output);
175
176 layout.prop(&sockptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
177}
178
180{
181 bNode *node = static_cast<bNode *>(ptr->data);
182
183 short multi = (node->id && (id_cast<Tex *>(node->id))->use_nodes &&
184 (node->type_legacy != TEX_NODE_TEXTURE));
185
186 template_id(&layout, C, ptr, "texture", "texture.new", nullptr, nullptr);
187
188 if (multi) {
189 /* Number Drawing not optimal here, better have a list. */
190 layout.prop(ptr, "node_output", DEFAULT_FLAGS, "", ICON_NONE);
191 }
192}
193
194static void node_buts_math(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
195{
196 layout.prop(ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
197 layout.prop(ptr, "use_clamp", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
198}
199
200static void node_buts_combsep_color(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
201{
202 layout.prop(ptr, "mode", DEFAULT_FLAGS, "", ICON_NONE);
203}
204
206
207/* -------------------------------------------------------------------- */
210
212 const bNode *node,
213 const int x,
214 const int y)
215{
216 const bool node_is_collapsed = node->flag & NODE_COLLAPSED;
217 const float size = NODE_RESIZE_MARGIN * math::max(snode.runtime->aspect, 1.0f) *
218 (node_is_collapsed ? 3.0f : 1.0f);
219
220 if (node->is_frame()) {
221 NodeFrame *data = static_cast<NodeFrame *>(node->storage);
222
223 /* shrinking frame size is determined by child nodes */
224 if (!(data->flag & NODE_FRAME_RESIZEABLE)) {
225 return NODE_RESIZE_NONE;
226 }
227
229
230 const rctf &bounds = node->runtime->draw_bounds;
231
232 if (x > bounds.xmax - size && x <= bounds.xmax && y >= bounds.ymin && y < bounds.ymax) {
233 dir |= NODE_RESIZE_RIGHT;
234 }
235 if (x >= bounds.xmin && x < bounds.xmin + size && y >= bounds.ymin && y < bounds.ymax) {
236 dir |= NODE_RESIZE_LEFT;
237 }
238 if (x >= bounds.xmin && x < bounds.xmax && y >= bounds.ymax - size && y < bounds.ymax) {
239 dir |= NODE_RESIZE_TOP;
240 }
241 if (x >= bounds.xmin && x < bounds.xmax && y >= bounds.ymin && y < bounds.ymin + size) {
242 dir |= NODE_RESIZE_BOTTOM;
243 }
244
245 return dir;
246 }
247
248 const rctf &bounds = node->runtime->draw_bounds;
250
251 if (x >= bounds.xmax - size && x < bounds.xmax && y >= bounds.ymin && y < bounds.ymax) {
252 dir |= NODE_RESIZE_RIGHT;
253 }
254 if (x >= bounds.xmin && x < bounds.xmin + size && y >= bounds.ymin && y < bounds.ymax) {
255 dir |= NODE_RESIZE_LEFT;
256
257 if (node_is_collapsed) {
258 /* Prevent conflict with the collapse/expand icon. */
259 if ((abs(y - BLI_rctf_cent_y(&bounds)) < 0.4f * U.widget_unit) &&
260 (x > (bounds.xmin + 0.4f * U.widget_unit)))
261 {
262 dir = NODE_RESIZE_NONE;
263 }
264 }
265 }
266 return dir;
267}
268
270
271/* -------------------------------------------------------------------- */
274
276{
277 template_id_browse(&layout, C, ptr, "node_tree", nullptr, nullptr, nullptr);
278}
279
280static void node_buts_frame_ex(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
281{
282 layout.prop(ptr, "label_size", DEFAULT_FLAGS, IFACE_("Label Size"), ICON_NONE);
283 layout.prop(ptr, "shrink", DEFAULT_FLAGS, IFACE_("Shrink"), ICON_NONE);
284 layout.prop(ptr, "text", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
285}
286
288{
289 switch (ntype->type_legacy) {
290 case NODE_GROUP:
292 break;
293 case NODE_FRAME:
295 break;
296 }
297}
298
300
301/* -------------------------------------------------------------------- */
304
306 bContext *C,
307 PointerRNA *ptr,
308 PointerRNA *imaptr,
309 PointerRNA *iuserptr,
310 const bool show_layer_selection,
311 const bool show_color_management)
312{
313 Image *image = static_cast<Image *>(imaptr->data);
314 if (!image) {
315 return;
316 }
317 ImageUser *iuser = static_cast<ImageUser *>(iuserptr->data);
318
319 ui::Layout &source_col = layout.column(false);
320
321 source_col.prop(imaptr, "source", DEFAULT_FLAGS, "", ICON_NONE);
322
323 const int source = RNA_enum_get(imaptr, "source");
324
325 if (source == IMA_SRC_SEQUENCE) {
326 /* don't use iuser->framenr directly
327 * because it may not be updated if auto-refresh is off */
328 Scene *scene = CTX_data_scene(C);
329
330 char numstr[32];
331 const int framenr = BKE_image_user_frame_get(iuser, scene->r.cfra, nullptr);
332 SNPRINTF_UTF8(numstr, IFACE_("Frame: %d"), framenr);
333 layout.label(numstr, ICON_NONE);
334 }
335
336 if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
337 ui::Layout &col = layout.column(true);
338 col.prop(ptr, "frame_duration", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
339 col.prop(ptr, "frame_start", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
340 col.prop(ptr, "frame_offset", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
341 col.prop(ptr, "use_cyclic", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
342 col.prop(ptr, "use_auto_refresh", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
343 }
344
345 if (show_layer_selection && RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER &&
346 RNA_boolean_get(ptr, "has_layers"))
347 {
348 ui::Layout &col = layout.column(false);
349 col.prop(ptr, "layer", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
350 }
351
352 if (show_color_management) {
353 ui::Layout &split = layout.split(0.33f, true);
354 PointerRNA colorspace_settings_ptr = RNA_pointer_get(imaptr, "colorspace_settings");
355 split.label(IFACE_("Color Space"), ICON_NONE);
356 split.prop_with_menu(&colorspace_settings_ptr,
357 "name",
359 "",
360 ICON_NONE,
361 "UI_MT_color_space_select");
362
363 if (image->source != IMA_SRC_GENERATED) {
364 ui::Layout &split_2 = layout.split(0.33f, true);
365 split_2.label(IFACE_("Alpha"), ICON_NONE);
366 split_2.prop(imaptr, "alpha_mode", DEFAULT_FLAGS, "", ICON_NONE);
367
368 bool is_data = IMB_colormanagement_space_name_is_data(image->colorspace_settings.name);
369 split_2.active_set(!is_data);
370 }
371
372 /* Avoid losing changes image is painted. */
373 if (BKE_image_is_dirty(static_cast<Image *>(imaptr->data))) {
374 split.enabled_set(false);
375 }
376 }
377}
378
380{
381 PointerRNA imaptr = RNA_pointer_get(ptr, "image");
382 PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
383
384 layout.context_ptr_set("image_user", &iuserptr);
385 template_id(&layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
386 layout.prop(ptr, "interpolation", DEFAULT_FLAGS, "", ICON_NONE);
387 layout.prop(ptr, "projection", DEFAULT_FLAGS, "", ICON_NONE);
388
389 if (RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX) {
390 layout.prop(ptr, "projection_blend", DEFAULT_FLAGS, IFACE_("Blend"), ICON_NONE);
391 }
392
393 layout.prop(ptr, "extension", DEFAULT_FLAGS, "", ICON_NONE);
394
395 /* NOTE: image user properties used directly here, unlike compositor image node,
396 * which redefines them in the node struct RNA to get proper updates.
397 */
398 node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false, true);
399}
400
402{
403 PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
404 uiTemplateImage(&layout, C, ptr, "image", &iuserptr, false, false);
405}
406
408{
409 PointerRNA imaptr = RNA_pointer_get(ptr, "image");
410 PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
411
412 layout.context_ptr_set("image_user", &iuserptr);
413 template_id(&layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
414
415 layout.prop(ptr, "interpolation", DEFAULT_FLAGS, "", ICON_NONE);
416 layout.prop(ptr, "projection", DEFAULT_FLAGS, "", ICON_NONE);
417
418 node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false, true);
419}
420
422{
423 PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
424 uiTemplateImage(&layout, C, ptr, "image", &iuserptr, false, false);
425
426 layout.prop(ptr, "interpolation", DEFAULT_FLAGS, IFACE_("Interpolation"), ICON_NONE);
427 layout.prop(ptr, "projection", DEFAULT_FLAGS, IFACE_("Projection"), ICON_NONE);
428}
429
431{
432 layout.prop(ptr, "space", DEFAULT_FLAGS, "", ICON_NONE);
433}
434
435static void node_shader_buts_glossy(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
436{
437 layout.prop(ptr, "distribution", DEFAULT_FLAGS, "", ICON_NONE);
438}
439
440static void node_buts_output_shader(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
441{
442 layout.prop(ptr, "target", DEFAULT_FLAGS, "", ICON_NONE);
443}
444
445static void node_shader_buts_scatter(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
446{
447 layout.prop(ptr, "phase", DEFAULT_FLAGS, "", ICON_NONE);
448}
449
450/* only once called */
452{
453 switch (ntype->type_legacy) {
454 case SH_NODE_NORMAL:
456 break;
459 break;
462 break;
465 break;
468 break;
469 case SH_NODE_VALTORGB:
471 break;
472 case SH_NODE_MATH:
474 break;
478 break;
482 break;
486 break;
490 break;
493 break;
498 break;
501 break;
502 }
503}
504
506
507/* -------------------------------------------------------------------- */
510
512 bContext * /*C*/,
513 PointerRNA *ptr,
514 PointerRNA *imaptr)
515{
516 if (!*imaptr) {
517 return;
518 }
519
520 ui::Layout &col = layout.column(false);
521
522 if (RNA_boolean_get(ptr, "has_views")) {
523 if (RNA_enum_get(ptr, "view") == 0) {
524 col.prop(ptr, "view", DEFAULT_FLAGS, std::nullopt, ICON_CAMERA_STEREO);
525 }
526 else {
527 col.prop(ptr, "view", DEFAULT_FLAGS, std::nullopt, ICON_SCENE);
528 }
529 }
530}
531
533{
534 bNode *node = static_cast<bNode *>(ptr->data);
535
536 PointerRNA iuserptr = RNA_pointer_create_discrete(ptr->owner_id, RNA_ImageUser, node->storage);
537 layout.context_ptr_set("image_user", &iuserptr);
538 template_id(&layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
539 if (!node->id) {
540 return;
541 }
542
543 PointerRNA imaptr = RNA_pointer_get(ptr, "image");
544
545 node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true, true);
546
547 node_buts_image_views(layout, C, ptr, &imaptr);
548}
549
551{
552 bNode *node = static_cast<bNode *>(ptr->data);
553
554 PointerRNA iuserptr = RNA_pointer_create_discrete(ptr->owner_id, RNA_ImageUser, node->storage);
555 layout.context_ptr_set("image_user", &iuserptr);
556 uiTemplateImage(&layout, C, ptr, "image", &iuserptr, false, true);
557}
558
560{
561 bNode *node = static_cast<bNode *>(ptr->data);
562 CurveMapping *cumap = static_cast<CurveMapping *>(node->storage);
563
564 if (_sample_col[0] != SAMPLE_FLT_ISNONE) {
565 cumap->flag |= CUMA_DRAW_SAMPLE;
567 }
568 else {
569 cumap->flag &= ~CUMA_DRAW_SAMPLE;
570 }
571
572 template_curve_mapping(&layout, ptr, "mapping", 'h', false, false, false, false, false);
573}
574
576{
577 bNode *node = static_cast<bNode *>(ptr->data);
578 NodeCMPCombSepColor *storage = static_cast<NodeCMPCombSepColor *>(node->storage);
579
580 layout.prop(ptr, "mode", DEFAULT_FLAGS, "", ICON_NONE);
581 if (storage->mode == CMP_NODE_COMBSEP_COLOR_YCC) {
582 layout.prop(ptr, "ycc_mode", DEFAULT_FLAGS, "", ICON_NONE);
583 }
584}
585
587 bContext * /*C*/,
588 PointerRNA *ptr)
589{
590 ui::Layout &col = layout.column(true);
591
592 col.label(IFACE_("Matte Objects:"), ICON_NONE);
593
594 ui::Layout &row = col.row(true);
595 template_crypto_picker(&row, ptr, "add", ICON_ADD);
596 template_crypto_picker(&row, ptr, "remove", ICON_REMOVE);
597
598 col.prop(ptr, "matte_id", DEFAULT_FLAGS, "", ICON_NONE);
599}
600
602 bContext * /*C*/,
603 PointerRNA * /*ptr*/)
604{
605 layout.op("NODE_OT_cryptomatte_layer_add", IFACE_("Add Crypto Layer"), ICON_ADD);
606 layout.op("NODE_OT_cryptomatte_layer_remove", IFACE_("Remove Crypto Layer"), ICON_REMOVE);
607}
608
610{
611 bNode *node = static_cast<bNode *>(ptr->data);
612
613 ui::Layout &row = layout.row(true);
614 row.prop(ptr, "source", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
615
616 ui::Layout &col = layout.column(false);
618 template_id(&col, C, ptr, "scene", nullptr, nullptr, nullptr);
619 }
620 else {
621 template_id(&col, C, ptr, "image", nullptr, "IMAGE_OT_open", nullptr);
622
623 NodeCryptomatte *crypto = static_cast<NodeCryptomatte *>(node->storage);
624 PointerRNA imaptr = RNA_pointer_get(ptr, "image");
626 ptr->owner_id, RNA_ImageUser, &crypto->iuser);
627 layout.context_ptr_set("image_user", &iuserptr);
628
629 node_buts_image_user(col, C, ptr, &imaptr, &iuserptr, false, false);
630 node_buts_image_views(col, C, ptr, &imaptr);
631 }
632
633 ui::Layout &col_2 = layout.column(true);
634 col_2.prop(ptr, "layer_name", UI_ITEM_NONE, "", ICON_NONE);
635 col_2.label(IFACE_("Matte ID:"), ICON_NONE);
636
637 ui::Layout &row_2 = col_2.row(true);
638 row_2.prop(ptr, "matte_id", DEFAULT_FLAGS, "", ICON_NONE);
639 template_crypto_picker(&row_2, ptr, "add", ICON_ADD);
640 template_crypto_picker(&row_2, ptr, "remove", ICON_REMOVE);
641}
642
643/* only once called */
676
678
679/* -------------------------------------------------------------------- */
682
683static void node_texture_buts_bricks(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
684{
685 {
686 ui::Layout &col = layout.column(true);
687 col.prop(ptr, "offset", DEFAULT_FLAGS | ui::ITEM_R_SLIDER, IFACE_("Offset"), ICON_NONE);
688 col.prop(ptr, "offset_frequency", DEFAULT_FLAGS, IFACE_("Frequency"), ICON_NONE);
689 }
690 {
691 ui::Layout &col = layout.column(true);
692 col.prop(ptr, "squash", DEFAULT_FLAGS, IFACE_("Squash"), ICON_NONE);
693 col.prop(ptr, "squash_frequency", DEFAULT_FLAGS, IFACE_("Frequency"), ICON_NONE);
694 }
695}
696
697static void node_texture_buts_proc(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
698{
699 bNode *node = static_cast<bNode *>(ptr->data);
700 ID *id = ptr->owner_id;
701 Tex *tex = static_cast<Tex *>(node->storage);
702
703 PointerRNA tex_ptr = RNA_pointer_create_discrete(id, RNA_Texture, tex);
704
705 ui::Layout &col = layout.column(false);
706
707 switch (tex->type) {
708 case TEX_BLEND: {
709 col.prop(&tex_ptr, "progression", DEFAULT_FLAGS, "", ICON_NONE);
710 ui::Layout &row = col.row(false);
711 row.prop(
712 &tex_ptr, "use_flip_axis", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
713 break;
714 }
715 case TEX_MARBLE: {
716 {
717 ui::Layout &row = col.row(false);
718 row.prop(
719 &tex_ptr, "marble_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
720 }
721 {
722 ui::Layout &row = col.row(false);
723 row.prop(
724 &tex_ptr, "noise_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
725 }
726 {
727 ui::Layout &row = col.row(false);
728 row.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
729 }
730 {
731 ui::Layout &row = col.row(false);
732 row.prop(
733 &tex_ptr, "noise_basis_2", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
734 }
735 break;
736 }
737 case TEX_MAGIC: {
738 col.prop(&tex_ptr, "noise_depth", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
739 break;
740 }
741 case TEX_STUCCI: {
742 {
743 ui::Layout &row = col.row(false);
744 row.prop(
745 &tex_ptr, "stucci_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
746 }
747 {
748 ui::Layout &row = col.row(false);
749 row.prop(
750 &tex_ptr, "noise_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
751 col.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
752 }
753 break;
754 }
755 case TEX_WOOD: {
756 col.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
757 col.prop(&tex_ptr, "wood_type", DEFAULT_FLAGS, "", ICON_NONE);
758 {
759 ui::Layout &row = col.row(false);
760 row.prop(
761 &tex_ptr, "noise_basis_2", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
762 }
763 {
764 ui::Layout &row = col.row(false);
765 row.active_set(!ELEM(tex->stype, TEX_BAND, TEX_RING));
766 row.prop(
767 &tex_ptr, "noise_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
768 }
769 break;
770 }
771 case TEX_CLOUDS: {
772 col.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
773 {
774 ui::Layout &row = col.row(false);
775 row.prop(
776 &tex_ptr, "cloud_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
777 }
778 {
779 ui::Layout &row = col.row(false);
780 row.prop(
781 &tex_ptr, "noise_type", DEFAULT_FLAGS | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
782 col.prop(&tex_ptr,
783 "noise_depth",
785 IFACE_("Depth"),
786 ICON_NONE);
787 }
788 break;
789 }
790 case TEX_DISTNOISE: {
791 col.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
792 col.prop(&tex_ptr, "noise_distortion", DEFAULT_FLAGS, "", ICON_NONE);
793 break;
794 }
795 case TEX_MUSGRAVE: {
796 col.prop(&tex_ptr, "musgrave_type", DEFAULT_FLAGS, "", ICON_NONE);
797 col.prop(&tex_ptr, "noise_basis", DEFAULT_FLAGS, "", ICON_NONE);
798 break;
799 }
800 case TEX_VORONOI: {
801 col.prop(&tex_ptr, "distance_metric", DEFAULT_FLAGS, "", ICON_NONE);
802 if (tex->vn_distm == TEX_MINKOVSKY) {
803 col.prop(&tex_ptr, "minkovsky_exponent", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
804 }
805 col.prop(&tex_ptr, "color_mode", DEFAULT_FLAGS, "", ICON_NONE);
806 break;
807 }
808 case TEX_NOISE:
809 case TEX_IMAGE:
810 break;
811 }
812}
813
815{
816 template_id(&layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
817}
818
820{
821 bNode *node = static_cast<bNode *>(ptr->data);
822 PointerRNA iuserptr = RNA_pointer_create_discrete(ptr->owner_id, RNA_ImageUser, node->storage);
823 uiTemplateImage(&layout, C, ptr, "image", &iuserptr, false, false);
824}
825
826static void node_texture_buts_output(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
827{
828 layout.prop(ptr, "filepath", DEFAULT_FLAGS, "", ICON_NONE);
829}
830
832{
833 layout.prop(ptr, "mode", DEFAULT_FLAGS, "", ICON_NONE);
834}
835
836/* only once called */
838{
839 if (ntype->type_legacy >= TEX_NODE_PROC && ntype->type_legacy < TEX_NODE_PROC_MAX) {
841 }
842 else {
843 switch (ntype->type_legacy) {
844
845 case TEX_NODE_MATH:
847 break;
848
849 case TEX_NODE_MIX_RGB:
851 break;
852
855 break;
856
859 break;
860
863 break;
864
865 case TEX_NODE_TEXTURE:
867 break;
868
869 case TEX_NODE_BRICKS:
871 break;
872
873 case TEX_NODE_IMAGE:
876 break;
877
878 case TEX_NODE_OUTPUT:
880 break;
881
885 break;
886 }
887 }
888}
889
891
892/* -------------------------------------------------------------------- */
897
898static void node_property_update_default(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
899{
900 bNodeTree *ntree = id_cast<bNodeTree *>(ptr->owner_id);
901 bNode *node = static_cast<bNode *>(ptr->data);
904}
905
916
918{
920
921 if (ntype->inputs) {
922 for (stemp = ntype->inputs; stemp->type >= 0; stemp++) {
924 }
925 }
926 if (ntype->outputs) {
927 for (stemp = ntype->outputs; stemp->type >= 0; stemp++) {
929 }
930 }
931}
932
934 ui::Layout *layout,
935 PointerRNA * /*ptr*/,
936 PointerRNA * /*node_ptr*/,
937 StringRef /*text*/)
938{
939 layout->label(IFACE_("Undefined Socket Type"), ICON_STATUS_ERROR);
940}
941
943 PointerRNA * /*ptr*/,
944 PointerRNA * /*node_ptr*/,
945 float *r_color)
946{
947 r_color[0] = 1.0f;
948 r_color[1] = 0.0f;
949 r_color[2] = 0.0f;
950 r_color[3] = 1.0f;
951}
952
954 float *r_color)
955{
956 r_color[0] = 1.0f;
957 r_color[1] = 0.0f;
958 r_color[2] = 0.0f;
959 r_color[3] = 1.0f;
960}
961
963 bNodeTreeInterfaceSocket * /*interface_socket*/,
964 bContext * /*C*/,
965 ui::Layout *layout)
966{
967 layout->label(IFACE_("Undefined Socket Type"), ICON_STATUS_ERROR);
968}
969
971
972} // namespace ed::space_node
973
974/* -------------------------------------------------------------------- */
977
979{
980 using namespace blender::ed::space_node;
981
982 /* Fallback types for undefined tree, nodes, sockets
983 * Defined in blenkernel, but not registered in type hashes.
984 */
985
988
991
996
997 /* node type ui functions */
998 for (bke::bNodeType *ntype : bke::node_types_get()) {
1000
1004
1005 /* define update callbacks for socket properties */
1007 }
1008}
1009
1011
1016
1018
1019namespace ed::space_node {
1020
1021/* -------------------------------------------------------------------- */
1024
1025static const float virtual_node_socket_color[4] = {0.2, 0.2, 0.2, 1.0};
1026
1027/* maps standard socket integer type to a color */
1028static const float std_node_socket_colors[][4] = {
1029 {0.63, 0.63, 0.63, 1.0}, /* SOCK_FLOAT */
1030 {0.39, 0.39, 0.78, 1.0}, /* SOCK_VECTOR */
1031 {0.78, 0.78, 0.16, 1.0}, /* SOCK_RGBA */
1032 {0.39, 0.78, 0.39, 1.0}, /* SOCK_SHADER */
1033 {0.80, 0.65, 0.84, 1.0}, /* SOCK_BOOLEAN */
1034 {0.0, 0.0, 0.0, 0.0}, /* UNUSED */
1035 {0.35, 0.55, 0.36, 1.0}, /* SOCK_INT */
1036 {0.44, 0.70, 1.00, 1.0}, /* SOCK_STRING */
1037 {0.93, 0.62, 0.36, 1.0}, /* SOCK_OBJECT */
1038 {0.39, 0.22, 0.39, 1.0}, /* SOCK_IMAGE */
1039 {0.00, 0.84, 0.64, 1.0}, /* SOCK_GEOMETRY */
1040 {0.96, 0.96, 0.96, 1.0}, /* SOCK_COLLECTION */
1041 {0.62, 0.31, 0.64, 1.0}, /* SOCK_TEXTURE */
1042 {0.92, 0.46, 0.51, 1.0}, /* SOCK_MATERIAL */
1043 {0.65, 0.39, 0.78, 1.0}, /* SOCK_ROTATION */
1044 {0.40, 0.40, 0.40, 1.0}, /* SOCK_MENU */
1045 {0.72, 0.20, 0.52, 1.0}, /* SOCK_MATRIX */
1046 {0.30, 0.50, 0.50, 1.0}, /* SOCK_BUNDLE */
1047 {0.49, 0.49, 0.23, 1.0}, /* SOCK_CLOSURE */
1048 {0.39, 0.34, 0.26, 1}, /* SOCK_FONT */
1049 {0, 0, 0, 1}, /* SOCK_SCENE */
1050 {0, 0, 0, 1}, /* SOCK_TEXT_ID */
1051 {0, 0, 0, 1}, /* SOCK_MASK */
1052 {0.39, 0.34, 0.26, 1}, /* SOCK_SOUND */
1053 {0.36, 0.47, 0.61, 1.0}, /* SOCK_INT_VECTOR */
1054};
1055
1056void std_node_socket_colors_get(int socket_type, float *r_color)
1057{
1058 BLI_assert(socket_type >= 0);
1059 BLI_assert(socket_type < std::size(std_node_socket_colors));
1060
1061 copy_v4_v4(r_color, std_node_socket_colors[socket_type]);
1062}
1063
1064/* Callback for colors that does not depend on the socket pointer argument to get the type. */
1065template<int socket_type>
1067 PointerRNA * /*ptr*/,
1068 PointerRNA * /*node_ptr*/,
1069 float *r_color)
1070{
1071 copy_v4_v4(r_color, std_node_socket_colors[socket_type]);
1072};
1073static void std_node_socket_color_simple_fn(const bke::bNodeSocketType *type, float *r_color)
1074{
1075 copy_v4_v4(r_color, std_node_socket_colors[type->type]);
1076};
1077
1078using SocketColorFn = void (*)(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color);
1079/* Callbacks for all built-in socket types. */
1095
1097
1098/* -------------------------------------------------------------------- */
1101
1103{
1104 const nodes::NodeDeclaration *node_decl = node.declaration();
1105 if (node_decl == nullptr) {
1106 return false;
1107 }
1108 if (node_decl->skip_updating_sockets) {
1109 return false;
1110 }
1111 if (socket.in_out == SOCK_OUT) {
1112 return false;
1113 }
1114 return socket.runtime->declaration->is_attribute_name;
1115}
1116
1117static bool socket_needs_layer_search(const bNode &node, const bNodeSocket &socket)
1118{
1119 const nodes::NodeDeclaration *node_decl = node.declaration();
1120 if (node_decl == nullptr) {
1121 return false;
1122 }
1123 if (node_decl->skip_updating_sockets) {
1124 return false;
1125 }
1126 if (socket.in_out == SOCK_OUT) {
1127 return false;
1128 }
1129 return socket.runtime->declaration->is_layer_name;
1130}
1131
1132static bool socket_needs_volume_grid_search(const bNode &node, const bNodeSocket &socket)
1133{
1134 const nodes::NodeDeclaration *node_decl = node.declaration();
1135 if (node_decl == nullptr) {
1136 return false;
1137 }
1138 if (node_decl->skip_updating_sockets) {
1139 return false;
1140 }
1141 if (socket.in_out == SOCK_OUT) {
1142 return false;
1143 }
1144 return socket.runtime->declaration->is_volume_grid_name;
1145}
1146
1147static bool socket_needs_bundle_type_search(const bNode &node, const bNodeSocket &socket)
1148{
1149 if (node.type_legacy == NODE_COMBINE_BUNDLE) {
1150 return socket.name == nodes::Bundle::type_item_name.ustr();
1151 }
1152 if (node.is_type("NodeGetNestedBundlePaths"_ustr)) {
1153 return socket.name == StringRef("Bundle Type");
1154 }
1155 return false;
1156}
1157
1158static void draw_gizmo_pin_icon(ui::Layout *layout, PointerRNA *socket_ptr)
1159{
1160 layout->prop(socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
1161}
1162
1164 bNodeSocket *sock,
1165 const StringRef text)
1166{
1167 if (sock->runtime->declaration) {
1168 if (sock->runtime->declaration->socket_name_rna) {
1171 layout->prop((&sock->runtime->declaration->socket_name_rna->owner),
1172 sock->runtime->declaration->socket_name_rna->property_name,
1175 "",
1176 ICON_NONE);
1177 return;
1178 }
1179 }
1180 layout->label(text, ICON_NONE);
1181}
1182
1184 bNodeSocket *sock,
1185 const StringRef text)
1186{
1187 draw_node_socket_name_editable(layout, sock, text);
1188}
1189
1191 bContext *C, ui::Layout *layout, PointerRNA *ptr, PointerRNA *node_ptr, StringRef label)
1192{
1193 bNode *node = static_cast<bNode *>(node_ptr->data);
1194 bNodeSocket *sock = static_cast<bNodeSocket *>(ptr->data);
1195 bNodeTree *tree = reinterpret_cast<bNodeTree *>(ptr->owner_id);
1196 int type = sock->typeinfo->type;
1197 // int subtype = sock->typeinfo->subtype;
1198
1199 const nodes::SocketDeclaration *socket_decl = sock->runtime->declaration;
1200
1201 if (sock->is_inactive()) {
1202 layout->active_set(false);
1203 }
1204
1205 const bool optional_label = (socket_decl && socket_decl->optional_label) || label.is_empty();
1206 const StringRef label_or_empty = optional_label ? "" : label;
1207
1208 const bool has_gizmo = tree->runtime->gizmo_propagation ?
1209 tree->runtime->gizmo_propagation->gizmo_endpoint_sockets.contains(
1210 sock) :
1211 false;
1212
1213 if (has_gizmo) {
1214 if (sock->in_out == SOCK_OUT && node->is_group_input()) {
1215 ui::Layout &row = layout->row(false);
1217 node_socket_button_label(C, &row, ptr, node_ptr, label);
1218 row.label("", ICON_GIZMO);
1219 return;
1220 }
1221 if (sock->in_out == SOCK_IN && sock->index() == 0 &&
1223 {
1224 ui::Layout *row = &layout->row(false);
1225 node_socket_button_label(C, row, ptr, node_ptr, label);
1226 draw_gizmo_pin_icon(row, ptr);
1227 return;
1228 }
1229 }
1230
1231 if ((sock->in_out == SOCK_OUT) || (sock->flag & SOCK_HIDE_VALUE) || sock->is_logically_linked())
1232 {
1233 draw_node_socket_without_value(layout, sock, label);
1234 return;
1235 }
1236 if (tree->type == NTREE_GEOMETRY &&
1238 {
1239 draw_node_socket_without_value(layout, sock, label);
1240 return;
1241 }
1242
1243 /* Some socket types draw the gizmo icon in a special way to look better. All others use a
1244 * fallback default code path. */
1245 bool gizmo_handled = false;
1246
1247 switch (type) {
1248 case SOCK_FLOAT:
1249 case SOCK_INT:
1250 case SOCK_BOOLEAN:
1251 layout->prop(ptr, "default_value", DEFAULT_FLAGS, label_or_empty, ICON_NONE);
1252 break;
1253 case SOCK_VECTOR:
1254 if (socket_decl && socket_decl->compact) {
1255 template_component_menu(layout, ptr, "default_value", label_or_empty);
1256 }
1257 else {
1258 if (sock->typeinfo->subtype == PROP_DIRECTION) {
1259 layout->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1260 }
1261 else {
1262 ui::Layout *column = &layout->column(false);
1263 {
1264 ui::Layout *row = &column->row(true);
1265 if (!optional_label) {
1266 draw_node_socket_name_editable(row, sock, label_or_empty);
1267 }
1268 if (has_gizmo) {
1269 draw_gizmo_pin_icon(row, ptr);
1270 gizmo_handled = true;
1271 }
1272 }
1273 column->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1274 }
1275 }
1276 break;
1277 case SOCK_INT_VECTOR:
1278 if (socket_decl && socket_decl->compact) {
1279 template_component_menu(layout, ptr, "default_value", label_or_empty);
1280 }
1281 else {
1282 ui::Layout *column = &layout->column(false);
1283 {
1284 ui::Layout *row = &column->row(true);
1285 if (!optional_label) {
1286 draw_node_socket_name_editable(row, sock, label_or_empty);
1287 }
1288 }
1289 column->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1290 }
1291 break;
1292 case SOCK_ROTATION: {
1293 ui::Layout *column = &layout->column(false);
1294 {
1295 ui::Layout *row = &column->row(true);
1296 if (!optional_label) {
1297 draw_node_socket_name_editable(row, sock, label_or_empty);
1298 }
1299 if (has_gizmo) {
1300 draw_gizmo_pin_icon(row, ptr);
1301 gizmo_handled = true;
1302 }
1303 }
1304 column->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1305 break;
1306 }
1307 case SOCK_MATRIX: {
1308 draw_node_socket_name_editable(layout, sock, label);
1309 break;
1310 }
1311 case SOCK_RGBA: {
1312 if (optional_label) {
1313 layout->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1314 }
1315 else {
1316 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1317 ui::Layout *label_layout = &row->column(true);
1318 label_layout->label(label, ICON_NONE);
1319 ui::Layout *color_layout = &row->column(true);
1320 color_layout->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1321 /* Keep color layout active to avoid darkened color appearance when inactive. */
1322 if (sock->is_inactive()) {
1323 layout->active_set(true);
1324 label_layout->active_set(false);
1325 color_layout->active_set(true);
1326 }
1327 }
1328 break;
1329 }
1330 case SOCK_STRING: {
1331 if (socket_needs_attribute_search(*node, *sock)) {
1332 if (optional_label) {
1333 node_geometry_add_attribute_search_button(*C, *node, *ptr, *layout, label);
1334 }
1335 else {
1336 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1337 row->label(label, ICON_NONE);
1339 }
1340 }
1341 else if (socket_needs_layer_search(*node, *sock)) {
1342 if (optional_label) {
1343 node_geometry_add_layer_search_button(*C, *node, *ptr, *layout, label);
1344 }
1345 else {
1346 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1347 row->label(label, ICON_NONE);
1349 }
1350 }
1351 else if (socket_needs_volume_grid_search(*node, *sock)) {
1352 if (optional_label) {
1353 node_geometry_add_volume_grid_search_button(*C, *node, *ptr, *layout, label);
1354 }
1355 else {
1356 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1357 row->label(label, ICON_NONE);
1359 }
1360 }
1361 else if (socket_needs_bundle_type_search(*node, *sock)) {
1362 if (optional_label) {
1363 node_bundle_type_add_string_search_button(*C, *node, *ptr, *layout, label);
1364 }
1365 else {
1366 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1367 row->label(label, ICON_NONE);
1369 }
1370 }
1371 else {
1372 if (optional_label) {
1373 layout->prop(ptr,
1374 RNA_struct_find_property(ptr, "default_value"),
1375 -1,
1376 0,
1378 "",
1379 ICON_NONE,
1380 label);
1381 }
1382 else {
1383 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1384 row->label(label, ICON_NONE);
1385 row->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1386 }
1387 }
1388 break;
1389 }
1390 case SOCK_MENU: {
1391 const bNodeSocketValueMenu *default_value =
1392 sock->default_value_typed<bNodeSocketValueMenu>();
1393 if (default_value->enum_items) {
1394 if (default_value->enum_items->items.is_empty()) {
1395 ui::Layout *row = &layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1396 row->label(label, ICON_NONE);
1397 row->label(IFACE_("No Items"), ICON_NONE);
1398 }
1399 else {
1400 bool expanded = false;
1401 if (const auto *menu_decl = dynamic_cast<const nodes::decl::Menu *>(socket_decl)) {
1402 expanded = menu_decl->is_expanded;
1403 }
1404 if (optional_label) {
1405 if (expanded) {
1406 /* Use a single space for the name to work around a bug. Also see
1407 * #item_enum_expand_exec. */
1408 layout->prop(ptr, "default_value", ui::ITEM_R_EXPAND, " ", ICON_NONE);
1409 }
1410 else {
1411 layout->prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1412 }
1413 }
1414 else {
1415 ui::Layout &row = layout->split(ui::Layout::PROPERTY_SPLIT_FACTOR, false);
1416 row.label(label, ICON_NONE);
1417 if (expanded) {
1418 /* Use a single space for the name to work around a bug. Also see
1419 * #item_enum_expand_exec. */
1420 row.row(true).prop(ptr, "default_value", ui::ITEM_R_EXPAND, " ", ICON_NONE);
1421 }
1422 else {
1423 row.prop(ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
1424 }
1425 }
1426 }
1427 }
1428 else if (default_value->has_conflict()) {
1429 layout->label(IFACE_("Menu Error"), ICON_STATUS_ERROR);
1430 }
1431 else {
1432 layout->label(IFACE_("Menu Undefined"), ICON_QUESTION);
1433 }
1434 break;
1435 }
1436 case SOCK_COLLECTION:
1437 case SOCK_OBJECT:
1438 case SOCK_MATERIAL:
1439 case SOCK_SCENE:
1440 case SOCK_TEXT_ID:
1441 case SOCK_MASK: {
1442 if (optional_label) {
1443 layout->prop(ptr,
1444 RNA_struct_find_property(ptr, "default_value"),
1445 -1,
1446 0,
1448 "",
1449 ICON_NONE,
1450 std::optional(label));
1451 }
1452 else {
1453 layout->prop(ptr,
1454 RNA_struct_find_property(ptr, "default_value"),
1455 -1,
1456 0,
1458 label,
1459 ICON_NONE);
1460 }
1461 break;
1462 }
1463 case SOCK_SOUND: {
1464 if (optional_label) {
1465 template_id(layout, C, ptr, "default_value", nullptr, "SOUND_OT_open", nullptr);
1466 }
1467 else {
1468 /* 0.3 is consistent with image sockets. */
1469 ui::Layout *row = &layout->split(0.3f, false);
1470 row->label(label, ICON_NONE);
1471 template_id(row, C, ptr, "default_value", nullptr, "SOUND_OT_open", nullptr);
1472 }
1473 break;
1474 }
1475 case SOCK_FONT: {
1476 if (optional_label) {
1477 template_id(layout, C, ptr, "default_value", nullptr, "FONT_OT_open", "FONT_OT_unlink");
1478 }
1479 else {
1480 /* 0.3 is consistent with image sockets. */
1481 ui::Layout *row = &layout->split(0.3f, false);
1482 row->label(label, ICON_NONE);
1483 template_id(row, C, ptr, "default_value", nullptr, "FONT_OT_open", "FONT_OT_unlink");
1484 }
1485 break;
1486 }
1487 case SOCK_IMAGE: {
1488 const bNodeTree *node_tree = id_cast<const bNodeTree *>(node_ptr->owner_id);
1489 if (node_tree->type == NTREE_GEOMETRY) {
1490 if (optional_label) {
1491 template_id(layout, C, ptr, "default_value", "image.new", "image.open", nullptr);
1492 }
1493 else {
1494 /* 0.3 split ratio is inconsistent, but use it here because the "New" button is large. */
1495 ui::Layout *row = &layout->split(0.3f, false);
1496 row->label(label, ICON_NONE);
1497 template_id(row, C, ptr, "default_value", "image.new", "image.open", nullptr);
1498 }
1499 }
1500 else {
1501 layout->prop(ptr, "default_value", DEFAULT_FLAGS, label_or_empty, ICON_NONE);
1502 }
1503 break;
1504 }
1505 case SOCK_TEXTURE: {
1506 if (optional_label) {
1507 template_id(layout, C, ptr, "default_value", "texture.new", nullptr, nullptr);
1508 }
1509 else {
1510 /* 0.3 split ratio is inconsistent, but use it here because the "New" button is large. */
1511 ui::Layout *row = &layout->split(0.3f, false);
1512 row->label(label, ICON_NONE);
1513 template_id(row, C, ptr, "default_value", "texture.new", nullptr, nullptr);
1514 }
1515
1516 break;
1517 }
1518 default:
1519 draw_node_socket_without_value(layout, sock, label_or_empty);
1520 break;
1521 }
1522
1523 if (has_gizmo && !gizmo_handled) {
1524 draw_gizmo_pin_icon(layout, ptr);
1525 }
1526}
1527
1529 bNodeTreeInterfaceSocket *interface_socket,
1530 bContext * /*C*/,
1531 ui::Layout *layout)
1532{
1533 PointerRNA ptr = RNA_pointer_create_discrete(id, RNA_NodeTreeInterfaceSocket, interface_socket);
1534
1535 const bke::bNodeSocketType *typeinfo = interface_socket->socket_typeinfo();
1536 BLI_assert(typeinfo != nullptr);
1537 eNodeSocketDatatype type = typeinfo->type;
1538
1539 ui::Layout *col = &layout->column(false);
1540
1541 switch (type) {
1542 case SOCK_FLOAT: {
1543 col->prop(&ptr, "subtype", DEFAULT_FLAGS, IFACE_("Subtype"), ICON_NONE);
1544 col->prop(&ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
1545 ui::Layout *sub = &col->column(true);
1546 sub->prop(&ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
1547 sub->prop(&ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
1548 break;
1549 }
1550 case SOCK_INT: {
1551 col->prop(&ptr, "subtype", DEFAULT_FLAGS, IFACE_("Subtype"), ICON_NONE);
1552 col->prop(&ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
1553 ui::Layout *sub = &col->column(true);
1554 sub->prop(&ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
1555 sub->prop(&ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
1556 break;
1557 }
1558 case SOCK_VECTOR: {
1559 col->prop(&ptr, "subtype", DEFAULT_FLAGS, IFACE_("Subtype"), ICON_NONE);
1560 col->prop(&ptr,
1561 "dimensions",
1564 ICON_NONE);
1565 col->prop(&ptr, "default_value", ui::ITEM_R_EXPAND, IFACE_("Default"), ICON_NONE);
1566 ui::Layout *sub = &col->column(true);
1567 sub->prop(&ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
1568 sub->prop(&ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
1569 break;
1570 }
1571 case SOCK_INT_VECTOR: {
1572 col->prop(&ptr, "subtype", DEFAULT_FLAGS, IFACE_("Subtype"), ICON_NONE);
1573 col->prop(&ptr,
1574 "dimensions",
1577 ICON_NONE);
1578 col->prop(&ptr, "default_value", ui::ITEM_R_EXPAND, IFACE_("Default"), ICON_NONE);
1579 ui::Layout *sub = &col->column(true);
1580 sub->prop(&ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
1581 sub->prop(&ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
1582 break;
1583 }
1584 case SOCK_STRING: {
1585 col->prop(&ptr, "subtype", DEFAULT_FLAGS, IFACE_("Subtype"), ICON_NONE);
1586 col->prop(&ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
1587 break;
1588 }
1589 case SOCK_BOOLEAN:
1590 case SOCK_ROTATION:
1591 case SOCK_RGBA:
1592 case SOCK_OBJECT:
1593 case SOCK_COLLECTION:
1594 case SOCK_IMAGE:
1595 case SOCK_TEXTURE:
1596 case SOCK_MATERIAL:
1597 case SOCK_FONT:
1598 case SOCK_SCENE:
1599 case SOCK_TEXT_ID:
1600 case SOCK_MASK:
1601 case SOCK_SOUND: {
1602 col->prop(&ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
1603 break;
1604 }
1605 case SOCK_MENU: {
1606 col->prop(&ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
1607 col->prop(&ptr, "menu_expanded", DEFAULT_FLAGS, IFACE_("Expanded"), ICON_NONE);
1608 break;
1609 }
1610 case SOCK_SHADER:
1611 case SOCK_GEOMETRY:
1612 case SOCK_MATRIX:
1613 case SOCK_BUNDLE:
1614 case SOCK_CLOSURE:
1615 break;
1616
1617 case SOCK_CUSTOM:
1619 break;
1620 }
1621
1622 col = &layout->column(false);
1623
1624 const bNodeTree *node_tree = reinterpret_cast<const bNodeTree *>(id);
1625 if (interface_socket->flag & NODE_INTERFACE_SOCKET_INPUT &&
1626 ELEM(node_tree->type, NTREE_GEOMETRY, NTREE_COMPOSIT))
1627 {
1629 (node_tree->type == NTREE_GEOMETRY && type == SOCK_OBJECT))
1630 {
1631 col->prop(&ptr, "default_input", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1632 }
1633 }
1634
1635 if (interface_socket->flag & NODE_INTERFACE_SOCKET_INPUT) {
1636 col->prop(&ptr, "optional_label", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1637 }
1638 {
1639 ui::Layout *sub = &col->column(false);
1640 sub->active_set(interface_socket->default_input == NODE_DEFAULT_INPUT_VALUE);
1641 sub->prop(&ptr, "hide_value", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1642 }
1643
1644 if (interface_socket->flag & NODE_INTERFACE_SOCKET_INPUT) {
1645 if (node_tree->type == NTREE_GEOMETRY) {
1646 if (type == SOCK_BOOLEAN) {
1647 col->prop(&ptr, "layer_selection_field", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1648 }
1649 ui::Layout *sub = &col->column(false);
1650 sub->active_set(!is_layer_selection_field(*interface_socket));
1651 sub->prop(&ptr, "hide_in_modifier", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1652 sub->prop(&ptr, "structure_type", DEFAULT_FLAGS, IFACE_("Shape"), ICON_NONE);
1653 }
1654 else if (node_tree->type == NTREE_COMPOSIT) {
1655 col->prop(&ptr, "hide_in_modifier", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
1656 }
1657 }
1658}
1659
1661 PointerRNA * /*ptr*/,
1662 PointerRNA * /*node_ptr*/,
1663 float *r_color)
1664{
1666}
1667
1669 float *r_color)
1670{
1672}
1673
1675
1676} // namespace ed::space_node
1677
1678/* -------------------------------------------------------------------- */
1681
1690
1698
1699void ED_node_type_draw_color(const char *idname, float *r_color)
1700{
1701 using namespace blender::ed::space_node;
1702
1703 const bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(idname);
1704 if (!typeinfo || typeinfo->type == SOCK_CUSTOM) {
1705 r_color[0] = 0.0f;
1706 r_color[1] = 0.0f;
1707 r_color[2] = 0.0f;
1708 r_color[3] = 0.0f;
1709 return;
1710 }
1711
1713 copy_v4_v4(r_color, std_node_socket_colors[typeinfo->type]);
1714}
1715
1717
1718namespace ed::space_node {
1719
1720/* -------------------------------------------------------------------- */
1723
1725 ARegion &region,
1726 SpaceNode &snode,
1727 bNodeInstanceKey parent_key)
1728{
1729 Main *bmain = CTX_data_main(&C);
1730 bNodeInstanceKey active_viewer_key = (snode.nodetree ? snode.nodetree->active_viewer_key :
1732
1733 /* Only the backdrop is color managed, which the draw manager enables when drawing it. */
1734 if (GPUViewport *viewport = WM_draw_region_get_bound_viewport(&region)) {
1736 }
1737
1745
1746 if (!(snode.flag & SNODE_BACKDRAW) || !ED_node_is_compositor(&snode) ||
1748 {
1749 return;
1750 }
1751
1752 if (parent_key.value != active_viewer_key.value) {
1753 return;
1754 }
1755
1758
1759 /* The draw manager is used to draw the backdrop image. */
1763 DRW_draw_view(&C);
1766 /* Draw manager changes the depth state. Set it back to NONE. Without this the
1767 * node preview images aren't drawn correctly. */
1769
1770 void *lock;
1771 Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
1772 ImBuf *ibuf = BKE_image_acquire_ibuf_gpu(ima, nullptr, &lock);
1773 if (ibuf) {
1774 /* somehow the offset has to be calculated inverse */
1776 const float2 offset = flag_is_set(ibuf->flags, ImBufFlags::HasDisplayWindow) ?
1777 float2(ibuf->display_offset) :
1778 float2(0.0f);
1779 const float offset_x = snode.xof + offset.x * snode.zoom;
1780 const float offset_y = snode.yof + offset.y * snode.zoom;
1781 const float x = (region.winx - snode.zoom * ibuf->x) / 2 + offset_x;
1782 const float y = (region.winy - snode.zoom * ibuf->y) / 2 + offset_y;
1783
1786 if (snode.edittree) {
1787 bNode *node = snode.edittree->nodes.first();
1788 while (node) {
1789 if (node->is_selected()) {
1790 if (node->typeinfo->draw_backdrop) {
1791 node->typeinfo->draw_backdrop(&snode, ibuf, node, x, y);
1792 }
1793 }
1794 node = node->next;
1795 }
1796 }
1797 }
1798
1799 BKE_image_release_ibuf(ima, ibuf, lock);
1802}
1803
1805 const bNodeSocket &socket,
1806 const bNodeLink &link)
1807{
1808 const float2 socket_location = socket.runtime->location;
1809 if (socket.is_multi_input() && socket.is_input() && !(node.flag & NODE_COLLAPSED)) {
1810 /* For internal link case, handle number of links as at least 1. */
1811 const int clamped_total_inputs = math::max<int>(1, socket.runtime->total_inputs);
1813 socket_location, link.multi_input_sort_id, clamped_total_inputs);
1814 }
1815 return socket_location;
1816}
1817
1818static void calculate_inner_link_bezier_points(std::array<float2, 4> &points)
1819{
1821 if (curving == 0) {
1822 /* Straight line: align all points. */
1823 points[1] = math::interpolate(points[0], points[3], 1.0f / 3.0f);
1824 points[2] = math::interpolate(points[0], points[3], 2.0f / 3.0f);
1825 }
1826 else {
1827 const float dist_x = math::distance(points[0].x, points[3].x);
1828 const float dist_y = math::distance(points[0].y, points[3].y);
1829
1830 /* Reduce the handle offset when the link endpoints are close to horizontal. */
1831 const float slope = math::safe_divide(dist_y, dist_x);
1832 const float clamp_factor = math::min(1.0f, slope * (4.5f - 0.25f * float(curving)));
1833
1834 const float handle_offset = curving * 0.1f * dist_x * clamp_factor;
1835
1836 points[1].x = points[0].x + handle_offset;
1837 points[1].y = points[0].y;
1838
1839 points[2].x = points[3].x - handle_offset;
1840 points[2].y = points[3].y;
1841 }
1842}
1843
1844static std::array<float2, 4> node_link_bezier_points(const bNodeLink &link)
1845{
1846 std::array<float2, 4> points;
1847 points[0] = socket_link_connection_location(*link.fromnode, *link.fromsock, link);
1848 points[3] = socket_link_connection_location(*link.tonode, *link.tosock, link);
1850 return points;
1851}
1852
1853static bool node_link_draw_is_visible(const View2D &v2d, const std::array<float2, 4> &points)
1854{
1855 if (std::min({points[0].x, points[1].x, points[2].x, points[3].x}) > v2d.cur.xmax) {
1856 return false;
1857 }
1858 if (std::max({points[0].x, points[1].x, points[2].x, points[3].x}) < v2d.cur.xmin) {
1859 return false;
1860 }
1861 return true;
1862}
1863
1865 std::array<float2, NODE_LINK_RESOL + 1> &coords)
1866{
1867 const std::array<float2, 4> points = node_link_bezier_points(link);
1868
1869 /* The extra +1 in size is required by these functions and would be removed ideally. */
1871 points[1].x,
1872 points[2].x,
1873 points[3].x,
1874 &coords[0].x,
1876 sizeof(float2));
1878 points[1].y,
1879 points[2].y,
1880 points[3].y,
1881 &coords[0].y,
1883 sizeof(float2));
1884}
1885
1887
1888/* -------------------------------------------------------------------- */
1891
1892/* Keep in sync with node socket shader. */
1893#define MAX_SOCKET_PARAMETERS 4
1894#define MAX_SOCKET_INSTANCE 32
1895
1901
1903{
1904 static GBatchNodesocket nodesocket_batch;
1905 return nodesocket_batch;
1906}
1907
1908static gpu::Batch *nodesocket_batch_init()
1909{
1910 if (g_batch_nodesocket().batch == nullptr) {
1911 GPUIndexBufBuilder ibuf;
1912 GPU_indexbuf_init(&ibuf, GPU_PRIM_TRIS, 2, 4);
1913 /* Quad to draw the node socket in. */
1914 GPU_indexbuf_add_tri_verts(&ibuf, 0, 1, 2);
1915 GPU_indexbuf_add_tri_verts(&ibuf, 2, 1, 3);
1916
1920 }
1921 return g_batch_nodesocket().batch;
1922}
1923
1925{
1926 if (g_batch_nodesocket().params.is_empty()) {
1927 return;
1928 }
1929
1930 gpu::Batch *batch = nodesocket_batch_init();
1931 if (g_batch_nodesocket().params.size() == 1) {
1932 /* draw single */
1935 batch,
1936 "parameters",
1937 4,
1938 reinterpret_cast<const float (*)[4]>(g_batch_nodesocket().params.data()));
1939 GPU_batch_draw(batch);
1940 }
1941 else {
1944 batch,
1945 "parameters",
1947 reinterpret_cast<const float (*)[4]>(g_batch_nodesocket().params.data()));
1948 GPU_batch_draw_instance_range(batch, 0, g_batch_nodesocket().params.size());
1949 }
1950 g_batch_nodesocket().params.clear();
1951}
1952
1954{
1955 BLI_assert(g_batch_nodesocket().enabled == false);
1956 g_batch_nodesocket().enabled = true;
1957}
1958
1968
1970{
1971 if (g_batch_nodesocket().enabled) {
1972 g_batch_nodesocket().params.append(socket_params);
1973
1974 if (g_batch_nodesocket().params.size() >= MAX_SOCKET_INSTANCE) {
1976 }
1977 }
1978 else {
1979 /* Draw single instead of batch. */
1980 gpu::Batch *batch = nodesocket_batch_init();
1983 batch, "parameters", MAX_SOCKET_PARAMETERS, (const float (*)[4])(&socket_params));
1984 GPU_batch_draw(batch);
1985 }
1986}
1987
1989 const float color_inner[4],
1990 const float color_outline[4],
1991 const float outline_thickness,
1992 const int shape,
1993 const float aspect)
1994{
1995 /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space.
1996 * If it has been scaled, then it's no longer valid. */
1997 BLI_assert((color_inner != nullptr) && (color_outline != nullptr));
1998
1999 NodeSocketShaderParameters socket_params = {};
2000 socket_params.rect[0] = rect->xmin;
2001 socket_params.rect[1] = rect->xmax;
2002 socket_params.rect[2] = rect->ymin;
2003 socket_params.rect[3] = rect->ymax;
2004 socket_params.color_inner[0] = color_inner[0];
2005 socket_params.color_inner[1] = color_inner[1];
2006 socket_params.color_inner[2] = color_inner[2];
2007 socket_params.color_inner[3] = color_inner[3];
2008 socket_params.color_outline[0] = color_outline[0];
2009 socket_params.color_outline[1] = color_outline[1];
2010 socket_params.color_outline[2] = color_outline[2];
2011 socket_params.color_outline[3] = color_outline[3];
2012 socket_params.outline_thickness = outline_thickness;
2013 socket_params.outline_offset = 0.0;
2014 socket_params.shape = float(shape) + 0.1f;
2015 socket_params.aspect = aspect;
2016
2018 draw_node_socket_batch(socket_params);
2020}
2021
2023
2024/* -------------------------------------------------------------------- */
2027
2028#define NODELINK_GROUP_SIZE 256
2029#define LINK_RESOL 24
2030#define LINK_WIDTH 2.5f
2031#define ARROW_SIZE (7 * UI_SCALE_FAC)
2032
2033/* Reroute arrow shape and mute bar. These are expanded here and shrunk in the GLSL code.
2034 * See: `gpu_shader_nodelink.bsl.hh`. */
2035static float arrow_verts[3][2] = {{-1.0f, 1.0f}, {0.0f, 0.0f}, {-1.0f, -1.0f}};
2036static float arrow_expand_axis[3][2] = {{0.7071f, 0.7071f}, {M_SQRT2, 0.0f}, {0.7071f, -0.7071f}};
2037static float mute_verts[3][2] = {{0.7071f, 1.0f}, {0.7071f, 0.0f}, {0.7071f, -1.0f}};
2038static float mute_expand_axis[3][2] = {{1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, -0.0f}};
2039
2040/* Is zero initialized because it is static data. */
2041static struct {
2042 gpu::Batch *batch;
2044 uint count;
2045 bool enabled;
2048
2050{
2051 g_batch_link.count = 0;
2052}
2053
2055 uint uv_id,
2056 uint pos_id,
2057 uint exp_id,
2058 uint v,
2059 const float uv[2],
2060 const float pos[2],
2061 const float exp[2])
2062{
2063 GPU_vertbuf_attr_set(vbo, uv_id, v, uv);
2064 GPU_vertbuf_attr_set(vbo, pos_id, v, pos);
2065 GPU_vertbuf_attr_set(vbo, exp_id, v, exp);
2066}
2067
2069{
2070 GPUVertFormat format = {0};
2071 uint uv_id = GPU_vertformat_attr_add(&format, "uv", gpu::VertAttrType::SFLOAT_32_32);
2072 uint pos_id = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2073 uint expand_id = GPU_vertformat_attr_add(&format, "expand", gpu::VertAttrType::SFLOAT_32_32);
2075 int vcount = LINK_RESOL * 2; /* curve */
2076 vcount += 2; /* restart strip */
2077 vcount += 3 * 2; /* arrow */
2078 vcount += 2; /* restart strip */
2079 vcount += 3 * 2; /* mute */
2080 vcount *= 2; /* shadow */
2081 vcount += 2; /* restart strip */
2082 GPU_vertbuf_data_alloc(*vbo, vcount);
2083 int v = 0;
2084
2085 for (int k = 0; k < 2; k++) {
2086 float uv[2] = {0.0f, 0.0f};
2087 float pos[2] = {0.0f, 0.0f};
2088 float exp[2] = {0.0f, 1.0f};
2089
2090 /* restart */
2091 if (k == 1) {
2092 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2093 }
2094
2095 /* curve strip */
2096 for (int i = 0; i < LINK_RESOL; i++) {
2097 uv[0] = (i / float(LINK_RESOL - 1));
2098 uv[1] = 0.0f;
2099 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2100 uv[1] = 1.0f;
2101 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2102 }
2103 /* restart */
2104 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2105
2106 uv[0] = 0.5f;
2107 uv[1] = 0.0f;
2108 copy_v2_v2(pos, arrow_verts[0]);
2110 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2111 /* arrow */
2112 for (int i = 0; i < 3; i++) {
2113 uv[1] = 0.0f;
2114 copy_v2_v2(pos, arrow_verts[i]);
2116 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2117
2118 uv[1] = 1.0f;
2119 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2120 }
2121
2122 /* restart */
2123 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2124
2125 uv[0] = 0.5f;
2126 uv[1] = 0.0f;
2127 copy_v2_v2(pos, mute_verts[0]);
2129 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2130 /* bar */
2131 for (int i = 0; i < 3; ++i) {
2132 uv[1] = 0.0f;
2133 copy_v2_v2(pos, mute_verts[i]);
2135 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2136
2137 uv[1] = 1.0f;
2138 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2139 }
2140
2141 /* restart */
2142 if (k == 0) {
2143 set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
2144 }
2145 }
2146
2149
2150 /* Instances data */
2153
2155}
2156
2157static char nodelink_get_color_id(int th_col)
2158{
2159 switch (th_col) {
2160 case TH_WIRE:
2161 return 1;
2162 case TH_WIRE_INNER:
2163 return 2;
2164 case TH_ACTIVE:
2165 return 3;
2166 case TH_EDGE_SELECT:
2167 return 4;
2168 case TH_REDALERT:
2169 return 5;
2170 }
2171 return 0;
2172}
2173
2174static void nodelink_batch_draw(const SpaceNode &snode)
2175{
2176 if (g_batch_link.count == 0) {
2177 return;
2178 }
2179
2181 NodeLinkUniformData node_link_data;
2182
2184 node_link_data.colors[nodelink_get_color_id(TH_WIRE_INNER)]);
2189
2190 /* Ensure alert wires are visible regardless of alert's alpha. */
2191 float alert_color[4];
2193 alert_color[3] = std::min(alert_color[3] + 0.6f, 0.8f);
2194 ui::theme::get_color_blend_3f(TH_WIRE_INNER, TH_REDALERT, alert_color[3], alert_color);
2195 copy_v4_v4(node_link_data.colors[nodelink_get_color_id(TH_REDALERT)], alert_color);
2196
2197 node_link_data.aspect = snode.runtime->aspect;
2198 node_link_data.arrow_size = ARROW_SIZE;
2199
2201 sizeof(node_link_data), &node_link_data, __func__);
2202
2203 /* TODO(fclem): Update sub. */
2205
2207 GPU_batch_uniformbuf_bind(g_batch_link.batch, "link_uniforms", ubo);
2208 GPU_storagebuf_bind(g_batch_link.link_buf, 0);
2210
2213
2215
2217}
2218
2219void nodelink_batch_start(const SpaceNode & /*snode*/)
2220{
2221 g_batch_link.enabled = true;
2222}
2223
2225{
2226 nodelink_batch_draw(snode);
2227 g_batch_link.enabled = false;
2228}
2229
2250
2251static void nodelink_batch_add_link(const SpaceNode &snode,
2252 const std::array<float2, 4> &points,
2253 const NodeLinkDrawConfig &draw_config)
2254{
2255 /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */
2256 BLI_assert(
2258 BLI_assert(
2260 BLI_assert(ELEM(draw_config.th_col3, TH_WIRE, TH_REDALERT, -1));
2261
2262 NodeLinkData &data = g_batch_link.data[g_batch_link.count++];
2263 data.bezier_P0 = points[0];
2264 data.bezier_P1 = points[1];
2265 data.bezier_P2 = points[2];
2266 data.bezier_P3 = points[3];
2267
2268 char *colid = reinterpret_cast<char *>(&data.color_ids);
2269 colid[0] = nodelink_get_color_id(draw_config.th_col1);
2270 colid[1] = nodelink_get_color_id(draw_config.th_col2);
2271 colid[2] = nodelink_get_color_id(draw_config.th_col3);
2272
2273 data.do_muted = draw_config.draw_muted;
2274 data.do_arrow = draw_config.draw_arrow;
2275 data.start_color = float4(draw_config.start_color);
2276 data.end_color = float4(draw_config.end_color);
2277 data.dim_factor = draw_config.dim_factor;
2278 data.thickness = draw_config.thickness;
2279 data.dash_length = draw_config.dash_length;
2280 data.dash_factor = draw_config.dash_factor;
2281 data.dash_alpha = draw_config.dash_alpha;
2282 data.has_back_link = draw_config.has_back_link;
2283
2284 if (g_batch_link.count == NODELINK_GROUP_SIZE) {
2285 nodelink_batch_draw(snode);
2286 }
2287}
2288
2289static void node_draw_link_end_marker(const float2 center,
2290 const float radius,
2291 const ColorTheme4f &color)
2292{
2293 rctf rect;
2294 BLI_rctf_init(&rect, center.x - radius, center.x + radius, center.y - radius, center.y + radius);
2295
2297 ui::draw_roundbox_4fv(&rect, true, radius, color);
2298 /* Round-box disables alpha. Re-enable it for node links that are drawn after this one. */
2300}
2301
2303 const NodeLinkDrawConfig &draw_config,
2304 const std::array<float2, 4> &points,
2305 const bool outline)
2306{
2307 const float radius = (outline ? 0.65f : 0.45f) * NODE_SOCKSIZE;
2308 if (link.fromsock) {
2310 points[0], radius, outline ? draw_config.outline_color : draw_config.start_color);
2311 }
2312 if (link.tosock) {
2314 points[3], radius, outline ? draw_config.outline_color : draw_config.end_color);
2315 }
2316}
2317
2318static bool node_link_is_field_link(const SpaceNode &snode, const bNodeLink &link)
2319{
2320 const bNodeTree &tree = *snode.edittree;
2321 if (tree.type != NTREE_GEOMETRY) {
2322 return false;
2323 }
2324 if (!link.fromsock) {
2325 return false;
2326 }
2328 /* Normally, StructureType::Dynamic would result in dashed links. We override that for socket
2329 * types we know currently can't be used as fields. */
2330 return false;
2331 }
2332 if (!link.fromsock->may_be_field()) {
2333 return false;
2334 }
2335 return true;
2336}
2337
2338static bool node_link_is_gizmo_link(const SpaceNode &snode, const bNodeLink &link)
2339{
2340 if (snode.edittree->type != NTREE_GEOMETRY) {
2341 return false;
2342 }
2343 if (!link.fromsock || !link.tosock) {
2344 return false;
2345 }
2346 const bNodeTree &tree = *snode.edittree;
2347 return tree.runtime->sockets_on_active_gizmo_paths.contains(link.fromsock) &&
2348 tree.runtime->sockets_on_active_gizmo_paths.contains(link.tosock);
2349}
2350
2352 const View2D &v2d,
2353 const SpaceNode &snode,
2354 const bNodeLink &link,
2355 const int th_col1,
2356 const int th_col2,
2357 const int th_col3,
2358 const bool selected)
2359{
2360 NodeLinkDrawConfig draw_config;
2361
2362 draw_config.th_col1 = th_col1;
2363 draw_config.th_col2 = th_col2;
2364 draw_config.th_col3 = th_col3;
2365
2366 draw_config.dim_factor = selected ? 1.0f : node_link_dim_factor(v2d, link);
2367
2368 const bTheme *btheme = ui::theme::theme_get();
2369 draw_config.dash_alpha = btheme->space_node.dash_alpha;
2370
2371 const bool field_link = node_link_is_field_link(snode, link);
2372 const bool gizmo_link = node_link_is_gizmo_link(snode, link);
2373
2374 draw_config.dash_factor = field_link ? 0.75f : 1.0f;
2375 draw_config.dash_length = 10.0f * UI_SCALE_FAC;
2376
2377 const float scale = ui::view2d_scale_get_x(&v2d);
2378 /* Clamp the thickness to make the links more readable when zooming out. */
2379 draw_config.thickness = LINK_WIDTH * max_ff(UI_SCALE_FAC * scale, 1.0f) *
2380 (field_link ? 0.7f : 1.0f);
2381 draw_config.has_back_link = gizmo_link;
2382 draw_config.highlighted = link.flag & NODE_LINK_TEMP_HIGHLIGHT;
2383 draw_config.draw_arrow = ((link.tonode && link.tonode->is_reroute()) &&
2384 (link.fromnode && link.fromnode->is_reroute()));
2385 draw_config.draw_muted = (link.flag & NODE_LINK_MUTED);
2386
2387 ui::theme::get_color_4fv(th_col3, draw_config.outline_color);
2388
2391 {
2392 const bNodeTree &node_tree = *snode.edittree;
2394 &const_cast<ID &>(node_tree.id), RNA_Node, link.fromnode);
2396 &const_cast<ID &>(node_tree.id), RNA_Node, link.tonode);
2397
2398 if (link.fromsock) {
2399 node_socket_color_get(C, node_tree, from_node_ptr, *link.fromsock, draw_config.start_color);
2400 }
2401 else {
2402 node_socket_color_get(C, node_tree, to_node_ptr, *link.tosock, draw_config.start_color);
2403 }
2404
2405 if (link.tosock) {
2406 node_socket_color_get(C, node_tree, to_node_ptr, *link.tosock, draw_config.end_color);
2407 }
2408 else {
2409 node_socket_color_get(C, node_tree, from_node_ptr, *link.fromsock, draw_config.end_color);
2410 }
2411 }
2412 else {
2413 ui::theme::get_color_4fv(th_col1, draw_config.start_color);
2414 ui::theme::get_color_4fv(th_col2, draw_config.end_color);
2415 }
2416
2417 draw_config.outline_color.a = 1.0f;
2418
2419 /* Highlight links connected to selected nodes. */
2420 if (selected) {
2421 ColorTheme4f color_selected;
2423 const float alpha = color_selected.a;
2424
2425 /* Interpolate color if highlight color is not fully transparent. */
2426 if (alpha != 0.0) {
2427 if (link.fromsock) {
2428 interp_v3_v3v3(draw_config.start_color, draw_config.start_color, color_selected, alpha);
2429 }
2430 if (link.tosock) {
2431 interp_v3_v3v3(draw_config.end_color, draw_config.end_color, color_selected, alpha);
2432 }
2433 }
2434 }
2435
2436 if (draw_config.highlighted) {
2437 ColorTheme4f link_preselection_highlight_color;
2438 ui::theme::get_color_4fv(TH_SELECT, link_preselection_highlight_color);
2439 /* Multi sockets can only be inputs. So we only have to highlight the end of the link. */
2440 copy_v4_v4(draw_config.end_color, link_preselection_highlight_color);
2441 }
2442
2443 return draw_config;
2444}
2445
2446static void node_draw_link_bezier_ex(const SpaceNode &snode,
2447 const NodeLinkDrawConfig &draw_config,
2448 const std::array<float2, 4> &points)
2449{
2450 if (g_batch_link.batch == nullptr) {
2452 }
2453
2454 if (g_batch_link.enabled && !draw_config.highlighted) {
2455 /* Add link to batch. */
2456 nodelink_batch_add_link(snode, points, draw_config);
2457 }
2458 else {
2459 /* Slow path but should eventually not be the majority of them. */
2460 nodelink_batch_start(snode);
2461 nodelink_batch_add_link(snode, points, draw_config);
2462 nodelink_batch_end(snode);
2463 }
2464}
2465
2467 const View2D &v2d,
2468 const SpaceNode &snode,
2469 const bNodeLink &link,
2470 const int th_col1,
2471 const int th_col2,
2472 const int th_col3,
2473 const bool selected)
2474{
2475 const std::array<float2, 4> points = node_link_bezier_points(link);
2476 if (!node_link_draw_is_visible(v2d, points)) {
2477 return;
2478 }
2479 const NodeLinkDrawConfig draw_config = nodelink_get_draw_config(
2480 C, v2d, snode, link, th_col1, th_col2, th_col3, selected);
2481
2482 node_draw_link_bezier_ex(snode, draw_config, points);
2483}
2484
2486 const View2D &v2d,
2487 const SpaceNode &snode,
2488 const bNodeLink &link,
2489 const bool selected)
2490{
2491 int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE;
2492
2493 if (link.fromsock == nullptr && link.tosock == nullptr) {
2494 return;
2495 }
2496
2497 /* going to give issues once... */
2498 if (link.tosock->flag & SOCK_UNAVAIL) {
2499 return;
2500 }
2501 if (link.fromsock->flag & SOCK_UNAVAIL) {
2502 return;
2503 }
2504
2505 if (link.flag & NODE_LINK_VALID) {
2506 /* special indicated link, on drop-node */
2508 th_col1 = th_col2 = TH_ACTIVE;
2509 }
2510 else if (link.flag & NODE_LINK_MUTED) {
2511 th_col1 = th_col2 = TH_REDALERT;
2512 }
2513 }
2514 else {
2515 /* Invalid link. */
2516 th_col1 = th_col2 = th_col3 = TH_REDALERT;
2517 // th_col3 = -1; /* no shadow */
2518 }
2519
2520 node_draw_link_bezier(C, v2d, snode, link, th_col1, th_col2, th_col3, selected);
2521}
2522
2523std::array<float2, 4> node_link_bezier_points_dragged(const SpaceNode &snode,
2524 const bNodeLink &link)
2525{
2526 const float2 cursor = snode.runtime->cursor * UI_SCALE_FAC;
2527 std::array<float2, 4> points;
2528 points[0] = link.fromsock ?
2530 cursor;
2531 points[3] = link.tosock ? socket_link_connection_location(*link.tonode, *link.tosock, link) :
2532 cursor;
2534 return points;
2535}
2536
2538 const View2D &v2d,
2539 const SpaceNode &snode,
2540 const bNodeLink &link)
2541{
2542 if (link.fromsock == nullptr && link.tosock == nullptr) {
2543 return;
2544 }
2545
2546 const std::array<float2, 4> points = node_link_bezier_points_dragged(snode, link);
2547
2548 const NodeLinkDrawConfig draw_config = nodelink_get_draw_config(
2549 C, v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE, true);
2550 /* End marker outline. */
2551 node_draw_link_end_markers(link, draw_config, points, true);
2552 /* Link. */
2553 node_draw_link_bezier_ex(snode, draw_config, points);
2554 /* End marker fill. */
2555 node_draw_link_end_markers(link, draw_config, points, false);
2556}
2557
2559
2560} // namespace ed::space_node
2561
2562} // namespace blender
#define NODE_GROUP
Definition BKE_node.hh:865
#define NODE_FRAME
Definition BKE_node.hh:866
#define SH_NODE_COMBINE_COLOR
#define SH_NODE_MIX_RGB_LEGACY
#define SH_NODE_CURVE_FLOAT
#define CMP_NODE_TIME
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_NORMAL
#define SH_NODE_TEX_IMAGE
#define TEX_NODE_PROC_MAX
#define CMP_NODE_SEPARATE_COLOR
#define CMP_NODE_CRYPTOMATTE
#define SH_NODE_SEPARATE_COLOR
#define TEX_NODE_BRICKS
#define SH_NODE_TEX_ENVIRONMENT
#define SH_NODE_CURVE_VEC
#define CMP_NODE_HUECORRECT
#define TEX_NODE_COMBINE_COLOR
#define SH_NODE_MATH
#define TEX_NODE_TEXTURE
#define TEX_NODE_SEPARATE_COLOR
#define CMP_NODE_CRYPTOMATTE_LEGACY
#define SH_NODE_OUTPUT_MATERIAL
#define TEX_NODE_IMAGE
#define CMP_NODE_CURVE_RGB
#define CMP_NODE_COMBINE_COLOR
#define SH_NODE_VECTOR_DISPLACEMENT
#define SH_NODE_VALTORGB
#define NODE_COMBINE_BUNDLE
#define SH_NODE_CURVE_RGB
#define TEX_NODE_OUTPUT
#define TEX_NODE_CURVE_TIME
#define SH_NODE_DISPLACEMENT
#define TEX_NODE_MATH
#define SH_NODE_BSDF_REFRACTION
#define CMP_NODE_IMAGE
#define TEX_NODE_PROC
#define CMP_NODE_NORMAL
#define SH_NODE_OUTPUT_LIGHT
#define SH_NODE_VOLUME_SCATTER
#define TEX_NODE_MIX_RGB
#define TEX_NODE_VALTORGB
#define TEX_NODE_CURVE_RGB
#define M_SQRT2
#define SNPRINTF_UTF8(dst, format,...)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_ID_TEXTURE
#define UI_SCALE_FAC
#define REGION_DRAW_BACKDROP
#define GPU_batch_uniformbuf_bind(batch, name, ubo)
Definition GPU_batch.hh:282
#define GPU_batch_uniform_4fv_array(batch, name, len, val)
Definition GPU_batch.hh:278
#define GPU_storagebuf_create(size)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
volatile int lock
#define BLI_assert_unreachable()
#define ELEM(...)
#define output
ChannelStorageType a
constexpr StringRef()
const nodes::SocketDeclaration * declaration
std::unique_ptr< nodes::gizmos::TreeGizmoPropagation > gizmo_propagation
Set< const bNodeSocket * > sockets_on_active_gizmo_paths
constexpr bool is_empty() const
std::unique_ptr< SocketNameRNA > socket_name_rna
#define LINK_RESOL
Definition drawnode.cc:2029
#define ARROW_SIZE
Definition drawnode.cc:2031
#define MAX_SOCKET_PARAMETERS
Definition drawnode.cc:1893
#define NODELINK_GROUP_SIZE
Definition drawnode.cc:2028
#define MAX_SOCKET_INSTANCE
Definition drawnode.cc:1894
#define DEFAULT_FLAGS
Definition drawnode.cc:78
#define SAMPLE_FLT_ISNONE
Definition drawnode.cc:135
#define LINK_WIDTH
Definition drawnode.cc:2030
#define storage(slot, qualifiers)
#define exp
#define abs
float3x3 scale(float3x3 mat, float2 scale)
bNodeSocketType NodeSocketTypeUndefined
Definition node.cc:135
Span< bNodeType * > node_types_get()
Definition node.cc:2951
bNodeType NodeTypeUndefined
Definition node.cc:134
bNodeSocketType * node_socket_type_find(StringRef idname)
Definition node.cc:2966
const bNodeInstanceKey NODE_INSTANCE_KEY_NONE
Definition node.cc:5601
static void std_node_socket_interface_draw(ID *id, bNodeTreeInterfaceSocket *interface_socket, bContext *, ui::Layout *layout)
Definition drawnode.cc:1528
static const float virtual_node_socket_color[4]
Definition drawnode.cc:1025
static void node_buts_mix_rgb(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:99
static const float std_node_socket_colors[][4]
Definition drawnode.cc:1028
void node_geometry_add_attribute_search_button(const bContext &, const bNode &node, PointerRNA &socket_ptr, ui::Layout &layout, const StringRef placeholder)
static bool socket_needs_volume_grid_search(const bNode &node, const bNodeSocket &socket)
Definition drawnode.cc:1132
static void node_composit_buts_cryptomatte(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:609
static float mute_expand_axis[3][2]
Definition drawnode.cc:2038
static void calculate_inner_link_bezier_points(std::array< float2, 4 > &points)
Definition drawnode.cc:1818
static void node_composit_buts_combsep_color(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:575
static void node_socket_undefined_draw(bContext *, ui::Layout *layout, PointerRNA *, PointerRNA *, StringRef)
Definition drawnode.cc:933
static void node_composit_buts_cryptomatte_legacy_ex(ui::Layout &layout, bContext *, PointerRNA *)
Definition drawnode.cc:601
void node_draw_link_bezier(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link, const int th_col1, const int th_col2, const int th_col3, const bool selected)
Definition drawnode.cc:2466
static void draw_node_socket_name_editable(ui::Layout *layout, bNodeSocket *sock, const StringRef text)
Definition drawnode.cc:1163
static bool socket_needs_bundle_type_search(const bNode &node, const bNodeSocket &socket)
Definition drawnode.cc:1147
static void draw_node_socket_without_value(ui::Layout *layout, bNodeSocket *sock, const StringRef text)
Definition drawnode.cc:1183
static bool node_link_is_gizmo_link(const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2338
void node_geometry_add_volume_grid_search_button(const bContext &, const bNode &node, PointerRNA &socket_ptr, ui::Layout &layout, const StringRef placeholder)
std::array< float2, 4 > node_link_bezier_points_dragged(const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2523
static float arrow_expand_axis[3][2]
Definition drawnode.cc:2036
static void node_texture_buts_output(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:826
static void node_template_properties_update(bke::bNodeType *ntype)
Definition drawnode.cc:917
void node_socket_color_get(const bContext &C, const bNodeTree &ntree, PointerRNA &node_ptr, const bNodeSocket &sock, float r_color[4])
static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link, const int th_col1, const int th_col2, const int th_col3, const bool selected)
Definition drawnode.cc:2351
static void node_shader_buts_scatter(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:445
static void node_buts_time(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:113
void node_draw_link(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link, const bool selected)
Definition drawnode.cc:2485
static void nodelink_batch_reset()
Definition drawnode.cc:2049
static void draw_node_socket_batch(const NodeSocketShaderParameters &socket_params)
Definition drawnode.cc:1969
static void node_shader_buts_tex_image_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:401
float2 node_link_calculate_multi_input_position(const float2 &socket_position, const int index, const int total_inputs)
Definition node_edit.cc:763
static void node_texture_buts_image_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:819
static void nodelink_batch_init()
Definition drawnode.cc:2068
static bool socket_needs_layer_search(const bNode &node, const bNodeSocket &socket)
Definition drawnode.cc:1117
static struct blender::ed::space_node::@127370036315071203143025210136121224333113371107 g_batch_link
void std_node_socket_colors_get(int socket_type, float *r_color)
Definition drawnode.cc:1056
static GBatchNodesocket & g_batch_nodesocket()
Definition drawnode.cc:1902
void node_draw_link_dragged(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2537
static char nodelink_get_color_id(int th_col)
Definition drawnode.cc:2157
static void nodelink_batch_add_link(const SpaceNode &snode, const std::array< float2, 4 > &points, const NodeLinkDrawConfig &draw_config)
Definition drawnode.cc:2251
static void node_composit_buts_image(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:532
static void std_node_socket_draw(bContext *C, ui::Layout *layout, PointerRNA *ptr, PointerRNA *node_ptr, StringRef label)
Definition drawnode.cc:1190
static void node_shader_buts_tex_environment_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:421
static void node_draw_buttons_group(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:275
static void node_composit_buts_image_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:550
static void node_buts_curvecol(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:150
void draw_nodespace_back_pix(const bContext &C, ARegion &region, SpaceNode &snode, bNodeInstanceKey parent_key)
Definition drawnode.cc:1724
static void node_socket_undefined_draw_color_simple(const bke::bNodeSocketType *, float *r_color)
Definition drawnode.cc:953
static void node_texture_buts_proc(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:697
float node_link_dim_factor(const View2D &v2d, const bNodeLink &link)
Definition node_edit.cc:891
void node_bundle_type_add_string_search_button(const bContext &, const bNode &node, PointerRNA &socket_ptr, ui::Layout &layout, const StringRef placeholder)
static void node_texture_buts_bricks(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:683
static void node_composit_set_butfunc(bke::bNodeType *ntype)
Definition drawnode.cc:644
static bool node_link_is_field_link(const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2318
static const SocketColorFn std_node_socket_color_funcs[]
Definition drawnode.cc:1080
static float arrow_verts[3][2]
Definition drawnode.cc:2035
static std::array< float2, 4 > node_link_bezier_points(const bNodeLink &link)
Definition drawnode.cc:1844
static void node_buts_image_views(ui::Layout &layout, bContext *, PointerRNA *ptr, PointerRNA *imaptr)
Definition drawnode.cc:511
static void std_node_socket_color_simple_fn(const bke::bNodeSocketType *type, float *r_color)
Definition drawnode.cc:1073
static void node_buts_frame_ex(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:280
static void node_buts_output_shader(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:440
static bool node_link_draw_is_visible(const View2D &v2d, const std::array< float2, 4 > &points)
Definition drawnode.cc:1853
static void node_common_set_butfunc(bke::bNodeType *ntype)
Definition drawnode.cc:287
static void nodesocket_cache_flush()
Definition drawnode.cc:1924
static void node_composit_buts_cryptomatte_legacy(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:586
static void node_buts_texture(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:179
void node_link_bezier_points_evaluated(const bNodeLink &link, std::array< float2, NODE_LINK_RESOL+1 > &coords)
Definition drawnode.cc:1864
static void node_buts_colorramp(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:118
static void node_buts_normal(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:169
static void node_texture_buts_combsep_color(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:831
static void node_texture_set_butfunc(bke::bNodeType *ntype)
Definition drawnode.cc:837
static void node_socket_virtual_draw_color(bContext *, PointerRNA *, PointerRNA *, float *r_color)
Definition drawnode.cc:1660
static void nodelink_batch_draw(const SpaceNode &snode)
Definition drawnode.cc:2174
float2 socket_link_connection_location(const bNode &node, const bNodeSocket &socket, const bNodeLink &link)
Definition drawnode.cc:1804
static void node_draw_link_bezier_ex(const SpaceNode &snode, const NodeLinkDrawConfig &draw_config, const std::array< float2, 4 > &points)
Definition drawnode.cc:2446
static void node_socket_undefined_draw_color(bContext *, PointerRNA *, PointerRNA *, float *r_color)
Definition drawnode.cc:942
static void node_texture_buts_image(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:814
static void node_socket_template_properties_update(bke::bNodeType *ntype, bke::bNodeSocketTemplate *stemp)
Definition drawnode.cc:906
static void node_socket_button_label(bContext *, ui::Layout *layout, PointerRNA *, PointerRNA *, const StringRef text)
Definition drawnode.cc:84
static void node_shader_set_butfunc(bke::bNodeType *ntype)
Definition drawnode.cc:451
NodeResizeDirection node_get_resize_direction(const SpaceNode &snode, const bNode *node, const int x, const int y)
Definition drawnode.cc:211
static void node_buts_curvevec(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:123
void nodelink_batch_end(const SpaceNode &snode)
Definition drawnode.cc:2224
static void node_shader_buts_tex_environment(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:407
void nodelink_batch_start(const SpaceNode &)
Definition drawnode.cc:2219
void std_node_socket_color_fn(bContext *, PointerRNA *, PointerRNA *, float *r_color)
Definition drawnode.cc:1066
static void node_shader_buts_glossy(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:435
static void node_draw_link_end_marker(const float2 center, const float radius, const ColorTheme4f &color)
Definition drawnode.cc:2289
static void node_buts_combsep_color(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:200
void(*)(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color) SocketColorFn
Definition drawnode.cc:1078
static void node_shader_buts_tex_image(ui::Layout &layout, bContext *C, PointerRNA *ptr)
Definition drawnode.cc:379
static void draw_gizmo_pin_icon(ui::Layout *layout, PointerRNA *socket_ptr)
Definition drawnode.cc:1158
static void node_socket_undefined_interface_draw(ID *, bNodeTreeInterfaceSocket *, bContext *, ui::Layout *layout)
Definition drawnode.cc:962
static void node_buts_math(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:194
static void node_socket_virtual_draw_color_simple(const bke::bNodeSocketType *, float *r_color)
Definition drawnode.cc:1668
void node_geometry_add_layer_search_button(const bContext &, const bNode &node, PointerRNA &socket_ptr, ui::Layout &layout, const StringRef placeholder)
static float mute_verts[3][2]
Definition drawnode.cc:2037
static void node_buts_image_user(ui::Layout &layout, bContext *C, PointerRNA *ptr, PointerRNA *imaptr, PointerRNA *iuserptr, const bool show_layer_selection, const bool show_color_management)
Definition drawnode.cc:305
static void node_composit_buts_huecorrect(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:559
void node_draw_nodesocket(const rctf *rect, const float color_inner[4], const float color_outline[4], float outline_thickness, int shape, float aspect)
Definition drawnode.cc:1988
static void node_draw_link_end_markers(const bNodeLink &link, const NodeLinkDrawConfig &draw_config, const std::array< float2, 4 > &points, const bool outline)
Definition drawnode.cc:2302
static gpu::Batch * nodesocket_batch_init()
Definition drawnode.cc:1908
static void node_property_update_default(Main *bmain, Scene *, PointerRNA *ptr)
Definition drawnode.cc:898
static void node_shader_buts_displacement(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:430
static void set_nodelink_vertex(gpu::VertBuf *vbo, uint uv_id, uint pos_id, uint exp_id, uint v, const float uv[2], const float pos[2], const float exp[2])
Definition drawnode.cc:2054
static bool socket_needs_attribute_search(bNode &node, bNodeSocket &socket)
Definition drawnode.cc:1102
static void node_buts_curvefloat(ui::Layout &layout, bContext *, PointerRNA *ptr)
Definition drawnode.cc:128
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
T safe_divide(const T &a, const T &b)
T distance(const T &a, const T &b)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T max(const T &a, const T &b)
bool is_builtin_gizmo_node(const bNode &node)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
int get_value_type(int colorid, int spacetype)
void get_color_4fv(int colorid, float col[4])
const bTheme * theme_get()
void get_color_blend_3f(int colorid1, int colorid2, float fac, float r_col[3])
void draw_roundbox_corner_set(int type)
float view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1902
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
BMesh Iterators.
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_storagebuf_update(gpu::StorageBuf *ssbo, const void *data)
gpu::FrameBuffer * GPU_framebuffer_active_get()
void uiTemplateImage(ui::Layout *layout, bContext *C, PointerRNA *ptr, StringRefNull propname, PointerRNA *userptr, bool compact, bool multiview)
void wmOrtho2_region_pixelspace(const ARegion *region)
void DRW_draw_view(const bContext *C)
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
int RNA_enum_get(PointerRNA *ptr, const char *name)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
@ IMA_TYPE_MULTILAYER
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GPU_framebuffer_restore()
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
void ED_node_sample_set(const float col[4])
Definition drawnode.cc:138
@ SOCK_DISPLAY_SHAPE_VOLUME_GRID
@ SOCK_DISPLAY_SHAPE_LIST
void GPU_matrix_identity_set()
MINLINE void copy_v2_v2(float r[2], const float a[2])
@ CMP_NODE_COMBSEP_COLOR_YCC
@ GPU_PRIM_TRI_STRIP
MINLINE void copy_v4_fl(float r[4], float f)
@ LOCK_DRAW_IMAGE
void ED_init_custom_node_socket_type(bke::bNodeSocketType *stype)
Definition drawnode.cc:1012
ATTR_WARN_UNUSED_RESULT const BMVert * v
void ED_node_type_draw_color(const char *idname, float *r_color)
Definition drawnode.cc:1699
void gpu_batch_storage_buffer_register(gpu::StorageBuf *preset_buffer)
bool is_layer_selection_field(const bNodeTreeInterfaceSocket &socket)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
VecBase< float, 4 > float4
void ED_node_init_butfuncs()
Definition drawnode.cc:978
@ SNODE_COMPOSITOR_SCENE
void GPU_viewport_colorspace_clear(GPUViewport *viewport)
ImBuf * BKE_image_acquire_ibuf_gpu(Image *ima, ImageUser *iuser, void **r_lock, bool *r_load_failed=nullptr, bool cached_only=false)
gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
VecBase< float, 2 > float2
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
BMesh const char void * data
void GPU_vertbuf_attr_set(gpu::VertBuf *, uint a_idx, uint v_idx, const void *data)
@ GPU_SHADER_2D_NODE_SOCKET_INST
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
void GPU_batch_draw_instance_range(gpu::Batch *batch, int instance_first, int instance_count)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void GPU_batch_draw(gpu::Batch *batch)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:48
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void gpu_batch_presets_register(gpu::Batch *preset_batch)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
void GPU_framebuffer_bind_no_srgb(gpu::FrameBuffer *fb)
void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
@ NODE_FRAME_RESIZEABLE
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
void ED_init_node_socket_type_virtual(bke::bNodeSocketType *stype)
Definition drawnode.cc:1691
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
Main * CTX_data_main(const bContext *C)
void GPU_matrix_pop_projection()
MINLINE float max_ff(float a, float b)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
ColorTheme4< float > ColorTheme4f
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ NODE_LINK_INSERT_TARGET
@ NODE_LINK_INSERT_TARGET_INVALID
@ NODE_LINK_TEMP_HIGHLIGHT
bool IMB_colormanagement_space_name_is_data(const char *name)
void ED_init_standard_node_socket_type(bke::bNodeSocketType *stype)
Definition drawnode.cc:1682
@ PROP_DIRECTION
Definition RNA_types.hh:319
void GPU_uniformbuf_unbind(gpu::UniformBuf *ubo)
@ CMP_NODE_CRYPTOMATTE_SOURCE_RENDER
void BLI_thread_unlock(int type)
Definition threads.cc:336
void GPU_matrix_pop()
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
Definition curve.cc:1696
void ED_init_custom_node_type(bke::bNodeType *ntype)
Definition drawnode.cc:1010
void GPU_matrix_push_projection()
int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, bool *r_is_in_range)
static float _sample_col[4]
Definition drawnode.cc:137
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
GPUViewport * WM_draw_region_get_bound_viewport(ARegion *region)
Definition wm_draw.cc:964
void GPU_matrix_push()
void BLI_thread_lock(int type)
Definition threads.cc:331
@ SN_OVERLAY_SHOW_OVERLAYS
@ SN_OVERLAY_SHOW_WIRE_COLORS
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
#define NODE_LINK_RESOL
#define NODE_RESIZE_MARGIN
#define NODE_SOCKSIZE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ThemeSpace space_node
eCurveMappingFlags flag
struct RenderData r
eSpaceNodeOverlay_Flag flag
SpaceNodeOverlay overlay
struct bNodeTree * edittree
struct bNodeTree * nodetree
ed::space_node::SpaceNode_Runtime * runtime
eSpaceNode_Flag flag
eTex_VoronoiDistMetric vn_distm
const bke::RuntimeNodeEnumItems * enum_items
bke::bNodeSocketType * typeinfo
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
eNodeSocketInOut in_out
eNodeSocketDisplayShape display_shape
eNodeTree_Type type
bke::bNodeTreeRuntime * runtime
bNodeInstanceKey active_viewer_key
ListBaseT< bNode > nodes
Vector< RuntimeNodeEnumItem > items
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a socket type.
Definition BKE_node.hh:163
void(*) draw_color(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color)
Definition BKE_node.hh:176
eNodeSocketDatatype type
Definition BKE_node.hh:198
void(*) draw_color_simple(const bNodeSocketType *socket_type, float *r_color)
Definition BKE_node.hh:177
void(*) interface_draw(ID *id, bNodeTreeInterfaceSocket *socket, bContext *C, ui::Layout *layout)
Definition BKE_node.hh:179
void(*) draw(bContext *C, ui::Layout *layout, PointerRNA *ptr, PointerRNA *node_ptr, StringRef text)
Definition BKE_node.hh:171
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
bNodeSocketTemplate * inputs
Definition BKE_node.hh:285
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:292
bNodeSocketTemplate * outputs
Definition BKE_node.hh:285
Vector< NodeSocketShaderParameters, MAX_SOCKET_INSTANCE > params
Definition drawnode.cc:1898
void alignment_set(LayoutAlign alignment)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & split(float percentage, bool align)
Layout & column(bool align)
Layout & row(bool align)
static constexpr float PROPERTY_SPLIT_FACTOR
void context_ptr_set(StringRef name, const PointerRNA *ptr)
void emboss_set(EmbossType emboss)