Debian Codegraph @

tests/manual/rhi/shared/imgui/imgui.frag

raw
1 #version 440
2
3 layout(location = 0) in vec2 v_texcoord;
4 layout(location = 1) in vec4 v_color;
5
6 layout(location = 0) out vec4 fragColor;
7
8 layout(std140, binding = 0) uniform buf {
9 mat4 mvp;
10 float opacity;
11 // Windows HDR: set to SDR_white_level_in_nits / 80
12 // macOS/iOS EDR: set to 1.0
13 // No HDR: set to 0.0, will do linear to sRGB at the end then.
14 float hdrWhiteLevelMult;
15 };
16
17 layout(binding = 1) uniform sampler2D tex;
18
19 vec3 linearToSRGB(vec3 color)
20 {
21 vec3 S1 = sqrt(color);
22 vec3 S2 = sqrt(S1);
23 vec3 S3 = sqrt(S2);
24 return 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3;
25 }
26
27 void main()
28 {
29 vec4 c = v_color * texture(tex, v_texcoord);
30 c.a *= opacity;
31 if (hdrWhiteLevelMult > 0.0)
32 c.rgb *= hdrWhiteLevelMult;
33 else
34 c.rgb = linearToSRGB(c.rgb);
35 c.rgb *= c.a; // premultiplied alpha
36 fragColor = c;
37 }