• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* GStreamer
2 * Copyright (C) 2020 Matthew Waters <matthew@centricular.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#version 450 core
21
22#include "view_defines.h"
23#include "swizzle.glsl"
24
25layout(location = 0) in vec2 inTexCoord;
26
27layout(set = 0, binding = 0) uniform ViewConvert {
28  ivec4 in_reorder_idx;
29  ivec4 out_reorder_idx;
30  vec4 tex_offset;
31  vec4 tex_scale;
32  ivec2 tex_size;
33  int output_type;
34  mat3 downmix[2];
35};
36layout(set = 0, binding = 1) uniform sampler2D l_tex;
37layout(set = 0, binding = 2) uniform sampler2D r_tex;
38
39layout(location = 0) out vec4 outColor0;
40
41void main()
42{
43  vec2 l_coord = inTexCoord * tex_scale.xy + tex_offset.xy;
44  vec2 r_coord = inTexCoord * tex_scale.zw + tex_offset.zw;
45  vec4 l = swizzle(texture(l_tex, l_coord), in_reorder_idx);
46  vec4 r = swizzle(texture(r_tex, r_coord), in_reorder_idx);
47
48  if (output_type == VIEW_MONO_DOWNMIX) {
49    vec3 lcol = l.rgb * l.a + vec3(1.0-l.a);
50    vec3 rcol = r.rgb * r.a + vec3(1.0-r.a);
51    if (l.a + r.a > 0.0) {
52      lcol = clamp (downmix[0] * lcol, 0.0, 1.0);
53      rcol = clamp (downmix[1] * rcol, 0.0, 1.0);
54      outColor0 = vec4 (lcol + rcol, 1.0);
55    } else {
56      outColor0 = vec4 (0.0);
57    }
58  } else if (output_type == VIEW_MONO_LEFT) {
59    outColor0 = swizzle(l, out_reorder_idx);
60  } else if (output_type == VIEW_MONO_RIGHT) {
61    outColor0 = swizzle(r, out_reorder_idx);
62  } else if (output_type == VIEW_SIDE_BY_SIDE) {
63    if (inTexCoord.x < 0.5) {
64      outColor0 = swizzle(l, out_reorder_idx);
65    } else {
66      outColor0 = swizzle(r, out_reorder_idx);
67    }
68  } else if (output_type == VIEW_TOP_BOTTOM) {
69    if (inTexCoord.y < 0.5) {
70      outColor0 = swizzle(l, out_reorder_idx);
71    } else {
72      outColor0 = swizzle(r, out_reorder_idx);
73    }
74  } else if (output_type == VIEW_COLUMN_INTERLEAVED) {
75    if (int(mod(l_coord.x * tex_size.x, 2.0)) == 0) {
76      outColor0 = swizzle(l, out_reorder_idx);
77    } else {
78      outColor0 = swizzle(r, out_reorder_idx);
79    }
80  } else if (output_type == VIEW_ROW_INTERLEAVED) {
81    if (int(mod(l_coord.y * tex_size.y, 2.0)) == 0) {
82      outColor0 = swizzle(l, out_reorder_idx);
83    } else {
84      outColor0 = swizzle(r, out_reorder_idx);
85    }
86  } else if (output_type == VIEW_CHECKERBOARD) {
87     if (int(mod(l_coord.x * tex_size.x, 2.0)) ==
88         int(mod(l_coord.y * tex_size.y, 2.0))) {
89      outColor0 = swizzle(l, out_reorder_idx);
90    } else {
91      outColor0 = swizzle(r, out_reorder_idx);
92    }
93  } else {
94    outColor0 = vec4(1.0, 0.0, 1.0, 1.0);
95  }
96}
97