Files
Triforce-Source/gpu/vk/shaders/colour_vision.comp
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

47 lines
2.6 KiB
Plaintext

#version 450
// ((Triforce) 11-24) The Display tab's Colour vision correction (vk_framegen.cpp framegen_scale): the finished SDR picture,
// sRGB-encoded, scaled from its crop to the window's size as the blit is, with the colours a red-green (protan, deutan) or a
// blue-yellow (tritan) colour vision deficiency confuses moved onto an axis it sees. Luminance-preserving and pixel-local, in
// linear light: the error rows are of I - S, S Machado et al.'s severity-1 Rec. 709 simulation; the error goes onto a visible
// opponent axis, and the chroma is drawn in towards neutral where it would leave the display's gamut. Neutral greys and the
// luminance stay as they are.
layout(local_size_x = 8, local_size_y = 8) in;
layout(binding = 0) uniform sampler2D src;
layout(binding = 1, rgba8) uniform writeonly image2D dst;
layout(push_constant) uniform P {
vec4 uv; // the source's crop: x0, y0, x1, y1 (0 to 1)
int mode; // 1 protan, 2 deutan, 3 tritan (0: the picture as it is)
} pc;
const vec3 Y709 = vec3(0.2126, 0.7152, 0.0722);
vec3 decode_srgb(vec3 c) {
return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), greaterThan(c, vec3(0.04045)));
}
vec3 encode_srgb(vec3 c) {
return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, greaterThan(c, vec3(0.0031308)));
}
vec3 correct(vec3 c, int mode) {
if (mode < 1 || mode > 3) return c;
const vec3 error_row = mode == 1 ? vec3(0.847714, 0.0, 0.204868)
: mode == 2 ? vec3(0.632678, 0.0, 0.227968) : vec3(-0.004733, 0.0, 0.696100);
// (green taken off first, so the rounded coefficients keep a neutral colour neutral)
const float error = dot(c - c.g, error_row);
const float yellow = -Y709.b / (1.0 - Y709.b);
const vec3 axis = mode == 3 ? vec3(1.0, -Y709.r / Y709.g, 0.0) : vec3(yellow, yellow, 1.0);
const vec3 corrected = c + 0.75 * error * (axis - dot(axis, Y709));
const float y = dot(c, Y709);
const vec3 chroma = corrected - y;
const float low = min(chroma.r, min(chroma.g, chroma.b));
const float high = max(chroma.r, max(chroma.g, chroma.b));
const float s = min(1.0, min(y / max(-low, 1e-9), (1.0 - y) / max(high, 1e-9)));
return clamp(y + max(s, 0.0) * chroma, 0.0, 1.0);
}
void main() {
const ivec2 size = imageSize(dst);
const ivec2 at = ivec2(gl_GlobalInvocationID.xy);
if (at.x >= size.x || at.y >= size.y) return;
const vec2 t = (vec2(at) + 0.5) / vec2(size);
const vec4 pixel = textureLod(src, mix(pc.uv.xy, pc.uv.zw, t), 0.0);
const vec3 light = decode_srgb(clamp(pixel.rgb, 0.0, 1.0));
imageStore(dst, at, vec4(encode_srgb(correct(light, pc.mode)), 1.0));
}