-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.h
4477 lines (3935 loc) · 178 KB
/
scene.h
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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <float.h>
#include <random>
#include <unordered_map>
#include <time.h>
#include <memory>
#include <algorithm>
#include <functional>
#include "helpers.h"
using namespace std;
// EXTERNAL GLOBALS
// Stick-man classes
extern DisplaySkeleton displayer;
extern Skeleton* skeleton;
extern Motion* motion;
extern int xRes;
extern int yRes;
extern int max_depth;
extern bool use_model;
// Camera settings
extern VEC3 eye;
extern VEC3 lookingAt;
extern VEC3 up;
extern float aspect;
extern float near; // distance to image plane
extern float fov;
extern float aperture; // diameter of sampling lens
extern float focal_length; // distance to focal plane
// Reflection
extern vector<string> refl_materials;
extern float refr_air;
extern float refr_glass;
// scene geometry
extern vector<shared_ptr<GeoPrimitive>> shapes;
extern vector<shared_ptr<LightPrimitive>> lights;
extern float phong;
extern VEC3 default_col;
// BVH settings
extern shared_ptr<BoundingVolume> bvh;
extern float c_isect; // Random assumption: traversal is 1/3 cost of ray-primitive intersection
extern float c_trav;
// Sampling settings
extern int antialias_samples;
extern int blur_samples;
mt19937 gen(0); // deterministic engine for triangle textures
// Texture
extern vector<vector<VEC3>> texture_frames;
extern vector<VEC2> texture_dims;
extern vector<string> frame_paths;
// Choreography
extern int frame_prism;
extern int frame_cloud;
extern int frame_blur;
extern int frame_range;
extern int frame_start;
extern int frame_move1;
extern int frame_move2;
extern int frame_sculp;
extern int total;
extern float far;
extern float tot_move;
extern float move_per_frame;
extern float accel_t;
extern VEC3 cap_center;
// Colors
extern VEC3 teal;
extern VEC3 pink;
extern VEC3 pastelpink;
extern VEC3 halogen;
extern VEC3 sunorange;
extern VEC3 violet;
extern VEC3 indigo;
extern VEC3 darkblue;
extern VEC3 maroonq;
extern VEC3 skyblue;
// Cloud parameters
extern bool perlin_cloud; // Indicator for creating perlin cloud default colors
extern float saturation;
extern float clouddist;
extern float cloudhoff; // height cutoff
extern VEC3 sun_outer;
extern VEC3 sun_inner;
extern VEC3 sun_core;
extern VEC3 bluesky;
extern VEC3 redsky;
//=================================================================================
// SCENE FUNCTIONS
//=================================================================================
//////////////////////////////////////////////////////////////////////////////////
// Load up a new motion captured frame
//////////////////////////////////////////////////////////////////////////////////
void setSkeletonsToSpecifiedFrame(int frameIndex)
{
if (frameIndex < 0)
{
printf("Error in SetSkeletonsToSpecifiedFrame: frameIndex %d is illegal.\n", frameIndex);
exit(0);
}
if (displayer.GetSkeletonMotion(0) != NULL)
{
int postureID;
if (frameIndex >= displayer.GetSkeletonMotion(0)->GetNumFrames())
{
cout << " We hit the last frame! You might want to pick a different sequence. " << endl;
postureID = displayer.GetSkeletonMotion(0)->GetNumFrames() - 1;
}
else
postureID = frameIndex;
displayer.GetSkeleton(0)->setPosture(* (displayer.GetSkeletonMotion(0)->GetPosture(postureID)));
}
}
// Create mesh of rectangles in shape of triangle prism
// 6 rectangles per side: scaled to triangle prism size
// Rectangles separated by 7 bounding strips
// Each frame pulls up the mesh by 1/210 * prism_length distance
// TODO: slowly rotate mesh by axis (y-axis?)
void generateTrianglePrismMesh(VEC3 a_cap0, VEC3 b_cap0, VEC3 c_cap0, VEC3 a_cap1, VEC3 b_cap1, VEC3 c_cap1, int time_frame,
bool texture = false, bool motion = false)
{
uniform_int_distribution<> unif(0, int(frame_paths.size())-1000);
// TODO: Make bottom triangle cap a light???
shapes.push_back(make_shared<Triangle>(a_cap1, b_cap1, c_cap1, VEC3(1, 1, 1)));
// Ball light in the center of mesh
// VEC3 flux_color(1, 0.756, 0.518);
// VEC3 mesh_center = ((a_cap1 + b_cap1 + c_cap1)/3 - (a_cap0 + b_cap0 + c_cap0)/3)/2 + (a_cap0 + b_cap0 + c_cap0)/3;
// shared_ptr<sphereLight> halogen_ball = make_shared<sphereLight>(mesh_center, 0.3, flux_color);
// lights.push_back(halogen_ball);
// shapes.push_back(halogen_ball);
// Point light in center of mesh
// VEC3 mesh_center = ((a_cap1 + b_cap1 + c_cap1)/3 - (a_cap0 + b_cap0 + c_cap0)/3)/2 + (a_cap0 + b_cap0 + c_cap0)/3;
// lights.push_back(make_shared<pointLight>(mesh_center, VEC3(1,1,1)));
int n_rect = 4; // # of rectangles for each side of prism
float bounding_width = 0.1;
float rect_height = ((a_cap0 - b_cap0).norm() - bounding_width * n_rect)/n_rect;
float rect_width = float(5)/3 * rect_height;
VEC3 length_v = (c_cap1 - c_cap0).normalized();
VEC3 ac_v = (a_cap0 - c_cap0).normalized();
VEC3 ab_v = (a_cap0 - b_cap0).normalized();
VEC3 bc_v = (c_cap0 - b_cap0).normalized();
VEC3 left_a = b_cap0 + bounding_width * length_v;
VEC3 left_b = left_a + rect_width * length_v;
VEC3 left_c = left_b + rect_height * ab_v;
VEC3 left_d = left_a + rect_height * ab_v;
// Note: We will be viewing rectangles from INSIDE so right side will need to have clockwise vetices
VEC3 right_b = c_cap0 + bounding_width * length_v;
VEC3 right_a = right_b + rect_width * length_v;
VEC3 right_d = right_a + rect_height * ac_v;
VEC3 right_c = right_b + rect_height * ac_v;
VEC3 bottom_a = b_cap0 + bounding_width * length_v + bounding_width * bc_v;
VEC3 bottom_b = bottom_a + rect_width * length_v;
VEC3 bottom_c = bottom_b + rect_height * bc_v;
VEC3 bottom_d = bottom_a + rect_height * bc_v;
VEC3 adj_b0 = b_cap0 + bc_v * bounding_width/2;
int tot = 0;
int seed_counter = 0;
while ((bottom_b - adj_b0).norm() <= (c_cap1 - c_cap0).norm())
{
// TODO: Skip below loop if furthest points are BEHIND eye (y-threshold)
for (int i = 0; i < n_rect; i++)
{
// SKIP CONDITIONS: Rectangle behind eye OR rectangle too far away (<1 pixel size)
if (!(left_b[1] > eye[1] && left_c[1] > eye[1]) & !((left_b - eye).norm() > far && (left_c - eye).norm() > far))
{
gen.seed(seed_counter);
int frame_ind = unif(gen) + (time_frame - frame_prism);
// Read in image for frame
loadTexture(frame_paths[frame_ind]);
int tex_index = texture_frames.size()-1;
shared_ptr<Rectangle> tmp = make_shared<Rectangle>(left_a + (bounding_width + rect_height) * ab_v * i,
left_b + (bounding_width + rect_height) * ab_v * i, left_c + (bounding_width + rect_height) * ab_v * i,
left_d + (bounding_width + rect_height) * ab_v * i, VEC3(0,1,0), "", motion, tex_index, "raw");
tmp->motion = motion;
tmp->texture = texture;
shapes.push_back(make_shared<Rectangle>(*tmp));
tot++;
}
seed_counter++;
if (!(right_a[1] > eye[1] && right_d[1] > eye[1]) & !((right_a - eye).norm() > far && (right_d - eye).norm() > far))
{
gen.seed(seed_counter+1);
int frame_ind = unif(gen) + (time_frame - frame_prism);
// Read in image for frame
loadTexture(frame_paths[frame_ind]);
int tex_index = texture_frames.size()-1;
shared_ptr<Rectangle> tmp = make_shared<Rectangle>(right_a + (bounding_width + rect_height) * ac_v * i,
right_b + (bounding_width + rect_height) * ac_v * i, right_c + (bounding_width + rect_height) * ac_v * i,
right_d + (bounding_width + rect_height) * ac_v * i, VEC3(0,1,0),"", motion, tex_index, "raw");
tmp->motion = motion;
tmp->texture = texture;
shapes.push_back(make_shared<Rectangle>(*tmp));
tot++;
}
seed_counter++;
if (!(bottom_b[1] > eye[1] && bottom_c[1] > eye[1]) & !((bottom_b - eye).norm() > far && (bottom_c - eye).norm() > far))
{
gen.seed(seed_counter+2);
int frame_ind = unif(gen) + (time_frame - frame_prism);
// Read in image for frame
loadTexture(frame_paths[frame_ind]);
int tex_index = texture_frames.size()-1;
shared_ptr<Rectangle> tmp = make_shared<Rectangle>(bottom_a + (bounding_width + rect_height) * bc_v * i,
bottom_b + (bounding_width + rect_height) * bc_v * i, bottom_c + (bounding_width + rect_height) * bc_v * i,
bottom_d + (bounding_width + rect_height) * bc_v * i, VEC3(0,1,0),"", motion, tex_index, "raw");
tmp->motion = motion;
tmp->texture = texture;
shapes.push_back(make_shared<Rectangle>(*tmp));
tot++;
}
seed_counter++;
}
left_a += length_v * (rect_width + bounding_width);
left_b += length_v * (rect_width + bounding_width);
left_c += length_v * (rect_width + bounding_width);
left_d += length_v * (rect_width + bounding_width);
right_a += length_v * (rect_width + bounding_width);
right_b += length_v * (rect_width + bounding_width);
right_c += length_v * (rect_width + bounding_width);
right_d += length_v * (rect_width + bounding_width);
bottom_a += length_v * (rect_width + bounding_width);
bottom_b += length_v * (rect_width + bounding_width);
bottom_c += length_v * (rect_width + bounding_width);
bottom_d += length_v * (rect_width + bounding_width);
}
printf("Pushed back %d rectangles to make mesh\n", tot);
}
// FINAL MODEL BUILDS + TRANSFORMS
void finalBuildModels(float frame)
{
float min_y = 0.301897 + tot_move;
float xmin = -0.1;
float xmax = 1.7;
float zmin = -0.4;
float zmax = 1.9;
VEC3 A(xmin, min_y, zmax);
VEC3 B((xmin+xmax)/2, min_y, zmax);
VEC3 C((xmin+xmax)/2, min_y, zmin);
VEC3 D(xmin, min_y, zmin);
VEC3 E(xmax, min_y, zmax);
VEC3 F(xmax, min_y, zmin);
VEC3 globalA(-10, min_y, -10);
VEC3 globalB(-10, min_y, 20);
VEC3 globalC(30, min_y, 20);
VEC3 globalD(30, min_y, -10);
VEC3 globalE(-10, 15, -10);
VEC3 globalF(-10, 15, 20);
VEC3 globalG(30, 15, 20);
VEC3 globalH(30, 15, -10);
// LOAD MODELS ====================================
// Position: STRADDLING WINDOW
// Load model vertices
vector<VEC3> vertices;
vector<VEC2> texcoords;
vector<VEC3I> v_inds;
vector<VEC3I> t_inds;
vector<VEC3> normals;
vector<VEC3I> n_inds;
loadObj("./models/Column_LP_obj/Column_LP.obj", "./models/Column_LP_obj", vertices, v_inds, texcoords, t_inds, normals, n_inds);
printf("Pedestal ===========\n# of vertices: %d, # of texcoords: %d, # of triangles: %d\n",
int(vertices.size()), int(texcoords.size()), int(v_inds.size()));
// Pedestal transform: scale up by 5x, move to right wall
// Note: we can apply scaling matrix directly because bottom is at WORLD ORIGIN
MATRIX4 column_transf; column_transf << 3, 0, 0, -3,
0, 3, 0, min_y,
0, 0, 3, 5,
0, 0, 0, 1;
vector<VEC3> pverts1;
for (int i = 0; i < vertices.size(); i++)
{
VEC4 tmp; tmp << vertices[i], 1;
VEC4 tmp2 = column_transf * tmp;
pverts1.push_back(tmp2.head<3>());
}
// Keep track of shape bounds
float x_min = FLT_MAX;
float y_min = FLT_MAX;
float z_min = FLT_MAX;
float x_max = FLT_MIN;
float y_max = FLT_MIN;
float z_max = FLT_MIN;
// Texture data
loadTexture("./models/Column_LP_obj/Textures/Marble_Base_Color.jpg");
int width, height, n;
string rough_file = "./models/Column_LP_obj/Textures/Marble_Roughness.jpg";
unsigned char* frame_data = stbi_load(rough_file.c_str(), &width, &height, &n, 0);
for (int i = 0; i < v_inds.size(); i++)
{
VEC3I v_ind = v_inds[i];
// Increase shape size by 3
VEC3 tmp_center = (pverts1[v_ind[0]] + pverts1[v_ind[1]] + pverts1[v_ind[2]])/3;
shared_ptr<Triangle> tmp = make_shared<Triangle>(pverts1[v_ind[0]],
pverts1[v_ind[1]],
pverts1[v_ind[2]],
VEC3(0.75, 0.75, 0.75), "marble", false, "oren-nayar");
// Texture coordinates can sometimes be over 1: repeat texture in that case
VEC2 uvA = texcoords[t_inds[i][0]];
VEC2 uvB = texcoords[t_inds[i][1]];
VEC2 uvC = texcoords[t_inds[i][2]];
if (uvA[0] > 1) uvA[0] = uvA[0] - int(uvA[0]);
if (uvA[1] > 1) uvA[1] = uvA[1] - int(uvA[1]);
if (uvB[0] > 1) uvB[0] = uvB[0] - int(uvB[0]);
if (uvB[1] > 1) uvB[1] = uvB[1] - int(uvB[1]);
if (uvC[0] > 1) uvC[0] = uvC[0] - int(uvC[0]);
if (uvC[1] > 1) uvC[1] = uvC[1] - int(uvC[1]);
// Check that texcoords are within bounds
if (!(uvA[0] >= 0 && uvA[1] <= 1 &&
uvB[0] >= 0 && uvB[1] <= 1 &&
uvC[0] >= 0 && uvC[1] <= 1))
{
cout << "A: " << uvA << endl;
cout << "B: " << uvB << endl;
cout << "C: " << uvC << endl;
printf("Texcoords out of bounds\n");
throw;
}
// Test: maybe flip Y value of UV
uvA[1] = 1 - uvA[1];
uvB[1] = 1 - uvB[1];
uvC[1] = 1 - uvC[1];
// Set vertex UVs
tmp->uv_verts = true;
tmp->uvA = uvA;
tmp->uvB = uvB;
tmp->uvC = uvC;
tmp->tex_frame = texture_frames.size()-1;
tmp->texture = true;
// Set roughness based on roughness map
// TODO: FIGURE OUT HOW TO ASSIGN THIS -- IS IT INTERPOLATED ACROSS VERTICES?
// Just assign average roughness across texcoords for now
float r1 = frame_data[int(texcoords[t_inds[i][0]][0] * int(width-1) + texcoords[t_inds[i][0]][1] * int(height-1) * (width-1))];
float r2 = frame_data[int(texcoords[t_inds[i][1]][0] * int(width-1) + texcoords[t_inds[i][1]][1] * int(height-1) * (width-1))];
float r3 = frame_data[int(texcoords[t_inds[i][2]][0] * int(width-1) + texcoords[t_inds[i][2]][1] * int(height-1) * (width-1))];
tmp->reflect_params.roughness = (r1+r2+r3)/(3 * 255);
shapes.push_back(make_shared<Triangle>(*tmp));
x_min = min({x_min, float(vertices[v_ind[0]][0]), float(vertices[v_ind[1]][0]), float(vertices[v_ind[2]][0])});
y_min = min({y_min, float(vertices[v_ind[0]][1]), float(vertices[v_ind[1]][1]), float(vertices[v_ind[2]][1])});
z_min = min({z_min, float(vertices[v_ind[0]][2]), float(vertices[v_ind[1]][2]), float(vertices[v_ind[2]][2])});
x_max = max({x_max, float(vertices[v_ind[0]][0]), float(vertices[v_ind[1]][0]), float(vertices[v_ind[2]][0])});
y_max = max({y_max, float(vertices[v_ind[0]][1]), float(vertices[v_ind[1]][1]), float(vertices[v_ind[2]][1])});
z_max = max({z_max, float(vertices[v_ind[0]][2]), float(vertices[v_ind[1]][2]), float(vertices[v_ind[2]][2])});
}
// Right straddle column
column_transf << 3, 0, 0, 3,
0, 3, 0, min_y,
0, 0, 3, 5,
0, 0, 0, 1;
vector<VEC3> pverts2;
for (int i = 0; i < vertices.size(); i++)
{
VEC4 tmp; tmp << vertices[i], 1;
VEC4 tmp2 = column_transf * tmp;
pverts2.push_back(tmp2.head<3>());
}
for (int i = 0; i < v_inds.size(); i++)
{
VEC3I v_ind = v_inds[i];
// Increase shape size by 3
VEC3 tmp_center = (pverts2[v_ind[0]] + pverts2[v_ind[1]] + pverts2[v_ind[2]])/3;
shared_ptr<Triangle> tmp = make_shared<Triangle>(pverts2[v_ind[0]],
pverts2[v_ind[1]],
pverts2[v_ind[2]],
VEC3(0.75, 0.75, 0.75), "marble", false, "oren-nayar");
// Texture coordinates can sometimes be over 1: repeat texture in that case
VEC2 uvA = texcoords[t_inds[i][0]];
VEC2 uvB = texcoords[t_inds[i][1]];
VEC2 uvC = texcoords[t_inds[i][2]];
if (uvA[0] > 1) uvA[0] = uvA[0] - int(uvA[0]);
if (uvA[1] > 1) uvA[1] = uvA[1] - int(uvA[1]);
if (uvB[0] > 1) uvB[0] = uvB[0] - int(uvB[0]);
if (uvB[1] > 1) uvB[1] = uvB[1] - int(uvB[1]);
if (uvC[0] > 1) uvC[0] = uvC[0] - int(uvC[0]);
if (uvC[1] > 1) uvC[1] = uvC[1] - int(uvC[1]);
// Check that texcoords are within bounds
if (!(uvA[0] >= 0 && uvA[1] <= 1 &&
uvB[0] >= 0 && uvB[1] <= 1 &&
uvC[0] >= 0 && uvC[1] <= 1))
{
cout << "A: " << uvA << endl;
cout << "B: " << uvB << endl;
cout << "C: " << uvC << endl;
printf("Texcoords out of bounds\n");
throw;
}
// Test: maybe flip Y value of UV
uvA[1] = 1 - uvA[1];
uvB[1] = 1 - uvB[1];
uvC[1] = 1 - uvC[1];
// Set vertex UVs
tmp->uv_verts = true;
tmp->uvA = uvA;
tmp->uvB = uvB;
tmp->uvC = uvC;
tmp->tex_frame = texture_frames.size()-1;
tmp->texture = true;
// Set roughness based on roughness map
// TODO: FIGURE OUT HOW TO ASSIGN THIS -- IS IT INTERPOLATED ACROSS VERTICES?
// Just assign average roughness across texcoords for now
float r1 = frame_data[int(texcoords[t_inds[i][0]][0] * int(width-1) + texcoords[t_inds[i][0]][1] * int(height-1) * (width-1))];
float r2 = frame_data[int(texcoords[t_inds[i][1]][0] * int(width-1) + texcoords[t_inds[i][1]][1] * int(height-1) * (width-1))];
float r3 = frame_data[int(texcoords[t_inds[i][2]][0] * int(width-1) + texcoords[t_inds[i][2]][1] * int(height-1) * (width-1))];
tmp->reflect_params.roughness = (r1+r2+r3)/(3 * 255);
shapes.push_back(make_shared<Triangle>(*tmp));
}
// Left side of room (FOR BALL LIGHT)
// column_transf << 5, 0, 0, 0,
// 0, 5, 0, min_y,
// 0, 0, 5, -3,
// 0, 0, 0, 1;
// vector<VEC3> pverts3;
// for (int i = 0; i < vertices.size(); i++)
// {
// VEC4 tmp; tmp << vertices[i], 1;
// VEC4 tmp2 = column_transf * tmp;
// pverts3.push_back(tmp2.head<3>());
// }
// for (int i = 0; i < v_inds.size(); i++)
// {
// VEC3I v_ind = v_inds[i];
// // Increase shape size by 3
// VEC3 tmp_center = (pverts3[v_ind[0]] + pverts3[v_ind[1]] + pverts3[v_ind[2]])/3;
//
// shared_ptr<Triangle> tmp = make_shared<Triangle>(pverts3[v_ind[0]],
// pverts3[v_ind[1]],
// pverts3[v_ind[2]],
// VEC3(0.75, 0.75, 0.75), "marble", false, "oren-nayar");
//
// // Texture coordinates can sometimes be over 1: repeat texture in that case
// VEC2 uvA = texcoords[t_inds[i][0]];
// VEC2 uvB = texcoords[t_inds[i][1]];
// VEC2 uvC = texcoords[t_inds[i][2]];
// if (uvA[0] > 1) uvA[0] = uvA[0] - int(uvA[0]);
// if (uvA[1] > 1) uvA[1] = uvA[1] - int(uvA[1]);
// if (uvB[0] > 1) uvB[0] = uvB[0] - int(uvB[0]);
// if (uvB[1] > 1) uvB[1] = uvB[1] - int(uvB[1]);
// if (uvC[0] > 1) uvC[0] = uvC[0] - int(uvC[0]);
// if (uvC[1] > 1) uvC[1] = uvC[1] - int(uvC[1]);
//
// // Check that texcoords are within bounds
// if (!(uvA[0] >= 0 && uvA[1] <= 1 &&
// uvB[0] >= 0 && uvB[1] <= 1 &&
// uvC[0] >= 0 && uvC[1] <= 1))
// {
// cout << "A: " << uvA << endl;
// cout << "B: " << uvB << endl;
// cout << "C: " << uvC << endl;
//
// printf("Texcoords out of bounds\n");
// throw;
// }
//
// // Test: maybe flip Y value of UV
// uvA[1] = 1 - uvA[1];
// uvB[1] = 1 - uvB[1];
// uvC[1] = 1 - uvC[1];
//
// // Set vertex UVs
// tmp->uv_verts = true;
// tmp->uvA = uvA;
// tmp->uvB = uvB;
// tmp->uvC = uvC;
// tmp->tex_frame = texture_frames.size()-1;
// tmp->texture = true;
//
// // Set roughness based on roughness map
// // TODO: FIGURE OUT HOW TO ASSIGN THIS -- IS IT INTERPOLATED ACROSS VERTICES?
// // Just assign average roughness across texcoords for now
// float r1 = frame_data[int(texcoords[t_inds[i][0]][0] * int(width-1) + texcoords[t_inds[i][0]][1] * int(height-1) * (width-1))];
// float r2 = frame_data[int(texcoords[t_inds[i][1]][0] * int(width-1) + texcoords[t_inds[i][1]][1] * int(height-1) * (width-1))];
// float r3 = frame_data[int(texcoords[t_inds[i][2]][0] * int(width-1) + texcoords[t_inds[i][2]][1] * int(height-1) * (width-1))];
// tmp->reflect_params.roughness = (r1+r2+r3)/(3 * 255);
// shapes.push_back(make_shared<Triangle>(*tmp));
// }
stbi_image_free(frame_data);
// TODO: SPHERE LIGHT ON PEDESTAL IN CENTER
// shared_ptr<sphereLight> halogen_ball = make_shared<sphereLight>(VEC3(0, 6.5 + min_y + 1.5, -3), 1.5, halogen);
// shapes.push_back(halogen_ball);
// lights.push_back(halogen_ball);
vertices.clear();
v_inds.clear();
texcoords.clear();
t_inds.clear();
normals.clear();
n_inds.clear();
loadObj("./models/helios_statue/helios_20.obj", "./models/helios_statue", vertices, v_inds, texcoords, t_inds, normals, n_inds);
printf("Helios bust ============\n# of vertices: %d, # of texcoords: %d, # of triangles: %d, # of normals: %d\n",
int(vertices.size()), int(texcoords.size()), int(v_inds.size()), int(normals.size()));
// Rotate helios head 180 to face down negative z-axis + standard transform (3x scale)
MATRIX4 bust_transf; bust_transf << 1.8 * cos(M_PI), 0, 1.8 * sin(M_PI), -3,
0, 1.8, 0, 3.9 + min_y,
-1.8 * sin(M_PI), 0, 1.8 * cos(M_PI), 4,
0, 0, 0, 1;
vector<VEC3> hvert1;
for (int i = 0; i < vertices.size(); i++)
{
VEC4 tmp; tmp << vertices[i], 1;
VEC4 tmp2 = bust_transf * tmp;
hvert1.push_back(tmp2.head<3>());
}
// Load triangles: FIRST TWO ARE ROOT
// Keep track of shape bounds
for (int i = 2; i < v_inds.size(); i++)
{
VEC3I v_ind = v_inds[i];
// Increase shape size by 3
VEC3 tmp_center = (hvert1[v_ind[0]] + hvert1[v_ind[1]] + hvert1[v_ind[2]])/3;
shared_ptr<Triangle> tmp = make_shared<Triangle>(hvert1[v_ind[0]],
hvert1[v_ind[1]],
hvert1[v_ind[2]],
VEC3(0.75, 0.75, 0.75), "marble", false, "oren-nayar");
tmp->reflect_params.roughness = 0.5;
shapes.push_back(make_shared<Triangle>(*tmp));
}
// GLASS HELIOS: BOLD
// SAVE NORMALS
bust_transf << 1.8 * cos(M_PI), 0, 1.8 * sin(M_PI), 3,
0, 1.8, 0, 3.9 + min_y,
-1.8 * sin(M_PI), 0, 1.8 * cos(M_PI), 4,
0, 0, 0, 1;
vector<VEC3> hvert2;
for (int i = 0; i < vertices.size(); i++)
{
VEC4 tmp; tmp << vertices[i], 1;
VEC4 tmp2 = bust_transf * tmp;
hvert2.push_back(tmp2.head<3>());
}
// Load triangles: FIRST TWO ARE ROOT
for (int i = 2; i < v_inds.size(); i++)
{
VEC3I v_ind = v_inds[i];
// Increase shape size by 3
VEC3 tmp_center = (hvert2[v_ind[0]] + hvert2[v_ind[1]] + hvert2[v_ind[2]])/3;
shared_ptr<Triangle> tmp = make_shared<Triangle>(hvert2[v_ind[0]],
hvert2[v_ind[1]],
hvert2[v_ind[2]],
VEC3(0.75, 0.75, 0.75), "marble", false, "oren-nayar");
// tmp->mesh = true;
// tmp->mesh_normal = normals[n_inds[i][0]]; // We only need the normal of one vertex
tmp->reflect_params.roughness = 0.5;
shapes.push_back(make_shared<Triangle>(*tmp));
}
}
// FINAL BUILD
void buildFinal(float frame)
{
// FINAL TIMINGS: GENERATE 70*8 EXTRA STATIC FRAMES IN BEGINNING
// Beginning 960 (0-119) frames: first room
// - Eye starts at wall: facing
// Middle 960 (120 - 239) frames: falling through triangle prism
// - Frames 180-239: exponential motion blur
// Last 240 (240-299) frames: perlin cloud texture + stickman falling in distance
// Perlin cloud texturing always on
perlin_cloud = true;
setSkeletonsToSpecifiedFrame(int(frame));
// Explicitly free memory
shapes.clear();
lights.clear();
displayer.ComputeBonePositions(DisplaySkeleton::BONES_AND_LOCAL_FRAMES);
// Get bone names in skeleton
Skeleton* skel = displayer.GetSkeleton(0);
// retrieve all the bones of the skeleton
vector<MATRIX4>& rotations = displayer.rotations();
vector<MATRIX4>& scalings = displayer.scalings();
vector<VEC4>& translations = displayer.translations();
vector<float>& lengths = displayer.lengths();
// Skip the first bone,
// it's just the origin
int totalBones = rotations.size();
for (int x = 1; x < totalBones; x++)
{
MATRIX4& rotation = rotations[x];
MATRIX4& scaling = scalings[x];
VEC4& translation = translations[x];
// get the endpoints of the cylinder
VEC4 leftVertex(0,0,0,1);
VEC4 rightVertex(0,0,lengths[x],1);
leftVertex = rotation * scaling * leftVertex + translation;
rightVertex = rotation * scaling * rightVertex + translation;
// CLOUD FRAMES: drop the cylinder man (just apply negative y)
if (frame >= frame_cloud)
{
leftVertex -= VEC4(0, (frame-frame_cloud), 0, 0);
rightVertex -= VEC4(0, (frame-frame_cloud), 0, 0);
}
// Cylinders
shapes.push_back(make_shared<Cylinder>(leftVertex.head<3>(), rightVertex.head<3>(), 0.05, VEC3(1,0,0)));
}
// CAMERA SETTINGS -----------------------
// Choreography
// Eye: starts with looking out window at ???
// 480 frames (2 sec): Slow move backwards for 10 pixels (should see helios statues at this point)
// 480 frames (2 sec): try the existing rotation code below
// TODO: REDO EYE SETTINGS FOR PRE-FALL SCENE
VEC3 init_eye(-7, 9, -4);
VEC3 init_lookingAt(8, 11, 6);
VEC3 int_eye(-3, 8, 2); // Set after end of first move
VEC3 int_lookingAt(-5, 8, 0);
VEC3 init_up(0,1,0);
VEC3 final_eye(0.5, 8, 1.1);
VEC3 final_lookingAt(0.5, 0.5, 1); //Set after frame_prism (4 seconds)
VEC3 final_up(0,0,-1);
if (frame <= frame_prism)
{
eye = init_eye;
lookingAt = init_lookingAt;
float final_theta = M_PI * 9/8;
float theta = min(final_theta, frame * final_theta/frame_move1);
eye = rotate(eye, VEC3(0,1,0), theta);
// Adjust eye if outside bounds
while (eye[0] < -10 || eye[0] > 10 || eye[2] < -5 || eye[2] > 8)
{
eye *= 0.999;
}
lookingAt = rotate(lookingAt, VEC3(0,1,0), theta);
lookingAt -= VEC3(0, frame/frame_move1 * 10, 0);
}
if (frame <= frame_prism && frame >= frame_move1)
{
// Linear interpolation of eye and lookingat
eye = eye + (final_eye - eye) * min(1.0, (double) (frame-frame_move1)/(frame_move2 - frame_move1));
// Linear interpolate lookingat vector
lookingAt = lookingAt + (final_lookingAt - lookingAt) * min(1.0, (double) (frame-frame_move1)/(frame_move2 - frame_move1));
// Rotate "up" vector simultaneously (rotate around x axis to get z-axis)
float theta = -M_PI/2 * min(1.0, (double) (frame-frame_move1)/(frame_move2 - frame_move1));
up = rotate(up, VEC3(1,0,0), theta);
}
if (frame > frame_prism) // Set eye, up, and looking at to (almost) final positions (not including below acceleration)
{
eye = final_eye;
lookingAt = final_lookingAt;
up = VEC3(0,0,-1);
focal_length = 20;
}
// GLOBALS ======================
// MOVEMENT PARAMETERS
float tunnel_transition = 20 * 8;
float movement_multiplier = max(float(0), frame-frame_prism);
// Slight acceleration to terminal velocity (0.5/8)
// ALWAYS RESET: because of motion blur sampling
move_per_frame = 0.1/8;
move_per_frame *= (1 + min(float(2), 2 * (movement_multiplier)/tunnel_transition));
tot_move = movement_multiplier * move_per_frame;
// Accelerate for 2 seconds (motion blur ON) until clouds
// We're going to need to adjust the prism height accordingly
float accel_d = accel_t * pow(frame-frame_blur, 3);
float dist = 263;
if (frame > frame_blur && frame <= frame_cloud)
{
// Let's be more accurate about distances
tot_move += accel_d;
// Update velocity as well (for motion blur)
move_per_frame += 0.1/(2 * 64) * pow(frame-frame_blur, 2);
}
// Trapdoor: NEVER TOUCH THESE
float min_y = 0.301897 + tot_move;
float xmin = -0.1;
float xmax = 1.7;
float zmin = -0.4;
float zmax = 1.9;
VEC3 A(xmin, min_y, zmax);
VEC3 B((xmin+xmax)/2, min_y, zmax);
VEC3 C((xmin+xmax)/2, min_y, zmin);
VEC3 D(xmin, min_y, zmin);
VEC3 E(xmax, min_y, zmax);
VEC3 F(xmax, min_y, zmin);
VEC3 globalA(-10, min_y, -5);
VEC3 globalB(-10, min_y, 8);
VEC3 globalC(10, min_y, 8);
VEC3 globalD(10, min_y, -5);
VEC3 globalE(-10, 10 + min_y, -5);
VEC3 globalF(-10, 10 + min_y, 8);
VEC3 globalG(10, 10 + min_y, 8);
VEC3 globalH(10, 10 + min_y, -5);
VEC3 globalEH = (globalE-globalH).normalized();
VEC3 globalEF = (globalE-globalF).normalized();
VEC3 globalAD = (globalA-globalD).normalized();
VEC3 globalCD = (globalC - globalD).normalized();
VEC3 globalcenter = (globalA + globalB + globalC + globalD + globalE + globalF + globalG + globalH)/8;
// TUNNEL TRANSITION ===========================
// Min calls ensure that these won't kick in prematurely
// Movement: bound below by frame_prism (0) and above by tunnel_transition (160)
// 2/3 second to transition into falling through tunnel
// Accelerate eye towards body (lookingAt point also moves)
VEC3 tunnel_point = VEC3((xmin+xmax)/2, 5, (zmin+zmax)/2);
VEC3 eye_path = (tunnel_point - eye).normalized();
float accel = (tunnel_point-eye).norm()/pow(tunnel_transition, 2);
eye = accel * pow(min(tunnel_transition, movement_multiplier), 2) * eye_path + eye;
lookingAt = accel * pow(min(tunnel_transition, movement_multiplier), 2) * eye_path + lookingAt;
// Create rectangle mesh that forms triangle prism
// Starting position: long axis is y-axis and top is right on the surface of the floor
// Length: 133 (computed by taking velocy + acceleration into account)
// Expand mesh by a lot: MUST MAKE EQUILATERAL TRIANGLE
VEC3 b_cap0(xmin, min_y, zmax);
VEC3 c_cap0(xmax, min_y, zmax);
VEC3 a_cap0((xmin+xmax)/2, min_y, (xmin - xmax) * sqrt(3)/2 + zmax); // Set A such that triangle is equilateral
cap_center = (a_cap0 + b_cap0 + c_cap0)/3;
a_cap0 = (a_cap0 - cap_center) * 5 + cap_center;
b_cap0 = (b_cap0 - cap_center) * 5 + cap_center;
c_cap0 = (c_cap0 - cap_center) * 5 + cap_center;
// Light source during tunnel (from eye)
if (frame >= frame_prism + tunnel_transition)
{
lights.push_back(make_shared<pointLight>(eye, VEC3(1,1,1)));
}
if (frame >= frame_cloud)
{
// DONT NEED THIS ANYMORE
aperture = 0;
antialias_samples = 1;
// Only have cylinder man left to render
// EXPLODE after 80 frames
redsky = redsky + (sunorange - redsky) * (frame-frame_cloud)/(total-frame_cloud);
bluesky = bluesky + (pastelpink - bluesky) * (frame-frame_cloud)/(total-frame_cloud);
sun_outer = sun_outer + (violet - sun_outer) * (frame-frame_cloud)/(total-frame_cloud);
sun_inner = sun_inner + (indigo - sun_inner) * (frame-frame_cloud)/(total-frame_cloud);
sun_core = sun_core + (darkblue - sun_core) * (frame-frame_cloud)/(total-frame_cloud);
// if (frame - frame_cloud > 80)
// {
// int frame_diff = int((frame-frame_cloud)/8) % 4;
// if (frame_diff == 0)
// {
// // Vanilla
// redsky = sunorange;
// bluesky = pastelpink;
// sun_outer = violet;
// sun_inner = indigo;
// sun_core = darkblue;
// }
// if (frame_diff == 1)
// {
// redsky = teal;
// bluesky = sunorange;
// sun_core = darkblue;
// sun_inner = indigo;
// sun_outer = violet;
// }
// if (frame_diff == 2)
// {
// redsky = violet;
// bluesky = darkblue;
// sun_core = halogen;
// sun_inner = sunorange;
// sun_outer = pastelpink;
// }
// if (frame_diff == 3)
// {
// redsky = pastelpink;
// bluesky = maroonq;
// sun_core = teal;
// sun_inner = skyblue;
// sun_outer = darkblue;
// }
// }
return;
}
// Pull up mesh by given velocity
a_cap0 += VEC3(0, tot_move, 0);
b_cap0 += VEC3(0, tot_move, 0);
c_cap0 += VEC3(0, tot_move, 0);
// Rotation: slow (180 every 3 seconds = 90 * 8 frames)
float rot_theta = (movement_multiplier)/720.0 * M_PI;
a_cap0 = rotate(a_cap0 - cap_center, VEC3(0,1,0), rot_theta) + cap_center;
b_cap0 = rotate(b_cap0 - cap_center, VEC3(0,1,0), rot_theta) + cap_center;
c_cap0 = rotate(c_cap0 - cap_center, VEC3(0,1,0), rot_theta) + cap_center;
// Length of tunnel: 4 seconds == 120 frames
VEC3 a_cap1 = a_cap0 - VEC3(0, dist, 0);
VEC3 b_cap1 = b_cap0 - VEC3(0, dist, 0);
VEC3 c_cap1 = c_cap0 - VEC3(0, dist, 0);
// Print out scene settings
// printf("Frame: %f ==========\n", frame);
// printf("Movement multiplier: %f\n", movement_multiplier);
// cout << "Eye: " << eye << endl;
// cout << "lookingAt: " << lookingAt << endl;
// cout << "Min y: " << min_y << endl;
if (frame >= frame_prism)
{
generateTrianglePrismMesh(a_cap0, b_cap0, c_cap0, a_cap1, b_cap1, c_cap1, int(frame), true, true);
}
// Only render objects while they are still relevant
if ((min_y + tot_move <= eye[1] + 2) || frame < frame_prism + tunnel_transition)
{
// Rotate inwards about hinges AD, EF
// TODO: MAKE THIS RECTANGULAR PRISM
float angle = min(float(1.1), movement_multiplier/(tunnel_transition)) * M_PI/2;
VEC3 B_left = rotate(B-A, D-A, angle) + A;
VEC3 C_left = rotate(C-A, D-A, angle) + A;
VEC3 B_right = rotate(B-E, F-E, -angle) + E;
VEC3 C_right = rotate(C-E, F-E, -angle) + E;
loadTexture("./textures/sad_finder1_adj.jpg");
int tex_index = texture_frames.size()-1;
shared_ptr<Rectangle> tmp = make_shared<Rectangle>(A, B_left, C_left, D, VEC3(0,0,0), "steel", false, tex_index, "cook-torrance");
tmp->reflect_params.roughness = 0.7;
tmp->reflect_params.refr = VEC2(2.75, 3.79);
tmp->reflect_params.glossy = true;
tmp->texture = true;
shapes.push_back(make_shared<Rectangle>(*tmp));
loadTexture("./textures/sad_finder2_adj.jpg");
tex_index = texture_frames.size()-1;
shared_ptr<Rectangle> tmp2 = make_shared<Rectangle>(B_right,E,F,C_right, VEC3(0,0,0), "steel", false, tex_index, "cook-torrance");
tmp2->reflect_params.roughness = 0.7;
tmp2->reflect_params.refr = VEC2(2.75, 3.79);
tmp2->reflect_params.glossy = true;
tmp2->texture = true;
shapes.push_back(make_shared<Rectangle>(*tmp2));
// OTHER INITIAL SCENE OBJECTS: indoors box
// Floor: linoleum (texture applies to each SQUARE) + bounding lines
loadTexture("./textures/floor.jpeg");
tex_index = texture_frames.size()-1;
float s = 1;
VEC3 checker_rgb0(0.58, 0.82, 1);
VEC3 checker_rgb1(1, 0.416, 0.835);
shared_ptr<CheckerboardWithHole> floor = make_shared<CheckerboardWithHole>(globalA,
globalB,
globalC,
globalD,
checker_rgb0, checker_rgb1, s,
make_shared<Rectangle>(A, E, F, D, VEC3(0,0,0)));
floor->tex_frame = tex_index;
floor->borderwidth = 0.05;
floor->bordercolor = VEC3(0.55, 0.55, 0.55);
floor->texture = true;
floor->reflect_params.material = "linoleum";
floor->reflect_params.roughness = 0.6;
floor->reflect_params.refr = VEC2(1.543,0);
floor->reflect_params.glossy = true;
shapes.push_back(make_shared<CheckerboardWithHole>(*floor));
// Walls
shapes.push_back(make_shared<Rectangle>(globalA, globalD, globalH, globalE, VEC3(0,0.81,0.99)));
shapes.push_back(make_shared<Rectangle>(globalA, globalB, globalF, globalE, VEC3(0,0.81,0.99)));
shapes.push_back(make_shared<Rectangle>(globalD, globalC, globalG, globalH, VEC3(0,0.81,0.99)));
// Right wall: aggregated prisms with window
VEC3 height_vector = (globalF-globalB).normalized();
float height = (globalF-globalB).norm();
VEC3 length_vector = (globalB-globalC).normalized();
float length = (globalC-globalB).norm();
VEC3 width_vector = (globalB-globalA).normalized();
float width = 2;
VEC3 globalBp = globalB + width_vector * width;
VEC3 globalCp = globalC + width_vector * width;
VEC3 globalFp = globalF + width_vector * width;
VEC3 globalGp = globalG + width_vector * width;
// Window centered eye position: 8, 8 (x,y) -> spans (7-9)
float window_size = 2;
float mid_height = (height-window_size)/2;
float mid_length = (length-window_size)/2;
VEC3 a1 = globalC + height_vector * mid_height;
VEC3 b1 = globalB + height_vector * mid_height;
VEC3 c1 = globalBp + height_vector * mid_height;
VEC3 d1 = globalCp + height_vector * mid_height;
VEC3 am1 = a1 + length_vector * mid_length;
VEC3 bm1 = am1 + length_vector * window_size;
VEC3 cm1 = bm1 + width_vector * width;
VEC3 dm1 = am1 + width_vector * width;
VEC3 a2 = a1 + height_vector * window_size;
VEC3 b2 = b1 + height_vector * window_size;
VEC3 c2 = c1 + height_vector * window_size;
VEC3 d2 = d1 + height_vector * window_size;
VEC3 am2 = am1 + height_vector * window_size;
VEC3 bm2 = bm1 + height_vector * window_size;
VEC3 cm2 = cm1 + height_vector * window_size;
VEC3 dm2 = dm1 + height_vector * window_size;
// OVERLAP PRISMS SLIGHTLY TO PREVENT WEIRD CRACKS
shapes.push_back(make_shared<RectPrismV2>(globalC, globalB, globalBp, globalCp,
a1 + VEC3(0, 1e3, 0), b1 + VEC3(0, 1e3, 0), c1 + VEC3(0, 1e3, 0), d1+ VEC3(0, 1e3, 0),
VEC3(0,0.81,0.99)));
shapes.push_back(make_shared<RectPrismV2>(a1-VEC3(0, 1e3, 0), am1-VEC3(0, 1e3, 0), dm1-VEC3(0, 1e3, 0),
d1-VEC3(0, 1e3, 0), a2, am2, dm2, d2,
VEC3(0,0.81,0.99)));
shapes.push_back(make_shared<RectPrismV2>(bm1-VEC3(0, 1e3, 0), b1-VEC3(0, 1e3, 0), c1-VEC3(0, 1e3, 0),
cm1-VEC3(0, 1e3, 0), bm2, b2, c2, cm2,
VEC3(0,0.81,0.99)));
shapes.push_back(make_shared<RectPrismV2>(a2, b2, c2, d2, globalG, globalF, globalFp, globalGp, VEC3(0,0.81,0.99)));
// point light right outside window simulates real light?
VEC3 windowlight_c = (cm1 + dm1 + cm2 + dm2)/4 + VEC3(0,0,1);
lights.push_back(make_shared<pointLight>(windowlight_c, VEC3(1,1,1)));
// Ceiling + lights
// 4 square lights on ceiling
shapes.push_back(make_shared<Rectangle>(globalE, globalF, globalG, globalH, VEC3(0,0.81,0.99)));
int nlights = 4;
VEC3 lightcol(1, 1, 1);
float lighth = (globalD[0]-globalA[0])/(nlights + (nlights+2)/2); // 10 l + (10+2) * hbound (1/2 l)
float hbound = lighth/2;
float lightw = (globalB[2] - globalA[2])/(2 + 4.0/5); // 2 w + (2 + 2) * wbound (1/5 w)
float wbound = lightw/5;
// Each light: lighth x lighth with wbound distance from center
VEC3 ceiling_center = (globalE + globalF + globalG + globalH)/4 - VEC3(0,0.05, 0);
VEC3 a_tmp = ceiling_center + globalEF * (lighth + wbound) - globalAD * wbound;
shared_ptr<rectangleLight> left_f = make_shared<rectangleLight>(a_tmp, a_tmp - lighth * globalEF,
a_tmp - lighth * globalEH - lighth *globalEF, a_tmp - lighth*globalEH, lightcol);
lights.push_back(left_f);