Repository navigation
Expand file tree
/
Copy pathgraphics_settings.cpp
More file actions
327 lines (245 loc) · 8.8 KB
/
Copy pathgraphics_settings.cpp
File metadata and controls
327 lines (245 loc) · 8.8 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
#include "graphics_settings.hpp"
#include <imgui/imgui.h>
#include <networking/serialisable.hpp>
#include <SFML/Graphics.hpp>
#include <toolkit/texture.hpp>
#include <toolkit/clock.hpp>
#include <iostream>
#include <toolkit/fs_helpers.hpp>
DEFINE_SERIALISE_FUNCTION(graphics_settings)
{
DO_FSERIALISE(pos_x);
DO_FSERIALISE(pos_y);
DO_FSERIALISE(width);
DO_FSERIALISE(height);
DO_FSERIALISE(field_of_view);
DO_FSERIALISE(fullscreen);
DO_FSERIALISE(supersample);
DO_FSERIALISE(supersample_factor);
DO_FSERIALISE(vsync_enabled);
DO_FSERIALISE(screenshot_width);
DO_FSERIALISE(screenshot_height);
DO_FSERIALISE(time_adjusted_controls);
DO_FSERIALISE(mouse_sensitivity);
DO_FSERIALISE(keyboard_sensitivity);
DO_FSERIALISE(use_steam_screenshots);
DO_FSERIALISE(anisotropy);
DO_FSERIALISE(no_gpu_reads);
DO_FSERIALISE(workgroup_size);
DO_FSERIALISE(use_old_redshift);
DO_FSERIALISE(use_adaptive_sampling);
DO_FSERIALISE(adaptive_sampling_threshold);
}
bool graphics_settings::display_video_settings()
{
ImGui::InputInt("Position (x)", &pos_x);
ImGui::InputInt("Position (y)", &pos_y);
ImGui::InputInt("Width", &width);
ImGui::InputInt("Height", &height);
ImGui::DragFloat("Field Of View (degrees)", &field_of_view, 1.f, 1.f, 179.f, "%.1f");
field_of_view = clamp(field_of_view, 1.f, 179.f);
ImGui::Checkbox("Fullscreen", &fullscreen);
ImGui::Checkbox("Vsync", &vsync_enabled);
ImGui::Checkbox("Supersample", &supersample);
ImGui::InputInt("Supersample Factor", &supersample_factor);
ImGui::InputInt("Screenshot Width", &screenshot_width);
ImGui::InputInt("Screenshot Height", &screenshot_height);
ImGui::Checkbox("Save screenshots to steam", &use_steam_screenshots);
ImGui::DragInt("Anisotropic Filtering", &anisotropy, 1, 1, 256);
ImGui::Checkbox("No GPU reads", &no_gpu_reads);
if(ImGui::IsItemHovered())
{
ImGui::SetTooltip("May improve performance");
}
std::vector<std::array<int, 2>> sizes = {{4, 4}, {8, 8}, {16, 8}, {8, 16}, {16, 16}};
if(ImGui::BeginListBox("Work Group Sizes"))
{
for(auto& i : sizes)
{
bool selected = workgroup_size[0] == i[0] && workgroup_size[1] == i[1];
std::string str = std::to_string(i[0]) + "x" + std::to_string(i[1]);
if(ImGui::Selectable(str.c_str(), selected))
{
workgroup_size = i;
}
}
ImGui::EndListBox();
}
if(ImGui::IsItemHovered())
{
ImGui::SetTooltip("Size of a local workgroup when raytracing\n8x8 is best on amd, and 16x16 may be better on nvidia");
}
ImGui::Checkbox("Use Old Redshift", &use_old_redshift);
ImGui::Checkbox("Use Adaptive Sampling", &use_adaptive_sampling);
if(ImGui::IsItemHovered())
{
ImGui::SetTooltip("Improves performance by lowering the sample rate in smooth regions");
}
ImGui::DragFloat("Adaptive Sample Threshold", &adaptive_sampling_threshold, 1.f, 0.f, 9999.f);
if(ImGui::IsItemHovered())
{
ImGui::SetTooltip("Higher is lower quality");
}
ImGui::NewLine();
bool dirty = false;
/*if(ImGui::Button("Reset"))
{
dirty = true;
*this = graphics_settings();
}*/
return ImGui::Button("Apply") || dirty;
}
bool graphics_settings::display_control_settings()
{
ImGui::Checkbox("Time adjusted controls", &time_adjusted_controls);
if(ImGui::IsItemHovered())
{
ImGui::SetTooltip("Setting this to true means that camera moves at a constant amount per second\nSetting this to false means that the camera moves at a constant speed per frame");
}
ImGui::SliderFloat("Mouse Sensitivity", &mouse_sensitivity, 0.f, 5.f);
ImGui::SliderFloat("Keyboard Sensitivity", &keyboard_sensitivity, 0.f, 5.f);
ImGui::NewLine();
return ImGui::Button("Apply");
}
DEFINE_SERIALISE_FUNCTION(background_settings)
{
DO_FSERIALISE(path1);
DO_FSERIALISE(path2);
}
sf::Image load_image(const std::string& fname)
{
sf::Image img;
img.loadFromFile(fname);
return img;
}
cl::image load_mipped_image(sf::Image& img, cl::context& ctx, cl::command_queue& cqueue)
{
const uint8_t* as_uint8 = reinterpret_cast<const uint8_t*>(img.getPixelsPtr());
texture_settings bsett;
bsett.width = img.getSize().x;
bsett.height = img.getSize().y;
bsett.is_srgb = false;
texture opengl_tex;
opengl_tex.load_from_memory(bsett, &as_uint8[0]);
#define MIP_LEVELS 10
int max_mips = floor(log2(std::min(img.getSize().x, img.getSize().y))) + 1;
max_mips = std::min(max_mips, MIP_LEVELS);
cl::image image_mipped(ctx);
image_mipped.alloc((vec3i){img.getSize().x, img.getSize().y, max_mips}, {CL_RGBA, CL_UNORM_INT8}, cl::image_flags::ARRAY);
///and all of THIS is to work around a bug in AMDs drivers, where you cant write to a specific array level!
int swidth = img.getSize().x;
int sheight = img.getSize().y;
std::vector<vec<4, cl_uchar>> as_uniform;
as_uniform.reserve(max_mips * sheight * swidth);
for(int i=0; i < max_mips; i++)
{
std::vector<vec4f> mip = opengl_tex.read(i);
int cwidth = swidth / pow(2, i);
int cheight = sheight / pow(2, i);
assert(cwidth * cheight == mip.size());
for(int y = 0; y < sheight; y++)
{
for(int x=0; x < swidth; x++)
{
///clamp to border
int lx = std::min(x, cwidth - 1);
int ly = std::min(y, cheight - 1);
vec4f in = mip[ly * cwidth + lx];
in = clamp(in, 0.f, 1.f);
as_uniform.push_back({in.x() * 255, in.y() * 255, in.z() * 255, in.w() * 255});
}
}
}
vec<3, size_t> origin = {0, 0, 0};
vec<3, size_t> region = {swidth, sheight, max_mips};
image_mipped.write(cqueue, (char*)as_uniform.data(), origin, region);
return image_mipped;
}
void background_images::load(const std::string& n1, const std::string& n2)
{
sf::Image img_1 = load_image(n1);
i1 = load_mipped_image(img_1, ctx, cqueue);
sf::Image img_2;
if(n1 == n2)
img_2 = img_1;
else
img_2 = load_image(n2);
bool is_eq = false;
if(img_1.getSize().x == img_2.getSize().x && img_1.getSize().y == img_2.getSize().y)
{
size_t len = size_t{img_1.getSize().x} * size_t{img_1.getSize().y} * 4;
if(memcmp(img_1.getPixelsPtr(), img_2.getPixelsPtr(), len) == 0)
{
i2 = i1;
is_eq = true;
}
}
if(!is_eq)
i2 = load_mipped_image(img_2, ctx, cqueue);
}
void background_settings::load()
{
try
{
nlohmann::json js = nlohmann::json::parse(file::read("backgrounds.json", file::mode::BINARY));
deserialise<background_settings>(js, *this, serialise_mode::DISK);
}
catch(...){}
}
void background_settings::display(background_images& bi)
{
std::string ext = ".png";
std::vector<std::string> credits;
std::vector<std::string> name;
std::vector<std::filesystem::path> paths;
std::vector<std::string> license_data;
for(const auto& entry : std::filesystem::directory_iterator{"backgrounds"})
{
if(entry.path().string().ends_with(ext))
{
name.push_back(entry.path().filename().string());
paths.push_back(entry.path());
std::filesystem::path path = entry.path();
std::string license_path = path.replace_extension("info").string();
std::string license = file::read(license_path, file::mode::TEXT);
license_data.push_back(license);
}
}
bool save = false;
for(int i=0; i < (int)name.size(); i++)
{
if(ImGui::TreeNode(name[i].c_str()))
{
if(ImGui::Button(("Set##" + std::to_string(i)).c_str()))
{
path1 = paths[i].string();
path2 = paths[i].string();
bi.load(path1, path2);
save = true;
}
ImGui::SameLine();
if(ImGui::Button(("Set Main Background##" + std::to_string(i)).c_str()))
{
path1 = paths[i].string();
bi.load(path1, path2);
save = true;
}
ImGui::SameLine();
if(ImGui::Button(("Set Second Background##" + std::to_string(i)).c_str()))
{
path2 = paths[i].string();
bi.load(path1, path2);
save = true;
}
if(license_data[i].size() > 0)
{
ImGui::TextWrapped("%s", license_data[i].c_str());
}
ImGui::TreePop();
}
}
if(save)
{
file::write_atomic("backgrounds.json", serialise(*this, serialise_mode::DISK).dump(), file::mode::BINARY);
}
}