Skip to content

Commit 234fbd2

Browse files
committed
Add Wilkie hero wavelength sampling
1 parent c2908d3 commit 234fbd2

File tree

28 files changed

+801
-144
lines changed

28 files changed

+801
-144
lines changed

assets/scenes/caustics.json

Lines changed: 3 additions & 3 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": 8000
21+
"emissionLuminance": 2000
2222
}
2323
}, {
2424
"index": 3,
@@ -70,13 +70,13 @@
7070
"meshIndex": 1,
7171
"localPosition": [4.04099988937378, -0.88300001621246338, 2.1210000514984131],
7272
"localRotation": [0, 0, 0],
73-
"localScale": [0.10000000149011612, 0.10000000149011612, 0.10000000149011612]
73+
"localScale": [0.20000000298023224, 0.20000000298023224, 0.20000000298023224]
7474
}, {
7575
"name": "suzanne",
7676
"parentIndex": null,
7777
"meshIndex": 2,
7878
"localPosition": [0.18600000441074371, 0.00999999977648258, 0.5],
79-
"localRotation": [-36.299999237060547, 0, 125.30000305175781],
79+
"localRotation": [-36.299999237060547, 11.800000190734863, 125.30000305175781],
8080
"localScale": [1, 1, 1]
8181
}],
8282
"sceneSettings": {

src/app/editor/inspector/camera.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ static void drawCameraShadingSection(VKRT* vkrt, VKRT_SceneSettingsSnapshot* set
141141
}
142142
}
143143

144+
if (settings->renderMode == VKRT_RENDER_MODE_SPECTRAL) {
145+
const char* spectralSamplingLabels[] = {"Single", "Hero (4)"};
146+
int spectralSamplingMode = (int)settings->spectralSamplingMode;
147+
if (ImGui_ComboCharEx(
148+
"Spectral Sampling",
149+
&spectralSamplingMode,
150+
spectralSamplingLabels,
151+
VKRT_SPECTRAL_SAMPLING_MODE_COUNT,
152+
VKRT_SPECTRAL_SAMPLING_MODE_COUNT
153+
)) {
154+
VKRT_Result result = VKRT_setSpectralSamplingMode(vkrt, (uint32_t)spectralSamplingMode);
155+
logCameraInspectorFailure("Updating spectral sampling mode failed", result);
156+
if (result == VKRT_SUCCESS) {
157+
settings->spectralSamplingMode = (uint32_t)spectralSamplingMode;
158+
}
159+
}
160+
}
161+
144162
bool autoExposureEnabled = settings->autoExposureEnabled != 0;
145163
if (ImGui_Checkbox("Auto Exposure", &autoExposureEnabled)) {
146164
uint8_t autoExposureFlag = (uint8_t)autoExposureEnabled;

src/app/editor/inspector/common.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,22 @@ bool inspectorPaddedButton(const char* label) {
8484
return pressed;
8585
}
8686

87+
enum {
88+
K_PCI_VENDOR_ID_NVIDIA = 0x10DEu,
89+
K_PCI_VENDOR_ID_INTEL = 0x8086u,
90+
};
91+
8792
void formatDriverVersionText(uint32_t vendorID, uint32_t driverVersion, char* out, size_t outSize) {
8893
if (!out || outSize == 0) return;
8994

90-
if (vendorID == 0x10DEu) { // NVIDIA
95+
if (vendorID == K_PCI_VENDOR_ID_NVIDIA) {
9196
uint32_t major = (driverVersion >> 22u) & 0x3ffu;
9297
uint32_t minor = (driverVersion >> 14u) & 0xffu;
9398
(void)snprintf(out, outSize, "%u.%02u", major, minor);
9499
return;
95100
}
96101

97-
if (vendorID == 0x8086u) { // INTEL
102+
if (vendorID == K_PCI_VENDOR_ID_INTEL) {
98103
uint32_t major = driverVersion >> 14u;
99104
uint32_t minor = driverVersion & 0x3fffu;
100105
if (major > 0 && minor > 0) {
@@ -106,7 +111,7 @@ void formatDriverVersionText(uint32_t vendorID, uint32_t driverVersion, char* ou
106111
(void)snprintf(
107112
out,
108113
outSize,
109-
"%u.%u.%u", // AMD / UNKNOWN
114+
"%u.%u.%u",
110115
VK_API_VERSION_MAJOR(driverVersion),
111116
VK_API_VERSION_MINOR(driverVersion),
112117
VK_API_VERSION_PATCH(driverVersion)

src/app/editor/inspector/render.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static void drawIdleRenderState(Session* session, const SessionRenderTimer* time
166166
}
167167

168168
if (timer->completedSeconds > 0.0f) {
169-
char totalText[K_RENDER_TIME_TEXT_CAPACITY];
169+
char totalText[K_RENDER_TIME_TEXT_CAPACITY];
170170
formatTime(timer->completedSeconds, totalText, sizeof(totalText));
171171
ImGui_TextDisabled(ICON_FA_CLOCK " Last render: %s", totalText);
172172
}
@@ -292,15 +292,15 @@ static void drawRenderProgressStatusText(
292292

293293
if (VKRT_renderStatusIsComplete(status)) {
294294
float elapsedDoneSeconds = completedSeconds > 0.0f ? completedSeconds : elapsedActiveSeconds;
295-
char elapsedText[K_RENDER_TIME_TEXT_CAPACITY];
295+
char elapsedText[K_RENDER_TIME_TEXT_CAPACITY];
296296
formatTime(fmaxf(elapsedDoneSeconds, 0.0f), elapsedText, sizeof(elapsedText));
297297
ImGui_Text(ICON_FA_CHECK " Complete " ICON_FA_CLOCK " %s", elapsedText);
298298
return;
299299
}
300300

301301
float etaSeconds = queryRenderEtaSeconds(status, elapsedActiveSeconds);
302302
if (etaSeconds >= 0.0f) {
303-
char etaText[K_RENDER_TIME_TEXT_CAPACITY];
303+
char etaText[K_RENDER_TIME_TEXT_CAPACITY];
304304
formatTime(etaSeconds, etaText, sizeof(etaText));
305305
ImGui_Text("Rendering " ICON_FA_CLOCK " ETA %s", etaText);
306306
return;
@@ -319,7 +319,7 @@ static void drawRenderProgressSection(
319319

320320
ImGui_TextDisabled("Output %ux%u", runtime->renderWidth, runtime->renderHeight);
321321
{
322-
char overlay[K_RENDER_PROGRESS_OVERLAY_CAPACITY];
322+
char overlay[K_RENDER_PROGRESS_OVERLAY_CAPACITY];
323323
float progress = 0.0f;
324324
uint64_t shownSamples = 0u;
325325

src/app/scene/controller.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ static int saveSceneSettings(cJSON* sceneRoot, const VKRT_SceneSettingsSnapshot*
785785
cJSON_AddNumberToObject(settingsObject, "rrMaxDepth", settings->rrMaxDepth);
786786
cJSON_AddNumberToObject(settingsObject, "toneMappingMode", settings->toneMappingMode);
787787
cJSON_AddNumberToObject(settingsObject, "renderMode", settings->renderMode);
788+
cJSON_AddNumberToObject(settingsObject, "spectralSamplingMode", settings->spectralSamplingMode);
788789
cJSON_AddNumberToObject(settingsObject, "exposure", settings->exposure);
789790
cJSON_AddBoolToObject(settingsObject, "autoExposureEnabled", settings->autoExposureEnabled != 0u);
790791
cJSON_AddItemToObject(settingsObject, "environmentColor", createFloatArray(settings->environmentColor, 3u));
@@ -842,6 +843,7 @@ static int applySceneSettings(
842843
uint32_t rrMaxDepth = settings.rrMaxDepth;
843844
uint32_t toneMappingMode = settings.toneMappingMode;
844845
uint32_t renderMode = settings.renderMode;
846+
uint32_t spectralSamplingMode = settings.spectralSamplingMode;
845847
float exposure = settings.exposure;
846848
uint8_t autoExposureEnabled = settings.autoExposureEnabled;
847849
vec3 environmentColor = {
@@ -861,6 +863,7 @@ static int applySceneSettings(
861863
!jsonReadOptionalUInt32Field(settingsObject, "rrMaxDepth", &rrMaxDepth) ||
862864
!jsonReadOptionalUInt32Field(settingsObject, "toneMappingMode", &toneMappingMode) ||
863865
!jsonReadOptionalUInt32Field(settingsObject, "renderMode", &renderMode) ||
866+
!jsonReadOptionalUInt32Field(settingsObject, "spectralSamplingMode", &spectralSamplingMode) ||
864867
!jsonReadOptionalFloatField(settingsObject, "exposure", &exposure) ||
865868
!jsonReadOptionalBoolField(settingsObject, "autoExposureEnabled", &autoExposureEnabled) ||
866869
!jsonReadOptionalFloatArrayField(settingsObject, "environmentColor", environmentColor, 3u) ||
@@ -876,6 +879,7 @@ static int applySceneSettings(
876879
return VKRT_setPathDepth(vkrt, rrMinDepth, rrMaxDepth) == VKRT_SUCCESS &&
877880
VKRT_setToneMappingMode(vkrt, toneMappingMode) == VKRT_SUCCESS &&
878881
VKRT_setRenderMode(vkrt, (VKRT_RenderMode)renderMode) == VKRT_SUCCESS &&
882+
VKRT_setSpectralSamplingMode(vkrt, spectralSamplingMode) == VKRT_SUCCESS &&
879883
VKRT_setExposure(vkrt, exposure) == VKRT_SUCCESS &&
880884
VKRT_setAutoExposureEnabled(vkrt, autoExposureEnabled) == VKRT_SUCCESS &&
881885
VKRT_setEnvironmentLight(vkrt, environmentColor, environmentStrength) == VKRT_SUCCESS &&
@@ -1535,7 +1539,7 @@ static int loadSceneDocument(VKRT* vkrt, Session* session, cJSON* root, const ch
15351539
const cJSON* environmentTexturePath = cJSON_GetObjectItemCaseSensitive(root, "environmentTexturePath");
15361540
uint32_t fileVersion = 0u;
15371541
if (!cJSON_IsString(format) || strcmp(format->valuestring, "vkrt.scene") != 0 ||
1538-
!jsonToUInt32(version, &fileVersion) || fileVersion != K_SCENE_FILE_VERSION ||
1542+
!jsonToUInt32(version, &fileVersion) || fileVersion != K_SCENE_FILE_VERSION ||
15391543
!cJSON_IsArray(meshImportsArray) || (textureImportsArray && !cJSON_IsArray(textureImportsArray)) ||
15401544
!cJSON_IsArray(meshesArray) || !cJSON_IsArray(sceneObjectsArray) || !cJSON_IsObject(settingsObject) ||
15411545
(materialsArray && !cJSON_IsArray(materialsArray)) ||

src/core/api/config.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

3-
#define VKRT_DEFAULT_WIDTH 1600u
4-
#define VKRT_DEFAULT_HEIGHT 900u
5-
#define VKRT_MAX_FRAMES_IN_FLIGHT 2u
3+
enum {
4+
VKRT_DEFAULT_WIDTH = 1600u,
5+
VKRT_DEFAULT_HEIGHT = 900u,
6+
VKRT_MAX_FRAMES_IN_FLIGHT = 2u,
7+
VKRT_FRAMETIME_HISTORY_SIZE = 128u,
8+
};
69

7-
#define VKRT_FRAMETIME_HISTORY_SIZE 128u
8-
9-
#define VKRT_RENDER_VIEW_ZOOM_MIN 1.0f
10-
#define VKRT_RENDER_VIEW_ZOOM_MAX 64.0f
10+
static const float VKRT_RENDER_VIEW_ZOOM_MIN = 1.0f;
11+
static const float VKRT_RENDER_VIEW_ZOOM_MAX = 64.0f;

src/core/api/lifecycle.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#include <GLFW/glfw3native.h>
3434
#include <dwmapi.h>
3535

36-
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
37-
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
36+
#ifdef DWMWA_USE_IMMERSIVE_DARK_MODE
37+
enum { VKRT_DWM_WINDOW_ATTRIBUTE_USE_IMMERSIVE_DARK_MODE = DWMWA_USE_IMMERSIVE_DARK_MODE };
38+
#else
39+
enum { VKRT_DWM_WINDOW_ATTRIBUTE_USE_IMMERSIVE_DARK_MODE = 20 };
3840
#endif
3941
#endif
4042

@@ -388,7 +390,7 @@ static VKRT_Result createRuntimeWindow(
388390
BOOL value = TRUE;
389391
HRESULT hr = DwmSetWindowAttribute(
390392
glfwGetWin32Window(vkrt->runtime.window),
391-
DWMWA_USE_IMMERSIVE_DARK_MODE,
393+
VKRT_DWM_WINDOW_ATTRIBUTE_USE_IMMERSIVE_DARK_MODE,
392394
&value,
393395
sizeof(value)
394396
);

src/core/api/settings.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ VKRT_Result VKRT_setRenderMode(VKRT* vkrt, VKRT_RenderMode renderMode) {
129129
return VKRT_SUCCESS;
130130
}
131131

132+
VKRT_Result VKRT_setSpectralSamplingMode(VKRT* vkrt, uint32_t spectralSamplingMode) {
133+
VKRT_Result stateReady = vkrtRequireSceneStateReady(vkrt);
134+
if (stateReady != VKRT_SUCCESS) return stateReady;
135+
136+
if (spectralSamplingMode >= VKRT_SPECTRAL_SAMPLING_MODE_COUNT) {
137+
return VKRT_ERROR_INVALID_ARGUMENT;
138+
}
139+
140+
if (vkrt->sceneSettings.spectralSamplingMode == spectralSamplingMode) return VKRT_SUCCESS;
141+
vkrt->sceneSettings.spectralSamplingMode = spectralSamplingMode;
142+
resetSceneData(vkrt);
143+
return VKRT_SUCCESS;
144+
}
145+
132146
VKRT_Result VKRT_setExposure(VKRT* vkrt, float exposure) {
133147
VKRT_Result stateReady = vkrtRequireSceneStateReady(vkrt);
134148
if (stateReady != VKRT_SUCCESS) return stateReady;

src/core/api/vkrt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ VKRT_Result VKRT_setAutoSPPEnabled(VKRT* vkrt, uint8_t enabled);
4141
VKRT_Result VKRT_setAutoSPPTargetFPS(VKRT* vkrt, uint32_t targetFPS);
4242
VKRT_Result VKRT_setToneMappingMode(VKRT* vkrt, VKRT_ToneMappingMode toneMappingMode);
4343
VKRT_Result VKRT_setRenderMode(VKRT* vkrt, VKRT_RenderMode renderMode);
44+
VKRT_Result VKRT_setSpectralSamplingMode(VKRT* vkrt, uint32_t spectralSamplingMode);
4445
VKRT_Result VKRT_setExposure(VKRT* vkrt, float exposure);
4546
VKRT_Result VKRT_setAutoExposureEnabled(VKRT* vkrt, uint8_t enabled);
4647
VKRT_Result VKRT_setEnvironmentLight(VKRT* vkrt, vec3 color, float strength);

src/core/api/vkrt_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ typedef struct VKRT_SceneSettingsSnapshot {
127127
uint32_t rrMinDepth;
128128
VKRT_ToneMappingMode toneMappingMode;
129129
VKRT_RenderMode renderMode;
130+
uint32_t spectralSamplingMode;
130131
float exposure;
131132
uint8_t autoExposureEnabled;
132133
uint8_t autoSPPEnabled;

0 commit comments

Comments
 (0)