diff options
author | Simon Ser <contact@emersion.fr> | 2023-10-17 12:21:08 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-10-17 17:28:56 +0200 |
commit | 5adf325333602d5b1e7ccdeb122633bbc8040ace (patch) | |
tree | afd116e7131bd9827e8b05eb9f2ff1cdd04f8f18 /render/vulkan/shaders/output.frag | |
parent | b560f362073f7981c15f820488441e50f697d306 (diff) |
render/vulkan: undo alpha premult before sRGB encoding/decoding
sRGB encoding/decoding needs to happen with straight alpha, not
pre-multiplied alpha.
Diffstat (limited to 'render/vulkan/shaders/output.frag')
-rw-r--r-- | render/vulkan/shaders/output.frag | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/render/vulkan/shaders/output.frag b/render/vulkan/shaders/output.frag index 28a8cdc5..263f3e19 100644 --- a/render/vulkan/shaders/output.frag +++ b/render/vulkan/shaders/output.frag @@ -5,17 +5,25 @@ layout (input_attachment_index = 0, binding = 0) uniform subpassInput in_color; layout(location = 0) in vec2 uv; layout(location = 0) out vec4 out_color; -float linear_to_srgb(float x) { +float linear_channel_to_srgb(float x) { return max(min(x * 12.92, 0.04045), 1.055 * pow(x, 1. / 2.4) - 0.055); } -void main() { - vec4 val = subpassLoad(in_color).rgba; - out_color = vec4( - linear_to_srgb(val.r), - linear_to_srgb(val.g), - linear_to_srgb(val.b), - val.a +vec4 linear_color_to_srgb(vec4 color) { + if (color.a == 0) { + return vec4(0); + } + color.rgb /= color.a; + color.rgb = vec3( + linear_channel_to_srgb(color.r), + linear_channel_to_srgb(color.g), + linear_channel_to_srgb(color.b) ); + color.rgb *= color.a; + return color; } +void main() { + vec4 val = subpassLoad(in_color).rgba; + out_color = linear_color_to_srgb(val); +} |