mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-07-21 14:52:04 +00:00
egl: correct ImGui overlay luminance in HDR
Render ImGui to an intermediate SDR framebuffer and map it into the native PQ or scRGB output using the Wayland surface reference white. Preserve premultiplied alpha during conversion and limit composition to damaged overlay regions.
This commit is contained in:
35
client/renderers/EGL/shader/hdr_overlay.frag
Normal file
35
client/renderers/EGL/shader/hdr_overlay.frag
Normal file
@@ -0,0 +1,35 @@
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
|
||||
#include "hdr.h"
|
||||
|
||||
in vec2 fragCoord;
|
||||
out vec4 color;
|
||||
|
||||
uniform sampler2D sampler1;
|
||||
uniform bool pq;
|
||||
uniform float referenceWhiteLevel;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = texture(sampler1, fragCoord);
|
||||
if (color.a <= 0.0)
|
||||
{
|
||||
color.rgb = vec3(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
// ImGui's framebuffer contains premultiplied sRGB. Convert the straight
|
||||
// color, then premultiply again for composition onto the HDR framebuffer.
|
||||
vec3 linear = srgb2lin(clamp(color.rgb / color.a, 0.0, 1.0));
|
||||
if (pq)
|
||||
{
|
||||
linear = bt709to2020(linear);
|
||||
color.rgb = lin2pq(linear * (referenceWhiteLevel / 10000.0)) * color.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
// scRGB is linear sRGB and defines 1.0 as 80 nits.
|
||||
color.rgb = linear * (referenceWhiteLevel / 80.0) * color.a;
|
||||
}
|
||||
}
|
||||
13
client/renderers/EGL/shader/hdr_overlay.vert
Normal file
13
client/renderers/EGL/shader/hdr_overlay.vert
Normal file
@@ -0,0 +1,13 @@
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
|
||||
layout(location = 0) in vec3 vertex;
|
||||
layout(location = 1) in vec2 coord;
|
||||
|
||||
out vec2 fragCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(vertex, 1.0);
|
||||
fragCoord = coord;
|
||||
}
|
||||
Reference in New Issue
Block a user