-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.cpp
More file actions
657 lines (554 loc) · 19.1 KB
/
GUI.cpp
File metadata and controls
657 lines (554 loc) · 19.1 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
#include "template.h"
#include "renderer.h"
#include "GUI.h"
#include "ImGuizmo.h"
#include "Noise.h"
#include "GUIHelpers.h"
#include "GameGUI.h"
static mat4 gridmat;
static bool isGridmatSet = false;
void GUI::Init()
{
GameGUI::m_renderer = &m_renderer;
}
void GUI::Render()
{
ImGui::PushItemWidth(140);
m_renderer.camera.GetViewMatrix(GUIHelpers::m_view);
m_renderer.camera.GetProjectionMatrix(GUIHelpers::m_proj);
if (!m_renderer.m_isRendering)
{
if (m_LODSystemDirty)
{
m_LODSystemDirty = false;
m_renderer.scene.BuildChunks();
}
if (m_skyDirty)
{
m_skyDirty = false;
m_renderer.sky.LoadAuto(m_settings.m_skydome, Skydome::paths[m_settings.m_skydome.m_fileIndex]);
}
}
if (IsKeyDown(GLFW_KEY_TAB) && CanReadInput())
{
m_open = !m_open;
m_inputTimer.reset();
}
if (!m_open)
{
if (DisplaySettingsShortcuts())
{
m_renderer.ResetAccumulator();
}
return;
}
if (IsKeyDown(GLFW_KEY_ENTER) && CanReadInput())
{
m_debugGUI = !m_debugGUI;
m_inputTimer.reset();
}
if (m_debugGUI)
{
DebugGUI();
}
Info();
GameGUI::Render();
}
void GUI::DebugGUI()
{
if (!isGridmatSet)
{
gridmat = mat4::Scale(1.f) * gridmat;
gridmat = mat4::Translate(0.5f) * gridmat;
isGridmatSet = true;
}
if (m_settings.m_showGizmos && m_settings.m_showGrid)
{
mat4 identity = mat4::Identity(); // Ensure this is a flat 0,0,0 plane
ImGuizmo::DrawGrid(GUIHelpers::m_view, GUIHelpers::m_proj, identity.cell, 100.f, 0x55);
mat4 cameraViewMat4; memcpy(cameraViewMat4.cell, GUIHelpers::m_view, 16 * sizeof(float));
mat4 cameraProjMat4; memcpy(cameraProjMat4.cell, GUIHelpers::m_proj, 16 * sizeof(float));
}
ImGui::Text("%5.2fms (%.1ffps) - %.1fMrays/s\n", m_renderer.m_profileInfo.ms, m_renderer.m_profileInfo.fps, m_renderer.m_profileInfo.rps / 1000.f);
ImGui::Text("cam: %.3f %.3f %.3f", m_renderer.camera.camPos.x, m_renderer.camera.camPos.y, m_renderer.camera.camPos.z);
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None;
bool dirty = false;
dirty |= DisplaySettingsShortcuts();
if (ImGui::BeginTabBar("Toptapbar", tab_bar_flags))
{
if (ImGui::BeginTabItem("General"))
{
dirty |= UIGeneral();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Picker"))
{
dirty |= UIPicker();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Lights"))
{
dirty |= UILights();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Materials"))
{
dirty |= UIMaterials();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
if (dirty)
{
m_renderer.ResetAccumulator();
dirty = false;
}
ImGui::PopItemWidth();
if (m_settings.m_showGizmos)
{
GUIHelpers::DrawWireCube(float3(0.5f), float3(1.f));
}
}
void GUI::Info()
{
const ImGuiIO& io = ImGui::GetIO();
constexpr int widgetWidth = 140, widgetHeight = 30;
constexpr int margin = 4;
const int x = static_cast<int>(io.DisplaySize.x) - widgetWidth - margin, y = margin;
GUIHelpers::NewPlainWindow(UNIQ_IMGUI_LABEL("Info", 0), int2(x, y), int2(widgetWidth, widgetHeight), [&]()
{
ImGui::Text("%5.2fms (%.1ffps)\n", m_renderer.m_profileInfo.ms, m_renderer.m_profileInfo.fps);
}, 0.6f);
}
bool GUI::UIGeneral()
{
bool dirty = false;
if (ImGui::Button("Reset camera"))
{
m_renderer.camera.Reset();
dirty = true;
}
dirty |= ImGui::Button("Flush accumulator");
bool ef_mlDenoising = false;
bool ef_mlDataset = false;
const ImVec4 colorExperimentalFeature = ImVec4(1.0f, 0.9f, 0.4f, 1.0f);
#ifdef ML_DENOISING
ef_mlDenoising = true;
#endif
#ifdef ML_DATASET
ef_mlDataset = true;
#endif
const bool anyExperimentalFeatures = ef_mlDenoising || ef_mlDataset;
if (anyExperimentalFeatures)
{
ImGui::PushStyleColor(ImGuiCol_Text, colorExperimentalFeature);
ImGui::Text("Experimental Features:");
if (ef_mlDataset)
{
ImGui::Text("ML Dataset");
}
if (ef_mlDenoising)
{
ImGui::Text("ML Denoising");
}
ImGui::PopStyleColor();
}
else
{
ImGui::Text("No Experimental Features");
}
dirty |= ImGui::Checkbox("Show gizmos", &m_settings.m_showGizmos);
if (m_settings.m_showGizmos)
{
dirty |= ImGui::Checkbox("Show grid", &m_settings.m_showGrid);
}
GUIHelpers::Drag("Max frames", m_settings.m_maxFrames, &dirty);
const bool isInGame = ImGui::Checkbox("Game mode", &m_settings.m_isInGame);
dirty |= isInGame;
ImGui::Separator();
if (ImGui::CollapsingHeader("Camera"))
{
dirty |= ImGui::Checkbox("Cinemachine", &m_settings.m_autoCameraRotate);
static bool showCinemachineControls = false;
dirty |= ImGui::Checkbox("Show control points", &showCinemachineControls);
Camera& cam = m_renderer.camera;
if (ImGui::Button("Add control point"))
{
cam.m_cinemachine.m_path.AppendControlPoint(cam.camPos);
}
for (int p = 0; p < cam.m_cinemachine.m_path.GetControlPointsNum(); ++p)
{
float3 control = cam.m_cinemachine.m_path.GetControlPoint(p);
ImGui::DragFloat3(("Control point " + std::to_string(p)).c_str(), &control.x, 0.01f);
cam.m_cinemachine.m_path.SetControlPoint(p, control);
}
if (showCinemachineControls)
{
for (int p = 0; p < cam.m_cinemachine.m_path.GetControlPointsNum(); ++p)
{
const float3 control = cam.m_cinemachine.m_path.GetControlPoint(p);
GUIHelpers::DrawWireCube(control, float3(0.05f), float3(1.f, 0.5f, 0.f));
if (p > 0 && p < cam.m_cinemachine.m_path.GetControlPointsNum() - 1)
{
const float3 p1 = cam.m_cinemachine.m_path.GetControlPoint(p);
const float3 p2 = cam.m_cinemachine.m_path.GetControlPoint(p + 1);
GUIHelpers::DrawLine(p1, p2, float3(0.5f, 0.5f, 1.f), 1.f, 1.f);
}
}
}
ImGui::DragFloat3("Focus point", &cam.m_cinemachine.m_focusPoint.x, 0.01f);
GUIHelpers::DrawWireCube(cam.m_cinemachine.m_focusPoint, float3(0.035f), float3(1.f));
dirty |= ImGui::DragFloat("Cinemachine speed", &cam.m_cinemachine.m_speed);
GUIHelpers::Drag("Movement speed", m_renderer.camera.m_movementSpeed, &dirty);
GUIHelpers::Drag("Rotation speed", m_renderer.camera.m_rotationSpeed, &dirty);
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Light sampling"))
{
Settings::LightSampler& lightSampler = m_settings.m_lightSampler;
dirty |= ImGui::Checkbox("Enable stochastic light processing", &lightSampler.m_useStochasticLightSampling);
if (lightSampler.m_useStochasticLightSampling)
{
GUIHelpers::Drag("% of lights per sample", lightSampler.m_stochasticSamplingDensity, &dirty);
}
dirty |= ImGui::Checkbox("Enable soft lights", &lightSampler.m_enableSoftLights);
GUIHelpers::Drag("Accumulation history weight", lightSampler.m_historyLightAccumulationWeight, &dirty);
GUIHelpers::Drag("Light impact threshold", lightSampler.m_lightImpactThreshold, &dirty);
GUIHelpers::Drag("Max total attempts", lightSampler.m_maxTotalAttempts, &dirty);
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Microfacets & material behaviour"))
{
GUIHelpers::Drag("Microfacet stochastic strength", m_settings.m_microfacetStochasticStrength, &dirty);
GUIHelpers::Drag("Detail distance falloff", m_settings.m_detailDistanceFalloff, &dirty);
GUIHelpers::Drag("Witted-style recursion depth", m_settings.m_recursionDepth, &dirty);
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Denoising"))
{
bool denoiserDirty = false;
{
if (ef_mlDenoising)
{
static const char* items[]{ "None", "CPU_Linear", "CPU_SIMD", "SVGF", "GPU_ONNX" };
constexpr int ONNX_INDEX = 4;
int selection = static_cast<int>(m_settings.m_denoiser.m_worker);
if (ImGui::BeginCombo("Worker", items[selection]))
{
for (int i = 0; i < IM_ARRAYSIZE(items); ++i)
{
bool isSelected = (selection == i);
if (i == ONNX_INDEX)
ImGui::PushStyleColor(ImGuiCol_Text, colorExperimentalFeature);
if (ImGui::Selectable(items[i], isSelected))
{
selection = i;
Settings::Denoiser::Worker value =
static_cast<Settings::Denoiser::Worker>(selection);
m_settings.m_denoiser.m_worker = value;
dirty = true;
denoiserDirty = true;
}
if (isSelected)
ImGui::SetItemDefaultFocus();
if (i == ONNX_INDEX)
ImGui::PopStyleColor();
}
ImGui::EndCombo();
}
}
else
{
static const char* items[]{ "None", "CPU_Linear", "CPU_SIMD", "SVGF" };
int selection = static_cast<int>(m_settings.m_denoiser.m_worker);
if (ImGui::Combo("Worker", &selection, items, IM_ARRAYSIZE(items)))
{
Settings::Denoiser::Worker value = static_cast<Settings::Denoiser::Worker>(selection);
m_settings.m_denoiser.m_worker = value;
dirty = true;
denoiserDirty = true;
}
}
}
const bool denoiserEnabled = m_settings.m_denoiser.m_worker != Settings::Denoiser::Worker::None;
if (denoiserEnabled)
{
ImGui::Text("Lens");
ImGui::Separator();
dirty |= ImGui::Checkbox("Use depth of field", &m_settings.m_lens.m_useDepthOfField);
GUIHelpers::Drag("Depth of field", m_settings.m_lens.m_depthOfField, &dirty);
GUIHelpers::Drag("Focus distance", m_settings.m_lens.m_focusDistance, &dirty);
ImGui::Text("Kernel");
ImGui::Separator();
GUIHelpers::Drag("Denoising kernel margin", m_settings.m_denoiser.m_kernelMargin, &denoiserDirty);
GUIHelpers::Drag("Denoising kernel radius", m_settings.m_denoiser.m_kernelRadius, &denoiserDirty);
GUIHelpers::Drag("Denoising strength", m_settings.m_denoiser.m_strength, &denoiserDirty);
GUIHelpers::Drag("Soft blending dist threshold", m_settings.m_denoiser.m_softBlendDistThreshold, &denoiserDirty);
GUIHelpers::Drag("Soft blending factor", m_settings.m_denoiser.m_softBlendFactor, &denoiserDirty);
if (denoiserDirty)
{
m_renderer.PrecomputeKernel(m_settings.m_denoiser.m_kernelRadius, m_settings.m_denoiser.m_kernelMargin);
}
dirty |= denoiserDirty;
GUIHelpers::Drag("Dynamic threshold", m_settings.m_denoiser.m_dynamicsThreshold, &dirty);
}
dirty |= ImGui::Checkbox("Enable TAA", &m_settings.m_enableTAA);
if (m_settings.m_enableTAA)
{
GUIHelpers::Drag("TAA strength", m_settings.m_taaStrength, &dirty);
}
static const char* items[]{ "White noise","Blue noise" };
static int selection = static_cast<int>(m_settings.m_denoiser.m_type);
if (ImGui::Combo("Denoise", &selection, items, IM_ARRAYSIZE(items)))
{
dirty = true;
Settings::Denoiser::Noise value = static_cast<Settings::Denoiser::Noise>(selection);
m_settings.m_denoiser.m_type = value;
}
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Extra features"))
{
dirty |= ImGui::Checkbox("Enable physics", &m_settings.m_enablePhysics);
dirty |= ImGui::Checkbox("Use smooth normals", &m_settings.m_useSmoothNormals);
}
{
std::vector<const char*> items;
for (int i = 0; i < m_renderer.scene.GetLevelsCount(); i++)
{
items.push_back(m_renderer.scene.GetLevelByIndexSafe(i)->m_name.c_str());
}
int levelindex = static_cast<int>(m_renderer.scene.GetCurrentLevelIndex());
if (ImGui::Combo("Level", &levelindex, items.data(), static_cast<int>(items.size())))
{
m_renderer.scene.TryLoadLevelSafe(levelindex);
dirty = true;
}
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Sky"))
{
std::vector<const char*> items;
for (const auto& name : Skydome::paths)
{
items.push_back(name.c_str());
}
int& currentIndex = m_settings.m_skydome.m_fileIndex;
if (ImGui::Combo("Sky Texture", ¤tIndex, items.data(), (int)items.size()))
{
m_skyDirty = true;
}
m_skyDirty |= GUIHelpers::Drag("Sky Intensity", m_settings.m_skydome.m_lightIntensity, &m_skyDirty);
m_skyDirty |= GUIHelpers::Drag("Sky Gamma", m_settings.m_skydome.m_gammaCorrection, &m_skyDirty);
dirty |= ImGui::Checkbox("Occlude the sky", &m_settings.m_enableSkyOcclusion);
dirty |= m_skyDirty;
ImGui::Spacing();
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Feature buffer display"))
{
dirty |= UIDisplay();
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Octree"))
{
if (GUIHelpers::Slider("Set LOD depth", m_settings.m_LODDepth, nullptr))
{
m_LODSystemDirty = true;
}
if (m_settings.m_showGizmos)
{
ImGui::Separator();
ImGui::Text("Gizmos");
static int loddepth = 0;
ImGui::SliderInt("Show", &loddepth, 0, m_settings.m_LODDepth - 1);
static const char* items[]{ "Mask","Spheres bool", "Spheres density" };
static int selection = 0;
static GIZMOS_LOD option = GIZMOS_LOD::SphereBool;
if (ImGui::Combo("Gizmos mode", &selection, items, IM_ARRAYSIZE(items)))
{
option = static_cast<GIZMOS_LOD>(selection);
}
DebugDrawLOD(m_renderer.scene, loddepth, option);
const Level* const level = m_renderer.scene.GetCurrentLevelR();
for (int i = 0; i < level->m_spheres.objects.size(); i++)
{
const Sphere& sphere = level->m_spheres.objects[i];
GUIHelpers::DrawWireSphere(sphere.m_center, sphere.m_radius);
}
}
}
if (ef_mlDataset)
{
ImGui::Separator();
ImGui::PushStyleColor(ImGuiCol_Text, colorExperimentalFeature);
if (ImGui::CollapsingHeader("Dataset for Deep Learning"))
{
dirty |= ImGui::Checkbox("Auto export", &m_settings.m_DL_Dataset.m_exportDataset);
GUIHelpers::Slider("Convergence SPP", m_settings.m_DL_Dataset.m_sppConvergence, &dirty);
ImGui::PopStyleColor();
}
}
return dirty;
}
bool GUI::UIPicker()
{
// ray query on mouse
const int2 xy = m_renderer.mousePos;
const float2 uv = float2(static_cast<float>(xy.x), static_cast<float>(xy.y)) * SCR_SIZE_RECIP;
Ray primary = m_renderer.camera.GetPrimaryRay(uv.x, uv.y);
const PixelMetadata metadata = m_renderer.Trace(primary, m_renderer.GetContext(xy.x, xy.y));
Material& mat = m_renderer.scene.m_LevelMaterialManager->GetMaterialRW(primary.GetMaterialIndex());
const float3 point = primary.m_origin + primary.m_direction * metadata.distance;
if (mat.m_transparency > 0)
{
ImGui::Text("Transparent");
float3 transmissionDirection = primary.m_direction;
if (mat.m_ior > 0)
{
//transmissionDirection = refract(transmissionDirection, N, mat.m_ior);
}
Ray transmissionRay(point, transmissionDirection);
m_renderer.scene.FindNearest(transmissionRay);
float3 TI = transmissionRay.IntersectionPoint();
uint color = RGBAF32_to_RGBA8(m_renderer.scene.m_LevelMaterialManager->GetMaterialR(transmissionRay.m_material).m_color);
unsigned char r, g, b; RGB24_to_R_G_B(color, r, g, b);
ImGui::Text("next opaque voxel color: %i %i %i", r, g, b);
ImGui::Text("next opaque voxel at %.2f %.2f %.2f", TI.x, TI.y, TI.z);
const float3 dir = normalize(m_renderer.camera.camPos - TI);
Ray shadowRay(TI, dir);
}
else
{
ImGui::Text("Opaque");
}
Ray r2(point, normalize(m_renderer.camera.camPos - point));
uint color = RGBAF32_to_RGBA8(m_renderer.scene.m_LevelMaterialManager->GetMaterialR(primary.m_material).m_color);
unsigned char r, g, b; RGB24_to_R_G_B(color, r, g, b);
ImGui::Text("next opaque voxel color: %i %i %i", r, g, b);
ImGui::Text("voxel at %.2f %.2f %.2f", point.x, point.y, point.z);
GUIHelpers::DrawWireSphere(point, 0.01f);
return UIMaterial(mat);
}
bool GUI::UILights()
{
bool dirty = false;
ImGui::Text("%d lights", m_renderer.scene.GetCurrentLevelRW()->GetLightsCount());
for (size_t i = 0; i < m_renderer.scene.GetCurrentLevelRW()->GetLightsCount(); i++)
{
Light& light = m_renderer.scene.GetCurrentLevelRW()->GetLightRW(i);
dirty |= UILight(light, i);
ImGui::Separator();
}
return dirty;
}
bool GUI::UILight(Light& light, size_t i)
{
bool dirty = false;
std::string name;
switch (light.m_type)
{
case Light::Type::Directional: name = "Directional"; break;
case Light::Type::Point: name = "Point"; break;
case Light::Type::Spot: name = "Spot"; break;
}
ImGui::Text((name + " %d").c_str(), i);
dirty |= ImGui::DragFloat3(UNIQ_IMGUI_LABEL("Position", i), &light.m_position.x, 0.01f, -1.f, 1.f);
dirty |= ImGui::DragFloat3(UNIQ_IMGUI_LABEL("Direction", i), &light.m_direction.x, 0.01f, -1.f, 1.f);
dirty |= ImGui::DragFloat(UNIQ_IMGUI_LABEL("Intensity", i), &light.m_intensity, 0.05f, 0.f, 10.f);
dirty |= ImGui::DragFloat(UNIQ_IMGUI_LABEL("Radius", i), &light.m_radius, 0.05f, 0.f, 5.f);
dirty |= ImGui::DragFloat(UNIQ_IMGUI_LABEL("Softness", i), &light.m_softness, 0.05f, 0.f, 4.f);
dirty |= ImGui::ColorEdit4(UNIQ_IMGUI_LABEL("Albedo", i), &light.m_color.x, ImGuiColorEditFlags_Float);
if (m_settings.m_showGizmos)
{
mat4 lightMat = light.GetMatrix();
float3 color = RandomMap1Dto3D((float)i, 0, 1);
ImGuizmo::DrawWireSphere(GUIHelpers::m_view, GUIHelpers::m_proj, lightMat.Transposed().cell, float4(color, 1.f));
mat4 lightMatSmall = light.GetMatrix(0.1f);
color = 1;
ImGuizmo::DrawWireSphere(GUIHelpers::m_view, GUIHelpers::m_proj, lightMatSmall.Transposed().cell, float4(color, 1.f));
}
return dirty;
}
bool GUI::UIMaterials()
{
bool dirty = false;
std::vector<Material>& mats = m_renderer.scene.m_LevelMaterialManager->GetAllRW();
for (size_t i = 0; i < mats.size(); i++)
{
if (!mats[i].m_isUsed) continue;
Material& mat = mats[i];
dirty |= UIMaterial(mat);
}
return dirty;
}
bool GUI::UIMaterial(Material& mat)
{
bool dirty = false;
unsigned char index = mat.m_index;
ImGui::Text((mat.m_identifier.m_name + " #" + to_string(mat.m_identifier.m_variantID)).c_str());
dirty |= ImGui::ColorEdit4(UNIQ_IMGUI_LABEL("Albedo", index), &mat.m_color.x, ImGuiColorEditFlags_Float);
dirty |= ImGui::SliderFloat(UNIQ_IMGUI_LABEL("Reflectivity", index), &mat.m_reflectivity, 0.f, 1.f);
dirty |= ImGui::SliderFloat(UNIQ_IMGUI_LABEL("Roughness", index), &mat.m_roughness, 0.f, 1.f);
dirty |= ImGui::SliderFloat(UNIQ_IMGUI_LABEL("Transparency", index), &mat.m_transparency, 0.f, 1.f);
dirty |= ImGui::SliderFloat(UNIQ_IMGUI_LABEL("IOR", index), &mat.m_ior, 0.f, 3.f);
dirty |= ImGui::SliderFloat(UNIQ_IMGUI_LABEL("Density", index), &mat.m_density, 0.f, 1.f);
return dirty;
}
void GUI::DebugDrawLOD(Scene& scene, size_t lodIndex, GIZMOS_LOD options)
{
assert(lodIndex < scene.m_lods.size());
const LOD& lod = scene.m_lods[lodIndex];
const float cellSize = 1.0f / float(lod.m_side);
const float3 cellWorldSize = float3(cellSize, cellSize, cellSize);
static constexpr float MARGIN = 0.05f;
for (int z = 0; z < lod.m_side; z++)
{
for (int y = 0; y < lod.m_side; y++)
{
for (int x = 0; x < lod.m_side; x++)
{
bool value = false;
float density = 1.f;
float3 color = 1.f;
const float3 center(
cellSize / 2.f + (x) * cellSize,
cellSize / 2.f + (y) * cellSize,
cellSize / 2.f + (z) * cellSize);
if (options == GIZMOS_LOD::MaskBool)
{
value = lod.IsNotEmpty(x, y, z);
color = value
? float3(1.0f, 1.0f, 1.0f) // white
: float3(0.0f, 0.0f, 0.0f); // black
}
if (options == GIZMOS_LOD::SphereBool)
{
value = lod.HasSphere(x, y, z);
color = value
? float3(1.0f, 1.0f, 1.0f) // white
: float3(0.0f, 0.0f, 0.0f); // black
}
if (options == GIZMOS_LOD::SphereDensity)
{
static constexpr float MAX_SPHERES = 3;
value = lod.HasSphere(x, y, z);
density = lod.m_sphereIDs[lod.Index(x, y, z)].size() / MAX_SPHERES;
float seed = 0;
for (auto id : lod.m_sphereIDs[lod.Index(x, y, z)])
{
seed += (id + 3);
seed *= 10;
}
color = RandomMap1Dto3D(seed, float3(0), float3(1));
}
const float alpha = (value ? 0.9f : 0.1f) * density;
GUIHelpers::DrawWireCube(
center,
cellWorldSize * (1.f - MARGIN),
color,
alpha);
}
}
}
}