The HDR hue setting drives the RenoDX colour reconstruction, its matrix chains fold at compile time, and the notices name the adapted code

hdr_hue (TOTK_HDR_HUE) scales the MacLeod-Boynton hue and purity transfer that replaced #442's blend: the default
moves from 80 to 70, where the transfer is RenoDX's default 70% hue shift and 65% SDR blowout, and 0 turns it off
as the menu text says. The shader's two-step colour space conversions become one constant matrix each and the D65
white point a constant, which halves its matrix-vector products. THIRD_PARTY_NOTICES.md and vk_hdr.c now say the
reconstruction is adapted from RenoDX at 43c067b, MIT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-12 23:21:04 +03:00
1 parent 9902e01aae
commit 97dd94eb99
6 files changed
+1034 -1053

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ Code copied or adapted from another project is listed here with its source, the
| MacNativeGames TotK 1.2.1 cursor and aim steps: the map cursor, vertical Ultrahand aim and vertical gyro aim sites, their instruction words and the step scaled by the frame ratio | https://github.com/ly05010419/MacNativeGames @ `363a6eb50434387f7d623349934bcf1e910be48f` (`games/totk/runtime/game_patches.c` patch_cursor_speed), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v121.txt`, `recomp/patches-v110.txt` (set cursor) |
| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt`, `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) |
| MacNativeGames TotK button icons: the Xbox controller's shoulder buttons, triggers, Menu, View and d-pad drawn with letters from the game's own text fonts, the .bfotf key, the button guide's images and their block-linear layout, the resource size table raised for the archives that grew | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/scripts/make_button_icons.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/button_icons.py`, `tools/make_romfs_patches.py` (--prompts) |
| RenoDX TotK mod (game mod by souperman9, tonemapper by Musa, RenoDX framework by ShortFuse, RenoVK fork by Ritsu): the approach of the HDR tonemap (the game's 1 - e^-x curve kept below a pivot and continued along its tangent above it, the saturation grade applied to the colour scaled into 0..1) and the observation that the passes after the tonemap keep values above 1. No code copied; the shader is our own | https://github.com/clshortfuse/renodx @ `b6f87272ad1bfdc0e6444910a93606815944a085` (`src/games/totk/tonemap.slang`, `addon.cpp`), Copyright (c) 2025 Carlos Lopez Jr. | MIT | `runtime/shaders/hdr_tonemap.frag`, `runtime/vk_hdr.c` |
| RenoDX TotK mod (game mod by souperman9, tonemapper by Musa, RenoDX framework by ShortFuse, RenoVK fork by Ritsu): the HDR tonemap's colour reconstruction (the game's 1 - e^-x curve continued along its tangent above 0.18, the SDR result as hue and purity donor through MacLeod-Boynton in BT.2020, the saturation grade on a Neutwo-compressed colour, per-channel Neutwo to the peak in BT.2020, the sRGB to gamma 2.2 correction) adapted into GLSL, and the observation that the passes after the tonemap keep values above 1 | https://github.com/clshortfuse/renodx @ `43c067b755a6a741f6500b2b936570f1462dcfbe` (`src/games/totk/tonemap.slang`, `src/games/totk/macleod_boynton.hlsli`, `src/shaders/colorcorrect.hlsl`, `src/shaders/tonemap/neutwo.hlsl`), Copyright (c) 2025 Carlos Lopez Jr. | MIT | `runtime/shaders/hdr_tonemap.frag`, `runtime/vk_hdr.c` |
| TOTK-Ultrawide, the community mod for emulators: the list of UI panes the ultrawide layout edits and the distances they move (data only, no code copied; the edit code is our own, and MacNativeGames' `ultrawide_layout.py` in the row above already carries the same values). The mod's repository URL and licence version are not recorded in this repository | TOTK-Ultrawide (community mod; URL not recorded here) | GPL (version not recorded here) | `tools/ultrawide_layout.py` (`KEEP_ROOT`, `edits`, `anim_edits`) |
| MacNativeGames TotK virtual-core preemption: asynchronous preemption of an owner in top-level game code, priority inheritance through guest mutexes, the SDK's preemption-disable protocol (TLR+0x100/+0x102, SVC 0x36), the core-wait diagnostics | https://github.com/ly05010419/MacNativeGames @ `33e8fa83052ea1ae09a3583137008e9797e12950` (`games/totk/runtime/threads.c`, commits 8bf0893 and 19730cd), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/kernel.c` (SuspendThread and a register-saving stub replace SIGUSR2), `runtime/hostfn.c`, `runtime/svc.c` (host depth) |
| MacNativeGames RomFS index builder (`TOTKRFS1` layout) | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/scripts/prepare_romfs_backend.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/romfs_index.py` |
+1 -1
View File
@@ -146,7 +146,7 @@ static const CfgMeta metas[] = {
{"COLOR_GAMMA", "1", "0.8..1.2", LIVE},
// HDR output (vk_hdr.c): on at start (the tonemap shader is swapped as shaders load); the nits apply at once
{"HDR", "0", "0|1", RESTART}, {"HDR_PEAK_NITS", "1000", "400..10000", LIVE}, {"HDR_GAME_NITS", "203", "80..500", LIVE},
{"HDR_UI_NITS", "203", "80..500", LIVE}, {"HDR_HUE", "80", "0..100", LIVE},
{"HDR_UI_NITS", "203", "80..500", LIVE}, {"HDR_HUE", "70", "0..100", LIVE},
{"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART},
{"SHADOW_RES", "game", "game|256|512|768|1024|1536|2048", RESTART},
{"SHADOW_SCALE", "1", "1..4", RESTART},
+1003 -1026
View File
File diff suppressed because it is too large. Load diff
+26 -22
View File
@@ -8,8 +8,10 @@
// The HDR reconstruction follows RenoDX's TotK defaults more closely than the original recomp implementation:
// - the game's 1 - e^-x tone curve is extended along its tangent above 0.18;
// - the vanilla SDR tonemap is kept as a donor for hue and purity;
// - MacLeod-Boynton hue/purity transfer is performed through XYZ/LMS in BT.2020, using RenoDX's default 70% hue
// emulation and 65% SDR blowout;
// - MacLeod-Boynton hue/purity transfer is performed through XYZ/LMS in BT.2020. hdr.z (TOTK_HDR_HUE, 0..1) scales
// both: at its default 0.7 the hue moves 70% and the purity 65% of the way to the SDR donor, RenoDX's defaults
// ("Hue Shift" and "SDR Blowout"); at 0 bright colours keep the extended curve's saturation. This replaces the
// earlier blend towards the SDR result scaled to the HDR luminance, which the same setting drove;
// - the game's saturation grade is applied after a temporary neutral max-channel compression, then expanded back;
// - the result is constrained to non-negative BT.709 and display-mapped with per-channel Neutwo in linear BT.2020;
// - RenoDX's default 2.2 gamma correction is folded into the native linear path: the Neutwo peak is corrected before
@@ -26,7 +28,7 @@ layout(location = 0) out vec4 color;
layout(set = 0, binding = 0, std140) uniform SupportBuffer {
vec4 pad[90];
vec4 hdr; // byte 1440 (vk_exec_draw.c support_fill): game white / HUD white, peak / game white
vec4 hdr; // byte 1440 (vk_exec_draw.c support_fill): game white / HUD white, peak / game white, hue correction
} support_buffer;
layout(set = 0, binding = 1) uniform sampler2D fp_t_tcb_8;
layout(set = 0, binding = 2) uniform sampler2D fp_t_tcb_A;
@@ -34,8 +36,7 @@ layout(set = 0, binding = 3, std140) uniform C1 { vec4 v[4096]; } fp_c1;
layout(set = 0, binding = 4, std140) uniform C3 { vec4 v[4096]; } fp_c3;
const float PIVOT = 0.18;
const float HUE_STRENGTH = 0.70;
const float PURITY_STRENGTH = 0.65;
const float PURITY_PER_HUE = 0.65 / 0.70; // RenoDX's default SDR blowout against its default hue shift
const float GAMMA = 2.2;
const float MB_EPSILON = 1e-20;
const float MB_INTERVAL_MAX = 1e30;
@@ -67,13 +68,21 @@ const mat3 XYZ_TO_BT2020 = mat3(
vec3(1.7166511880, -0.6666843518, 0.0176398574),
vec3(-0.3556707838, 1.6164812366, -0.0427706133),
vec3(-0.2533662814, 0.0157685458, 0.9421031212));
// The chains the per-pixel code uses, folded at compile time: one matrix per conversion instead of two.
const mat3 BT709_TO_BT2020 = XYZ_TO_BT2020 * BT709_TO_XYZ;
const mat3 BT2020_TO_BT709 = XYZ_TO_BT709 * BT2020_TO_XYZ;
const mat3 BT2020_TO_LMS = XYZ_TO_LMS_2006 * BT2020_TO_XYZ;
const mat3 LMS_TO_BT2020 = XYZ_TO_BT2020 * LMS_TO_XYZ_2006;
// D65 white (x 0.31272, y 0.32903) in LMS, and its MacLeod-Boynton coordinates (l, s) = (L, S) / (L + M).
const vec3 WHITE_LMS = XYZ_TO_LMS_2006 * vec3(0.31272 / 0.32903, 1.0, (1.0 - 0.31272 - 0.32903) / 0.32903);
const vec2 MB_WHITE = vec2(WHITE_LMS.x, WHITE_LMS.z) / (WHITE_LMS.x + WHITE_LMS.y);
float maxc(vec3 c) { return max(c.r, max(c.g, c.b)); }
float minc(vec3 c) { return min(c.r, min(c.g, c.b)); }
float div_safe(float a, float b, float fallback) { return b == 0.0 ? fallback : a / b; }
vec3 to_bt2020(vec3 c) { return XYZ_TO_BT2020 * (BT709_TO_XYZ * c); }
vec3 to_bt709(vec3 c) { return XYZ_TO_BT709 * (BT2020_TO_XYZ * c); }
vec3 to_bt2020(vec3 c) { return BT709_TO_BT2020 * c; }
vec3 to_bt709(vec3 c) { return BT2020_TO_BT709 * c; }
// RenoDX GammaSafe(c, true, 2.2): sRGBDecode(GammaEncode(c, 2.2)). Used on the peak ratio before Neutwo.
float srgb_decode(float c) {
@@ -140,12 +149,6 @@ vec3 lms_from_mb_t(vec2 mb, float t) {
return vec3(mb.x * t, (1.0 - mb.x) * t, mb.y * t);
}
vec2 mb_white_d65() {
const vec2 xy = vec2(0.31272, 0.32903);
vec3 xyz = vec3(xy.x / xy.y, 1.0, (1.0 - xy.x - xy.y) / xy.y);
return mb_from_lms(XYZ_TO_LMS_2006 * xyz);
}
void interval_lower_zero(float a, float b, out float lo, out float hi) {
if (abs(a) < MB_EPSILON) {
if (b >= 0.0) {
@@ -179,15 +182,15 @@ MBResult mb_apply_bt2020(vec3 rgb, float purity_value) {
outv.rgb = rgb;
outv.purity = 0.0;
vec3 lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * rgb);
vec3 lms = BT2020_TO_LMS * rgb;
float t = lms.x + lms.y;
if (t <= MB_T_MIN) return outv;
vec2 white = mb_white_d65();
vec2 white = MB_WHITE;
vec2 direction = mb_from_lms(lms) - white;
if (dot(direction, direction) < MB_NEAR_WHITE_EPSILON) return outv;
vec3 rgb_white = XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * lms_from_mb_t(white, t));
vec3 rgb_white = LMS_TO_BT2020 * lms_from_mb_t(white, t);
vec3 a = rgb - rgb_white;
float t_lo = 0.0, t_hi = MB_INTERVAL_MAX, lo, hi;
@@ -203,7 +206,7 @@ MBResult mb_apply_bt2020(vec3 rgb, float purity_value) {
outv.purity = t_max > MB_EPSILON ? clamp(1.0 / t_max, 0.0, 1.0) : 0.0;
float t_final = clamp(purity_value, 0.0, 1.0) * t_max;
vec3 lms_final = lms_from_mb_t(white + t_final * direction, t);
outv.rgb = max(XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * lms_final), vec3(0.0));
outv.rgb = max(LMS_TO_BT2020 * lms_final, vec3(0.0));
return outv;
}
@@ -223,7 +226,7 @@ vec3 correct_hue_and_purity(vec3 target709, vec3 reference709, float hue_strengt
vec3 target2020 = to_bt2020(target709);
vec3 reference2020 = to_bt2020(reference709);
vec3 target_lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * target2020);
vec3 target_lms = BT2020_TO_LMS * target2020;
float target_t = target_lms.x + target_lms.y;
if (target_t <= MB_T_MIN) return target709;
@@ -231,8 +234,8 @@ vec3 correct_hue_and_purity(vec3 target709, vec3 reference709, float hue_strengt
float reference_purity = mb_apply_bt2020(reference2020, 1.0).purity;
float applied_purity = mix(target_purity, reference_purity, clamp(purity_strength, 0.0, 1.0));
vec3 reference_lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * reference2020);
vec2 white = mb_white_d65();
vec3 reference_lms = BT2020_TO_LMS * reference2020;
vec2 white = MB_WHITE;
vec2 target_direction = mb_from_lms(target_lms) - white;
vec2 reference_direction = mb_from_lms(reference_lms) - white;
float target_len_sq = dot(target_direction, target_direction);
@@ -261,7 +264,7 @@ vec3 correct_hue_and_purity(vec3 target709, vec3 reference709, float hue_strengt
seed_len = max(seed_len, 1e-6);
vec3 seed_lms = lms_from_mb_t(white + blended_unit * seed_len, target_t);
vec3 seed2020 = XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * seed_lms);
vec3 seed2020 = LMS_TO_BT2020 * seed_lms;
return to_bt709(mb_apply_bt2020(seed2020, applied_purity).rgb);
}
@@ -305,7 +308,8 @@ void main() {
// Extended HDR carrier plus the original bounded SDR rendering used as RenoDX's color donor.
vec3 c = extended_vanilla_tonemap(x);
vec3 donor = clamp(vanilla_tonemap(x), vec3(0.0), vec3(1.0));
c = correct_hue_and_purity(c, donor, HUE_STRENGTH * hue_transfer_gate(donor), PURITY_STRENGTH);
float hue = clamp(support_buffer.hdr.z, 0.0, 1.0);
c = correct_hue_and_purity(c, donor, hue * hue_transfer_gate(donor), hue * PURITY_PER_HUE);
// RenoDX temporarily compresses the largest channel with neutral Neutwo while the original TotK saturation grade
// runs, then divides the compression back out. This avoids feeding the SDR-authored grade arbitrarily large HDR RGB.
+2 -2
View File
@@ -18,8 +18,8 @@
// 3. vk_hdr_encode: on the present, the crop rectangle goes to PQ code values in an RGBA16F image (shaders/hdr_encode.comp)
// that FSR 1 or the blit scale into the swapchain. vk_hdr_ui_*: the in-game menu draws into an RGBA8 image and
// shaders/hdr_ui.frag blends it onto the swapchain at the HUD's white.
// The tonemap's approach is RenoDX's TotK mod by souperman9 and Musa on ShortFuse's RenoDX (github.com/clshortfuse/renodx,
// src/games/totk, MIT); the code is ours.
// The tonemap's colour reconstruction is adapted from RenoDX's TotK mod by souperman9 and Musa on ShortFuse's RenoDX
// (github.com/clshortfuse/renodx, src/games/totk, MIT; THIRD_PARTY_NOTICES.md); the rest of this file is ours.
#include "vk.h"
#include <math.h>
+1 -1
View File
@@ -291,7 +291,7 @@
# hdr_ui_nits = 203
# Highlight hue correction in percent (0 to 100): bright colours such as fire turn towards white as in the game's SDR
# picture, matching the light they cast; 0 keeps them fully saturated. Changes take effect at once.
# hdr_hue = 80
# hdr_hue = 70
[language]
# Language: a Windows locale such as de-DE, or a Switch code (en-US, ja, zh-Hant, ...). Default: the Windows locale.