-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathvulkan_bistro.cpp
More file actions
183 lines (151 loc) · 6.38 KB
/
Copy pathvulkan_bistro.cpp
File metadata and controls
183 lines (151 loc) · 6.38 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
#include "threepp/extras/imgui/ImguiContext.hpp"
#include "threepp/loaders/FBXLoader.hpp"
#include "threepp/loaders/GLTFLoader.hpp"
#include "threepp/loaders/RGBELoader.hpp"
#include "threepp/threepp.hpp"
#include <algorithm>
#include <filesystem>
using namespace threepp;
namespace fs = std::filesystem;
int main(int argc, char** argv) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <path_to_bistro_folder>" << std::endl;
return 1;
}
fs::path modelFolder = argv[1];
if (!fs::exists(modelFolder) || !fs::is_directory(modelFolder)) {
std::cerr << "Invalid folder path: " << fs::absolute(modelFolder) << std::endl;
return 1;
}
// ---- Window & Renderer ----
Canvas canvas("Bistro scene",
{{"vsync", false}});
VulkanRenderer renderer(canvas);
renderer.outputColorSpace = ColorSpace::sRGB;
renderer.toneMapping = ToneMapping::Neutral;
renderer.setRestirDIEnabled(true);
renderer.setFireflyClamp(8.f);
renderer.setDeferredAO(true);
renderer.setRenderScale(0.75);
// ---- Scene ----
Scene scene;
RGBELoader imgLoader;
if (auto env = imgLoader.load(modelFolder / "san_giuseppe_bridge_4k.hdr")) {
scene.background = env;
scene.environment = env;
}
// ---- Camera ----
PerspectiveCamera camera(60.f, canvas.aspect(), 0.01f, 1000.f);// 100k far/near is fine now: reversed-Z raster (was z-fighting before; near was bumped to 0.1 as a workaround)
camera.position.set(-10.f, 3.f, -5.f);
OrbitControls controls{camera, canvas};
controls.enableKeys = false;
controls.update();
// ---- Async model loading ----
FBXLoader loader;
// Bistro emissives (lamps, signs, string lights) are authored at low factors;
// the official Falcor scene multiplies every emissive factor by 1000 to get a
// well-exposed image, so do the same here for interior lighting to read.
loader.emissiveScale = 100.0f;
auto interior = loadAsync(loader, modelFolder / "BistroInterior_Wine.fbx");
auto exterior = loadAsync(loader, modelFolder / "BistroExterior.fbx");
scene.add(interior);
scene.add(exterior);
auto toggleBistroLights = [&] {
scene.traverseType<Light>([&](Light& l) {
l.visible = !l.visible;
});
};
// ---- UI ----
bool denoiserOn = renderer.denoise();
bool restdirOn = renderer.restirDIEnabled();
bool restdirVisReuse = renderer.restirDIVisibilityReuse();
bool restdirGiOn = renderer.restirGIEnabled();
float renderScale = renderer.renderScale();
// Tone-map dropdown state, initialized from the renderer's current setting so
// the label matches what's actually applied at startup. The selection maps
// straight to ToneMapping (index 2 -> Reinhard, etc.).
const char* tmNames[] = {"ACES Filmic", "Neutral (PBR)", "Reinhard", "Cineon", "Linear"};
const ToneMapping tmVals[] = {ToneMapping::ACESFilmic, ToneMapping::Neutral,
ToneMapping::Reinhard, ToneMapping::Cineon, ToneMapping::Linear};
int tmIdx = 0;
for (int i = 0; i < IM_ARRAYSIZE(tmVals); ++i)
if (tmVals[i] == renderer.toneMapping) { tmIdx = i; break; }
float fps = 0.f, fpsAccum = 0.f;
int fpsFrames = 0;
ImguiFunctionalContext ui(canvas, renderer, [&] {
ImGui::SetNextWindowPos({0, 0});
ImGui::SetNextWindowSize({300, 0});
ImGui::Begin("Bistro scene");
ImGui::Text("FPS: %.1f", fps);
ImGui::Separator();
ImGui::SliderFloat("Exposure", &renderer.toneMappingExposure, 0.1f, 2.0f);
// Tone-map selector. Reinhard is per-channel so it keeps saturated
// emitters (blue/green bulbs) coloured; ACES and Neutral desaturate very
// bright values toward white. Switchable live.
if (ImGui::Combo("Tone map", &tmIdx, tmNames, IM_ARRAYSIZE(tmNames))) {
renderer.toneMapping = tmVals[tmIdx];
}
if (ImGui::Checkbox("Denoiser", &denoiserOn)) {
renderer.setDenoise(denoiserOn);
}
if (ImGui::Checkbox("REsTDIR DI", &restdirOn)) {
renderer.setRestirDIEnabled(restdirOn);
}
if (ImGui::Checkbox(" DI visibility reuse", &restdirVisReuse)) {
renderer.setRestirDIVisibilityReuse(restdirVisReuse);
}
if (ImGui::Checkbox("REsTDIR GI", &restdirGiOn)) {
renderer.setRestirGIEnabled(restdirGiOn);
}
if (ImGui::SliderFloat("Render scale", &renderScale, 0.25f, 1.0f)) {
renderer.setRenderScale(renderScale);
}
if (ImGui::Button("Toggle bistro lights")) {
toggleBistroLights();
}
ImGui::End();
});
IOCapture ioCapture;
ioCapture.preventMouseEvent = []() -> bool { return ImGui::GetIO().WantCaptureMouse; };
ioCapture.preventScrollEvent = []() -> bool { return ImGui::GetIO().WantCaptureMouse; };
ioCapture.preventKeyboardEvent = []() -> bool { return ImGui::GetIO().WantCaptureKeyboard; };
canvas.setIOCapture(&ioCapture);
canvas.onWindowResize([&](const WindowSize& ns) {
renderer.setSize(ns);
camera.aspect = canvas.aspect();
camera.updateProjectionMatrix();
});
Clock clock;
canvas.animate([&] {
const float dt = clock.getDelta();
fpsAccum += dt;
++fpsFrames;
if (fpsAccum >= 0.5f) {
fps = fpsFrames / fpsAccum;
fpsAccum = 0.f;
fpsFrames = 0;
}
controls.update();
renderer.render(scene, camera);
// auto t = renderer.lastFrameTimings();
// static int frames = 0;
// static double accum = 0.0;
// accum += t.cpuFrameMs;
// if (++frames >= 60) {
// std::cout << std::fixed << std::setprecision(2)
// << "frame " << t.cpuFrameMs << " ms"
// << " | PT " << t.pathTraceMs
// << " | denoise " << t.denoiseMs
// << " | TAA " << t.taaMs
// << " | gbuf " << t.rasterGbufMs
// << " | overlay " << t.overlayMs
// << " | photon " << t.photonEmitMs
// << " | cpu(scene " << t.cpuEnsureSceneMs
// << ", record " << t.cpuRecordMs << ")"
// << '\n';
// frames = 0;
// accum = 0.0;
// }
ui.render();
});
}