mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
render/vulkan: add texture color transformation matrix
This commit is contained in:
parent
56d95c2ecb
commit
3a51a5c623
3 changed files with 10 additions and 7 deletions
|
|
@ -340,6 +340,7 @@ struct wlr_vk_vert_pcr_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_vk_frag_texture_pcr_data {
|
struct wlr_vk_frag_texture_pcr_data {
|
||||||
|
float matrix[4][4]; // only a 3x3 subset is used
|
||||||
float alpha;
|
float alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -816,9 +816,13 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float color_matrix[9];
|
||||||
|
wlr_matrix_identity(color_matrix);
|
||||||
|
|
||||||
struct wlr_vk_frag_texture_pcr_data frag_pcr_data = {
|
struct wlr_vk_frag_texture_pcr_data frag_pcr_data = {
|
||||||
.alpha = alpha,
|
.alpha = alpha,
|
||||||
};
|
};
|
||||||
|
encode_color_matrix(color_matrix, frag_pcr_data.matrix);
|
||||||
|
|
||||||
bind_pipeline(pass, pipe->vk);
|
bind_pipeline(pass, pipe->vk);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,9 @@ layout(location = 0) in vec2 uv;
|
||||||
layout(location = 0) out vec4 out_color;
|
layout(location = 0) out vec4 out_color;
|
||||||
|
|
||||||
// struct wlr_vk_frag_texture_pcr_data
|
// struct wlr_vk_frag_texture_pcr_data
|
||||||
layout(push_constant) uniform UBO {
|
layout(push_constant, row_major) uniform UBO {
|
||||||
layout(offset = 80) float alpha;
|
layout(offset = 80) mat4 matrix;
|
||||||
|
float alpha;
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
layout (constant_id = 0) const int TEXTURE_TRANSFORM = 0;
|
layout (constant_id = 0) const int TEXTURE_TRANSFORM = 0;
|
||||||
|
|
@ -33,11 +34,6 @@ vec3 srgb_color_to_linear(vec3 color) {
|
||||||
void main() {
|
void main() {
|
||||||
vec4 in_color = textureLod(tex, uv, 0);
|
vec4 in_color = textureLod(tex, uv, 0);
|
||||||
|
|
||||||
if (TEXTURE_TRANSFORM == TEXTURE_TRANSFORM_IDENTITY) {
|
|
||||||
out_color = in_color * data.alpha;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert from pre-multiplied alpha to straight alpha
|
// Convert from pre-multiplied alpha to straight alpha
|
||||||
float alpha = in_color.a;
|
float alpha = in_color.a;
|
||||||
vec3 rgb;
|
vec3 rgb;
|
||||||
|
|
@ -51,6 +47,8 @@ void main() {
|
||||||
rgb = srgb_color_to_linear(rgb);
|
rgb = srgb_color_to_linear(rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rgb = mat3(data.matrix) * rgb;
|
||||||
|
|
||||||
// Back to pre-multiplied alpha
|
// Back to pre-multiplied alpha
|
||||||
out_color = vec4(rgb * alpha, alpha);
|
out_color = vec4(rgb * alpha, alpha);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue