forked from Ubpa/USTC_CG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenScene.cpp
524 lines (430 loc) · 22.5 KB
/
GenScene.cpp
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
#include "GenScene.h"
#include <UEngine/Engine.h>
#include <_deps/imgui/imgui.h>
#include <UScene/core.h>
#include <UScene/tool.h>
#include "Cmpt/PathTracerAgency.h"
#include <fstream>
#include <sstream>
#include <string>
using namespace Ubpa;
using namespace std;
namespace Ubpa::detail::dynamic_reflection {
void ReflRegist_Rotater();
void ReflRegist_ImGUIExample();
}
struct Rotater : Component {
static void OnRegist() {
detail::dynamic_reflection::ReflRegist_Rotater();
}
void OnUpdate(Cmpt::Rotation* rot) const {
rot->value = quatf{ vecf3{1.f}, to_radian(1.f) } *rot->value;
}
};
class ImGUIExample : Component {
public:
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
static void OnRegist() {
detail::dynamic_reflection::ReflRegist_ImGUIExample();
}
void OnUpdate() {
Engine::Instance().AddIMGUICommand([this]() {
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}
// 3. Show another simple window.
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
});
}
};
namespace Ubpa::detail::dynamic_reflection {
void ReflRegist_Rotater() {
Reflection<Rotater>::Instance() // name : struct ::Rotater
;
if constexpr (std::is_base_of_v<Component, Rotater>) {
Reflection<Rotater>::Instance().RegisterConstructor([](SObj* sobj) {
if constexpr (std::is_base_of_v<Component, Rotater>) {
if constexpr (Ubpa::detail::SObj_::IsNecessaryCmpt<Rotater>)
return sobj->Get<Rotater>();
else
return sobj->GetOrAttach<Rotater>();
};
});
}
}
}
namespace Ubpa::detail::dynamic_reflection {
void ReflRegist_ImGUIExample() {
Reflection<ImGUIExample>::Instance() // name : class ::ImGUIExample
.Register(&ImGUIExample::show_demo_window, "show_demo_window") // bool
.Register(&ImGUIExample::show_another_window, "show_another_window") // bool
;
if constexpr (std::is_base_of_v<Component, ImGUIExample>) {
Reflection<ImGUIExample>::Instance().RegisterConstructor([](SObj* sobj) {
if constexpr (std::is_base_of_v<Component, ImGUIExample>) {
if constexpr (Ubpa::detail::SObj_::IsNecessaryCmpt<ImGUIExample>)
return sobj->Get<ImGUIExample>();
else
return sobj->GetOrAttach<ImGUIExample>();
};
});
}
}
}
SceneGenerator::SceneGenerator() {
CmptRegistrar::Instance().Register<Rotater, ImGUIExample, Cmpt::PathTracerAgency>();
}
void SceneGenerator::PrintSerializedScene(Scene* scene) {
SerializerJSON serializer;
cout << serializer.Serialize(scene) << endl;
}
std::string SceneGenerator::getSerializedSceneStr(Scene* scene)
{
SerializerJSON serializer;
return serializer.Serialize(scene);
}
Scene* SceneGenerator::GenScene(const string& path) {
std::ifstream t(path);
if (!t.is_open())
return nullptr;
std::stringstream buffer;
buffer << t.rdbuf();
auto data = buffer.str();
DeserializerJSON deserializer;
return deserializer.DeserializeScene(data);
}
namespace Ubpa::detail::GenScene_ {
Scene* GenScene_0() {
auto scene = new Scene("scene");
auto [camera_obj, camera, agency] = scene->CreateSObj<Cmpt::Camera, Cmpt::PathTracerAgency>("camera_obj");
auto [cornellbox] = scene->CreateSObj<>("cornellbox");
auto [wall_left, geo_wall_left, mat_wall_left] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_left", cornellbox);
auto [wall_right, geo_wall_right, mat_wall_right] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_right", cornellbox);
auto [wall_up, geo_wall_up, mat_wall_up] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_up", cornellbox);
auto [wall_down, geo_wall_down, mat_wall_down] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_down", cornellbox);
auto [wall_back, geo_wall_back, mat_wall_back] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_back", cornellbox);
auto [rectlight_obj, geo_rectlight, rectlight] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Light>("rectlight");
// scene->CreateSObj<ImGUIExample>("imguiExample");
auto [env_obj, env_light] = scene->CreateSObj<Cmpt::Light>("env light");
auto env_texture = new Texture2D{ "../data/textures/newport_loft.hdr" };
env_texture->inv_v = true;
env_light->SetLight(new EnvLight(1.f, rgbf{ 1.f }, env_texture));
camera_obj->Get<Cmpt::Position>()->value = { 0,0,0 };
// wall
geo_wall_left->SetPrimitive(new Square);
geo_wall_right->SetPrimitive(new Square);
geo_wall_up->SetPrimitive(new Square);
geo_wall_down->SetPrimitive(new Square);
geo_wall_back->SetPrimitive(new Square);
mat_wall_left->SetMaterial(new stdBRDF{ rgbf{0.8,0.2,0.2} });
mat_wall_right->SetMaterial(new stdBRDF{ rgbf{0.2,0.2,0.8} });
mat_wall_up->SetMaterial(new stdBRDF{ rgbf{0.8f} });
mat_wall_down->SetMaterial(new stdBRDF{ rgbf{0.8f} });
mat_wall_back->SetMaterial(new stdBRDF{ rgbf{0.8f} });
wall_left->Get<Cmpt::Position>()->value = { -1,0,0 };
wall_left->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(-90.f) };
wall_right->Get<Cmpt::Position>()->value = { 1,0,0 };
wall_right->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(90.f) };
wall_up->Get<Cmpt::Position>()->value = { 0,1,0 };
wall_up->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(180.f) };
wall_down->Get<Cmpt::Position>()->value = { 0,-1,0 };
wall_back->Get<Cmpt::Position>()->value = { 0,0,-1 };
wall_back->Get<Cmpt::Rotation>()->value = { vecf3{1,0,0},to_radian(90.f) };
cornellbox->Get<Cmpt::Position>()->value = { 0,0,-6 };
cornellbox->Get<Cmpt::Scale>()->value = { 2,2,2 };
auto [metal_ball, metal_ball_geo, metal_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("metal_ball", cornellbox);
metal_ball_geo->SetPrimitive(new Sphere);
metal_ball->Get<Cmpt::Scale>()->value = 0.4f;
metal_ball->Get<Cmpt::Position>()->value = { -0.5f,-0.6f,-0.2f };
auto metal = new stdBRDF;
metal->albedo_factor = { 1.f, 0.8f, 0.2f };
metal->roughness_factor = 0.1f;
metal_ball_mat->SetMaterial(metal);
auto [plastic_ball, plastic_ball_geo, plastic_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("plastic_ball", cornellbox);
plastic_ball_geo->SetPrimitive(new Sphere);
plastic_ball->Get<Cmpt::Scale>()->value = 0.4f;
plastic_ball->Get<Cmpt::Position>()->value = { 0.5f,-0.6f,0.2f };
auto plastic = new stdBRDF;
plastic->albedo_factor = { 0.9f, 0.9f, 0.9f };
plastic->roughness_factor = 0.6f;
plastic->metalness_factor = 0.f;
plastic_ball_mat->SetMaterial(plastic);
rectlight->SetLight(new AreaLight{ 50.f, {1,1,1} });
geo_rectlight->SetPrimitive(new Square);
rectlight_obj->Get<Cmpt::Position>()->value = { 0,1.9f,-6 };
rectlight_obj->Get<Cmpt::Scale>()->value = { 0.5f,0.5f,0.5f };
rectlight_obj->Get<Cmpt::Rotation>()->value = quatf{ vecf3{1,0,0}, to_radian(180.f) };
auto [cube, geo_cube, mat_cube] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("cube", cornellbox);
auto cube_BRDF = new stdBRDF;
cube_BRDF->albedo_factor = { 0.1f, 0.63f, 0.84f };
cube_BRDF->roughness_factor = 0.5f;
mat_cube->SetMaterial(cube_BRDF);
geo_cube->SetPrimitive(new TriMesh("../data/models/cube.obj"));
cube->Get<Cmpt::Scale>()->value = { 0.15f,0.1f,0.15f };
cube->Get<Cmpt::Position>()->value = { -0.2f,-0.9f,0.65f };
SceneGenerator::Instance().PrintSerializedScene(scene);
return scene;
}
Scene* GenScene_1()
{
auto scene = new Scene("scene");
auto [camera_obj, camera, agency] = scene->CreateSObj<Cmpt::Camera, Cmpt::PathTracerAgency>("camera_obj");
auto [cornellbox] = scene->CreateSObj<>("cornellbox");
// auto [wall_left, geo_wall_left, mat_wall_left] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_left", cornellbox);
// auto [wall_right, geo_wall_right, mat_wall_right] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_right", cornellbox);
// auto [wall_up, geo_wall_up, mat_wall_up] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_up", cornellbox);
auto [wall_down, geo_wall_down, mat_wall_down] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_down", cornellbox);
// auto [wall_back, geo_wall_back, mat_wall_back] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_back", cornellbox);
// auto [rectlight_obj, geo_rectlight, rectlight] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Light>("rectlight");
// scene->CreateSObj<ImGUIExample>("imguiExample");
auto [env_obj, env_light] = scene->CreateSObj<Cmpt::Light>("env light");
auto env_texture = new Texture2D{ "../data/textures/newport_loft.hdr" };
env_texture->inv_v = true;
env_light->SetLight(new EnvLight(1.f, rgbf{ 1.f }, env_texture));
camera_obj->Get<Cmpt::Position>()->value = { 0,0,0 };
// wall
// geo_wall_left->SetPrimitive(new Square);
// geo_wall_right->SetPrimitive(new Square);
// geo_wall_up->SetPrimitive(new Square);
geo_wall_down->SetPrimitive(new Square);
// geo_wall_back->SetPrimitive(new Square);
// mat_wall_left->SetMaterial(new stdBRDF{ rgbf{0.8,0.2,0.2} });
// mat_wall_right->SetMaterial(new stdBRDF{ rgbf{0.2,0.2,0.8} });
// mat_wall_up->SetMaterial(new stdBRDF{ rgbf{0.8f} });
auto metal_floor = new stdBRDF;
metal_floor->albedo_factor = { 1.f, 0.9f, 0.1f };
metal_floor->roughness_factor = 0.4f;
mat_wall_down->SetMaterial(metal_floor);
// mat_wall_back->SetMaterial(new stdBRDF{ rgbf{0.8f} });
// wall_left->Get<Cmpt::Position>()->value = { -1,0,0 };
// wall_left->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(-90.f) };
// wall_right->Get<Cmpt::Position>()->value = { 1,0,0 };
// wall_right->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(90.f) };
// wall_up->Get<Cmpt::Position>()->value = { 0,1,0 };
// wall_up->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(180.f) };
wall_down->Get<Cmpt::Position>()->value = { 0,-1,0 };
// wall_back->Get<Cmpt::Position>()->value = { 0,0,-1 };
// wall_back->Get<Cmpt::Rotation>()->value = { vecf3{1,0,0},to_radian(90.f) };
cornellbox->Get<Cmpt::Position>()->value = { 0,0,-6 };
cornellbox->Get<Cmpt::Scale>()->value = { 2,2,2 };
auto [metal_ball, metal_ball_geo, metal_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("metal_ball", cornellbox);
metal_ball_geo->SetPrimitive(new Sphere);
metal_ball->Get<Cmpt::Scale>()->value = 0.7f;
metal_ball->Get<Cmpt::Position>()->value = { -0.5f,-0.6f,-0.2f };
auto metal = new stdBRDF;
metal->albedo_factor = { 1.f, 0.8f, 0.2f };
metal->roughness_factor = 0.1f;
metal_ball_mat->SetMaterial(metal);
// auto [plastic_ball, plastic_ball_geo, plastic_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("plastic_ball", cornellbox);
// plastic_ball_geo->SetPrimitive(new Sphere);
// plastic_ball->Get<Cmpt::Scale>()->value = 0.4f;
// plastic_ball->Get<Cmpt::Position>()->value = { 0.5f,-0.6f,0.2f };
// auto plastic = new stdBRDF;
// plastic->albedo_factor = { 0.9f, 0.9f, 0.9f };
// plastic->roughness_factor = 0.6f;
// plastic->metalness_factor = 0.f;
// plastic_ball_mat->SetMaterial(plastic);
// rectlight->SetLight(new AreaLight{ 50.f, {1,1,1} });
// geo_rectlight->SetPrimitive(new Square);
// rectlight_obj->Get<Cmpt::Position>()->value = { 0,1.9f,-6 };
// rectlight_obj->Get<Cmpt::Scale>()->value = { 0.5f,0.5f,0.5f };
// rectlight_obj->Get<Cmpt::Rotation>()->value = quatf{ vecf3{1,0,0}, to_radian(180.f) };
// auto [cube, geo_cube, mat_cube] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("cube", cornellbox);
// auto cube_BRDF = new stdBRDF;
// cube_BRDF->albedo_factor = { 0.1f, 0.63f, 0.84f };
// cube_BRDF->roughness_factor = 0.5f;
// mat_cube->SetMaterial(cube_BRDF);
// geo_cube->SetPrimitive(new TriMesh("../data/models/cube.obj"));
// cube->Get<Cmpt::Scale>()->value = { 0.15f,0.1f,0.15f };
// cube->Get<Cmpt::Position>()->value = { -0.2f,-0.9f,0.65f };
SceneGenerator::Instance().PrintSerializedScene(scene);
return scene;
}
Scene* GenScene_2()
{
auto scene = new Scene("scene");
auto [camera_obj, camera, agency] = scene->CreateSObj<Cmpt::Camera, Cmpt::PathTracerAgency>("camera_obj");
auto [cornellbox] = scene->CreateSObj<>("cornellbox");
// auto [wall_left, geo_wall_left, mat_wall_left] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_left", cornellbox);
// auto [wall_right, geo_wall_right, mat_wall_right] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_right", cornellbox);
// auto [wall_up, geo_wall_up, mat_wall_up] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_up", cornellbox);
auto [wall_down, geo_wall_down, mat_wall_down] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_down", cornellbox);
// auto [wall_back, geo_wall_back, mat_wall_back] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_back", cornellbox);
// auto [rectlight_obj, geo_rectlight, rectlight] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Light>("rectlight");
// scene->CreateSObj<ImGUIExample>("imguiExample");
auto [env_obj, env_light] = scene->CreateSObj<Cmpt::Light>("env light");
auto env_texture = new Texture2D{ "../data/textures/night.hdr" };
env_texture->inv_v = true;
env_light->SetLight(new EnvLight(1.f, rgbf{ 1.f }, env_texture));
camera_obj->Get<Cmpt::Position>()->value = { 0,0,0 };
// wall
// geo_wall_left->SetPrimitive(new Square);
// geo_wall_right->SetPrimitive(new Square);
// geo_wall_up->SetPrimitive(new Square);
geo_wall_down->SetPrimitive(new Square);
// geo_wall_back->SetPrimitive(new Square);
// mat_wall_left->SetMaterial(new stdBRDF{ rgbf{0.8,0.2,0.2} });
// mat_wall_right->SetMaterial(new stdBRDF{ rgbf{0.2,0.2,0.8} });
// mat_wall_up->SetMaterial(new stdBRDF{ rgbf{0.8f} });
auto metal_floor = new stdBRDF;
metal_floor->albedo_factor = { 1.f, 0.9f, 0.1f };
metal_floor->roughness_factor = 0.4f;
mat_wall_down->SetMaterial(metal_floor);
// mat_wall_back->SetMaterial(new stdBRDF{ rgbf{0.8f} });
// wall_left->Get<Cmpt::Position>()->value = { -1,0,0 };
// wall_left->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(-90.f) };
// wall_right->Get<Cmpt::Position>()->value = { 1,0,0 };
// wall_right->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(90.f) };
// wall_up->Get<Cmpt::Position>()->value = { 0,1,0 };
// wall_up->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(180.f) };
wall_down->Get<Cmpt::Position>()->value = { 0,-1,0 };
// wall_back->Get<Cmpt::Position>()->value = { 0,0,-1 };
// wall_back->Get<Cmpt::Rotation>()->value = { vecf3{1,0,0},to_radian(90.f) };
cornellbox->Get<Cmpt::Position>()->value = { 0,0,-6 };
cornellbox->Get<Cmpt::Scale>()->value = { 2,2,2 };
// auto [metal_ball, metal_ball_geo, metal_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("metal_ball", cornellbox);
// metal_ball_geo->SetPrimitive(new Sphere);
// metal_ball->Get<Cmpt::Scale>()->value = 0.7f;
// metal_ball->Get<Cmpt::Position>()->value = { -0.5f,-0.6f,-0.2f };
auto metal = new stdBRDF;
metal->albedo_factor = { 1.f, 0.8f, 0.2f };
metal->roughness_factor = 0.1f;
// metal_ball_mat->SetMaterial(metal);
// auto [plastic_ball, plastic_ball_geo, plastic_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("plastic_ball", cornellbox);
// plastic_ball_geo->SetPrimitive(new Sphere);
// plastic_ball->Get<Cmpt::Scale>()->value = 0.4f;
// plastic_ball->Get<Cmpt::Position>()->value = { 0.5f,-0.6f,0.2f };
// auto plastic = new stdBRDF;
// plastic->albedo_factor = { 0.9f, 0.9f, 0.9f };
// plastic->roughness_factor = 0.6f;
// plastic->metalness_factor = 0.f;
// plastic_ball_mat->SetMaterial(plastic);
// rectlight->SetLight(new AreaLight{ 50.f, {1,1,1} });
// geo_rectlight->SetPrimitive(new Square);
// rectlight_obj->Get<Cmpt::Position>()->value = { 0,1.9f,-6 };
// rectlight_obj->Get<Cmpt::Scale>()->value = { 0.5f,0.5f,0.5f };
// rectlight_obj->Get<Cmpt::Rotation>()->value = quatf{ vecf3{1,0,0}, to_radian(180.f) };
// auto [cube, geo_cube, mat_cube] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("cube", cornellbox);
// auto cube_BRDF = new stdBRDF;
// cube_BRDF->albedo_factor = { 0.1f, 0.63f, 0.84f };
// cube_BRDF->roughness_factor = 0.5f;
// mat_cube->SetMaterial(cube_BRDF);
auto [teapot, geo_teapot, mat_teapot] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("teapot", cornellbox);
geo_teapot->SetPrimitive(new TriMesh("../data/models/dragon.obj"));
mat_teapot->SetMaterial(metal);
teapot->Get<Cmpt::Position>()->value = { 0.5f,-0.6f,0.6f };
// geo_cube->SetPrimitive(new TriMesh("../data/models/cube.obj"));
// cube->Get<Cmpt::Scale>()->value = { 0.15f,0.1f,0.15f };
// cube->Get<Cmpt::Position>()->value = { -0.2f,-0.9f,0.65f };
SceneGenerator::Instance().PrintSerializedScene(scene);
return scene;
}
Scene* GenScene_3() {
auto scene = new Scene("scene");
auto [camera_obj, camera, agency] = scene->CreateSObj<Cmpt::Camera, Cmpt::PathTracerAgency>("camera_obj");
auto [cornellbox] = scene->CreateSObj<>("cornellbox");
auto [wall_left, geo_wall_left, mat_wall_left] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_left", cornellbox);
auto [wall_right, geo_wall_right, mat_wall_right] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_right", cornellbox);
auto [wall_up, geo_wall_up, mat_wall_up] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_up", cornellbox);
auto [wall_down, geo_wall_down, mat_wall_down] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_down", cornellbox);
auto [wall_back, geo_wall_back, mat_wall_back] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("wall_back", cornellbox);
auto [rectlight_obj, geo_rectlight, rectlight] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Light>("rectlight");
// scene->CreateSObj<ImGUIExample>("imguiExample");
auto [env_obj, env_light] = scene->CreateSObj<Cmpt::Light>("env light");
auto env_texture = new Texture2D{ "../data/textures/night.hdr" };
env_texture->inv_v = true;
env_light->SetLight(new EnvLight(1.f, rgbf{ 1.f }, env_texture));
camera_obj->Get<Cmpt::Position>()->value = { 0,0,0 };
// wall
geo_wall_left->SetPrimitive(new Square);
geo_wall_right->SetPrimitive(new Square);
geo_wall_up->SetPrimitive(new Square);
geo_wall_down->SetPrimitive(new Square);
geo_wall_back->SetPrimitive(new Square);
mat_wall_left->SetMaterial(new stdBRDF{ rgbf{0.8,0.2,0.2} });
mat_wall_right->SetMaterial(new stdBRDF{ rgbf{0.2,0.2,0.8} });
mat_wall_up->SetMaterial(new stdBRDF{ rgbf{0.8f} });
mat_wall_down->SetMaterial(new stdBRDF{ rgbf{0.8f} });
mat_wall_back->SetMaterial(new stdBRDF{ rgbf{0.8f} });
wall_left->Get<Cmpt::Position>()->value = { -1,0,0 };
wall_left->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(-90.f) };
wall_right->Get<Cmpt::Position>()->value = { 1,0,0 };
wall_right->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(90.f) };
wall_up->Get<Cmpt::Position>()->value = { 0,1,0 };
wall_up->Get<Cmpt::Rotation>()->value = { vecf3{0,0,1},to_radian(180.f) };
wall_down->Get<Cmpt::Position>()->value = { 0,-1,0 };
wall_back->Get<Cmpt::Position>()->value = { 0,0,-1 };
wall_back->Get<Cmpt::Rotation>()->value = { vecf3{1,0,0},to_radian(90.f) };
cornellbox->Get<Cmpt::Position>()->value = { 0,0,-6 };
cornellbox->Get<Cmpt::Scale>()->value = { 2,2,2 };
auto [metal_ball, metal_ball_geo, metal_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("metal_ball", cornellbox);
metal_ball_geo->SetPrimitive(new Sphere);
metal_ball->Get<Cmpt::Scale>()->value = 0.4f;
metal_ball->Get<Cmpt::Position>()->value = { -0.5f,-0.6f,-0.2f };
auto metal = new stdBRDF;
metal->albedo_factor = { 1.f, 0.8f, 0.2f };
metal->roughness_factor = 0.1f;
metal_ball_mat->SetMaterial(metal);
auto [plastic_ball, plastic_ball_geo, plastic_ball_mat] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("plastic_ball", cornellbox);
plastic_ball_geo->SetPrimitive(new Sphere);
plastic_ball->Get<Cmpt::Scale>()->value = 0.4f;
plastic_ball->Get<Cmpt::Position>()->value = { 0.5f,-0.6f,0.2f };
auto plastic = new stdBRDF;
plastic->albedo_factor = { 0.9f, 0.9f, 0.9f };
plastic->roughness_factor = 0.6f;
plastic->metalness_factor = 0.f;
plastic_ball_mat->SetMaterial(plastic);
rectlight->SetLight(new AreaLight{ 50.f, {1,1,1} });
geo_rectlight->SetPrimitive(new Square);
rectlight_obj->Get<Cmpt::Position>()->value = { 0,1.9f,-6 };
rectlight_obj->Get<Cmpt::Scale>()->value = { 0.5f,0.5f,0.5f };
rectlight_obj->Get<Cmpt::Rotation>()->value = quatf{ vecf3{1,0,0}, to_radian(180.f) };
auto [cube, geo_cube, mat_cube] = scene->CreateSObj<Cmpt::Geometry, Cmpt::Material>("cube", cornellbox);
auto cube_BRDF = new stdBRDF;
cube_BRDF->albedo_factor = { 0.1f, 0.63f, 0.84f };
cube_BRDF->roughness_factor = 0.5f;
mat_cube->SetMaterial(cube_BRDF);
geo_cube->SetPrimitive(new TriMesh("../data/models/cube.obj"));
cube->Get<Cmpt::Scale>()->value = { 0.15f,0.1f,0.15f };
cube->Get<Cmpt::Position>()->value = { -0.2f,-0.9f,0.65f };
SceneGenerator::Instance().PrintSerializedScene(scene);
return scene;
}
}
Scene* SceneGenerator::GenScene(size_t n) {
// assert(n < 1);
using Func = Scene * ();
Func* funcs[] = {
&detail::GenScene_::GenScene_0,
&detail::GenScene_::GenScene_1,
&detail::GenScene_::GenScene_2,
&detail::GenScene_::GenScene_3
};
return funcs[n]();
}