-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGroundTruthAberration.cpp
More file actions
2618 lines (2213 loc) · 123 KB
/
GroundTruthAberration.cpp
File metadata and controls
2618 lines (2213 loc) · 123 KB
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "PCH.h"
#include "GroundTruthAberration.h"
#include "ComplexBlur.h"
#include "TiledSplatBlur.h"
namespace GroundTruthAberration
{
////////////////////////////////////////////////////////////////////////////////
// Define the component
DEFINE_COMPONENT(GROUND_TRUTH_ABERRATION);
DEFINE_OBJECT(GROUND_TRUTH_ABERRATION);
REGISTER_OBJECT_UPDATE_CALLBACK(GROUND_TRUTH_ABERRATION, AFTER, INPUT);
REGISTER_OBJECT_RENDER_CALLBACK(GROUND_TRUTH_ABERRATION, "Ground Truth Aberration (HDR)", OpenGL, AFTER, "Effects (HDR) [Begin]", 1,
&GroundTruthAberration::renderObjectOpenGL, &RenderSettings::firstCallTypeCondition,
&GroundTruthAberration::renderObjectPreconditionHDROpenGL, nullptr, nullptr);
REGISTER_OBJECT_RENDER_CALLBACK(GROUND_TRUTH_ABERRATION, "Ground Truth Aberration (LDR)", OpenGL, AFTER, "Effects (LDR) [Begin]", 1,
&GroundTruthAberration::renderObjectOpenGL, &RenderSettings::firstCallTypeCondition,
&GroundTruthAberration::renderObjectPreconditionLDROpenGL, nullptr, nullptr);
////////////////////////////////////////////////////////////////////////////////
Aberration::WavefrontAberration& getAberration(Scene::Scene& scene, Scene::Object* object)
{
return object->component<GroundTruthAberrationComponent>().m_aberration;
}
////////////////////////////////////////////////////////////////////////////////
Aberration::WavefrontAberrationPresets& getAberrationPresets(Scene::Scene& scene, Scene::Object* object)
{
return object->component<GroundTruthAberrationComponent>().m_aberrationPresets;
}
////////////////////////////////////////////////////////////////////////////////
void initAberrationPresets(Scene::Scene& scene, Scene::Object* object)
{
Aberration::initAberrationStructure(scene, getAberration(scene, object), getAberrationPresets(scene, object));
}
////////////////////////////////////////////////////////////////////////////////
void loadShaders(Scene::Scene& scene, Scene::Object* object)
{
Aberration::loadShaders(scene, getAberration(scene, object));
}
////////////////////////////////////////////////////////////////////////////////
void loadNeuralNetworks(Scene::Scene& scene, Scene::Object* object)
{
Aberration::loadNeuralNetworks(scene, getAberration(scene, object));
}
////////////////////////////////////////////////////////////////////////////////
void initObject(Scene::Scene& scene, Scene::Object& object)
{
Scene::appendResourceInitializer(scene, object.m_name, Scene::Custom, initAberrationPresets, "Aberration Presets");
Scene::appendResourceInitializer(scene, object.m_name, Scene::Shader, loadShaders, "Shaders");
Scene::appendResourceInitializer(scene, object.m_name, Scene::NeuralNetwork, loadNeuralNetworks, "Neural Networks");
DelayedJobs::postJob(scene, &object, "Load Previous Results", [](Scene::Scene& scene, Scene::Object& object)
{
loadPreviousResults(scene, &object);
});
}
////////////////////////////////////////////////////////////////////////////////
void releaseObject(Scene::Scene& scene, Scene::Object& object)
{
// Store the shader initializer
Scene::removeResourceInitializer(scene, object.m_name, Scene::Shader);
}
////////////////////////////////////////////////////////////////////////////////
void updateObject(Scene::Scene& scene, Scene::Object* simulationSettings, Scene::Object* object)
{}
////////////////////////////////////////////////////////////////////////////////
void uploadResultTexture(Scene::Scene& scene, Scene::Object* object, Results& result, std::string const& suffix, const void* data)
{
std::string textureName = object->m_name + "_" + suffix;
Scene::createTexture(scene, textureName, GL_TEXTURE_2D, result.m_width, result.m_height, 1, GL_RGBA8, GL_RGBA, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_UNSIGNED_BYTE, data);
}
////////////////////////////////////////////////////////////////////////////////
using ResultsTextures = std::unordered_map<Results::ResultAttribute, const char*>;
////////////////////////////////////////////////////////////////////////////////
static ResultsTextures s_allTextures =
{
{ Results::Original, "original" },
{ Results::Convolution, "result" },
{ Results::Depth, "depth" },
{ Results::Normalization, "normalization" },
{ Results::NumberOfSamples, "number_of_samples" },
{ Results::IncidentAngles, "incident_angles" },
{ Results::Defocus, "defocus" },
{ Results::BinIncidentAngles, "bin_incident_angles" },
{ Results::BinDefocus, "bin_defocus" },
{ Results::BlurRadius, "radii" },
{ Results::Reference, "reference" },
{ Results::Ssim, "ssim" },
{ Results::SsimJet, "ssim_jet" },
{ Results::HdrVdp3, "hdrvdp3" },
{ Results::HdrVdp3Jet, "hdrvdp3_jet" },
{ Results::Difference, "diff" },
};
////////////////////////////////////////////////////////////////////////////////
static ResultsTextures s_resultsTextures =
{
{ Results::Original, "original" },
{ Results::Convolution, "result" },
{ Results::Depth, "depth" },
{ Results::Normalization, "normalization" },
{ Results::NumberOfSamples, "number_of_samples" },
{ Results::IncidentAngles, "incident_angles" },
{ Results::Defocus, "defocus" },
{ Results::BinIncidentAngles, "bin_incident_angles" },
{ Results::BinDefocus, "bin_defocus" },
{ Results::BlurRadius, "radii" },
};
////////////////////////////////////////////////////////////////////////////////
static ResultsTextures s_metricsTextures =
{
{ Results::Original, "original" },
{ Results::Convolution, "ground_truth" },
{ Results::Reference, "reference" },
{ Results::Ssim, "ssim" },
{ Results::SsimJet, "ssim_jet" },
{ Results::HdrVdp3, "hdrvdp3" },
{ Results::HdrVdp3Jet, "hdrvdp3_jet" },
{ Results::Difference, "diff" },
};
////////////////////////////////////////////////////////////////////////////////
std::string getTextureNamePrefix(Results& result)
{
std::stringstream ss;
ss << result.m_scene;
ss << "_" << result.m_aberration;
ss << "_" << ConvolutionSettings::Algorithm_value_to_string(result.m_algorithm);
return ss.str();
}
////////////////////////////////////////////////////////////////////////////////
std::string getTextureName(Results::ResultAttribute attrib, std::string const& prefix)
{
std::stringstream ss;
ss << prefix;
ss << "_" << s_allTextures[attrib];
ss << ".png";
return ss.str();
}
////////////////////////////////////////////////////////////////////////////////
std::string getTextureName(Results& result, Results::ResultAttribute attrib)
{
return getTextureName(attrib, getTextureNamePrefix(result));
}
////////////////////////////////////////////////////////////////////////////////
void uploadResultRender(Scene::Scene& scene, Scene::Object* object, Results& result)
{
for (auto const& texture : result.m_textures)
if (s_allTextures.find(texture.first) != s_allTextures.end())
uploadResultTexture(scene, object, result, s_allTextures[texture.first], texture.second.data());
}
////////////////////////////////////////////////////////////////////////////////
void uploadResultTooltip(Scene::Scene& scene, Scene::Object* object, Results& result)
{
uploadResultTexture(scene, object, result, "tooltip_color", result.m_textures[Results::Original].data());
uploadResultTexture(scene, object, result, "tooltip_result", result.m_textures[Results::Convolution].data());
}
////////////////////////////////////////////////////////////////////////////////
bool isDisplayResultValid(Scene::Scene& scene, Scene::Object* object)
{
auto const& results = object->component<GroundTruthAberrationComponent>().m_results;
return !results.empty() && object->component<GroundTruthAberrationComponent>().m_outputSettings.m_resultRenderId < results.size();
}
////////////////////////////////////////////////////////////////////////////////
Results& getDisplayResults(Scene::Scene& scene, Scene::Object* object)
{
return object->component<GroundTruthAberrationComponent>().m_results[object->component<GroundTruthAberrationComponent>().m_outputSettings.m_resultRenderId];
}
////////////////////////////////////////////////////////////////////////////////
void loadTexture(Scene::Scene& scene, std::filesystem::directory_entry subFolder, std::string const& fileName, Results& results, std::vector<unsigned char>& outImage)
{
// Try to load the image
auto imgPath = (subFolder.path() / fileName).string();
Debug::log_debug() << "Trying to load previous image; filename: " << imgPath << Debug::end;
if (Asset::existsFile(imgPath) == false) return;
auto const& imageOpt = Asset::loadImage(scene, imgPath);
cv::Mat image = imageOpt.value();
Debug::log_debug() << "Image dimensions: " << image.cols << ", " << image.rows << Debug::end;
// Allocate memory for the result
outImage.resize(image.rows * image.cols * 4);
// Read out the pixels
for (size_t row = 0; row < image.rows; ++row)
for (size_t col = 0; col < image.cols; ++col)
{
size_t arrayId = ((row * image.cols) + col) * 4;
cv::Vec4b pixelValue = image.at<cv::Vec4b>(row, col);
outImage[arrayId + 0] = pixelValue[0];
outImage[arrayId + 1] = pixelValue[1];
outImage[arrayId + 2] = pixelValue[2];
outImage[arrayId + 3] = pixelValue[3];
}
// Store the image size, if needed
if (results.m_width < 0 || results.m_height < 0)
{
results.m_width = image.cols;
results.m_height = image.rows;
}
}
////////////////////////////////////////////////////////////////////////////////
void allocEmptyTexture(Scene::Scene& scene, Results& results, std::vector<unsigned char>& outImage)
{
// Only do this if the result is not empty
if (outImage.size() > 0) return;
// Alloc space in the image
outImage.resize(results.m_width * results.m_height * 4);
// Clear out the pixels
for (size_t row = 0; row < results.m_height; ++row)
for (size_t col = 0; col < results.m_width; ++col)
{
size_t arrayId = ((row * results.m_width) + col) * 4;
outImage[arrayId + 0] = 0;
outImage[arrayId + 1] = 0;
outImage[arrayId + 2] = 0;
outImage[arrayId + 3] = 255;
}
}
////////////////////////////////////////////////////////////////////////////////
void loadResultAttributes(Scene::Scene& scene, std::filesystem::directory_entry subFolder, std::string const& fileName, Results& results)
{
// Try to load the image
auto attributesPath = (subFolder.path() / fileName).string();
if (Asset::existsFile(attributesPath) == false) return;
std::ordered_pairs_in_blocks attributes = Asset::loadPairsInBlocks(scene, attributesPath).value();
for (auto const& stateVar : attributes["Resolution"])
{
if (stateVar.first == "Width") results.m_width = std::from_string<int>(stateVar.second);
if (stateVar.first == "Height") results.m_height = std::from_string<int>(stateVar.second);
}
for (auto const& stateVar : attributes["Settings"])
{
if (stateVar.first == "TimestampDisplay") results.m_timestampDisplay = stateVar.second;
if (stateVar.first == "TimestampFile") results.m_timestampFile = stateVar.second;
if (stateVar.first == "Aberration") results.m_aberration = stateVar.second;
if (stateVar.first == "Scene") results.m_scene = stateVar.second;
if (stateVar.first == "Camera") results.m_camera = stateVar.second;
if (stateVar.first == "Focus") results.m_focusDistance = std::from_string<float>(stateVar.second);
if (stateVar.first == "Aperture") results.m_apertureDiameter = std::from_string<float>(stateVar.second);
if (stateVar.first == "Channels") results.m_channels = std::from_string<int>(stateVar.second);
if (stateVar.first == "Off-Axis") results.m_simulateOffAxis = std::from_string<bool>(stateVar.second);
if (stateVar.first == "HDR") results.m_isHdr = std::from_string<bool>(stateVar.second);
if (stateVar.first == "BlendMode") results.m_blendMode = ConvolutionSettings::BlendMode_meta_from_name(stateVar.second).value_or(ConvolutionSettings::BlendMode_meta.members[0]).value;
if (stateVar.first == "Algorithm") results.m_algorithm = ConvolutionSettings::Algorithm_meta_from_name(stateVar.second).value_or(ConvolutionSettings::Algorithm_meta.members[0]).value;
if (stateVar.first == "NumDepthSlices") results.m_numDepthSlices = std::from_string<int>(stateVar.second);
}
for (auto const& stateVar : attributes["Bins"])
{
if (stateVar.first == "NumBins") results.m_numBins = std::from_string<int>(stateVar.second);
if (stateVar.first == "DioptresPrecision") results.m_dioptresPrecision = std::from_string<float>(stateVar.second);
if (stateVar.first == "IncidentAnglesPrecision") results.m_incidentAnglesPrecision = std::from_string<float>(stateVar.second);
if (stateVar.first == "CenterDioptres") results.m_centerDioptres = std::from_string<bool>(stateVar.second);
if (stateVar.first == "CenterIncidentAngles") results.m_centerIncidentAngles = std::from_string<bool>(stateVar.second);
}
for (auto const& stateVar : attributes["RunningTimes"])
{
if (stateVar.first == "PsfBins") results.m_psfBinTime = std::from_string<float>(stateVar.second);
if (stateVar.first == "Convolution") results.m_convolutionTime = std::from_string<float>(stateVar.second);
if (stateVar.first == "TotalProcessing") results.m_totalProcessingTime = std::from_string<float>(stateVar.second);
}
for (auto const& stateVar : attributes["Limits"])
{
if (stateVar.first == "MinDepth") results.m_minDepth = std::from_string<float>(stateVar.second);
if (stateVar.first == "MaxDepth") results.m_maxDepth = std::from_string<float>(stateVar.second);
if (stateVar.first == "MinDefocus") results.m_minDefocus = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MaxDefocus") results.m_maxDefocus = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MinBlurRadius") results.m_minBlurRadius = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MaxBlurRadius") results.m_maxBlurRadius = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MinWeight") results.m_minWeight = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MaxWeight") results.m_maxWeight = std::from_string<glm::vec4>(stateVar.second);
if (stateVar.first == "MinNumSamples") results.m_minNumSamples = std::from_string<glm::ivec4>(stateVar.second);
if (stateVar.first == "MaxNumSamples") results.m_maxNumSamples = std::from_string<glm::ivec4>(stateVar.second);
}
}
////////////////////////////////////////////////////////////////////////////////
void loadPreviousResults(Scene::Scene& scene, Scene::Object* object)
{
// Get the root filesystem path
std::filesystem::path root = EnginePaths::generatedFilesFolder() / "GroundTruthAberration";
// Make sure the path exists
if (std::filesystem::exists(root) == false) return;
// Go through the subfolders
for (auto const& subFolder : std::filesystem::directory_iterator(root))
{
// Make sure its a results folder
if (subFolder.is_directory() == false || std::filesystem::exists(subFolder.path() / "attributes.ini") == false)
continue;
// Make a new entry
object->component<GroundTruthAberrationComponent>().m_results.emplace_back();
auto& results = object->component<GroundTruthAberrationComponent>().m_results.back();
// Read back the attributes
loadResultAttributes(scene, subFolder, "attributes.ini", results);
// Read back the textures
for (auto& texture : s_allTextures)
{
std::string const& fileName = getTextureName(results, texture.first);
allocEmptyTexture(scene, results, results.m_textures[texture.first]);
loadTexture(scene, subFolder, fileName, results, results.m_textures[texture.first]);
}
}
// Show the last result
if (object->component<GroundTruthAberrationComponent>().m_results.size() > 0)
{
// Upload the results
uploadResultRender(scene, object, object->component<GroundTruthAberrationComponent>().m_results.back());
object->component<GroundTruthAberrationComponent>().m_outputSettings.m_resultRenderId = object->component<GroundTruthAberrationComponent>().m_results.size() - 1;
object->component<GroundTruthAberrationComponent>().m_outputSettings.m_outputMode = Results::Convolution;
}
}
////////////////////////////////////////////////////////////////////////////////
// Represents the data for a single input pixel
struct InputPixelData
{
float m_color = 0.0f;
float m_depth = 0.0f;
float m_blurRadius = 0.0f;
float m_defocus = 0.0f;
glm::vec2 m_incidentAngles{ 0.0f };
std::pair<glm::vec2, float> m_psfBinParams{ glm::vec2(0.0f), 0.0f };
glm::vec3 m_worldSpaceCoords{ 0.0f };
glm::vec3 m_viewSpaceCoords{ 0.0f };
glm::vec3 m_sphericalCoords{ 0.0f };
};
////////////////////////////////////////////////////////////////////////////////
// Represents the data for a single output pixel
struct OutputPixelData
{
float m_result = 0.0f;
float m_weight = 0.0f;
int m_numSamples = 0;
};
////////////////////////////////////////////////////////////////////////////////
// A single entry in the PSF bin
struct PsfBinEntry
{
float m_radius;
float m_defocus;
Aberration::Psf m_psf;
};
////////////////////////////////////////////////////////////////////////////////
// Represents a single sample
struct Sample
{
float m_depth;
float m_color;
float m_weight;
};
////////////////////////////////////////////////////////////////////////////////
meta_enum(ConvolutionPhase, int,
PsfBins,
Convolution,
Total);
////////////////////////////////////////////////////////////////////////////////
// Common data
struct CommonData
{
// Necessary scene objects
Scene::Object* m_renderSettings;
Scene::Object* m_camera;
// Per-pixel property textures
boost::multi_array<InputPixelData, 3> m_inputPixels;
boost::multi_array<OutputPixelData, 3> m_outputPixels;
// Render parameters
glm::ivec2 m_renderResolution;
size_t m_numPixelsRender;
glm::mat4 m_projection;
float m_fovy;
glm::vec2 m_fov;
// PSF parameters
bool m_offAxis;
float m_focusDistance;
float m_apertureDiameter;
size_t m_numChannels;
float m_dioptresPrecision;
float m_incidentAnglesPrecision;
bool m_centerIncidentAngles;
bool m_centerDioptres;
size_t m_maxBlurRadius;
std::vector<float> m_lambdas;
// File names
std::string m_resultFileName;
std::filesystem::path m_resultsFolder;
std::string m_resultsPrefix;
std::filesystem::path m_psfFolderOriginal;
std::filesystem::path m_psfFolderDownscaled;
// PSF bins
std::unordered_map<glm::vec2, std::unordered_map<float, std::vector<PsfBinEntry>>> m_psfBins;
std::vector<std::pair<glm::vec2, float>> m_psfBinParams;
std::vector<float> m_psfBinHorizontalAngles;
std::vector<float> m_psfBinVerticalAngles;
std::vector<float> m_psfBinDioptres;
std::vector<float> m_psfBinDepths;
// Aberration preset
Aberration::WavefrontAberration m_aberration;
// Various timers
std::unordered_map<ConvolutionPhase, DateTime::Timer> m_timers;
};
////////////////////////////////////////////////////////////////////////////////
// Per-thread data
struct PerThreadData
{
// Per-pixel PSF sample list
std::vector<std::vector<Sample>> m_samples;
};
////////////////////////////////////////////////////////////////////////////////
PsfBinEntry& psfChannel(CommonData& commonData, InputPixelData& pixelData, size_t channel)
{
// Make sure that the pixel is properly binned
if (commonData.m_psfBins.find(pixelData.m_psfBinParams.first) == commonData.m_psfBins.end())
Debug::log_error() << "Found an incident angle with no matching bin entry; bin params: " << pixelData.m_psfBinParams.first << Debug::end;
if (commonData.m_psfBins[pixelData.m_psfBinParams.first].find(pixelData.m_psfBinParams.second) == commonData.m_psfBins[pixelData.m_psfBinParams.first].end())
Debug::log_error() << "Found a diopter with no matching bin entry; bin params: " << pixelData.m_psfBinParams.second << Debug::end;
// Return the corresponding PSF entry
return commonData.m_psfBins[pixelData.m_psfBinParams.first][pixelData.m_psfBinParams.second][glm::min(commonData.m_numChannels - 1, channel)];
}
////////////////////////////////////////////////////////////////////////////////
std::string resultLabel(Results const& result)
{
std::stringstream ss;
ss << result.m_scene << "---";
ss << result.m_camera << "---";
ss << ConvolutionSettings::Algorithm_value_to_string(result.m_algorithm) << "---";
ss << result.m_aberration << "---";
ss << result.m_timestampDisplay;
return ss.str();
}
////////////////////////////////////////////////////////////////////////////////
std::string resultFilename(Results const& result)
{
// Generate the necessary file name properties
std::stringstream ss;
//ss << result.m_scene << "_";
ss << result.m_camera << "_";
ss << ConvolutionSettings::Algorithm_value_to_string(result.m_algorithm) << "_";
ss << result.m_aberration << "_";
ss << result.m_timestampFile;
return ss.str();
}
////////////////////////////////////////////////////////////////////////////////
void setFileLogging(Scene::Scene& scene, Scene::Object* object, bool enable)
{
if (object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_omitFileLogging)
{
// Extract the necessary scene objects
Scene::Object* debugSettings = Scene::findFirstObject(scene, Scene::OBJECT_TYPE_DEBUG_SETTINGS);
if (enable)
{
// Reset the old state
debugSettings->component<DebugSettings::DebugSettingsComponent>().m_logToFile =
object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_fileLogState;
// Update the logger state
DebugSettings::updateLoggerStates(scene, debugSettings);
}
else
{
// Store the previous state
object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_fileLogState =
debugSettings->component<DebugSettings::DebugSettingsComponent>().m_logToFile;
// Disable debug and trace logs to file
debugSettings->component<DebugSettings::DebugSettingsComponent>().m_logToFile.m_debug = false;
debugSettings->component<DebugSettings::DebugSettingsComponent>().m_logToFile.m_trace = false;
// Update the logger state
DebugSettings::updateLoggerStates(scene, debugSettings);
}
}
}
////////////////////////////////////////////////////////////////////////////////
bool shouldLog(Scene::Scene& scene, Scene::Object* object, Threading::ThreadedExecuteEnvironment const& environment)
{
// Only the leading thread prints
return environment.isLeadingThread();
}
////////////////////////////////////////////////////////////////////////////////
bool outputFilterLevel(Scene::Scene& scene, Scene::Object* object, ConvolutionSettings::PrintDetail level, const bool logFlag)
{
return logFlag && object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail >= level;
}
////////////////////////////////////////////////////////////////////////////////
Debug::DebugOutputLevel outputLogLevel(Scene::Scene& scene, Scene::Object* object, ConvolutionSettings::PrintDetail level)
{
return object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail >= level ? Debug::Info : Debug::Null;
}
////////////////////////////////////////////////////////////////////////////////
glm::vec2 roundIncidentAngles(const glm::vec2 incidentAngles, const float precision, const bool center)
{
return (glm::round(incidentAngles / precision) * precision) + (center ? 0.5f * precision : 0.0f);
}
////////////////////////////////////////////////////////////////////////////////
float roundDioptres(const float depth, const float precision, const bool center)
{
return (glm::round(depth / precision) * precision) + (center ? 0.5f * precision : 0.0f);
}
////////////////////////////////////////////////////////////////////////////////
std::pair<glm::vec2, float> constructBinParams(CommonData& commonData, const glm::vec2 incidentAngles, const float depth)
{
return std::make_pair
(
!commonData.m_offAxis ? glm::vec2(0.0f) :
roundIncidentAngles(incidentAngles, commonData.m_incidentAnglesPrecision, commonData.m_centerIncidentAngles),
roundDioptres(1.0f / depth, commonData.m_dioptresPrecision, commonData.m_centerDioptres)
);
}
////////////////////////////////////////////////////////////////////////////////
void prepareCommonData(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, Results& results, Aberration::WavefrontAberration aberration)
{
// Extract the necessary scene objects
Scene::Object* renderSettings = Scene::findFirstObject(scene, Scene::OBJECT_TYPE_RENDER_SETTINGS);
Scene::Object* camera = RenderSettings::getMainCamera(scene, renderSettings);
// Id of the current gbuffer
const int gbufferId = renderSettings->component<RenderSettings::RenderSettingsComponent>().m_gbufferWrite;
auto const& gbuffer = scene.m_gbuffer[gbufferId];
// Resolution the effect is rendered at
const glm::ivec2 renderResolution = renderSettings->component<RenderSettings::RenderSettingsComponent>().m_resolution;
const size_t renderWidth = renderResolution[0], renderHeight = renderResolution[1];
const size_t numPixelsRender = renderWidth * renderHeight;
// Vertical FOV of the camera
const float fovy = camera->component<Camera::CameraComponent>().m_fovy;
// Extract the projection matrix to reproject the camera depth
const auto projection = Camera::getProjectionMatrix(renderSettings, camera);
// Start the total processing timer
commonData.m_timers[ConvolutionPhase::Total].start();
// Write out the necessary objects
commonData.m_renderSettings = renderSettings;
commonData.m_camera = camera;
// Store the render parameters
commonData.m_renderResolution = renderResolution;
commonData.m_numPixelsRender = numPixelsRender;
commonData.m_projection = projection;
commonData.m_fovy = fovy;
commonData.m_fov = Camera::getFieldOfView(renderResolution, fovy);
// Extract the PSF generation settings
commonData.m_offAxis = object->component<GroundTruthAberrationComponent>().m_convolutionSettings.m_simulateOffAxis;
commonData.m_focusDistance = commonData.m_camera->component<Camera::CameraComponent>().m_focusDistance;
commonData.m_apertureDiameter = commonData.m_camera->component<Camera::CameraComponent>().m_fixedAperture;
commonData.m_numChannels = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_numChannels;
commonData.m_dioptresPrecision = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_dioptresPrecision;
commonData.m_incidentAnglesPrecision = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_incidentAnglesPrecision;
commonData.m_centerIncidentAngles = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_centerIncidentAngles;
commonData.m_centerDioptres = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_centerDioptres;
commonData.m_lambdas = std::vector<float>(aberration.m_psfParameters.m_lambdas.begin(), aberration.m_psfParameters.m_lambdas.begin() + commonData.m_numChannels);
// Initialize the aberration
commonData.m_aberration = aberration;
commonData.m_aberration.m_psfParameters.m_logProgress = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail >= ConvolutionSettings::Detailed;
commonData.m_aberration.m_psfParameters.m_logStats = object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail >= ConvolutionSettings::Detailed;
commonData.m_aberration.m_psfParameters.m_apertureDiameters = { commonData.m_apertureDiameter, commonData.m_apertureDiameter, 1 };
commonData.m_aberration.m_psfParameters.m_focusDistances = { 1.0f / commonData.m_focusDistance, 1.0f / commonData.m_focusDistance, 1 };
commonData.m_aberration.m_psfParameters.m_lambdas = commonData.m_lambdas;
commonData.m_aberration.m_psfParameters.m_objectDistances = { FLT_MAX, FLT_MAX, 1 };
commonData.m_aberration.m_psfParameters.m_incidentAnglesHorizontal = { FLT_MAX, FLT_MAX, 1 };
commonData.m_aberration.m_psfParameters.m_incidentAnglesVertical = { FLT_MAX, FLT_MAX, 1 };
const Aberration::PsfStackComputation computationFlags =
Aberration::PsfStackComputation_RelaxedEyeParameters |
Aberration::PsfStackComputation_FocusedEyeParameters |
Aberration::PsfStackComputation_PsfUnits |
Aberration::PsfStackComputation_PsfBesselTerms |
Aberration::PsfStackComputation_PsfEnzCoefficients;
Aberration::computePSFStack(scene, commonData.m_aberration, computationFlags);
// Prepare the various per-pixel buffers
commonData.m_inputPixels.resize(decltype(commonData.m_inputPixels)::extent_gen()[renderHeight][renderWidth][3]);
commonData.m_outputPixels.resize(decltype(commonData.m_outputPixels)::extent_gen()[renderHeight][renderWidth][3]);
// Make sure the texture has been updated
glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
// Allocate memory for the GBuffer textures
std::unique_ptr<unsigned char[]> pixelBuffer(new unsigned char[numPixelsRender * 4]);
std::unique_ptr<float[]> depthBuffer(new float[numPixelsRender]);
// Extract the color and depth buffers
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glGetTextureSubImage(gbuffer.m_colorTextures[gbuffer.m_readBuffer], 0, 0, 0, 0, renderWidth, renderHeight, 1,
GL_RGBA, GL_UNSIGNED_BYTE, numPixelsRender * 4 * sizeof(unsigned char), pixelBuffer.get());
glGetTextureSubImage(gbuffer.m_depthTexture, 0, 0, 0, 0, renderWidth, renderHeight, 1,
GL_DEPTH_COMPONENT, GL_FLOAT, numPixelsRender * sizeof(float), depthBuffer.get());
// Extract the relevant scene information
Threading::threadedExecuteIndices(Threading::numThreads(),
[&](Threading::ThreadedExecuteEnvironment const& environment, size_t y, size_t x, size_t c)
{
// Pixel id into the buffer
const size_t pixelId = (x + y * renderWidth);
// Extract the scene information
InputPixelData pixelData;
pixelData.m_viewSpaceCoords = Camera::screenToCameraSpaceMeters(renderSettings, camera, glm::ivec2(x, y), depthBuffer[pixelId]);
pixelData.m_worldSpaceCoords = Camera::screenToWorldSpaceMeters(renderSettings, camera, glm::ivec2(x, y), depthBuffer[pixelId]);
pixelData.m_sphericalCoords = Camera::screenToSphericalCoordinatesDegM(renderSettings, camera, glm::ivec2(x, y), depthBuffer[pixelId]);
pixelData.m_color = float(pixelBuffer[pixelId * 4 + c]) / 255.0f;
pixelData.m_depth = pixelData.m_sphericalCoords.z;
pixelData.m_incidentAngles = glm::vec2(pixelData.m_sphericalCoords.x, pixelData.m_sphericalCoords.y);
pixelData.m_psfBinParams = constructBinParams(commonData, pixelData.m_incidentAngles, pixelData.m_depth);
// Write out the output pixel
commonData.m_inputPixels[y][x][c] = pixelData;
/*
if (environment.isLeadingThread())
{
Debug::log_info()
<< y << ", " << x << ", " << c << ": "
<< "cam-space: " << pixelData.m_viewSpaceCoords << ", "
<< "spherical: " << glm::vec3(glm::degrees(pixelData.m_sphericalCoords.x), glm::degrees(pixelData.m_sphericalCoords.y), pixelData.m_sphericalCoords.z) << ", "
<< "psf bin: " << pixelData.m_psfBinParams << ", "
<< Debug::end;
}
*/
},
renderHeight, renderWidth, 3);
// Generate the necessary file and folder names
commonData.m_resultFileName = resultFilename(results);
commonData.m_resultsFolder = EnginePaths::generatedFilesFolder() / "GroundTruthAberration" / commonData.m_resultFileName;
commonData.m_resultsPrefix = getTextureNamePrefix(results);
commonData.m_psfFolderOriginal = commonData.m_resultsFolder / "PSFs"s / "original";
commonData.m_psfFolderDownscaled = commonData.m_resultsFolder / "PSFs"s / "downscaled";
}
////////////////////////////////////////////////////////////////////////////////
void preparePerThreadData(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, std::vector<PerThreadData>& perThreadData)
{
DateTime::ScopedTimer timer(Debug::Info, 1, DateTime::Seconds, "Per-thread Data");
// Prepare the per-thread data
Threading::threadedExecuteIndices(Threading::numThreads(),
[&](Threading::ThreadedExecuteEnvironment const& environment, size_t threadId)
{
// Extract the current thread's data
PerThreadData& threadData = perThreadData[threadId];
// Init the per-pixel sample lists
threadData.m_samples.resize(3);
},
perThreadData.size());
}
////////////////////////////////////////////////////////////////////////////////
void cleanupCommonData(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, Results& results, Aberration::WavefrontAberration aberration)
{
// Nothing to do
}
////////////////////////////////////////////////////////////////////////////////
void cleanupPerThreadData(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, std::vector<PerThreadData>& perThreadData)
{
// Nothing to do
}
////////////////////////////////////////////////////////////////////////////////
void initPsfBinsFromPixelDepths(Scene::Scene& scene, Scene::Object* object, CommonData& commonData)
{
auto width = commonData.m_renderResolution[0], height = commonData.m_renderResolution[1];
// Collect the unique PSF bin param occurences
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
auto const& pixelData = commonData.m_inputPixels[y][x][0];
auto const& psfBinParams = pixelData.m_psfBinParams;
if (commonData.m_psfBins.count(psfBinParams.first) == 0 || commonData.m_psfBins[psfBinParams.first].count(psfBinParams.second) == 0)
{
commonData.m_psfBinParams.push_back(psfBinParams);
commonData.m_psfBins[psfBinParams.first][psfBinParams.second].resize(commonData.m_numChannels);
}
}
}
////////////////////////////////////////////////////////////////////////////////
void initPsfBinsFromStack(Scene::Scene& scene, Scene::Object* object, CommonData& commonData)
{
if (commonData.m_offAxis)
{
// Generate depth slices
auto const& horizontalAngles = Aberration::generateHorizontalAxes(scene, getAberration(scene, object));
auto const& verticalAngles = Aberration::generateVerticalAxes(scene, getAberration(scene, object));
auto const& defocusDioptres = Aberration::generateObjectDioptres(scene, getAberration(scene, object));
for (size_t h = 0; h < horizontalAngles.size(); ++h)
for (size_t v = 0; v < verticalAngles.size(); ++v)
for (size_t d = 0; d < defocusDioptres.size(); ++d)
{
auto const& psfBinParams = std::make_pair(glm::vec2(horizontalAngles[h], verticalAngles[v]), defocusDioptres[d]);
commonData.m_psfBinParams.push_back(psfBinParams);
commonData.m_psfBins[psfBinParams.first][psfBinParams.second].resize(commonData.m_numChannels);
}
}
else
{
// Generate depth slices
auto const& defocusDioptres = Aberration::generateObjectDioptres(scene, getAberration(scene, object));
for (size_t i = 0; i < defocusDioptres.size(); ++i)
{
auto const& psfBinParams = std::make_pair(glm::vec2(0.0f), defocusDioptres[i]);
commonData.m_psfBinParams.push_back(psfBinParams);
commonData.m_psfBins[psfBinParams.first][psfBinParams.second].resize(commonData.m_numChannels);
}
}
}
////////////////////////////////////////////////////////////////////////////////
void computePsf(Scene::Scene& scene, Scene::Object* object, Threading::ThreadedExecuteEnvironment const& environment,
CommonData& commonData, PerThreadData& threadData, size_t binId)
{
// Whether we should be logging from this thread or not
const bool log = shouldLog(scene, object, environment);
// Extract the corresponding PSF bin
auto const& psfBinParams = commonData.m_psfBinParams[binId];
std::vector<PsfBinEntry>& psfs = commonData.m_psfBins[psfBinParams.first][psfBinParams.second];
// Whether we have a new incident angle or not
const bool newIncidentAngle = psfBinParams.first[0] != commonData.m_aberration.m_psfParameters.m_incidentAnglesHorizontal.m_min ||
psfBinParams.first[1] != commonData.m_aberration.m_psfParameters.m_incidentAnglesVertical.m_min;
if (outputFilterLevel(scene, object, ConvolutionSettings::Detailed, log))
{
Debug::log_debug() << " < "
<< "Bin parameters: " << psfBinParams
<< Debug::end;
}
// Compute the PSF
commonData.m_aberration.m_psfParameters.m_incidentAnglesHorizontal = { psfBinParams.first[0], psfBinParams.first[0], 1 };
commonData.m_aberration.m_psfParameters.m_incidentAnglesVertical = { psfBinParams.first[1], psfBinParams.first[1], 1 };
commonData.m_aberration.m_psfParameters.m_objectDistances = { psfBinParams.second, psfBinParams.second, 1 };
const Aberration::PsfStackComputation computationFlags =
(newIncidentAngle ? Aberration::PsfStackComputation_AberrationCoefficients : 0) |
Aberration::PsfStackComputation_PsfUnits |
Aberration::PsfStackComputation_PsfBesselTerms |
Aberration::PsfStackComputation_PsfEnzCoefficients |
Aberration::PsfStackComputation_Psfs;
Aberration::computePSFStack(scene, commonData.m_aberration, computationFlags);
// Store the downscaled PSF
psfs.resize(commonData.m_numChannels);
for (int channelId = 0; channelId < psfs.size(); ++channelId)
{
// Extract the resulting PSF
auto const& psfParams = commonData.m_aberration.m_psfStack.m_psfEntryParameters[0][0][0][channelId][0][0];
auto const& psfEntry = commonData.m_aberration.m_psfStack.m_psfs[0][0][0][channelId][0][0];
// Compute its radius
const float psfRadius = Aberration::blurRadiusPixels(psfEntry, commonData.m_renderResolution, commonData.m_fovy);
if (outputFilterLevel(scene, object, ConvolutionSettings::Detailed, log))
{
Debug::log_debug() << " < "
<< "Channel[" << channelId << "]: "
<< "PSF Radius: " << psfRadius << " (" << psfEntry.m_psf.cols() << "), "
<< "Defocus: " << psfParams.m_focus.m_defocusParam
<< Debug::end;
}
// Actual PSF to convolve with
psfs[channelId].m_defocus = psfParams.m_focus.m_defocusParam;
psfs[channelId].m_radius = psfRadius;
psfs[channelId].m_psf = Aberration::resizePsfNormalized(scene, commonData.m_aberration, psfEntry.m_psf, psfRadius);
if (object->component<GroundTruthAberrationComponent>().m_convolutionSettings.m_exportPsfs)
{
// Name of the generated psfs
std::stringstream ss;
ss << "_c" << channelId;
ss << "_h" << (psfBinParams.first[0]);
ss << "_v" << (psfBinParams.first[1]);
ss << "_m" << (1.0f / psfBinParams.second);
std::string psfName = ss.str();
// Export the original PSF image
{
Aberration::Psf psf = psfEntry.m_psf / psfEntry.m_psf.maxCoeff();
std::string filePath = (commonData.m_psfFolderOriginal / ("psf_original" + psfName + ".png")).string();
Asset::saveImage(scene, filePath, psf);
}
// Export the downscaled PSF image
{
Aberration::Psf psf = psfs[channelId].m_psf / psfs[channelId].m_psf.maxCoeff();
std::string filePath = (commonData.m_psfFolderDownscaled / ("psf_downscaled" + psfName + ".png")).string();
Asset::saveImage(scene, filePath, psf);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
void computePsfBins(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, std::vector<PerThreadData>& perThreadData)
{
// Start the PSF bin timer
commonData.m_timers[ConvolutionPhase::PsfBins].start();
{
DateTime::ScopedTimer timer(Debug::Info, 1, DateTime::Seconds, "PSF Bins");
// Init the PSF bins first
switch (object->component<GroundTruthAberrationComponent>().m_convolutionSettings.m_algorithm)
{
case ConvolutionSettings::PerPixel:
initPsfBinsFromPixelDepths(scene, object, commonData);
break;
case ConvolutionSettings::PerPixelStack:
initPsfBinsFromStack(scene, object, commonData);
break;
case ConvolutionSettings::DepthLayers:
initPsfBinsFromStack(scene, object, commonData);
break;
}
// Sort the slices by off-axis angle
std::sort(commonData.m_psfBinParams.begin(), commonData.m_psfBinParams.end(), [](auto const& a, auto const& b)
{
return
a.first[0] < b.first[0] ||
(a.first[0] == b.first[0] && a.first[1] < b.first[1]) ||
(a.first == b.first && a.second < b.second);
});
// Build the separate PSF bin param vectors too
for (auto const& binParams : commonData.m_psfBinParams)
{
commonData.m_psfBinHorizontalAngles.push_back(binParams.first[0]);
commonData.m_psfBinVerticalAngles.push_back(binParams.first[1]);
commonData.m_psfBinDioptres.push_back(binParams.second);
commonData.m_psfBinDepths.push_back(1.0f / binParams.second);
}
}
{
DateTime::ScopedTimer timer(Debug::Info, commonData.m_psfBinParams.size(), DateTime::Seconds, "PSFs");
// Disable logging to file to avoid generating gigabytes of data during this operation
if (object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail < ConvolutionSettings::Detailed)
setFileLogging(scene, object, false);
// Populate the bins
Threading::threadedExecuteIndices(
Threading::ThreadedExecuteParams(1, "Computing PSF bins", "PSF", outputLogLevel(scene, object, ConvolutionSettings::Progress)),
[&](Threading::ThreadedExecuteEnvironment const& environment, size_t binId)
{
computePsf(scene, object, environment, commonData, perThreadData[Threading::currentThreadId()], binId);
},
commonData.m_psfBinParams.size());
// Re-enable file logging
if (object->component<GroundTruthAberration::GroundTruthAberrationComponent>().m_convolutionSettings.m_printDetail < ConvolutionSettings::Detailed)
setFileLogging(scene, object, true);
}
{
DateTime::ScopedTimer timer(Debug::Info, commonData.m_psfBinParams.size(), DateTime::Seconds, "Max PSF Size");
commonData.m_maxBlurRadius = 0;
for (auto const& psfsAngle: commonData.m_psfBins)
for (auto const& psfsDepth: psfsAngle.second)
for (auto const& psf: psfsDepth.second)
{
commonData.m_maxBlurRadius = glm::max(commonData.m_maxBlurRadius, size_t(glm::ceil(psf.m_radius) + 1));
}
}
// Stop the PSF bin timer
commonData.m_timers[ConvolutionPhase::PsfBins].stop();
}
////////////////////////////////////////////////////////////////////////////////
void computePerPixelProperties(Scene::Scene& scene, Scene::Object* object, Threading::ThreadedExecuteEnvironment const& environment,
CommonData& commonData, PerThreadData& perThreadData, int img_row, int img_col)
{
// Whether we should be logging from this thread or not
const bool log = shouldLog(scene, object, environment);
// Pixel id into the buffer
auto width = commonData.m_renderResolution[0], height = commonData.m_renderResolution[1];
// Perform the summation for each channel
for (int channelId = 0; channelId < 3; ++channelId)
{
// Extract the pixel's data entry
auto& pixelData = commonData.m_inputPixels[img_row][img_col][channelId];
// Extract the PSF
auto const& centerPixelPsfEntry = psfChannel(commonData, pixelData, channelId);
// Store the center pixel properties (defocus, blur radius, etc.)
pixelData.m_defocus = centerPixelPsfEntry.m_defocus;
pixelData.m_blurRadius = centerPixelPsfEntry.m_radius;
}
}
////////////////////////////////////////////////////////////////////////////////
void computePixelProperties(Scene::Scene& scene, Scene::Object* object, CommonData& commonData, std::vector<PerThreadData>& perThreadData)
{
// Only do this for the per-pixel algorithm
if (object->component<GroundTruthAberrationComponent>().m_convolutionSettings.m_algorithm != ConvolutionSettings::PerPixel)
return;
DateTime::ScopedTimer timer(Debug::Info, 1, DateTime::Seconds, "Per-Pixel Properties");
// Compute the per-pixel properties
Threading::threadedExecuteIndices(
Threading::ThreadedExecuteParams(Threading::numThreads(), "Processing pixels", "pixel", outputLogLevel(scene, object, ConvolutionSettings::Progress)),
[&](Threading::ThreadedExecuteEnvironment const& environment, int img_row, int img_col)
{
computePerPixelProperties(scene, object, environment, commonData, perThreadData[Threading::currentThreadId()], img_row, img_col);
},
commonData.m_renderResolution[1], commonData.m_renderResolution[0]);
}
////////////////////////////////////////////////////////////////////////////////
void gatherPixel(Scene::Scene& scene, Scene::Object* object, Threading::ThreadedExecuteEnvironment const& environment,
CommonData& commonData, PerThreadData& threadData, int img_row, int img_col)
{
// Whether we should be logging from this thread or not
const bool log = shouldLog(scene, object, environment);
// Image dimensions
auto width = commonData.m_renderResolution[0], height = commonData.m_renderResolution[1];