mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-15 19:19:58 -04:00
The game's ACES tonemap shader gets a GLSL function linked into its SPIR-V where it clamps each channel: the game's SDR result upgraded to the HDR range by luminance and mapped to the display with the RenoDRT curve, exposure, highlights, shadows, contrast, saturation, highlight saturation, blowout, flare and hue correction. The settings reach it as four vec4 the support buffer gains at 1440. The present encode is a port of the swap chain pass: gamma correction, gamut compression, the peak clamp and PQ. Without an HDR10 swapchain the shader gives the game's own SDR picture; native HDR is unchanged. The menu offers Off, RenoDX and Native, with gamma correction, the tone mapper and its grading rows. The shader build compiles sources marked "keep functions" without optimisation so their functions survive for the splice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.5 KiB
GLSL
30 lines
1.5 KiB
GLSL
#version 450
|
|
// The in-game menu on an HDR10 swapchain (runtime/vk_hdr.c vk_hdr_ui_compose): ImGui drew it into an RGBA8 image,
|
|
// premultiplied sRGB colour over a clear 0; this turns each pixel back into its colour (with the picture's gamma
|
|
// correction p.y: 0 none, 1: 2.2, 2: 2.4, as shaders/hdr_encode.comp applies it), puts its white at p.x nits and
|
|
// writes the PQ code with its coverage, which the pipeline blends over the picture (in PQ code values, as the menu
|
|
// blends in sRGB code values on an SDR swapchain). PQ: SMPTE ST 2084; Rec. 709 to Rec. 2020: ITU-R BT.2087.
|
|
layout(location = 0) in vec2 uv;
|
|
layout(location = 0) out vec4 color;
|
|
layout(binding = 0) uniform sampler2D ui;
|
|
layout(push_constant) uniform P { vec4 p; } pc;
|
|
|
|
vec3 srgb_decode(vec3 c) {
|
|
return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), greaterThan(c, vec3(0.04045)));
|
|
}
|
|
|
|
vec3 pq(vec3 nits) {
|
|
const float m1 = 0.1593017578125, m2 = 78.84375, c1 = 0.8359375, c2 = 18.8515625, c3 = 18.6875;
|
|
vec3 y = pow(clamp(nits / 10000.0, 0.0, 1.0), vec3(m1));
|
|
return pow((c1 + c2 * y) / (1.0 + c3 * y), vec3(m2));
|
|
}
|
|
|
|
void main() {
|
|
vec4 u = texture(ui, uv);
|
|
if (u.a <= 0.0) discard;
|
|
vec3 code = clamp(u.rgb / u.a, 0.0, 1.0);
|
|
vec3 c = pc.p.y == 1.0 ? pow(code, vec3(2.2)) : pc.p.y == 2.0 ? pow(code, vec3(2.4)) : srgb_decode(code);
|
|
const mat3 to2020 = mat3(0.6274, 0.0691, 0.0164, 0.3293, 0.9195, 0.0880, 0.0433, 0.0114, 0.8956);
|
|
color = vec4(pq(max(to2020 * c, vec3(0.0)) * pc.p.x), u.a);
|
|
}
|