-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
1259 lines (991 loc) · 41.4 KB
/
utils.cpp
File metadata and controls
1259 lines (991 loc) · 41.4 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 "tests.h"
#include <cmath>
#include <cstring>
#include <fstream>
#include <vector>
#include <sstream>
#include "simplerandom.h"
#include "HR_HDRImageTool.h"
#include "HydraTextureUtils.h"
///////////////////////////////////////////////////////////////////////////////////
#pragma warning(disable:4838)
using HDRImage4f = HydraRender::HDRImage4f;
std::vector<bool> g_resultTest;
namespace TEST_UTILS
{
SystemInfo::SystemInfo(const std::wstring& a_operationSystem, const std::wstring& a_videocard) :
m_operationSystem(a_operationSystem),
m_videocard(a_videocard) {}
void SystemInfo::SetOperSys(const std::wstring& a_operationSystem) { m_operationSystem = a_operationSystem; }
void SystemInfo::SetVideocard(const std::wstring& a_videocard) { m_videocard = a_videocard; }
std::wstring SystemInfo::GetFolderNameFromInfo() { return m_operationSystem + L"_" + m_videocard; }
std::wstring SystemInfo::GetOsName() { return m_operationSystem; }
std::wstring SystemInfo::GetVideocardName() { return m_videocard; }
void show_me_texture_ldr(const std::string& a_inFleName, const std::string& a_outFleName)
{
int32_t wh[2];
std::ifstream fin(a_inFleName, std::iostream::binary);
fin.read((char*)wh, sizeof(int) * 2);
if (wh[0] <= 0 || wh[1] <= 0)
return;
std::vector<uint32_t> sdata(wh[0] * wh[1]);
fin.read((char*)&sdata[0], sdata.size() * sizeof(uint32_t));
fin.close();
HydraRender::SaveImageToFile(a_outFleName, wh[0], wh[1], &sdata[0]);
}
void show_me_texture_hdr(const std::string& a_inFleName, const std::string& a_outFleName)
{
int32_t wh[2];
std::ifstream fin(a_inFleName, std::iostream::binary);
fin.read((char*)wh, sizeof(int) * 2);
if (wh[0] <= 0 || wh[1] <= 0)
return;
HDRImage4f colorImg(wh[0], wh[1]);
fin.read((char*)colorImg.data(), wh[0] * wh[1] * 4 * sizeof(float));
fin.close();
HydraRender::SaveImageToFile(a_outFleName, colorImg, 2.2f);
}
std::vector<unsigned int> CreateStripedImageData(unsigned int* a_colors, int a_stripsNum, int w, int h)
{
std::vector<unsigned int> imageData(w*h);
int currH = 0;
int strideH = (h / a_stripsNum);
for (int stripId = 0; stripId < a_stripsNum; stripId++)
{
unsigned int color = a_colors[stripId];
#pragma omp parallel for
for (int y = currH; y < currH + strideH; y++)
{
for (int x = 0; x < w; x++)
imageData[y*w + x] = color;
}
currH += strideH;
}
return imageData;
}
HRTextureNodeRef AddRandomTextureFromMemory(size_t& memTotal, simplerandom::RandomGen& rgen)
{
int choice = rand(rgen) % 3;
int w = rand(rgen) % 2048 + 1 + 128;
int h = rand(rgen) % 2048 + 1 + 128;
if (choice == 0) // add LDR texture
{
std::vector<int> data(w*h);
for (size_t i = 0; i < data.size(); i++)
data[i] = 0xFFFF00FF;
memTotal += w*h * 4;
return hrTexture2DCreateFromMemory(w, h, 4, &data[0]);
}
else if (choice == 1) // add LDR texture
{
std::vector<int> data(w*h);
for (size_t i = 0; i < data.size(); i++)
data[i] = 0xFF7F0060;
memTotal += w*h * 4;
return hrTexture2DCreateFromMemory(w, h, 4, &data[0]);
}
else // add HDR texture
{
std::vector<int> data(w*h);
for (size_t i = 0; i < data.size(); i++)
data[i] = 0xFFA070F0;
memTotal += w*h * 4;
return hrTexture2DCreateFromMemory(w, h, 4, &data[0]);
}
}
static inline float clamp(float u, float a, float b) { return fminf(fmaxf(a, u), b); }
void procTexCheckerLDR(unsigned char* a_buffer, int w, int h, void* a_repeat)
{
if (a_repeat == nullptr)
return;
int* data = (int*)a_repeat;
int repeats = *data;
repeats *= 2;
#pragma omp parallel for
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
float cx = floor(repeats * (float(x) / w));
float cy = floor(repeats * (float(y) / h));
float result = fmod(cx + cy, 2.0f);
clamp(result, 0.0, 1.0);
a_buffer[(y*w + x) * 4 + 0] = (unsigned char)(result * 255);
a_buffer[(y*w + x) * 4 + 1] = (unsigned char)(result * 255);
a_buffer[(y*w + x) * 4 + 2] = (unsigned char)(result * 255);
a_buffer[(y*w + x) * 4 + 3] = 255;
}
}
}
void procTexCheckerHDR(float* a_buffer, int w, int h, void* a_repeat)
{
if (a_repeat == nullptr)
return;
int* data = (int*)a_repeat;
int repeats = *data;
repeats *= 2;
#pragma omp parallel for
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
float cx = floor(repeats * (float(x) / w));
float cy = floor(repeats * (float(y) / h));
float result = fmod(cx + cy, 2.0f);
if (result < 0.001f)
result = 0.0f;
else
result = 10.0f;
a_buffer[(y*w + x) * 4 + 0] = result;
a_buffer[(y*w + x) * 4 + 1] = result;
a_buffer[(y*w + x) * 4 + 2] = result;
a_buffer[(y*w + x) * 4 + 3] = 1.0;
}
}
}
void customDisplacement1(const float *pos, const float *normal, const HRUtils::BBox &bbox, float displace_vec[3],
void* a_customData, uint32_t a_customDataSize)
{
auto *data = (displace_data_1 *) a_customData;
float3 N(normal[0], normal[1], normal[2]);
auto tmp = cross(data->global_dir, N);
auto d = cross(N, tmp);
d = normalize(d);
float mult = 5.0f - pos[1];
if(mult < 0.0f) mult = 0.0f;
displace_vec[0] = d.x * data->mult * mult;
displace_vec[1] = d.y * data->mult * mult;
displace_vec[2] = d.z * data->mult * mult;
}
void customDisplacementSpots(const float *pos, const float *normal, const HRUtils::BBox &bbox, float displace_vec[3],
void* a_customData, uint32_t a_customDataSize)
{
auto *data = (displace_data_1 *) a_customData;
float3 N(normal[0], normal[1], normal[2]);
float3 position(pos[0], pos[1], pos[2]-2.2f);
float spots_scale = 120.0f;
float spots_detail = 0.1f;
float spots_thr = 0.58;
float n2 = HRTextureUtils::noise(position * spots_scale, 0.0f, spots_detail) - spots_thr;
n2 = clamp(n2, 0.0f, 1.0f);
n2 = powf(n2, 0.15f);
/*float y_gen = (position.y) / 8.1f; //bbox_y = 8.1f
n2 = clamp(n2, 0.0f, 1.0f) * (1.0f - HRTextureUtils::fitRange(y_gen, 0.4, 1.0f, 0.0f, 1.0f));
*/
//
// float mult = 1.0f - pos[1];
// if(mult < 0.0f) mult = 0.0f;
auto d = N * n2;
displace_vec[0] = d.x * data->mult;
displace_vec[1] = d.y * data->mult;
displace_vec[2] = d.z * data->mult;
}
void customDisplacementFBM(const float *p, const float *normal, const HRUtils::BBox &bbox, float displace_vec[3],
void* a_customData, uint32_t a_customDataSize)
{
auto *data = (displace_data_1 *) a_customData;
float3 N(normal[0], normal[1], normal[2]);
float3 pos(p[0]+0.45f, p[1]-0.5f, p[2]);
//float3 gen_pos = make_float3(pos.x/(bbox.x_max - bbox.x_min), pos.y/(bbox.y_max - bbox.y_min), pos.z/(bbox.z_max - bbox.z_min));
float3 gen_pos = make_float3(HRTextureUtils::fitRange(pos.x, bbox.x_min, bbox.x_max, 0.0f, 1.0f)-0.15f,
HRTextureUtils::fitRange(pos.y, bbox.y_min, bbox.y_max, 0.0f, 1.0f),
HRTextureUtils::fitRange(pos.z, bbox.z_min, bbox.z_max, 0.0f, 1.0f));
float scale = 0.750f;
float dimension = 0.1f;
float octaves = 8;
float lacunarity = 2*1.5f;
gen_pos = gen_pos * scale;
// float n = octave(gen_pos, 8, 0.5f, 2.0, 5.0f);
float n1 = HRTextureUtils::noise_musgrave_fBm(gen_pos, dimension, lacunarity, octaves);
float n2 = HRTextureUtils::noise_musgrave_fBm(gen_pos/(scale), dimension, 4.0f, 4);
int tmp = 0;
if(n1 < -0.5f)
tmp = 1;
float w = n2 / (tmp - n1);
if(gen_pos.y / scale < 1.25f)
{
w = w / (gen_pos.y / scale);
}
else if(gen_pos.y / scale > 1.25f)
w = 0.0f;
float mult = 1.25f - gen_pos.y;
if(mult < 0.0f) mult = 0.0f;
if (pos.z < -2.0f && pos.x > 0.3f)
mult *= 5.0f;
else
mult /=5.0f;
w = clamp(w, 0.0, 1.0);
auto d = N * w;
displace_vec[0] = d.x * data->mult * mult;
displace_vec[1] = d.y * data->mult * mult;
displace_vec[2] = d.z * data->mult * mult;
}
void CreateTestBigTexturesFilesIfNeeded()
{
const int TXSZ = 4096;
if (!FileExists("data/textures_gen/texture_big_red.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int color = 0xFF0000FF;
CreateStripedImageFile("data/textures_gen/texture_big_red.png", &color, 1, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_green.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int color = 0xFF00FF00;
CreateStripedImageFile("data/textures_gen/texture_green.png", &color, 1, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_blue.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int color = 0xFFFF0000;
CreateStripedImageFile("data/textures_gen/texture_blue.png", &color, 1, TXSZ, TXSZ);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!FileExists("data/textures_gen/texture_big_z01.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[2] = { 0xFF0000FF, 0xFF00FF00 };
CreateStripedImageFile("data/textures_gen/texture_big_z01.png", colors, 2, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_big_z02.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[2] = { 0xFF0000FF, 0xFFFF0000 };
CreateStripedImageFile("data/textures_gen/texture_big_z02.png", colors, 2, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_big_z03.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[2] = { 0xFF00FFFF, 0xFF0000FF };
CreateStripedImageFile("data/textures_gen/texture_big_z03.png", colors, 2, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_big_z04.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[2] = { 0xFFFF0000, 0xFF00FF00 };
CreateStripedImageFile("data/textures_gen/texture_big_z04.png", colors, 2, TXSZ, TXSZ);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!FileExists("data/textures_gen/texture_big_z05.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[4] = { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFF00FF };
CreateStripedImageFile("data/textures_gen/texture_big_z05.png", colors, 4, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_big_z06.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[4] = { 0xFF00FF00, 0xFFFF0000, 0xFFFF00FF, 0xFFFFFFFF };
CreateStripedImageFile("data/textures_gen/texture_big_z06.png", colors, 4, TXSZ, TXSZ);
}
if (!FileExists("data/textures_gen/texture_big_z07.png"))
{
std::cout << "creating test texture and saving it to disk ... " << std::endl;
unsigned int colors[4] = { 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF, 0xFF000000 };
CreateStripedImageFile("data/textures_gen/texture_big_z07.png", colors, 4, TXSZ, TXSZ);
}
}
HRTextureNodeRef CreateRandomStrippedTextureFromMemory(size_t& a_byteSize, simplerandom::RandomGen& rgen)
{
int TXSZ = 1024;
int choice1 = simplerandom::rand(rgen) % 3;
if (choice1 == 0)
{
a_byteSize += size_t(2048 * 2048 * 4);
TXSZ = 2048;
}
else if (choice1 == 2)
{
a_byteSize += size_t(512 * 512 * 4);
TXSZ = 512;
}
else
{
a_byteSize += size_t(1024 * 1024 * 4);
TXSZ = 1024;
}
int choice = simplerandom::rand(rgen) % 10;
if (choice == 0)
{
unsigned int color = 0xFF0000FF;
auto data = CreateStripedImageData(&color, 1, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 1)
{
unsigned int color = 0xFF00FF00;
auto data = CreateStripedImageData(&color, 1, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 2)
{
unsigned int color = 0xFFFF0000;
auto data = CreateStripedImageData(&color, 1, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 3)
{
unsigned int colors[2] = { 0xFF0000FF, 0xFF00FF00 };
auto data = CreateStripedImageData(colors, 2, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 4)
{
unsigned int colors[2] = { 0xFF0000FF, 0xFFFF0000 };
auto data = CreateStripedImageData(colors, 2, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 5)
{
unsigned int colors[2] = { 0xFF00FFFF, 0xFF0000FF };
auto data = CreateStripedImageData(colors, 2, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 6)
{
unsigned int colors[2] = { 0xFFFF0000, 0xFF00FF00 };
auto data = CreateStripedImageData(colors, 2, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 7)
{
unsigned int colors[4] = { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFF00FF };
auto data = CreateStripedImageData(colors, 4, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else if (choice == 8)
{
unsigned int colors[4] = { 0xFF00FF00, 0xFFFF0000, 0xFFFF00FF, 0xFFFFFFFF };
auto data = CreateStripedImageData(colors, 4, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
else
{
unsigned int colors[4] = { 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF, 0xFF000000 };
auto data = CreateStripedImageData(colors, 4, TXSZ, TXSZ);
return hrTexture2DCreateFromMemory(TXSZ, TXSZ, 4, &data[0]);
}
}
bool FileExists(const char* a_fileName)
{
std::ifstream fin(a_fileName);
bool res = fin.is_open();
fin.close();
return res;
}
void CreateStripedImageFile(const char* a_fileName, unsigned int* a_colors, int a_stripsNum, int w, int h)
{
std::vector<unsigned int> imageData = CreateStripedImageData(a_colors, a_stripsNum, w, h);
HydraRender::SaveImageToFile(a_fileName, w, h, imageData.data());
}
std::vector<HRMeshRef> CreateRandomMeshesArray(int a_size, simplerandom::RandomGen& rgen)
{
std::vector<HRMeshRef> meshes(a_size);
for (size_t i = 0; i < meshes.size(); i++)
{
int choice = simplerandom::rand(rgen) % 3;
if (choice == 0)
meshes[i] = HRMeshFromSimpleMesh(L"my_cube", CreateCube(0.5f), simplerandom::rand(rgen) % 50);
else if (choice == 1)
meshes[i] = HRMeshFromSimpleMesh(L"my_sphere", CreateSphere(0.5f, 128), simplerandom::rand(rgen) % 50);
else
meshes[i] = HRMeshFromSimpleMesh(L"my_torus2", CreateTorus(0.2f, 0.5f, 128, 128), simplerandom::rand(rgen) % 50);
if (i % 20 == 0)
std::cout << "[test_mbm]: MB, total meshes = " << i << "\r";
}
std::cout << std::endl;
return meshes;
}
HRMeshRef HRMeshFromSimpleMesh(const wchar_t* a_name, const SimpleMesh& a_mesh, int a_matId)
{
HRMeshRef meshRef = hrMeshCreate(a_name);
hrMeshOpen(meshRef, HR_TRIANGLE_IND3, HR_WRITE_DISCARD);
{
hrMeshVertexAttribPointer4f(meshRef, L"pos", &a_mesh.vPos[0]);
hrMeshVertexAttribPointer4f(meshRef, L"norm", &a_mesh.vNorm[0]);
hrMeshVertexAttribPointer2f(meshRef, L"texcoord", &a_mesh.vTexCoord[0]);
hrMeshMaterialId(meshRef, a_matId);
hrMeshAppendTriangles3(meshRef, int(a_mesh.triIndices.size()), &a_mesh.triIndices[0]);
}
hrMeshClose(meshRef);
return meshRef;
}
HRMeshRef CreateCornellBox(const float a_size, HRMaterialRef a_leftWallMat, HRMaterialRef a_rightWallMat, HRMaterialRef a_ceilingMat, HRMaterialRef a_backWallMat, HRMaterialRef a_floorMat)
{
SimpleMesh cubeOpen = CreateCubeOpen(a_size);
HRMeshRef meshRef = hrMeshCreate(L"CornellBox");
hrMeshOpen(meshRef, HR_TRIANGLE_IND3, HR_WRITE_DISCARD);
{
hrMeshVertexAttribPointer4f(meshRef, L"pos", &cubeOpen.vPos[0]);
hrMeshVertexAttribPointer4f(meshRef, L"norm", &cubeOpen.vNorm[0]);
hrMeshVertexAttribPointer2f(meshRef, L"texcoord", &cubeOpen.vTexCoord[0]);
int cubeMatIndices[10] = {
a_ceilingMat.id, a_ceilingMat.id,
a_backWallMat.id, a_backWallMat.id,
a_floorMat.id, a_floorMat.id,
a_rightWallMat.id, a_rightWallMat.id,
a_leftWallMat.id, a_leftWallMat.id };
hrMeshPrimitiveAttribPointer1i(meshRef, L"mind", cubeMatIndices);
hrMeshAppendTriangles3(meshRef, int(cubeOpen.triIndices.size()), &cubeOpen.triIndices[0]);
}
hrMeshClose(meshRef);
return meshRef;
}
void AddDiffuseNode(HAPI pugi::xml_node& matNode, const wchar_t* a_diffuseColor,
const wchar_t* a_brdfType, const float a_roughness, HRTextureNodeRef a_texture,
const wchar_t* a_addressingModeU, const wchar_t* a_addressingModeV, const float a_tileU,
const float a_tileV, const float a_inputGamma, const wchar_t* a_inputAlpha,
const wchar_t* a_texApplyMode)
{
auto diff = matNode.append_child(L"diffuse");
diff.append_attribute(L"brdf_type") = a_brdfType;
auto color = diff.append_child(L"color");
color.append_attribute(L"val") = a_diffuseColor;
if (std::wstring(a_brdfType) == L"orennayar")
{
auto rough = diff.append_child(L"roughness");
rough.append_attribute(L"val") = a_roughness;
}
if (a_texture.id != -1)
{
color.append_attribute(L"tex_apply_mode") = a_texApplyMode;
hrTextureBind(a_texture, color);
auto texNode = color.child(L"texture");
texNode.append_attribute(L"matrix");
float samplerMatrix[16] = { a_tileU, 0, 0, 0,
0, a_tileV, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
texNode.append_attribute(L"addressing_mode_u") = a_addressingModeU;
texNode.append_attribute(L"addressing_mode_v") = a_addressingModeV;
texNode.append_attribute(L"input_gamma") = a_inputGamma;
texNode.append_attribute(L"input_alpha") = a_inputAlpha;
HydraXMLHelpers::WriteMatrix4x4(texNode, L"matrix", samplerMatrix);
}
VERIFY_XML(matNode);
}
void AddReflectionNode(HAPI pugi::xml_node& matNode, const wchar_t* a_brdfType, const wchar_t* a_color,
const float a_glossiness, const bool a_fresnel, const float a_ior, const wchar_t* a_extrusion, const bool a_energyFix)
{
auto refl = matNode.append_child(L"reflectivity");
refl.append_attribute(L"brdf_type") = a_brdfType;
refl.append_child(L"color").append_attribute(L"val") = a_color;
refl.append_child(L"glossiness").append_attribute(L"val") = a_glossiness;
refl.append_child(L"extrusion").append_attribute(L"val") = a_extrusion;
refl.append_child(L"fresnel").append_attribute(L"val") = (int)(a_fresnel);
refl.append_child(L"fresnel_ior").append_attribute(L"val") = a_ior;
refl.append_child(L"energy_fix").append_attribute(L"val") = (int)(a_energyFix);
VERIFY_XML(matNode);
}
void AddOpacityNode(HAPI pugi::xml_node& matNode, HRTextureNodeRef a_texture, const bool a_skipShadow,
const wchar_t* a_addressingModeU, const wchar_t* a_addressingModeV,
const float a_tileU, const float a_tileV, const float a_inputGamma, const wchar_t* a_inputAlpha)
{
auto opacity = matNode.append_child(L"opacity");
opacity.append_child(L"skip_shadow").append_attribute(L"val") = (int)(a_skipShadow);
auto texNode = hrTextureBind(a_texture, opacity);
texNode.append_attribute(L"matrix");
float samplerMatrix[16] = { a_tileU, 0, 0, 0,
0, a_tileV, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
texNode.append_attribute(L"addressing_mode_u") = a_addressingModeU;
texNode.append_attribute(L"addressing_mode_v") = a_addressingModeV;
texNode.append_attribute(L"input_gamma") = a_inputGamma;
texNode.append_attribute(L"input_alpha") = a_inputAlpha;
HydraXMLHelpers::WriteMatrix4x4(texNode, L"matrix", samplerMatrix);
VERIFY_XML(matNode);
}
void AddTranslucencyNode(HAPI pugi::xml_node& matNode, const wchar_t* a_color)
{
auto transl = matNode.append_child(L"translucency");
transl.append_child(L"color").append_attribute(L"val") = a_color;
VERIFY_XML(matNode);
}
void AddReliefNode(HAPI pugi::xml_node& matNode, const wchar_t* a_type, const float a_amount,
HRTextureNodeRef a_texture, const wchar_t* a_addressingModeU, const wchar_t* a_addressingModeV,
const float a_tileU, const float a_tileV, const float a_inputGamma, const wchar_t* a_inputAlpha)
{
auto displacement = matNode.append_child(L"displacement");
pugi::xml_node heightNode;
if (std::wstring(a_type) == L"height_bump") heightNode = displacement.append_child(L"height_map");
else if (std::wstring(a_type) == L"normal_bump") heightNode = displacement.append_child(L"normal_map");
displacement.append_attribute(L"type") = a_type;
heightNode.append_attribute(L"amount") = a_amount;
auto texNode = hrTextureBind(a_texture, heightNode);
texNode.append_attribute(L"matrix");
float samplerMatrix[16] = { a_tileU, 0, 0, 0,
0, a_tileV, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
texNode.append_attribute(L"addressing_mode_u") = a_addressingModeU;
texNode.append_attribute(L"addressing_mode_v") = a_addressingModeV;
texNode.append_attribute(L"input_gamma") = a_inputGamma;
texNode.append_attribute(L"input_alpha") = a_inputAlpha;
HydraXMLHelpers::WriteMatrix4x4(texNode, L"matrix", samplerMatrix);
VERIFY_XML(matNode);
}
void CreateCamera(const float a_fov, const wchar_t* a_position, const wchar_t* a_lookAt,
const wchar_t* a_name, const float a_nearClipPlane, const float a_farClipPlane, const wchar_t* a_up,
const bool a_dof, const float a_dofLensRadius)
{
auto camRef = hrCameraCreate(a_name);
hrCameraOpen(camRef, HR_WRITE_DISCARD);
{
auto camNode = hrCameraParamNode(camRef);
camNode.append_child(L"fov").text() = a_fov;
camNode.append_child(L"nearClipPlane").text() = a_nearClipPlane;
camNode.append_child(L"farClipPlane").text() = a_farClipPlane;
camNode.append_child(L"up").text() = a_up;
camNode.append_child(L"position").text() = a_position;
camNode.append_child(L"look_at").text() = a_lookAt;
camNode.append_child(L"enable_dof").text() = (int)(a_dof);
camNode.append_child(L"dof_lens_radius").text() = a_dofLensRadius;
VERIFY_XML(camNode);
}
hrCameraClose(camRef);
}
void AddMeshToScene(HRSceneInstRef& scnRef, HRMeshRef& a_meshRef, float3 pos, float3 rot, float3 scale,
const int32_t* a_mmListm, int32_t a_mmListSize)
{
float4x4 mRotX;
float4x4 mRotY;
float4x4 mRotZ;
float4x4 mScale;
float4x4 mTranslate;
float4x4 mRes;
mRotX.identity();
mRotY.identity();
mRotZ.identity();
mScale.identity();
mTranslate.identity();
mRes.identity();
mScale = scale4x4(scale);
mRotZ = rotate4x4Z(rot.z * DEG_TO_RAD);
mRotY = rotate4x4Y(rot.y * DEG_TO_RAD);
mRotX = rotate4x4X(rot.x * DEG_TO_RAD);
mTranslate = translate4x4(pos);
mRes = mul(mScale, mRes);
mRes = mul(mRotZ, mRes);
mRes = mul(mRotY, mRes);
mRes = mul(mRotX, mRes);
mRes = mul(mTranslate, mRes);
if (a_mmListSize > 0)
hrMeshInstance(scnRef, a_meshRef, mRes.L(), a_mmListm, a_mmListSize);
else
hrMeshInstance(scnRef, a_meshRef, mRes.L());
//float mRot[4][4];
//float mTranslate[4][4];
//float matrixT[4][4];
//float mRes[4][4];
//mat4x4_identity(mTranslate);
//mat4x4_identity(mRot);
//mat4x4_translate(mTranslate, pos.x, pos.y, pos.z);
//mat4x4_rotate_Z(mRot, mRot, rot.z * DEG_TO_RAD);
//mat4x4_rotate_Y(mRot, mRot, rot.y * DEG_TO_RAD);
//mat4x4_rotate_X(mRot, mRot, rot.x * DEG_TO_RAD);
//mat4x4_mul(mRes, mTranslate, mRot);
//mat4x4_transpose(matrixT, mRes); //swap rows and columns
//if (a_mmListSize > 0)
// hrMeshInstance(scnRef, a_meshRef, &matrixT[0][0], a_mmListm, a_mmListSize);
//else
// hrMeshInstance(scnRef, a_meshRef, &matrixT[0][0]);
}
void AddLightToScene(HRSceneInstRef& scnRef, HRLightRef& a_lightRef, const float3 a_pos,
const float3 a_rot, const float3 a_scale)
{
float4x4 mRotX;
float4x4 mRotY;
float4x4 mRotZ;
float4x4 mScale;
float4x4 mTranslate;
float4x4 mRes;
mRotX.identity();
mRotY.identity();
mRotZ.identity();
mScale.identity();
mTranslate.identity();
mRes.identity();
mScale = scale4x4(a_scale);
mRotZ = rotate4x4Z(a_rot.z * DEG_TO_RAD);
mRotY = rotate4x4Y(a_rot.y * DEG_TO_RAD);
mRotX = rotate4x4X(a_rot.x * DEG_TO_RAD);
mTranslate = translate4x4(a_pos);
mRes = mul(mScale, mRes);
mRes = mul(mRotZ, mRes);
mRes = mul(mRotY, mRes);
mRes = mul(mRotX, mRes);
mRes = mul(mTranslate, mRes);
hrLightInstance(scnRef, a_lightRef, mRes.L());
//float mRot[4][4];
//float mTranslate[4][4];
//float matrixT[4][4];
//float mRes[4][4];
//mat4x4_identity(mTranslate);
//mat4x4_identity(mRot);
//mat4x4_translate(mTranslate, a_pos.x, a_pos.y, a_pos.z);
//mat4x4_rotate_Z(mRot, mRot, a_rot.z * DEG_TO_RAD);
//mat4x4_rotate_Y(mRot, mRot, a_rot.y * DEG_TO_RAD);
//mat4x4_rotate_X(mRot, mRot, a_rot.x * DEG_TO_RAD);
//mat4x4_mul(mRes, mTranslate, mRot);
//mat4x4_transpose(matrixT, mRes); //swap rows and columns
//hrLightInstance(scnRef, a_lightRef, &matrixT[0][0]);
}
HRRenderRef CreateBasicTestRenderPT(int a_deviceId, int a_w, int a_h, int a_minRays, int a_maxRays,
int a_rayBounce, int a_diffBounce, const wchar_t* a_drvName)
{
auto renderRef = hrRenderCreate(a_drvName);
hrRenderEnableDevice(renderRef, a_deviceId, true);
hrRenderOpen(renderRef, HR_WRITE_DISCARD);
{
auto node = hrRenderParamNode(renderRef);
node.append_child(L"width").text() = a_w;
node.append_child(L"height").text() = a_h;
node.append_child(L"method_primary").text() = L"pathtracing";
node.append_child(L"method_secondary").text() = L"pathtracing";
node.append_child(L"method_tertiary").text() = L"pathtracing";
node.append_child(L"method_caustic").text() = L"pathtracing";
node.append_child(L"qmc_variant").text() = QMC_ALL;
node.append_child(L"trace_depth").text() = a_rayBounce;
node.append_child(L"diff_trace_depth").text() = a_diffBounce;
node.append_child(L"maxRaysPerPixel").text() = a_maxRays;
node.append_child(L"resources_path").text() = L"..";
node.append_child(L"offline_pt").text() = 0;
}
hrRenderClose(renderRef);
return renderRef;
}
HRRenderRef CreateBasicTestRenderPTNoCaust(int deviceId, int w, int h, int minRays, int maxRays,
const float a_clamp)
{
auto renderRef = hrRenderCreate(L"HydraModern");
hrRenderEnableDevice(renderRef, deviceId, true);
hrRenderOpen(renderRef, HR_WRITE_DISCARD);
{
auto node = hrRenderParamNode(renderRef);
node.append_child(L"width").text() = w;
node.append_child(L"height").text() = h;
node.append_child(L"method_primary").text() = L"pathtracing";
node.append_child(L"method_secondary").text() = L"pathtracing";
node.append_child(L"method_tertiary").text() = L"pathtracing";
node.append_child(L"method_caustic").text() = L"none";
node.append_child(L"trace_depth").text() = L"5";
node.append_child(L"diff_trace_depth").text() = L"3";
node.append_child(L"qmc_variant").text() = QMC_ALL;
node.append_child(L"minRaysPerPixel").text() = minRays;
node.append_child(L"maxRaysPerPixel").text() = maxRays;
node.append_child(L"clamping").text() = a_clamp;
}
hrRenderClose(renderRef);
return renderRef;
}
HRRenderRef CreateBasicTestRenderPTFastBackground(int deviceId, int w, int h, int minRays, int maxRays, const wchar_t* a_drvName)
{
auto renderRef = hrRenderCreate(a_drvName);
hrRenderEnableDevice(renderRef, deviceId, true);
hrRenderOpen(renderRef, HR_WRITE_DISCARD);
{
auto node = hrRenderParamNode(renderRef);
node.append_child(L"width").text() = w;
node.append_child(L"height").text() = h;
node.append_child(L"method_primary").text() = L"pathtracing";
node.append_child(L"method_secondary").text() = L"pathtracing";
node.append_child(L"method_tertiary").text() = L"pathtracing";
node.append_child(L"method_caustic").text() = L"pathtracing";
//node.append_child(L"qmc_variant").text() = QMC_ALL; not work with offline_pt
node.append_child(L"trace_depth").text() = 6;
node.append_child(L"diff_trace_depth").text() = 4;
node.append_child(L"maxRaysPerPixel").text() = maxRays;
node.append_child(L"resources_path").text() = L"..";
node.append_child(L"offline_pt").text() = 1;
}
hrRenderClose(renderRef);
return renderRef;
}
HRLightRef CreateLight(const wchar_t* a_name, const wchar_t* a_type, const wchar_t* a_shape,
const wchar_t* a_distribution, const float a_halfLength, const float a_halfWidth,
const wchar_t* a_color, const float a_multiplier, const bool a_spot,
const float a_innerRadius, const float a_outerRadius, const float a_shadowSoft)
{
auto light = hrLightCreate(a_name);
hrLightOpen(light, HR_WRITE_DISCARD);
{
auto lightNode = hrLightParamNode(light);
lightNode.attribute(L"type") = a_type;
lightNode.attribute(L"shape") = a_shape;
lightNode.attribute(L"distribution") = a_distribution;
lightNode.force_child(L"shadow_softness").force_attribute(L"val") = a_shadowSoft;
auto sizeNode = lightNode.append_child(L"size");
if (std::wstring(a_shape) == L"rect")
{
sizeNode.force_attribute(L"half_length") = a_halfLength;
sizeNode.force_attribute(L"half_width") = a_halfWidth;
}
else if (std::wstring(a_shape) == L"sphere")
{
sizeNode.force_attribute(L"radius") = a_halfLength;
}
if (a_spot)
{
sizeNode.force_attribute(L"inner_radius") = a_innerRadius;
sizeNode.force_attribute(L"outer_radius") = a_outerRadius;
}
auto intensityNode = lightNode.force_child(L"intensity");
intensityNode.force_child(L"color").force_attribute(L"val") = a_color;
intensityNode.force_child(L"multiplier").force_attribute(L"val") = a_multiplier;
VERIFY_XML(lightNode);
}
hrLightClose(light);
return light;
}
HRLightRef CreateSky(const wchar_t* a_name, const wchar_t* a_color, const float a_multiplier,
const wchar_t* a_distribution, const int a_sunId, const float a_turbidity, HRTextureNodeRef a_texture,
const wchar_t* a_addressingModeU, const wchar_t* a_addressingModeV, const float a_tileU,
const float a_tileV, const float a_inputGamma, const wchar_t* a_inputAlpha,
const wchar_t* a_texApplyMode)
{
HRLightRef sky = hrLightCreate(a_name);
hrLightOpen(sky, HR_WRITE_DISCARD);
{
auto lightNode = hrLightParamNode(sky);
lightNode.attribute(L"type").set_value(L"sky");
lightNode.attribute(L"distribution") = a_distribution;
auto intensityNode = lightNode.append_child(L"intensity");
intensityNode.append_child(L"color").append_attribute(L"val") = a_color;
intensityNode.append_child(L"multiplier").append_attribute(L"val") = a_multiplier;
if (std::wstring(a_distribution) == L"perez")
{
auto sunModel = lightNode.append_child(L"perez");
sunModel.append_attribute(L"sun_id") = a_sunId;
sunModel.append_attribute(L"turbidity") = a_turbidity;
}
else if (std::wstring(a_distribution) == L"map")
{
auto texNode = hrTextureBind(a_texture, intensityNode.child(L"color"));
texNode.append_attribute(L"matrix");
float samplerMatrix[16] = { a_tileU, 0, 0, 0,
0, a_tileV, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
texNode.append_attribute(L"addressing_mode_u") = a_addressingModeU;
texNode.append_attribute(L"addressing_mode_v") = a_addressingModeV;
texNode.append_attribute(L"input_gamma") = a_inputGamma;
texNode.append_attribute(L"input_alpha") = a_inputAlpha;
HydraXMLHelpers::WriteMatrix4x4(texNode, L"matrix", samplerMatrix);
}
VERIFY_XML(lightNode);
}
hrLightClose(sky);
return sky;
}
ResultTest::ResultTest(const std::wstring a_name, const std::vector<bool> a_res, const bool a_skip, const std::vector<float> a_mse,
const float a_rendTime, const std::vector<std::wstring>& a_linkRefImgs, const std::vector<std::wstring>& a_linkRenderImgs)
{
m_nameTest = a_name;
if (a_skip)
{
m_result = L"skipped";
m_resultHtml = L"🗑"; // trash can
m_mse = L"-";
m_mseHtml = L"-";
m_renderTime = L"-";
}