From bd615692615c53206f4bdd1afd66cc2e91b78ea1 Mon Sep 17 00:00:00 2001 From: Marek Kost Date: Mon, 10 Apr 2023 15:57:09 +0200 Subject: [PATCH] Linearize colors in frag shader https://github.com/ocornut/imgui/issues/4890 --- backends/vulkan/glsl_shader.frag | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backends/vulkan/glsl_shader.frag b/backends/vulkan/glsl_shader.frag index ce7e6f72b25d..70e4e2e536cf 100644 --- a/backends/vulkan/glsl_shader.frag +++ b/backends/vulkan/glsl_shader.frag @@ -8,7 +8,16 @@ layout(location = 0) in struct { vec2 UV; } In; +vec4 to_linear(vec4 sRGB) +{ + bvec3 cutoff = lessThan(sRGB.rgb, vec3(0.04045)); + vec3 higher = pow((sRGB.rgb + vec3(0.055)) / vec3(1.055), vec3(2.4)); + vec3 lower = sRGB.rgb / vec3(12.92); + + return vec4(mix(higher, lower, cutoff), sRGB.a); +} + void main() { - fColor = In.Color * texture(sTexture, In.UV.st); + fColor = to_linear(In.Color) * to_linear(texture(sTexture, In.UV.st)); }