diff options
author | Manuel Stoeckl <code@mstoeckl.com> | 2022-11-11 22:53:06 -0500 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-25 14:19:27 +0000 |
commit | 3ed69b49465f0b542d163da905dbc0864e19d5d8 (patch) | |
tree | d4909ffd0b1b8eff89d41dd67557f5422ac3a88d /render/vulkan/shaders | |
parent | 060df4c6c0f92e3989ce6fa13e5862bb3bee7dae (diff) |
render/vulkan: add support for RGB565 texture format
Since this does not have a matching _SRGB-type vulkan format, add a
new shader variant/pipeline to perform the sRGB->linear texture
conversion.
Diffstat (limited to 'render/vulkan/shaders')
-rw-r--r-- | render/vulkan/shaders/texture.frag | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/render/vulkan/shaders/texture.frag b/render/vulkan/shaders/texture.frag index 0f9c52f1..15ef52af 100644 --- a/render/vulkan/shaders/texture.frag +++ b/render/vulkan/shaders/texture.frag @@ -9,8 +9,28 @@ layout(push_constant) uniform UBO { layout(offset = 80) float alpha; } data; +layout (constant_id = 0) const int TEXTURE_TRANSFORM = 0; + +#define TEXTURE_TRANSFORM_IDENTITY 0 +#define TEXTURE_TRANSFORM_SRGB 1 + +float srgb_to_linear(float x) { + return max(x / 12.92, pow((x + 0.055) / 1.055, 2.4)); +} + void main() { - out_color = textureLod(tex, uv, 0); + vec4 val = textureLod(tex, uv, 0); + if (TEXTURE_TRANSFORM == TEXTURE_TRANSFORM_SRGB) { + out_color = vec4( + srgb_to_linear(val.r), + srgb_to_linear(val.g), + srgb_to_linear(val.b), + val.a + ); + } else { // TEXTURE_TRANSFORM_IDENTITY + out_color = val; + } + out_color *= data.alpha; } |