Triforce v0.2.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ruckus7382sfgsgdf
2026-11-10 19:32:48 -06:00
commit 34b3683441
1730 changed files with 554853 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#version 450
// (hookshot) HDR10 out (the Insert menu's HDR): the game's finished picture, SDR and sRGB-encoded, to PQ in Rec. 2020 for an HDR10
// swapchain. White in the picture is shown at the paper white (nits); its highlights are expanded towards the peak brightness, the
// brightest part of the picture reaching the peak, the rest at the paper white as the game made it. Scaled from its crop as the blit was.
layout(local_size_x = 8, local_size_y = 8) in;
layout(binding = 0) uniform sampler2D src;
layout(binding = 1, rgb10_a2) uniform writeonly image2D dst;
layout(push_constant) uniform P {
vec4 uv; // the source's crop: x0, y0, x1, y1 (0 to 1)
float white; // paper white, nits
float peak; // peak brightness, nits
float knee; // where the highlights start to be expanded (0 to 1 of the picture's white)
float pad;
} pc;
vec3 srgb_to_linear(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;
const vec3 l = pow(clamp(nits / 10000.0, 0.0, 1.0), vec3(m1));
return pow((c1 + c2 * l) / (1.0 + c3 * l), vec3(m2));
}
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 vec3 lin = srgb_to_linear(clamp(textureLod(src, mix(pc.uv.xy, pc.uv.zw, t), 0.0).rgb, 0.0, 1.0));
// (the highlights: past the knee the light rises with the square of how far it is past it, to the peak at the picture's white)
const float y = dot(lin, vec3(0.2126, 0.7152, 0.0722));
const float over = clamp((y - pc.knee) / max(1.0 - pc.knee, 1e-3), 0.0, 1.0);
const float gain = 1.0 + (pc.peak / pc.white - 1.0) * over * over;
// (Rec. 709 primaries to Rec. 2020's, ITU-R BT.2087)
const mat3 to2020 = mat3(0.6274, 0.0691, 0.0164, 0.3293, 0.9195, 0.0880, 0.0433, 0.0114, 0.8956);
const vec3 nits = max(to2020 * lin, vec3(0.0)) * pc.white * gain;
imageStore(dst, at, vec4(pq(nits), 1.0));
}