-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIRDS.diff
828 lines (820 loc) · 30.6 KB
/
SIRDS.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
diff --git a/scripts/startup/nodeitems_builtins.py b/scripts/startup/nodeitems_builtins.py
index 3deec135888..33bdc7b9c80 100644
--- a/scripts/startup/nodeitems_builtins.py
+++ b/scripts/startup/nodeitems_builtins.py
@@ -336,6 +336,7 @@ compositor_node_categories = [
NodeItem("CompositorNodeSunBeams"),
NodeItem("CompositorNodeDenoise"),
NodeItem("CompositorNodeAntiAliasing"),
+ NodeItem("CompositorNodeSIRDS"),
]),
CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
NodeItem("CompositorNodeNormal"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index d7d17600683..3420b2d9a1f 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1346,6 +1346,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
#define CMP_NODE_COMBINE_XYZ 331
#define CMP_NODE_COMBINE_COLOR 332
#define CMP_NODE_SEPARATE_COLOR 333
+#define CMP_NODE_SIRDS 334
/* channel toggles */
#define CMP_CHAN_RGB 1
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index f49a9694ab3..2ab639b3a4e 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -323,6 +323,8 @@ if(WITH_COMPOSITOR_CPU)
nodes/COM_InpaintNode.h
nodes/COM_PosterizeNode.cc
nodes/COM_PosterizeNode.h
+ nodes/COM_SIRDSNode.cc
+ nodes/COM_SIRDSNode.h
operations/COM_BlurBaseOperation.cc
operations/COM_BlurBaseOperation.h
@@ -354,6 +356,8 @@ if(WITH_COMPOSITOR_CPU)
operations/COM_MovieDistortionOperation.h
operations/COM_PosterizeOperation.cc
operations/COM_PosterizeOperation.h
+ operations/COM_SIRDSOperation.cc
+ operations/COM_SIRDSOperation.h
operations/COM_SMAAOperation.cc
operations/COM_SMAAOperation.h
operations/COM_VariableSizeBokehBlurOperation.cc
diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc
index 6d7341376e9..26ed419657e 100644
--- a/source/blender/compositor/intern/COM_Converter.cc
+++ b/source/blender/compositor/intern/COM_Converter.cc
@@ -87,6 +87,7 @@
#include "COM_SeparateXYZNode.h"
#include "COM_SetAlphaNode.h"
#include "COM_SetValueOperation.h"
+#include "COM_SIRDSNode.h"
#include "COM_SplitViewerNode.h"
#include "COM_Stabilize2dNode.h"
#include "COM_SunBeamsNode.h"
@@ -417,6 +418,9 @@ Node *COM_convert_bnode(bNode *b_node)
case CMP_NODE_DENOISE:
node = new DenoiseNode(b_node);
break;
+ case CMP_NODE_SIRDS:
+ node = new SIRDSNode(b_node);
+ break;
case CMP_NODE_EXPOSURE:
node = new ExposureNode(b_node);
break;
diff --git a/source/blender/compositor/nodes/COM_SIRDSNode.cc b/source/blender/compositor/nodes/COM_SIRDSNode.cc
new file mode 100644
index 00000000000..5f511b3d174
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_SIRDSNode.cc
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2011 Blender Foundation. */
+
+#include "COM_SIRDSNode.h"
+#include "COM_SIRDSOperation.h"
+
+namespace blender::compositor {
+
+void SIRDSNode::convert_to_operations(NodeConverter &converter,
+ const CompositorContext & /*context*/) const
+{
+ const bNode *editor_node = this->get_bnode();
+ const NodeSIRDS *data = static_cast<const NodeSIRDS *>(editor_node->storage);
+
+ SIRDSOperation *operation = new SIRDSOperation();
+ operation->set_data(*data);
+ converter.add_operation(operation);
+
+ converter.map_input_socket(this->get_input_socket(0), operation->get_input_socket(0));
+ converter.map_input_socket(this->get_input_socket(1), operation->get_input_socket(1));
+ converter.map_input_socket(this->get_input_socket(2), operation->get_input_socket(2));
+ converter.map_input_socket(this->get_input_socket(3), operation->get_input_socket(3));
+ converter.map_input_socket(this->get_input_socket(4), operation->get_input_socket(4));
+ converter.map_input_socket(this->get_input_socket(5), operation->get_input_socket(5));
+ converter.map_output_socket(this->get_output_socket(0), operation->get_output_socket(0));
+}
+
+} // namespace blender::compositor
\ No newline at end of file
diff --git a/source/blender/compositor/nodes/COM_SIRDSNode.h b/source/blender/compositor/nodes/COM_SIRDSNode.h
new file mode 100644
index 00000000000..eec998fd09a
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_SIRDSNode.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2011 Blender Foundation. */
+
+#pragma once
+
+#include "COM_Node.h"
+
+namespace blender::compositor {
+
+/**
+ * \brief SIRDSNode
+ * \ingroup Node
+ */
+class SIRDSNode : public Node {
+ public:
+ SIRDSNode(bNode *editor_node) : Node(editor_node)
+ {
+ }
+ void convert_to_operations(NodeConverter &converter,
+ const CompositorContext &context) const override;
+};
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SIRDSOperation.cc b/source/blender/compositor/operations/COM_SIRDSOperation.cc
new file mode 100644
index 00000000000..ee1160b81a2
--- /dev/null
+++ b/source/blender/compositor/operations/COM_SIRDSOperation.cc
@@ -0,0 +1,394 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2011 Blender Foundation. */
+
+#include "MEM_guardedalloc.h"
+
+#include "COM_SIRDSOperation.h"
+
+namespace blender::compositor {
+
+#define COM_NUM_CHANNELS_COLOR 4
+
+/* Forward declarations. */
+float zbuf_depth_map(float depth,
+ const float view_plane_distance,
+ const float eye_distance_px,
+ bool flip_z);
+void zbuf_accumulate_sirds(NodeSIRDS *nsirds,
+ int width,
+ int height,
+ SocketReader *centerReader,
+ float *outbuf,
+ const float *imgbuf,
+ const float *zbuf);
+
+SIRDSOperation::SIRDSOperation() : NodeOperation()
+{
+ this->add_input_socket(DataType::Color);
+ this->add_input_socket(DataType::Value);
+ this->add_input_socket(DataType::Value);
+ this->add_input_socket(DataType::Value);
+ this->add_input_socket(DataType::Value);
+ this->add_input_socket(DataType::Value);
+ this->add_output_socket(DataType::Color);
+ this->set_canvas_input_index(1);
+
+ this->flags_.complex = true;
+
+ this->m_cachedInstance = NULL;
+ this->m_patternReader = NULL;
+ this->m_depthReader = NULL;
+ this->m_clipstartReader = NULL;
+ this->m_clipendReader = NULL;
+ this->m_fovReader = NULL;
+ this->m_centerReader = NULL;
+}
+
+void SIRDSOperation::init_execution()
+{
+ init_mutex();
+ this->m_patternReader = this->get_input_socket_reader(0);
+ this->m_depthReader = this->get_input_socket_reader(1);
+ this->m_clipstartReader = this->get_input_socket_reader(2);
+ this->m_clipendReader = this->get_input_socket_reader(3);
+ this->m_fovReader = this->get_input_socket_reader(4);
+ this->m_centerReader = this->get_input_socket_reader(5);
+ this->m_cachedInstance = NULL;
+}
+
+void SIRDSOperation::execute_pixel(float output[4], int x, int y, void *data)
+{
+ float *buffer = (float *)data;
+ int index = (y * this->get_width() + x) * COM_NUM_CHANNELS_COLOR;
+ copy_v4_v4(output, &buffer[index]);
+}
+
+void SIRDSOperation::deinit_execution()
+{
+ deinit_mutex();
+ this->m_patternReader = NULL;
+ this->m_depthReader = NULL;
+ this->m_clipstartReader = NULL;
+ this->m_clipendReader = NULL;
+ this->m_fovReader = NULL;
+ this->m_centerReader = NULL;
+ if (this->m_cachedInstance) {
+ MEM_freeN(this->m_cachedInstance);
+ this->m_cachedInstance = NULL;
+ }
+}
+
+void *SIRDSOperation::initialize_tile_data(rcti *rect)
+{
+ if (this->m_cachedInstance) {
+ return this->m_cachedInstance;
+ }
+
+ lock_mutex();
+ if (this->m_cachedInstance == NULL) {
+ MemoryBuffer *tile = NULL;
+ tile = (MemoryBuffer *)this->m_patternReader->initialize_tile_data(rect);
+ MemoryBuffer *z = (MemoryBuffer *)this->m_depthReader->initialize_tile_data(rect);
+ float *data = (float *)MEM_dupallocN(tile->get_buffer());
+
+ float out[4];
+ this->m_clipstartReader->read_sampled(out, 0, 0, PixelSampler::Nearest);
+ this->m_data.clip_near = out[0];
+ this->m_clipendReader->read_sampled(out, 0, 0, PixelSampler::Nearest);
+ this->m_data.clip_far = out[0];
+ this->m_fovReader->read_sampled(out, 0, 0, PixelSampler::Nearest);
+ this->m_data.camera_fov = out[0];
+
+ this->generate_sirds(data, tile, z);
+ this->m_cachedInstance = data;
+ }
+ unlock_mutex();
+ return this->m_cachedInstance;
+}
+
+bool SIRDSOperation::determine_depending_area_of_interest(rcti * /*input*/,
+ ReadBufferOperation *readOperation,
+ rcti *output)
+{
+ if (this->m_cachedInstance == NULL) {
+ rcti newInput;
+ newInput.xmax = this->get_width();
+ newInput.xmin = 0;
+ newInput.ymax = this->get_height();
+ newInput.ymin = 0;
+ return NodeOperation::determine_depending_area_of_interest(&newInput, readOperation, output);
+ }
+ else {
+ return false;
+ }
+}
+
+void SIRDSOperation::get_area_of_interest(const int /*input_idx*/,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ r_input_area.xmax = this->get_width();
+ r_input_area.xmin = 0;
+ r_input_area.ymax = output_area.ymax;
+ r_input_area.ymin = output_area.ymin;
+}
+
+void SIRDSOperation::generate_sirds(float *data, MemoryBuffer *inputImage, MemoryBuffer *inputZ)
+{
+ zbuf_accumulate_sirds(&m_data,
+ this->get_width(),
+ this->get_height(),
+ this->m_centerReader,
+ data,
+ inputImage->get_buffer(),
+ inputZ->get_buffer());
+ return;
+}
+
+float zbuf_depth_map(float depth,
+ const float view_plane_distance,
+ const float eye_distance_px,
+ bool flip_z)
+{
+ if (flip_z) {
+ return depth / (depth - view_plane_distance) * eye_distance_px;
+ }
+ else {
+ return (depth - view_plane_distance) / depth * eye_distance_px;
+ }
+}
+
+void zbuf_accumulate_sirds(NodeSIRDS *nsirds,
+ int width,
+ int height,
+ SocketReader *centerReader,
+ float *outbuf,
+ const float *imgbuf,
+ const float *zbuf)
+{
+ const float eye_distance = 0.064f;
+
+ const float eye_distance_px = width * eye_distance / nsirds->view_width;
+
+ const bool flip_z = !!(nsirds->flag & CMP_NODEFLAG_SIRDS_INVERT_Z);
+ const bool elastic = !!(nsirds->flag & CMP_NODEFLAG_SIRDS_ELASTIC);
+
+ const float near_plane_distance = nsirds->clip_near;
+ const float far_plane_distance = fmaxf(near_plane_distance, nsirds->clip_far);
+ const float mean_distance = (near_plane_distance + far_plane_distance) / 2;
+
+ const float image_width_scene = tanf(nsirds->camera_fov / 2) * 2 * mean_distance;
+ const float view_plane_distance = nsirds->view_width *
+ (image_width_scene / nsirds->view_distance);
+
+ float width_tile_min = fabsf(
+ zbuf_depth_map(near_plane_distance, view_plane_distance, eye_distance_px, flip_z));
+ float width_tile_max = fabsf(
+ zbuf_depth_map(far_plane_distance, view_plane_distance, eye_distance_px, flip_z));
+ if (width_tile_min > width_tile_max) {
+ SWAP(float, width_tile_min, width_tile_max);
+ }
+ const unsigned int width_tile = round_fl_to_int(clamp_f(fabsf(width_tile_max), 3, width / 2));
+
+ const unsigned int x_center_base = (width - width_tile) / 2;
+ const unsigned int x_tile_center = width_tile / 2;
+
+ const float biggest_shift = width_tile_max - width_tile_min;
+
+ int *links = (int *)MEM_malloc_arrayN(width, sizeof(*links), "sirds links array");
+ float *depth_left = (float *)MEM_malloc_arrayN(
+ width, sizeof(*depth_left), "sirds depth_left array");
+ float *depth_right = (float *)MEM_malloc_arrayN(
+ width, sizeof(*depth_right), "sirds depth_right array");
+ float *reorder = (float *)MEM_malloc_arrayN(width_tile, sizeof(*reorder), "sirds reorder array");
+ float *reorder_priority = (float *)MEM_malloc_arrayN(
+ width_tile, sizeof(*reorder_priority), "sirds reorder_priority array");
+ float *border = (float *)MEM_malloc_arrayN(width, sizeof(*border), "sirds border array");
+
+ /* Apply filter line after line. */
+ for (int y = 0; y < height; y++) {
+ float out[4];
+ centerReader->read_sampled(out, 0, y, PixelSampler::Nearest);
+ unsigned int x_center = (width - width_tile) * out[0];
+ int line_offset = y * width;
+ float scale = 1.0f;
+
+ int visible_width = width_tile;
+ if (elastic) {
+ /* determine center row scale */
+ if (biggest_shift > 0) {
+ float max_depth = near_plane_distance;
+ float min_depth = far_plane_distance;
+ for (int x = 0; x < width; x++) {
+ float depth = zbuf[x + line_offset];
+ max_depth = max_ff(max_depth, depth);
+ min_depth = min_ff(min_depth, depth);
+ }
+ visible_width = max_ff(
+ fabsf(zbuf_depth_map(max_depth, view_plane_distance, eye_distance_px, flip_z)),
+ fabsf(zbuf_depth_map(min_depth, view_plane_distance, eye_distance_px, flip_z)));
+ scale = width_tile / (float)visible_width;
+ }
+ }
+
+ /* Reset links. */
+ for (int x = 0; x < width; x++) {
+ links[x] = x % width_tile;
+ depth_left[x] = far_plane_distance;
+ depth_right[x] = far_plane_distance;
+ }
+ for (int x = 0; x < width_tile; x++) {
+ reorder[x] = x;
+ }
+ memset(reorder_priority, 0, width_tile * sizeof(*reorder_priority));
+ /* Make links by depth. */
+ for (int i = 0; i < 1; i++) {
+ for (int j = 0; j < width - 1 - width_tile_min; j++) {
+ int x_int = (j + x_center) % (int)(width - 1 - width_tile_min / 2);
+ if (x_int < x_center) {
+ x_int = x_center - x_int;
+ }
+ float depth1 = zbuf[x_int + line_offset];
+ float depth2 = zbuf[x_int + 1 + line_offset];
+ /* Make pairs in subpixel precision. */
+ for (float k = 0.0f; k < 1.0f; k += 0.2f) {
+ float x = x_int + k;
+ float depth = fabsf(depth1 - depth2) < 0.1f ? depth1 + (depth2 - depth1) * k : depth1;
+ depth = clamp_f(depth, near_plane_distance, far_plane_distance);
+ float link_width = fabsf(
+ zbuf_depth_map(depth, view_plane_distance, eye_distance_px, flip_z));
+ float center = link_width / 2.0f;
+ if (x > x_center) {
+ /* Right side. */
+ if (x + center <= width - 1 && x - center >= 0) {
+ int index_dest = round_fl_to_int(x + center);
+ int index_src = round_fl_to_int(x - center);
+ if (depth_right[index_dest] >= depth && depth_left[index_src] >= depth) {
+ int link_index = links[index_src];
+ links[index_dest] = link_index;
+ depth_left[index_src] = depth;
+ depth_right[index_dest] = depth;
+ }
+ }
+ }
+ else {
+ /* Left side. */
+ if (x + center <= width - 1 && x - center >= 0) {
+ int index_dest = round_fl_to_int(x - center);
+ int index_src = round_fl_to_int(x + center);
+ if (depth_left[index_dest] >= depth && depth_right[index_src] >= depth) {
+ int link_index = links[index_src];
+ links[index_dest] = link_index;
+ depth_right[index_src] = depth;
+ depth_left[index_dest] = depth;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (elastic) {
+ /* Assign color to each link. */
+ memset(reorder, 0, width_tile * sizeof(*reorder));
+ memset(reorder_priority, 0, width_tile * sizeof(*reorder_priority));
+ unsigned int counter = 0;
+ for (int i = width_tile - 1; i >= 0; i--) {
+ int index = links[i + x_center];
+ if (reorder_priority[index] == 0.0f) {
+ reorder[index] = fmodf(i * scale + width_tile * (1.0f - scale), width); // TODO CHECK!
+ reorder_priority[index] = 1.0f;
+ counter++;
+ }
+ }
+ /* Patch holes. */
+ for (int i = 1; i < width - 1; i++) {
+ int index = links[i];
+ if (reorder_priority[index] == 0.0f) {
+ int left_index = links[i - 1];
+ int right_index = links[i + 1];
+ float p = 0;
+ if (reorder_priority[left_index] > 0.0f && reorder_priority[right_index] > 0.0f) {
+ p += reorder[left_index];
+ p += reorder[right_index];
+ p /= 2.0f;
+ }
+ else {
+ p = i * scale + width_tile * (1.0f - scale); // TODO CHECK!
+ }
+ reorder[index] = fmodf(p, width);
+ reorder_priority[index] = 1.0f;
+ counter++;
+ }
+ if (counter == width_tile) {
+ break;
+ }
+ }
+ }
+ else {
+ /* Calculate border map. */
+ int influence_size = 7;
+ for (int x = 0; x < width; x++) {
+ border[x] = 0;
+ float depth = clamp_f(zbuf[x + line_offset], near_plane_distance, far_plane_distance);
+ for (int i = max_ii(-influence_size, -x); i <= min_ii(influence_size, (width - 1) - x);
+ i++) {
+ if (i != 0) {
+ float depth2 = clamp_f(
+ zbuf[x + i + line_offset], near_plane_distance, far_plane_distance);
+ if (flip_z) {
+ depth2 = near_plane_distance + far_plane_distance - depth2;
+ }
+ border[x] = max_ff(border[x], (depth2 - depth) / fabsf((float)i));
+ }
+ }
+ }
+ /* Assign color to each link. (Texturemapping) */
+ for (int j = 0; j < width; j++) {
+ int i = (j + x_center) % width;
+ if (i < x_center) {
+ i = x_center - i;
+ }
+ int index = links[i];
+ float depth;
+ int offset;
+ if (i > width_tile_min / 2 && i < width - width_tile_min / 2) {
+ depth = max_ff(depth_left[i], depth_right[i]);
+ offset = (int)floorf(
+ fabsf(zbuf_depth_map(depth, view_plane_distance, eye_distance_px, flip_z)) / 2.0f);
+ if (i + offset > 0 && i + offset < width) {
+ float priority = 1.0f / depth + border[i + offset];
+ if (reorder_priority[index] < priority) {
+ reorder[index] = i + offset;
+ reorder_priority[index] = priority;
+ }
+ }
+ }
+ }
+ }
+
+ /* Write output. */
+ for (int x = 0; x < width; x++) {
+ int pixel1 = (int)floorf(reorder[links[x]]);
+ int pixel2 = (int)ceilf(reorder[links[x]]);
+ if (pixel1 >= 0 && pixel2 < width) {
+ unsigned int index = (line_offset + x) * COM_NUM_CHANNELS_COLOR;
+ int index_shifted1 = (line_offset + pixel1) * COM_NUM_CHANNELS_COLOR;
+ int index_shifted2 = (line_offset + pixel2) * COM_NUM_CHANNELS_COLOR;
+ float fac = remainder(reorder[links[x]], 1.0f);
+ for (int i = 0; i < COM_NUM_CHANNELS_COLOR; i++) {
+ outbuf[index + i] = imgbuf[index_shifted1 + i] +
+ (imgbuf[index_shifted2 + i] - imgbuf[index_shifted1 + i]) * fac;
+ }
+ }
+ }
+ }
+ MEM_freeN(links);
+ MEM_freeN(depth_left);
+ MEM_freeN(depth_right);
+ MEM_freeN(reorder);
+ MEM_freeN(reorder_priority);
+ MEM_freeN(border);
+}
+
+} // namespace blender::compositor
\ No newline at end of file
diff --git a/source/blender/compositor/operations/COM_SIRDSOperation.h b/source/blender/compositor/operations/COM_SIRDSOperation.h
new file mode 100644
index 00000000000..b5b261ecc3b
--- /dev/null
+++ b/source/blender/compositor/operations/COM_SIRDSOperation.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2017 Blender Foundation. */
+
+#pragma once
+
+#include "COM_MultiThreadedOperation.h"
+
+namespace blender::compositor {
+
+class SIRDSOperation : public NodeOperation {
+ public:
+ SIRDSOperation();
+
+ void execute_pixel(float output[4], int x, int y, void *data) override;
+
+ void init_execution() override;
+
+ void *initialize_tile_data(rcti *rect) override;
+
+ void deinit_execution() override;
+
+ bool determine_depending_area_of_interest(rcti *input,
+ ReadBufferOperation *read_operation,
+ rcti *output) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+
+ void set_data(const NodeSIRDS &data)
+ {
+ m_data = data;
+ }
+
+ protected:
+ void generate_sirds(float *data, MemoryBuffer *inputImage, MemoryBuffer *inputZ);
+
+ private:
+ NodeSIRDS m_data;
+
+ SocketReader *m_patternReader;
+ SocketReader *m_depthReader;
+
+ SocketReader *m_clipstartReader;
+ SocketReader *m_clipendReader;
+ SocketReader *m_fovReader;
+ SocketReader *m_centerReader;
+
+ float *m_cachedInstance;
+};
+
+} // namespace blender::compositor
\ No newline at end of file
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 9e4505ca529..c35b007ba80 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1298,6 +1298,16 @@ typedef struct NodeMapRange {
char _pad[5];
} NodeMapRange;
+typedef struct NodeSIRDS {
+ float clip_near;
+ float clip_far;
+ float camera_fov;
+ float view_width;
+ float view_distance;
+
+ int flag;
+} NodeSIRDS;
+
typedef struct NodeRandomValue {
/* eCustomDataType. */
uint8_t data_type;
@@ -2103,6 +2113,12 @@ enum {
CMP_NODEFLAG_STABILIZE_INVERSE = 1,
};
+/* SIRDS node */
+enum {
+ CMP_NODEFLAG_SIRDS_INVERT_Z = 1,
+ CMP_NODEFLAG_SIRDS_ELASTIC = 2,
+};
+
/* Set Alpha Node. */
/** #NodeSetAlpha.mode */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 12d4827bd9b..146a07c67e8 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9276,6 +9276,35 @@ static void def_cmp_antialiasing(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
+static void def_cmp_sirds(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ RNA_def_struct_sdna_from(srna, "NodeSIRDS", "storage");
+
+ prop = RNA_def_property(srna, "elastic", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CMP_NODEFLAG_SIRDS_ELASTIC);
+ RNA_def_property_ui_text(prop, "Elastic", "Stretch tile width to use the same width on every row");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "invert_z", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CMP_NODEFLAG_SIRDS_INVERT_Z);
+ RNA_def_property_ui_text(prop, "Invert Z", "Invert depth for crossing eyes instead of looking through the image (parallel viewing)");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "view_width", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "view_width");
+ RNA_def_property_range(prop, 0.0, FLT_MAX);
+ RNA_def_property_ui_text(prop, "View Width", "The size of the displayed image in real world units");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "view_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "view_distance");
+ RNA_def_property_range(prop, 0.0, FLT_MAX);
+ RNA_def_property_ui_text(prop, "View Distance", "The usual inspection distance to the image in real world units");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
/* -- Texture Nodes --------------------------------------------------------- */
static void def_tex_output(StructRNA *srna)
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index cb97e88ac9f..a5d5d023842 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -223,6 +223,7 @@ DefNode(CompositorNode, CMP_NODE_COMBINE_XYZ, 0, "COMBIN
DefNode(CompositorNode, CMP_NODE_SEPARATE_XYZ, 0, "SEPARATE_XYZ", SeparateXYZ, "Separate XYZ", "" )
DefNode(CompositorNode, CMP_NODE_SEPARATE_COLOR, def_cmp_combsep_color, "SEPARATE_COLOR", SeparateColor, "Separate Color", "" )
DefNode(CompositorNode, CMP_NODE_COMBINE_COLOR, def_cmp_combsep_color, "COMBINE_COLOR", CombineColor, "Combine Color", "" )
+DefNode(CompositorNode, CMP_NODE_SIRDS, def_cmp_sirds, "SIRDS", SIRDS, "SIRDS", "" )
DefNode(TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" )
DefNode(TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" )
diff --git a/source/blender/nodes/composite/CMakeLists.txt b/source/blender/nodes/composite/CMakeLists.txt
index 6fb4e9ba753..f9df0477482 100644
--- a/source/blender/nodes/composite/CMakeLists.txt
+++ b/source/blender/nodes/composite/CMakeLists.txt
@@ -105,6 +105,7 @@ set(SRC
nodes/node_composite_sepcomb_ycca.cc
nodes/node_composite_sepcomb_yuva.cc
nodes/node_composite_setalpha.cc
+ nodes/node_composite_sirds.cc
nodes/node_composite_split_viewer.cc
nodes/node_composite_stabilize2d.cc
nodes/node_composite_sunbeams.cc
diff --git a/source/blender/nodes/composite/node_composite_register.cc b/source/blender/nodes/composite/node_composite_register.cc
index 38796cbea60..84b01647cab 100644
--- a/source/blender/nodes/composite/node_composite_register.cc
+++ b/source/blender/nodes/composite/node_composite_register.cc
@@ -92,6 +92,7 @@ void register_composite_nodes()
register_node_type_cmp_sepycca();
register_node_type_cmp_sepyuva();
register_node_type_cmp_setalpha();
+ register_node_type_cmp_sirds();
register_node_type_cmp_splitviewer();
register_node_type_cmp_stabilize2d();
register_node_type_cmp_sunbeams();
diff --git a/source/blender/nodes/composite/node_composite_register.hh b/source/blender/nodes/composite/node_composite_register.hh
index f15a71cfae1..5495fb8fd03 100644
--- a/source/blender/nodes/composite/node_composite_register.hh
+++ b/source/blender/nodes/composite/node_composite_register.hh
@@ -88,6 +88,7 @@ void register_node_type_cmp_seprgba();
void register_node_type_cmp_sepycca();
void register_node_type_cmp_sepyuva();
void register_node_type_cmp_setalpha();
+void register_node_type_cmp_sirds();
void register_node_type_cmp_splitviewer();
void register_node_type_cmp_stabilize2d();
void register_node_type_cmp_sunbeams();
diff --git a/source/blender/nodes/composite/nodes/node_composite_sirds.cc b/source/blender/nodes/composite/nodes/node_composite_sirds.cc
new file mode 100644
index 00000000000..67cbcf4e647
--- /dev/null
+++ b/source/blender/nodes/composite/nodes/node_composite_sirds.cc
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2006 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup cmpnodes
+ */
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "COM_node_operation.hh"
+
+#include "node_composite_util.hh"
+
+namespace blender::nodes::node_composite_sirds_cc {
+
+static void cmp_node_sirds_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Color>(N_("Pattern"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("Depth"))
+ .default_value(0.0f)
+ .subtype(PROP_NONE)
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Clip Start"))
+ .default_value(5.0f)
+ .min(0.0001f)
+ .max(10000.0f)
+ .subtype(PROP_DISTANCE)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Clip End"))
+ .default_value(10.0f)
+ .min(0.0001f)
+ .max(10000.0f)
+ .subtype(PROP_DISTANCE)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Camera FOV"))
+ .default_value(0.691112f)
+ .min(0.0001f)
+ .max(3.14f)
+ .subtype(PROP_ANGLE)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Center"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(1);
+ b.add_output<decl::Color>(N_("Image"));
+}
+
+static void node_composit_init_sirds(bNodeTree * /*ntree*/, bNode *node)
+{
+ NodeSIRDS *nsirds = (NodeSIRDS *)MEM_callocN(sizeof(NodeSIRDS), "node sirds data");
+ nsirds->clip_far = 5.0f;
+ nsirds->clip_near = 0.5f;
+ nsirds->camera_fov = 0.691112f; /* Default startup camera FOV */
+ nsirds->view_width = 0.4f;
+ nsirds->view_distance = 0.5f;
+ node->storage = nsirds;
+}
+
+static void node_composit_buts_sirds(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiLayout *col = uiLayoutColumn(layout, true);
+ uiItemR(col, ptr, "view_width", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "view_distance", 0, NULL, ICON_NONE);
+
+ col = uiLayoutColumn(layout, true);
+ uiItemR(col, ptr, "elastic", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "invert_z", 0, NULL, ICON_NONE);
+}
+
+using namespace blender::realtime_compositor;
+
+class SIRDSOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_result("Image").allocate_invalid();
+ context().set_info_message("Viewport compositor setup not fully supported");
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new SIRDSOperation(context, node);
+}
+
+} // namespace blender::nodes::node_composite_sirds_cc
+
+void register_node_type_cmp_sirds(void)
+{
+ namespace file_ns = blender::nodes::node_composite_sirds_cc;
+
+ static bNodeType ntype;
+
+ cmp_node_type_base(&ntype, CMP_NODE_SIRDS, "SIRDS", NODE_CLASS_OP_FILTER);
+ ntype.declare = file_ns::cmp_node_sirds_declare;
+ ntype.draw_buttons = file_ns::node_composit_buts_sirds;
+ ntype.initfunc = file_ns::node_composit_init_sirds;
+ node_type_storage(&ntype, "NodeSIRDS", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
+ ntype.realtime_compositor_unsupported_message = N_(
+ "Node not supported in the Viewport compositor");
+
+ nodeRegisterType(&ntype);
+}