mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
render/vulkan: Use shader variants for different output transforms
This commit is contained in:
parent
d9345f4d9c
commit
26006035b6
5 changed files with 107 additions and 77 deletions
|
|
@ -2,22 +2,22 @@
|
|||
|
||||
layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput in_color;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler3D lut_3d;
|
||||
// Matches enum wlr_vk_output_transform
|
||||
#define OUTPUT_TRANSFORM_INVERSE_SRGB 0
|
||||
#define OUTPUT_TRANSFORM_LUT_3D 1
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
/* struct wlr_vk_frag_output_pcr_data */
|
||||
layout(push_constant) uniform UBO {
|
||||
layout(offset = 80) float lut_3d_offset;
|
||||
float lut_3d_scale;
|
||||
} data;
|
||||
#if OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_LUT_3D
|
||||
layout(set = 1, binding = 0) uniform sampler3D lut_3d;
|
||||
|
||||
layout (constant_id = 0) const int OUTPUT_TRANSFORM = 0;
|
||||
|
||||
// Matches enum wlr_vk_output_transform
|
||||
#define OUTPUT_TRANSFORM_INVERSE_SRGB 0
|
||||
#define OUTPUT_TRANSFORM_LUT_3D 1
|
||||
/* struct wlr_vk_frag_output_pcr_data */
|
||||
layout(push_constant) uniform UBO {
|
||||
layout(offset = 80) float lut_3d_offset;
|
||||
float lut_3d_scale;
|
||||
} data;
|
||||
#endif
|
||||
|
||||
float linear_channel_to_srgb(float x) {
|
||||
return max(min(x * 12.92, 0.04045), 1.055 * pow(x, 1. / 2.4) - 0.055);
|
||||
|
|
@ -33,17 +33,19 @@ void main() {
|
|||
// Convert from pre-multiplied alpha to straight alpha
|
||||
vec3 rgb = val.rgb / val.a;
|
||||
|
||||
if (OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_LUT_3D) {
|
||||
// Apply 3D LUT
|
||||
vec3 pos = data.lut_3d_offset + rgb * data.lut_3d_scale;
|
||||
rgb = texture(lut_3d, pos).rgb;
|
||||
} else { // OUTPUT_TRANSFORM_INVERSE_SRGB
|
||||
rgb = vec3(
|
||||
linear_channel_to_srgb(rgb.r),
|
||||
linear_channel_to_srgb(rgb.g),
|
||||
linear_channel_to_srgb(rgb.b)
|
||||
);
|
||||
}
|
||||
#if OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_LUT_3D
|
||||
// Apply 3D LUT
|
||||
vec3 pos = data.lut_3d_offset + rgb * data.lut_3d_scale;
|
||||
rgb = texture(lut_3d, pos).rgb;
|
||||
#endif
|
||||
|
||||
#if OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_INVERSE_SRGB
|
||||
rgb = vec3(
|
||||
linear_channel_to_srgb(rgb.r),
|
||||
linear_channel_to_srgb(rgb.g),
|
||||
linear_channel_to_srgb(rgb.b)
|
||||
);
|
||||
#endif
|
||||
|
||||
// Back to pre-multiplied alpha
|
||||
out_color = vec4(rgb * val.a, val.a);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue