Bring the tone mapped HDR picture's settings back to the menu, with defaults that give the look it had while it was fixed.

The sixteen settings the fixed look took away are settings again: the tone mapper choice, gamma correction, mid grey, match tone slope, tone slope, hue clip emulation, exposure, highlights, shadows, contrast, saturation, highlight saturation, blowout, flare, hue correction and colour grading. They have their rows in the settings table with the defaults and ranges they had, their rows in the Screen tab under HDR output's three brightness rows (none of them with the game's own HDR), their texts in the four languages, and their lines in the example ini. The tonemap library has the luminance mapper and the grading of the observer-response mapper again, and the support buffer carries five vec4 for it.

A player who changes nothing sees the picture as before. The observer-response mapper leaves each grading step out when its value is 1, and the slider values are divided, not multiplied by a rounded reciprocal, so 50 and 100 % arrive as exactly 1. Evaluated on the CPU in single precision, the shader with every default gave the same bits as the fixed one for 400,000 random scene colours, gains and whites, in HDR and for the SDR picture; the luminance mapper and the game's curve gave the same bits as before they were removed, and the observer-response mapper with its sliders moved stayed within 0.004 % of the pixel of its old result.

Gamma correction now counts with every tone mapper, 2.2 by default, which is what gave the fixed look its true blacks; before the fixed look it ran with the luminance mapper only and the other two showed the dark tones far above black. Its off value brings that lighter picture back for a player who asks for it. The game's own HDR does not take the setting and stays at 2.2.

Lines for these settings that an nx2navi.ini still holds from before the fixed look count again; the example ini and the release notes say so. Nothing of this was seen in the game.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-14 07:43:43 -05:00
parent 5eef43742d
commit 1e8045b36b
14 changed files with 582 additions and 75 deletions

View File

@@ -1,8 +1,13 @@
// HDR output (NX2NAVI_HDR=1): an HDR10 swapchain (Rec. 2020 primaries, PQ) and a game picture tone mapped to the
// display's range, one fixed look (shaders/hdr_tonemap.frag says which). Settings: NX2NAVI_HDR, on and off following
// the menu during a run (vk_hdr_wanted), the game's own HDR (native, the menu's other HDR) from the start only; and
// the nits NX2NAVI_HDR_PEAK_NITS (the display's peak), NX2NAVI_HDR_GAME_NITS (the picture's white, "paper white") and
// NX2NAVI_HDR_UI_NITS (the HUD's and this menu's white), read when the settings change (vk_hdr_support). With
// display's range (shaders/hdr_tonemap.frag says how). Settings: NX2NAVI_HDR, on and off following the menu during a
// run (vk_hdr_wanted), the game's own HDR (native, the menu's other HDR) from the start only; the nits
// NX2NAVI_HDR_PEAK_NITS (the display's peak), NX2NAVI_HDR_GAME_NITS (the picture's white, "paper white") and
// NX2NAVI_HDR_UI_NITS (the HUD's and this menu's white); NX2NAVI_HDR_TONEMAP with what each tone mapper takes
// (NX2NAVI_HDR_MIDGRAY, NX2NAVI_HDR_MATCH_SLOPE, NX2NAVI_HDR_TONE_SLOPE and NX2NAVI_HDR_HUE_CLIP, or
// NX2NAVI_HDR_HIGHLIGHT_SAT .. NX2NAVI_HDR_GRADE), the grading sliders NX2NAVI_HDR_EXPOSURE .. NX2NAVI_HDR_SATURATION
// of both and NX2NAVI_HDR_GAMMA, the display the present shows the picture as; all read when the settings change
// (vk_hdr_support). Left at their defaults they give one look: the observer-response mapper anchored to the game's mid
// grey and tone slope, half of the hue bend of the game's clamp, no grading, shown as a 2.2 display would. With
// NX2NAVI_HDR=0 the swapchain is SDR, the spliced tonemap gives the game's own SDR picture (vk_hdr_support, p0.w = -1)
// and the present is what it was.
//
@@ -12,10 +17,10 @@
// 1. vk_hdr_shader_swap, on each fragment shader as it loads (in memory only; the cache keeps the translator's): 1.1.1's
// tonemap ends in the fitted ACES curve and a clamp to 0..1 per channel. tonemap_splice links the function
// nx_tonemap of shaders/hdr_tonemap.frag into that shader and stores its result in place of the three clamped
// channels: the scene mapped onto the display (that file says how), from the values the curve takes and the scene
// before the game's exposure gain, with the settings in a vec4 the support buffer gains at 1440. Recognised by the curve's constants, not by a hash, so
// another translator still finds it. The game's FSR 1 upscale after it would clamp the picture to 1 again;
// fsr_unclamp drops that clamp in its SPIR-V.
// channels: the scene mapped onto the display by the tone mapper chosen (that file says how each does it), from the
// values the curve takes and the scene before the game's exposure gain, with the settings in five vec4 the support
// buffer gains at 1440. Recognised by the curve's constants, not by a hash, so another translator still finds it.
// The game's FSR 1 upscale after it would clamp the picture to 1 again; fsr_unclamp drops that clamp in its SPIR-V.
// 2. vk_hdr_draw / vk_hdr_present_source: a draw into a presented window texture that samples one float texture of
// its size is that copy; the present then reads the float texture instead of the window texture. Any other last
// draw into it leaves the window texture, decoded from sRGB: menus and movies stay SDR at the HUD's white.
@@ -104,13 +109,17 @@ void vk_hdr_off(void) { g_native = 0, g_armed = 0; }
// that encode decodes, its darkest tones sit up to a hundred times above where such a display puts them (a scene
// value of 0.001, 0.08 nits at a white of 350 nits against 0.001), the floor of a dark scene lifted to grey. So the
// present shows the picture as a 2.2 display would (hdr_encode.comp, hdr_ui.frag: the power 2.2 of the sRGB code),
// and the tonemap aims its peak below the display's by that correction's inverse (hdr_tonemap.frag nx_tonemap).
#define HDR_GAMMA 1.0f // the present's correction: 0 none, 1: 2.2, 2: 2.4
// and the tonemap aims its peak below the display's by that correction's inverse (hdr_tonemap.frag
// peak_before_gamma). That holds for every tone mapper and is the default of NX2NAVI_HDR_GAMMA, which can make it 2.4
// or switch it off (the picture as its sRGB code decodes, the dark tones lighter). The game's own HDR does not take
// the setting: what the present still encodes there (the menu, the 8-bit pictures before the game's switch) is shown
// as a 2.2 display would.
#define HDR_GAMMA_22 1.0f // the present's correction: 0 none, 1: 2.2, 2: 2.4
typedef struct {
float peak, game, ui; // nits
float gamma; // HDR_GAMMA (hdr_encode.comp, hdr_ui.frag)
float tm[4]; // the support buffer's vec4 (shaders/hdr_tonemap.frag p0)
float gamma; // the present's correction, as HDR_GAMMA_22 numbers it (hdr_encode.comp, hdr_ui.frag)
float tm[20]; // the support buffer's five vec4 (shaders/hdr_tonemap.frag p0..p4)
} Nits;
static struct { unsigned seen; int cur; Nits snap[2]; PlatMutex lock; } N = {.seen = ~0u, .lock = PLAT_MUTEX_INIT};
@@ -125,8 +134,34 @@ static Nits nits(void) {
n->peak = clampf((float)cfg_double("NX2NAVI_HDR_PEAK_NITS"), 80.0f, 10000.0f);
n->game = clampf((float)cfg_double("NX2NAVI_HDR_GAME_NITS"), 48.0f, 500.0f);
n->ui = clampf((float)cfg_double("NX2NAVI_HDR_UI_NITS"), 48.0f, 500.0f);
n->gamma = HDR_GAMMA;
n->tm[0] = n->peak, n->tm[1] = n->game, n->tm[2] = n->ui, n->tm[3] = 1.0f;
// the tone mapper as shaders/hdr_tonemap.frag numbers it: the game's curve, the luminance mapper, the
// observer-response mapper (the default, and what any other value gives)
const char *tm = cfg_value("NX2NAVI_HDR_TONEMAP");
float mapper = !strcmp(tm, "vanilla") ? 0.0f : !strcmp(tm, "renodrt") ? 3.0f : 9.0f;
const char *g = cfg_value("NX2NAVI_HDR_GAMMA");
n->gamma = vk_hdr_native() ? HDR_GAMMA_22
: !strcmp(g, "off") || !strcmp(g, "0") ? 0.0f : !strcmp(g, "2.4") ? 2.0f : HDR_GAMMA_22;
// The sliders' 0..100 with 50 unchanged become factors around 1; blowout, hue, grade and hue clip are
// fractions. Divided, not multiplied by a rounded reciprocal: 50 and 100 % come out as exactly 1, which
// the shader compares for to leave a grading step out.
float pct[10];
static const char *const keys[10] = {"NX2NAVI_HDR_HIGHLIGHTS", "NX2NAVI_HDR_SHADOWS", "NX2NAVI_HDR_CONTRAST",
"NX2NAVI_HDR_SATURATION", "NX2NAVI_HDR_HIGHLIGHT_SAT", "NX2NAVI_HDR_BLOWOUT",
"NX2NAVI_HDR_FLARE", "NX2NAVI_HDR_HUE", "NX2NAVI_HDR_TONE_SLOPE",
"NX2NAVI_HDR_HUE_CLIP"};
for (int i = 0; i < 10; i++) pct[i] = clampf((float)cfg_double(keys[i]), 0.0f, 100.0f);
float *t = n->tm;
t[0] = n->peak, t[1] = n->game, t[2] = n->ui;
t[3] = mapper;
t[4] = clampf((float)cfg_double("NX2NAVI_HDR_EXPOSURE"), 0.0f, 200.0f) / 100.0f;
t[5] = pct[0] / 50.0f, t[6] = pct[1] / 50.0f, t[7] = pct[2] / 50.0f;
t[8] = pct[3] / 50.0f, t[9] = pct[4] / 50.0f, t[10] = pct[5] / 100.0f, t[11] = pct[6] / 50.0f;
t[12] = pct[7] / 100.0f;
t[13] = clampf((float)cfg_double("NX2NAVI_HDR_GRADE"), 0.0f, 100.0f) / 100.0f;
t[14] = n->gamma, t[15] = pct[8] / 50.0f;
t[16] = pct[9] / 100.0f;
t[17] = !strcmp(cfg_value("NX2NAVI_HDR_MIDGRAY"), "render") ? 0.0f : 1.0f;
t[18] = cfg_bool("NX2NAVI_HDR_MATCH_SLOPE") ? 1.0f : 0.0f, t[19] = 0;
__atomic_store_n(&N.cur, !N.cur, __ATOMIC_RELEASE);
__atomic_store_n(&N.seen, v, __ATOMIC_RELEASE);
}
@@ -135,7 +170,7 @@ static Nits nits(void) {
return N.snap[__atomic_load_n(&N.cur, __ATOMIC_ACQUIRE)];
}
void vk_hdr_support(float out[4]) {
void vk_hdr_support(float out[20]) {
Nits n = nits();
memcpy(out, n.tm, sizeof n.tm);
if (!vk_hdr_active()) out[3] = -1.0f; // no HDR10 swapchain (yet): the game's own SDR picture
@@ -420,7 +455,7 @@ static int spv_top_level(const uint32_t *w, uint64_t first_label, uint64_t end,
// translator's SupportBuffer ends there). The library's types are matched to the game's where the same (SPIR-V allows
// one declaration of each), its constants and functions appended with new ids. Gives up (0) on any shape it does not
// expect, and the shader stays as it was.
enum { HDR_SETS = 1, HDR_PARAMS = HDR_SETS + 2 }; // nx_tonemap(vec3 x, vec4 scene, vec4 settings[HDR_SETS])
enum { HDR_SETS = 5, HDR_PARAMS = HDR_SETS + 2 }; // nx_tonemap(vec3 x, vec4 scene, vec4 settings[HDR_SETS])
static int tonemap_splice(uint32_t **spirv, uint64_t *words) {
uint32_t *w = *spirv;
uint64_t n = *words;