Skip to content

Commit ff32464

Browse files
committed
Fix hero wavelength, cli controls, bug fixes
1 parent 760fc50 commit ff32464

20 files changed

Lines changed: 362 additions & 218 deletions

File tree

assets/scenes/caustics.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"baseColor": [0, 0, 0],
1919
"roughness": 1,
2020
"diffuseRoughness": 1,
21-
"emissionLuminance": 2000
21+
"emissionLuminance": 32000
2222
}
2323
}, {
2424
"index": 3,
@@ -70,7 +70,7 @@
7070
"meshIndex": 1,
7171
"localPosition": [4.04099988937378, -0.88300001621246338, 2.1210000514984131],
7272
"localRotation": [0, 0, 0],
73-
"localScale": [0.20000000298023224, 0.20000000298023224, 0.20000000298023224]
73+
"localScale": [0.050000004470348358, 0.050000004470348358, 0.050000004470348358]
7474
}, {
7575
"name": "suzanne",
7676
"parentIndex": null,
@@ -90,6 +90,7 @@
9090
"rrMaxDepth": 8,
9191
"toneMappingMode": 1,
9292
"renderMode": 1,
93+
"spectralSamplingMode": 1,
9394
"exposure": 1,
9495
"autoExposureEnabled": false,
9596
"environmentColor": [0, 0, 0],

src/app/cli/cli.c

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#define VKRT_TURBOJPEG_VERSION "unknown"
2828
#endif
2929

30-
static const uint32_t kBenchmarkWidth = 3840u;
31-
static const uint32_t kBenchmarkHeight = 2160u;
32-
static const uint32_t kBenchmarkTargetSamples = 16384u;
30+
static const uint32_t kOfflineRenderWidth = 3840u;
31+
static const uint32_t kOfflineRenderHeight = 2160u;
32+
static const uint32_t kOfflineRenderTargetSamples = 16384u;
3333

3434
static int stringsEqual(const char* lhs, const char* rhs) {
3535
if (!lhs || !rhs) return 0;
@@ -125,9 +125,9 @@ void CLIDefaultLaunchOptions(CLILaunchOptions* options) {
125125
memset(options, 0, sizeof(*options));
126126
options->mode = CLI_MODE_RUN;
127127
options->loadDefaultScene = 1u;
128-
options->benchmark.width = kBenchmarkWidth;
129-
options->benchmark.height = kBenchmarkHeight;
130-
options->benchmark.targetSamples = kBenchmarkTargetSamples;
128+
options->offlineRender.width = kOfflineRenderWidth;
129+
options->offlineRender.height = kOfflineRenderHeight;
130+
options->offlineRender.targetSamples = kOfflineRenderTargetSamples;
131131
VKRT_defaultCreateInfo(&options->createInfo);
132132
}
133133

@@ -179,7 +179,7 @@ static int parseWindowArgument(
179179
return -1;
180180
}
181181

182-
static int parseBenchmarkArgument(
182+
static int parseOfflineRenderArgument(
183183
const char* arg,
184184
int argc,
185185
char* argv[],
@@ -188,28 +188,28 @@ static int parseBenchmarkArgument(
188188
char* error,
189189
size_t errorSize
190190
) {
191-
if (stringsEqual(arg, "--benchmark")) {
192-
options->benchmark.enabled = 1u;
193-
options->benchmark.headless = 0u;
191+
if (stringsEqual(arg, "--render") || stringsEqual(arg, "--benchmark")) {
192+
options->offlineRender.enabled = 1u;
193+
options->offlineRender.headless = 0u;
194194
return 1;
195195
}
196-
if (stringsEqual(arg, "--benchmark-headless")) {
197-
options->benchmark.enabled = 1u;
198-
options->benchmark.headless = 1u;
196+
if (stringsEqual(arg, "--render-headless")) {
197+
options->offlineRender.enabled = 1u;
198+
options->offlineRender.headless = 1u;
199199
return 1;
200200
}
201-
if (optionMatches(arg, "--benchmark-width")) {
202-
const char* value = requireOptionValue(argc, argv, index, "--benchmark-width", error, errorSize);
203-
return value && parseUnsignedValue(value, &options->benchmark.width, "--benchmark-width", error, errorSize);
201+
if (optionMatches(arg, "--render-width")) {
202+
const char* value = requireOptionValue(argc, argv, index, "--render-width", error, errorSize);
203+
return value && parseUnsignedValue(value, &options->offlineRender.width, "--render-width", error, errorSize);
204204
}
205-
if (optionMatches(arg, "--benchmark-height")) {
206-
const char* value = requireOptionValue(argc, argv, index, "--benchmark-height", error, errorSize);
207-
return value && parseUnsignedValue(value, &options->benchmark.height, "--benchmark-height", error, errorSize);
205+
if (optionMatches(arg, "--render-height")) {
206+
const char* value = requireOptionValue(argc, argv, index, "--render-height", error, errorSize);
207+
return value && parseUnsignedValue(value, &options->offlineRender.height, "--render-height", error, errorSize);
208208
}
209-
if (optionMatches(arg, "--benchmark-samples")) {
210-
const char* value = requireOptionValue(argc, argv, index, "--benchmark-samples", error, errorSize);
209+
if (optionMatches(arg, "--render-samples")) {
210+
const char* value = requireOptionValue(argc, argv, index, "--render-samples", error, errorSize);
211211
return value &&
212-
parseUnsignedValue(value, &options->benchmark.targetSamples, "--benchmark-samples", error, errorSize);
212+
parseUnsignedValue(value, &options->offlineRender.targetSamples, "--render-samples", error, errorSize);
213213
}
214214
return -1;
215215
}
@@ -227,22 +227,38 @@ static int parseSceneArgument(
227227
options->loadDefaultScene = 0u;
228228
return 1;
229229
}
230+
if (optionMatches(arg, "--scene")) {
231+
const char* value = requireOptionValue(argc, argv, index, "--scene", error, errorSize);
232+
if (!value || !value[0]) return setCLIError(error, errorSize, "Invalid value for --scene", NULL);
233+
options->startupScenePath = value;
234+
options->loadDefaultScene = 0u;
235+
return 1;
236+
}
230237
if (optionMatches(arg, "--import")) {
231238
const char* value = requireOptionValue(argc, argv, index, "--import", error, errorSize);
232239
if (!value || !value[0]) return setCLIError(error, errorSize, "Invalid value for --import", NULL);
233240
options->startupImportPath = value;
234241
return 1;
235242
}
243+
if (optionMatches(arg, "--render-output")) {
244+
const char* value = requireOptionValue(argc, argv, index, "--render-output", error, errorSize);
245+
if (!value || !value[0]) return setCLIError(error, errorSize, "Invalid value for --render-output", NULL);
246+
options->renderOutputPath = value;
247+
return 1;
248+
}
236249
return -1;
237250
}
238251

239252
static int validateCLIArgumentCombination(const CLILaunchOptions* options, char* error, size_t errorSize) {
240-
if (!options->benchmark.enabled) return 1;
241-
if (!options->loadDefaultScene) {
242-
return setCLIError(error, errorSize, "--benchmark requires the default scene", NULL);
243-
}
253+
if (!options->offlineRender.enabled) return 1;
244254
if (options->startupImportPath) {
245-
return setCLIError(error, errorSize, "--benchmark cannot be combined with --import", NULL);
255+
return setCLIError(error, errorSize, "--render cannot be combined with --import", NULL);
256+
}
257+
if (!options->loadDefaultScene && !options->startupScenePath) {
258+
return setCLIError(error, errorSize, "--render requires either the default scene or --scene", NULL);
259+
}
260+
if (options->renderOutputPath && !options->offlineRender.headless) {
261+
return setCLIError(error, errorSize, "--render-output currently requires --render-headless", NULL);
246262
}
247263
return 1;
248264
}
@@ -270,7 +286,7 @@ int CLIParseArguments(int argc, char* argv[], CLILaunchOptions* outOptions, char
270286
if (parseResult == 0) return 0;
271287
if (parseResult > 0) continue;
272288

273-
parseResult = parseBenchmarkArgument(arg, argc, argv, &i, outOptions, error, errorSize);
289+
parseResult = parseOfflineRenderArgument(arg, argc, argv, &i, outOptions, error, errorSize);
274290
if (parseResult == 0) return 0;
275291
if (parseResult > 0) continue;
276292

@@ -345,15 +361,18 @@ void CLIPrintHelp(void) {
345361
printf(" --device-index <index> Force a Vulkan device by enumerated index\n");
346362
printf(" --device-name <text> Force a Vulkan device if its name contains this text\n");
347363
printf(" --empty-scene Skip loading the default starter scene\n");
348-
printf(" --benchmark Run the default benchmark with presentation enabled\n");
364+
printf(" --scene <path> Load a vkrt scene (.json) on startup\n");
365+
printf(" --render Run an offline render with presentation enabled\n");
349366
printf(
350-
" --benchmark-headless Run the default benchmark offscreen with no window or "
367+
" --render-headless Run an offline render offscreen with no window or "
351368
"presentation\n"
352369
);
353-
printf(" --benchmark-width <px> Override benchmark render width (default: 3840)\n");
354-
printf(" --benchmark-height <px> Override benchmark render height (default: 2160)\n");
355-
printf(" --benchmark-samples <n> Override benchmark target samples (default: 16384)\n");
370+
printf(" --render-width <px> Override offline render width (default: 3840)\n");
371+
printf(" --render-height <px> Override offline render height (default: 2160)\n");
372+
printf(" --render-samples <n> Override offline render target samples (default: 16384)\n");
356373
printf(" --import <path> Import a mesh on startup\n");
374+
printf(" --render-output <path> Save the --render-headless image after completion\n");
375+
printf(" --benchmark Alias for --render\n");
357376
printf("\nViewport Controls:\n");
358377
printf(" Middle mouse drag Orbit camera\n");
359378
printf(" Shift + middle mouse drag Pan camera\n");

src/app/cli/cli.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ typedef enum CLIMode {
1111
CLI_MODE_VERSION,
1212
} CLIMode;
1313

14-
typedef struct CLIBenchmarkOptions {
14+
typedef struct CLIOfflineRenderOptions {
1515
uint8_t enabled;
1616
uint8_t headless;
1717
uint32_t width;
1818
uint32_t height;
1919
uint32_t targetSamples;
20-
} CLIBenchmarkOptions;
20+
} CLIOfflineRenderOptions;
2121

2222
typedef struct CLILaunchOptions {
2323
CLIMode mode;
2424
VKRT_CreateInfo createInfo;
2525
uint8_t loadDefaultScene;
26+
const char* startupScenePath;
2627
const char* startupImportPath;
27-
CLIBenchmarkOptions benchmark;
28+
const char* renderOutputPath;
29+
CLIOfflineRenderOptions offlineRender;
2830
} CLILaunchOptions;
2931

3032
void CLIDefaultLaunchOptions(CLILaunchOptions* options);

src/app/editor/editor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,18 @@ static void applyEditorCameraInput(
847847
applyInteractiveCameraInput(vkrt, viewportHovered, imguiIO);
848848
}
849849

850+
void editorRegisterAppHooks(VKRT* vkrt, Session* session) {
851+
if (!vkrt || !session) return;
852+
853+
VKRT_AppHooks hooks = {
854+
.init = editorUIInitialize,
855+
.deinit = editorUIShutdown,
856+
.drawOverlay = editorUIDraw,
857+
.userData = session,
858+
};
859+
VKRT_registerAppHooks(vkrt, hooks);
860+
}
861+
850862
void editorUIInitialize(VKRT* vkrt, void* userData) {
851863
Session* session = (Session*)userData;
852864
if (!session || session->editor.uiState) return;

src/app/editor/editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ void editorUIShutdown(VKRT* vkrt, void* userData);
99
void editorUIUpdate(VKRT* vkrt, Session* session);
1010
void editorUIDraw(VKRT* vkrt, VkCommandBuffer commandBuffer, void* userData);
1111
void editorUIProcessDialogs(Session* session);
12+
void editorRegisterAppHooks(VKRT* vkrt, Session* session);

src/app/main.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "scene/controller.h"
88
#include "session.h"
99
#include "vkrt.h"
10-
#include "vkrt_overlay.h"
1110
#include "vkrt_types.h"
1211

1312
#include <stdint.h>
@@ -24,7 +23,7 @@ int main(int argc, char* argv[]) {
2423
int earlyExitCode = EXIT_SUCCESS;
2524
if (CLIHandleImmediateMode(&launchOptions, &earlyExitCode)) return earlyExitCode;
2625

27-
benchmarkPrepareLaunchOptions(&launchOptions);
26+
offlineRenderPrepareLaunchOptions(&launchOptions);
2827

2928
VKRT* vkrt = NULL;
3029
Session session = {0};
@@ -37,15 +36,9 @@ int main(int argc, char* argv[]) {
3736

3837
sessionInit(&session);
3938

40-
const uint8_t benchmarkMode = launchOptions.benchmark.enabled;
41-
if (!benchmarkMode) {
42-
VKRT_AppHooks hooks = {
43-
.init = editorUIInitialize,
44-
.deinit = editorUIShutdown,
45-
.drawOverlay = editorUIDraw,
46-
.userData = &session,
47-
};
48-
VKRT_registerAppHooks(vkrt, hooks);
39+
const uint8_t offlineRenderMode = launchOptions.offlineRender.enabled;
40+
if (!offlineRenderMode) {
41+
editorRegisterAppHooks(vkrt, &session);
4942
}
5043

5144
if (VKRT_initWithCreateInfo(vkrt, &launchOptions.createInfo) != VKRT_SUCCESS) {
@@ -54,43 +47,38 @@ int main(int argc, char* argv[]) {
5447
goto cleanup;
5548
}
5649

57-
if (launchOptions.loadDefaultScene) {
58-
if (!sceneControllerLoadDefaultScene(vkrt, &session)) {
50+
if (!sceneControllerLoadStartupScene(
51+
vkrt,
52+
&session,
53+
launchOptions.startupScenePath,
54+
launchOptions.loadDefaultScene
55+
)) {
56+
if (launchOptions.startupScenePath) {
57+
LOG_ERROR("Loading startup scene failed. Path: %s", launchOptions.startupScenePath);
58+
} else {
5959
LOG_ERROR("Loading default scene failed");
60-
exitCode = EXIT_FAILURE;
61-
goto cleanup;
62-
}
63-
}
64-
65-
if (launchOptions.startupImportPath) {
66-
if (!meshControllerImportMesh(vkrt, &session, launchOptions.startupImportPath, NULL, NULL)) {
67-
LOG_ERROR("Startup mesh import failed. Path: %s", launchOptions.startupImportPath);
68-
exitCode = EXIT_FAILURE;
69-
goto cleanup;
7060
}
61+
exitCode = EXIT_FAILURE;
62+
goto cleanup;
7163
}
7264

73-
if (benchmarkMode) {
74-
exitCode = benchmarkRun(vkrt, &launchOptions.benchmark);
65+
if (launchOptions.startupImportPath &&
66+
!meshControllerImportMesh(vkrt, &session, launchOptions.startupImportPath, NULL, NULL)) {
67+
LOG_ERROR("Startup mesh import failed. Path: %s", launchOptions.startupImportPath);
68+
exitCode = EXIT_FAILURE;
7569
goto cleanup;
7670
}
7771

78-
while (!VKRT_shouldDeinit(vkrt)) {
79-
VKRT_poll(vkrt);
80-
81-
editorUIProcessDialogs(&session);
82-
sceneControllerApplySessionActions(vkrt, &session);
83-
meshControllerApplySessionActions(vkrt, &session);
84-
renderControllerApplySessionActions(vkrt, &session);
85-
editorUIUpdate(vkrt, &session);
86-
87-
if (VKRT_draw(vkrt) != VKRT_SUCCESS) {
88-
LOG_ERROR("Frame render failed");
89-
exitCode = EXIT_FAILURE;
90-
break;
72+
if (offlineRenderMode) {
73+
exitCode = offlineRenderRun(vkrt, &launchOptions.offlineRender);
74+
if (exitCode == EXIT_SUCCESS && launchOptions.renderOutputPath) {
75+
exitCode = offlineRenderSaveOutput(vkrt, launchOptions.renderOutputPath);
9176
}
77+
goto cleanup;
9278
}
9379

80+
exitCode = renderControllerRunInteractiveLoop(vkrt, &session);
81+
9482
cleanup:
9583
VKRT_destroy(vkrt);
9684
sessionDeinit(&session);

0 commit comments

Comments
 (0)