2021-02-21 18:30:12 +01:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2D tex;
|
|
|
|
|
|
|
|
layout(location = 0) in vec2 uv;
|
|
|
|
layout(location = 0) out vec4 out_color;
|
|
|
|
|
|
|
|
layout(push_constant) uniform UBO {
|
|
|
|
layout(offset = 80) float alpha;
|
|
|
|
} data;
|
|
|
|
|
2022-11-12 04:53:06 +01:00
|
|
|
layout (constant_id = 0) const int TEXTURE_TRANSFORM = 0;
|
|
|
|
|
2023-05-24 11:25:30 +02:00
|
|
|
// Matches enum wlr_vk_texture_transform
|
2022-11-12 04:53:06 +01:00
|
|
|
#define TEXTURE_TRANSFORM_IDENTITY 0
|
|
|
|
#define TEXTURE_TRANSFORM_SRGB 1
|
|
|
|
|
2023-10-17 12:21:08 +02:00
|
|
|
float srgb_channel_to_linear(float x) {
|
2022-11-12 04:53:06 +01:00
|
|
|
return max(x / 12.92, pow((x + 0.055) / 1.055, 2.4));
|
|
|
|
}
|
|
|
|
|
2023-10-17 12:21:08 +02:00
|
|
|
vec4 srgb_color_to_linear(vec4 color) {
|
|
|
|
if (color.a == 0) {
|
|
|
|
return vec4(0);
|
|
|
|
}
|
|
|
|
color.rgb /= color.a;
|
|
|
|
color.rgb = vec3(
|
|
|
|
srgb_channel_to_linear(color.r),
|
|
|
|
srgb_channel_to_linear(color.g),
|
|
|
|
srgb_channel_to_linear(color.b)
|
|
|
|
);
|
|
|
|
color.rgb *= color.a;
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2021-02-21 18:30:12 +01:00
|
|
|
void main() {
|
2022-11-12 04:53:06 +01:00
|
|
|
vec4 val = textureLod(tex, uv, 0);
|
|
|
|
if (TEXTURE_TRANSFORM == TEXTURE_TRANSFORM_SRGB) {
|
2023-10-17 12:21:08 +02:00
|
|
|
out_color = srgb_color_to_linear(val);
|
2022-11-12 04:53:06 +01:00
|
|
|
} else { // TEXTURE_TRANSFORM_IDENTITY
|
|
|
|
out_color = val;
|
|
|
|
}
|
|
|
|
|
2021-10-16 16:31:48 +02:00
|
|
|
out_color *= data.alpha;
|
2021-02-21 18:30:12 +01:00
|
|
|
}
|