-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameGUI.cpp
More file actions
262 lines (231 loc) · 8.97 KB
/
GameGUI.cpp
File metadata and controls
262 lines (231 loc) · 8.97 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
#pragma once
#include "template.h"
#include "GUIHelpers.h"
#include "GameGUI.h"
#include "ImGuizmo.h"
#include "imgui.h"
#include "scene.h"
#include "renderer.h"
#include "amath.h"
PlanetGen GameGUI::m_planetGen;
Tmpl8::Renderer* GameGUI::m_renderer = nullptr;
void GameGUI::Render()
{
if (m_renderer->scene.IsInDemoScene())
{
Intro();
}
else if (m_renderer->scene.IsInGameScene())
{
PlanetEditor();
}
}
void GameGUI::PlanetEditor()
{
GUIHelpers::NewNormalWindow("Planet Editor", float2(0, 0), float2(350, 530), []()
{
ImGui::Separator();
if (ImGui::Button("Back to intro"))
{
m_renderer->scene.LoadDemoScene();
}
ImGui::Separator();
ImGui::Text("Player's flashlight");
Light* flashlight = m_renderer->m_player.GetFlashlight();
if (flashlight)
{
ImGui::SliderFloat("Radius", &flashlight->m_radius, 0.f, 3.f);
ImGui::SliderFloat("Intensity", &flashlight->m_intensity, 0.f, 3.f);
static float angle = std::acosf(flashlight->m_angleCos) * 180.f / PI;
if (ImGui::SliderFloat("Cone angle", &angle, 0.f, 60.f))
{
flashlight->Angle(angle);
}
ImGui::SliderFloat("Softness", &flashlight->m_softness, 0.f, 0.5f);
ImGui::ColorEdit3("Color", &flashlight->m_color.x);
}
ImGui::Separator();
ImGui::Text("Planet!");
bool levelDirty = false;
static Range<float, 0.f, 1.f> size = 0.5f;
static Range<float, 0.f, 1.f> oceanness = 0.5f;
bool changed = false;
changed |= GUIHelpers::Slider("Size", size, &levelDirty);
changed |= GUIHelpers::Slider("Oceanness", oceanness, &levelDirty);
if (changed)
{
const float baseRadius = amath::Remap(size.Get(), 0.f, 1.f, 0.1f, 0.7f);
const float oceanOffset = amath::Remap(oceanness.Get(), 0.f, 1.f, -0.05f, 0.2f);
m_planetGen.radius = baseRadius;
m_planetGen.seaLevel = baseRadius + oceanOffset;
}
levelDirty |= GUIHelpers::Slider("Mountains height", m_planetGen.mountainsFac);
levelDirty |= GUIHelpers::Slider("Mountains amount", m_planetGen.mountainsFreq);
levelDirty |= GUIHelpers::Slider("Jagged peaks", m_planetGen.peaks);
levelDirty |= GUIHelpers::Slider("Rivers frequency", m_planetGen.riversFreq);
levelDirty |= GUIHelpers::Slider("Rivers width", m_planetGen.riverWidth);
decltype(m_planetGen.snow) snow = amath::Remap(m_planetGen.snow.Get(), snow.min, snow.max, snow.max, snow.min);
levelDirty |= GUIHelpers::Slider("Snow", snow);
m_planetGen.snow = amath::Remap(snow.Get(), snow.min, snow.max, snow.max, snow.min);
ImGui::Separator();
if (ImGui::CollapsingHeader("Advanced"))
{
levelDirty |= GUIHelpers::Slider("Sea level", m_planetGen.seaLevel);
levelDirty |= GUIHelpers::Slider("Radius", m_planetGen.radius);
}
if (ImGui::Button("Randomize!"))
{
levelDirty = true;
m_planetGen.Randomize();
}
if (ImGui::Button("Clear edits"))
{
levelDirty = true;
m_renderer->m_player.ClearEdits();
}
if (levelDirty)
{
m_renderer->scene.ReloadCurrentLevel();
m_renderer->scene.ApplyEdits(m_renderer->m_player.GetEdits());
m_renderer->ResetAccumulator();
}
ImGui::SliderFloat("Brush size", &m_renderer->m_player.m_brushRadius, 1.5f, 20.f, "%.1f");
int brushMat = static_cast<int>(m_renderer->m_player.m_brushMaterial);
if (ImGui::SliderInt("Brush material", &brushMat, 1, static_cast<int>(m_renderer->scene.GetCurrentLevelR()->m_materialManager.GetCount()) - 1))
{
m_renderer->m_player.m_brushMaterial = static_cast<Material::ID_T>(brushMat);
}
});
}
void GameGUI::Intro()
{
const float2 size(380, 350);
const float2 shift(0, -180);
GUIHelpers::NewNormalWindow("Welcome to the Planet Editor game!", float2(SCRWIDTH - size.x / 2.f + shift.x, SCRHEIGHT - size.y / 2.0f + shift.y), size, []()
{
ImGui::Text("Cosmos exploration station");
ImGui::Text("This scene is a feature-intro");
if (ImGui::Button("Start game"))
{
m_renderer->scene.LoadGameScene();
}
ImGui::Text("This is a planet editor game");
ImGui::Text("Use WASD and Mouse Wheel to navigate");
ImGui::Text("Use Right Mouse Button to remove voxels");
ImGui::Text("Use Left Mouse Button to add voxels");
static bool LIGHTS_SHOWN = false;
if (ImGui::Button(LIGHTS_SHOWN ? "Hide lights" : "Show lights"))
{
LIGHTS_SHOWN = !LIGHTS_SHOWN;
m_renderer->scene.GetSettingsRW().m_showGizmos = LIGHTS_SHOWN;
}
if (LIGHTS_SHOWN)
{
Lights();
}
static bool MATERIALS_SHOWN = false;
if (ImGui::Button(MATERIALS_SHOWN ? "Hide materials" : "Show materials"))
{
MATERIALS_SHOWN = !MATERIALS_SHOWN;
}
if (MATERIALS_SHOWN)
{
Materials();
}
static bool COSMOS_SKY = true;
if (ImGui::Button(COSMOS_SKY ? "Switch to rural sky" : "Switch to cosmos sky"))
{
COSMOS_SKY = !COSMOS_SKY;
if (COSMOS_SKY)
{
m_renderer->scene.GetSettingsRW().m_skydome.m_fileIndex = 2;
m_renderer->scene.GetSettingsRW().m_skydome.m_lightIntensity = 3.f;
}
else
{
m_renderer->scene.GetSettingsRW().m_skydome.m_fileIndex = 1;
m_renderer->scene.GetSettingsRW().m_skydome.m_lightIntensity = 0.74f;
}
m_renderer->m_gui.MarkSkyDirty();
}
ImGui::Separator();
ImVec4 extrasColor(1.f, 0.8f, 0.1f, 1.f);
ImGui::PushStyleColor(ImGuiCol_Text, extrasColor);
ImGui::Text("Below you can find extra ray tracer features");
ImGui::Text("They are NOT part of the game");
static bool SVGF_ON = m_renderer->scene.GetSettingsR().m_denoiser.m_worker == Settings::Denoiser::Worker::SVGF;
if (ImGui::Button(SVGF_ON ? "Disable SVGF" : "Enable SVGF"))
{
SVGF_ON = !SVGF_ON;
if (SVGF_ON)
{
m_renderer->scene.GetSettingsRW().m_denoiser.m_worker = Settings::Denoiser::Worker::SVGF;
}
else
{
m_renderer->scene.GetSettingsRW().m_denoiser.m_worker = Settings::Denoiser::Worker::None;
}
}
if (SVGF_ON)
{
ImGui::Text("Depth of field is a part of denoiser");
bool dirty = false;
dirty |= ImGui::Checkbox("Use depth of field", &m_renderer->scene.GetSettingsRW().m_lens.m_useDepthOfField);
if (m_renderer->scene.GetSettingsR().m_lens.m_useDepthOfField)
{
GUIHelpers::Drag("Depth of field", m_renderer->scene.GetSettingsRW().m_lens.m_depthOfField, &dirty);
GUIHelpers::Drag("Focus distance", m_renderer->scene.GetSettingsRW().m_lens.m_focusDistance, &dirty);
}
if (dirty)
{
m_renderer->ResetAccumulator();
}
}
ImGui::PopStyleColor();
static bool SPHERES = false;
if (ImGui::Button(SPHERES ? "Remove spheres" : "1000 spheres!"))
{
SPHERES = !SPHERES;
if (SPHERES)
{
m_renderer->scene.GetCurrentLevelRW()->m_spheres.objects.clear();
constexpr int SIDE = 10;
for (int x = 0; x < SIDE; ++x)
{
for (int y = 0; y < SIDE; ++y)
{
for (int z = 0; z < SIDE; ++z)
{
const int3 gridPos(x, y, z);
const float3 pos = make_float3(gridPos) / static_cast<float>(SIDE + 1) + float3(1.f / static_cast<float>(SIDE + 1));
m_renderer->scene.GetCurrentLevelRW()->AddSphere(pos, 0.02f, 1);
}
}
}
}
else
{
m_renderer->scene.GetCurrentLevelRW()->m_spheres.objects.clear();
}
m_renderer->scene.ReloadCurrentLevel();
}
});
}
void GameGUI::Lights()
{
const float2 size(400, 650);
const float2 shift(size.x, -180);
GUIHelpers::NewNormalWindow("Lights", float2(SCRWIDTH - size.x / 2.f + shift.x, SCRHEIGHT - size.y / 2.0f + shift.y), size, []()
{
m_renderer->m_gui.UILights();
});
}
void GameGUI::Materials()
{
const float2 size(400, 650);
const float2 shift(-size.x, -180);
GUIHelpers::NewNormalWindow("Materials", float2(SCRWIDTH - size.x / 2.f + shift.x, SCRHEIGHT - size.y / 2.0f + shift.y), size, []()
{
m_renderer->m_gui.UIMaterials();
});
}