File: cutout-rect.vert

package info (click to toggle)
phoc 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,152 kB
  • sloc: ansic: 108,724; xml: 3,963; sh: 138; makefile: 33; javascript: 5
file content (28 lines) | stat: -rw-r--r-- 817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#version 310 es

/* Rectangle position */
layout(location=1) uniform vec2 u_pos;
/* Rectangle size */
layout(location=2) uniform vec2 u_size;
/* Window size */
layout(location=3) uniform vec2 u_win;
layout(location=0) in vec4 v_pos;

void main()
{
  vec2 size = 2.0 * u_size / u_win;
  vec2 pos = vec2 (-1.0 + 2.0 * (u_pos.x / u_win.x),
                    1.0 - 2.0 * (u_pos.y / u_win.y));

  mat4 scale = mat4(size.x, 0.0,    0.0, 0.0,
                    0.0,    size.y, 0.0, 0.0,
                    0.0,    0.0,    1.0, 0.0,
                    0.0,    0.0,    0.0, 1.0);

  mat4 translate = mat4(1.0,   0.0,   0.0, 0.0,
                        0.0,   1.0,   0.0, 0.0,
                        0.0,   0.0,   1.0, 0.0,
                        pos.x, pos.y, 0.0, 1.0);

  gl_Position = translate * scale * v_pos;
}