qt5base-lts/tests/manual/rhi/hdr/hdrtexture.frag
Laszlo Agocs 547b9da7ad rhi: Enhance the hdr info struct and add a manual test
...while sharing the related code between the d3d backends.

The isHardCodedDefaults flag is not used in practice and is
now removed. Add the luminance behavior and SDR white level
(for Windows) to help creating portable 2D/3D renderers that
composite SDR and HDR content. (sadly the Windows HDR and Apple
EDR behavior is different, as usual)

The new test application is expected to run with the command-line
argument "scrgb" or "sdr". It allows seeing SDR content correction
(on Windows) in action, and has some simple HDR 3D content with
a basic, optional tonemapper. Also shows the platform-dependent
HDR-related screen info. With some helpful tooltips even.

Additionally, it needs a .hdr file after the 'file' argument.
The usual -d, -D, -v, etc. arguments apply to select the 3D API.

For example, to run with D3D12 in HDR mode:

hdr -D scrgb file image.hdr

The same in non-HDR mode:

hdr -D sdr file image.hdr

Change-Id: I7fdfc7054cc0352bc99398fc1c7b1e2f0874421f
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2023-08-03 12:17:25 +02:00

45 lines
1.0 KiB
GLSL

#version 440
layout(location = 0) in vec2 v_texcoord;
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
int flip;
int sdr;
float tonemapInMax;
float tonemapOutMax;
} ubuf;
layout(binding = 1) uniform sampler2D tex;
vec3 linearToSRGB(vec3 color)
{
vec3 S1 = sqrt(color);
vec3 S2 = sqrt(S1);
vec3 S3 = sqrt(S2);
return 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3;
}
// https://learn.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range
vec3 simpleReinhardTonemapper(vec3 c, float inMax, float outMax)
{
c /= vec3(inMax);
c.r = c.r / (1 + c.r);
c.g = c.g / (1 + c.g);
c.b = c.b / (1 + c.b);
c *= vec3(outMax);
return c;
}
void main()
{
vec4 c = texture(tex, v_texcoord);
if (ubuf.tonemapInMax != 0)
c.rgb = simpleReinhardTonemapper(c.rgb, ubuf.tonemapInMax, ubuf.tonemapOutMax);
else if (ubuf.sdr != 0)
c.rgb = linearToSRGB(c.rgb);
fragColor = vec4(c.rgb * c.a, c.a);
}