mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-07-21 14:52:04 +00:00
[client] egl: make native HDR encoding-safe
Request true floating-point EGL configs for scRGB and expose the native encodings supported by the selected surface. Fall back to software HDR mapping when the surface cannot represent the incoming wire format. Resample PQ in linear light, keep SDR-only effects out of native PQ chains, and consume the cursor-specific white level without changing binary monochrome cursor mask operations.
This commit is contained in:
@@ -9,7 +9,7 @@ out vec4 color;
|
||||
|
||||
uniform sampler2D sampler1;
|
||||
uniform float scale;
|
||||
uniform bool mapSDRtoPQ;
|
||||
uniform int wireTransfer; // 0: sRGB, 1: scRGB, 2: PQ
|
||||
uniform float sdrWhiteLevel;
|
||||
|
||||
void main()
|
||||
@@ -30,11 +30,13 @@ void main()
|
||||
if (tmp.rgb == vec3(0.0, 0.0, 0.0))
|
||||
discard;
|
||||
|
||||
if (mapSDRtoPQ)
|
||||
if (wireTransfer == 2)
|
||||
{
|
||||
vec3 linear = bt709to2020(srgb2lin(tmp.rgb));
|
||||
tmp.rgb = lin2pq(linear * (sdrWhiteLevel / 10000.0));
|
||||
}
|
||||
else if (wireTransfer == 1)
|
||||
tmp.rgb = srgb2lin(tmp.rgb) * (sdrWhiteLevel / 80.0);
|
||||
|
||||
color = tmp;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,27 @@ uniform bool mapHDRtoSDR;
|
||||
uniform float mapHDRGain;
|
||||
uniform bool mapHDRPQ;
|
||||
|
||||
vec4 samplePQLinear(vec2 coord)
|
||||
{
|
||||
ivec2 size = textureSize(sampler1, 0);
|
||||
vec2 samplePos = coord * vec2(size) - 0.5;
|
||||
ivec2 base = ivec2(floor(samplePos));
|
||||
vec2 f = fract(samplePos);
|
||||
ivec2 limit = size - ivec2(1);
|
||||
|
||||
vec3 c00 = pq2lin(texelFetch(sampler1,
|
||||
clamp(base, ivec2(0), limit), 0).rgb, 1.0);
|
||||
vec3 c10 = pq2lin(texelFetch(sampler1,
|
||||
clamp(base + ivec2(1, 0), ivec2(0), limit), 0).rgb, 1.0);
|
||||
vec3 c01 = pq2lin(texelFetch(sampler1,
|
||||
clamp(base + ivec2(0, 1), ivec2(0), limit), 0).rgb, 1.0);
|
||||
vec3 c11 = pq2lin(texelFetch(sampler1,
|
||||
clamp(base + ivec2(1, 1), ivec2(0), limit), 0).rgb, 1.0);
|
||||
|
||||
vec3 linear = mix(mix(c00, c10, f.x), mix(c01, c11, f.x), f.y);
|
||||
return vec4(lin2pq(max(linear, 0.0)), 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
switch (scaleAlgo)
|
||||
@@ -39,7 +60,7 @@ void main()
|
||||
|
||||
case EGL_SCALE_LINEAR:
|
||||
{
|
||||
color = texture(sampler1, uv);
|
||||
color = isHDR && mapHDRPQ ? samplePQLinear(uv) : texture(sampler1, uv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -47,10 +68,13 @@ void main()
|
||||
if (isHDR && mapHDRtoSDR)
|
||||
color.rgb = mapToSDR(color.rgb, mapHDRGain, mapHDRPQ);
|
||||
|
||||
if (cbMode > 0)
|
||||
// The legacy effects are defined for an SDR signal. Do not apply them to a
|
||||
// native HDR signal where their nonlinear operations would alter luminance
|
||||
// and gamut incorrectly. They remain available after HDR-to-SDR mapping.
|
||||
if (cbMode > 0 && (!isHDR || mapHDRtoSDR))
|
||||
color = cbTransform(color, cbMode);
|
||||
|
||||
if (nvGain > 0.0)
|
||||
if (nvGain > 0.0 && (!isHDR || mapHDRtoSDR))
|
||||
{
|
||||
highp float lumi = (0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b);
|
||||
if (lumi < 0.5)
|
||||
|
||||
Reference in New Issue
Block a user