source: trunk/tools/neercs/video/text.lolfx @ 2138

Last change on this file since 2138 was 2138, checked in by sam, 8 years ago

neercs: remove deprecated GLSL constructs in text shader.

File size: 2.0 KB
Line 
1[vert.glsl]
2
3#version 130
4
5#define HAVE_UINT 1
6
7#if HAVE_UINT
8in uint in_Char, in_Attr;
9#else
10in vec4 in_Char, in_Attr;
11#endif
12
13out vec4 pass_Foreground;
14out vec4 pass_Background;
15out vec2 pass_UV;
16
17uniform vec2 u_DataSize;
18uniform mat4 u_Transform;
19
20void main()
21{
22#if HAVE_UINT
23    float u = float(in_Char & 0xfu) / 32.0 + 0.0;
24    float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5;
25#else
26    float u = mod(in_Char.x, 16.0) / 32.0 + 0.0;
27    float v = floor(in_Char.x / 16.0) / 32.0 + 0.5;
28#endif
29    pass_UV = vec2(u, v);
30
31#if HAVE_UINT
32    float A = float(in_Attr >> 29u) / 7.0;
33    float B = float((in_Attr >> 25u) & 0xfu) / 15.0;
34    float C = float((in_Attr >> 21u) & 0xfu) / 15.0;
35    float D = float((in_Attr >> 18u) & 0x7u) / 7.0;
36
37    float E = float((in_Attr >> 15u) & 0x7u) / 7.0;
38    float F = float((in_Attr >> 11u) & 0xfu) / 15.0;
39    float G = float((in_Attr >> 7u) & 0xfu) / 15.0;
40    float H = float((in_Attr >> 4u) & 0x7u) / 7.0;
41#else
42    float A = 0.0;
43    float B = 0.0;
44    float C = 0.0;
45    float D = 0.0;
46
47    float E = 0.0;
48    float F = mod(floor(in_Attr.y / 8.0), 16.0) / 15.0;
49    float G = (mod(in_Attr.y, 8.0) * 2.0 + floor(in_Attr.x / 128.0)) / 15.0;
50    float H = mod(floor(in_Attr.x / 16.0), 8.0) / 7.0;
51#endif
52
53    pass_Background = vec4(B + 0.0625, C + 0.125, D + 0.125, 1.0 - A);
54    pass_Foreground = vec4(F, G, H, 1.0 - E);
55    if (B + C + D < 0.01) A = 1.0;
56    if (F + G + H < 0.01) E = 1.0;
57
58    // This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
59    gl_PointSize = u_DataSize[1];
60
61    vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]),
62                      gl_VertexID / int(u_DataSize[0]));
63    gl_Position = u_Transform * vec4(coord, 0.0, 1.0);
64}
65
66[frag.glsl]
67
68#version 130
69
70in vec4 pass_Foreground;
71in vec4 pass_Background;
72in vec2 pass_UV;
73
74uniform sampler2D u_Texture;
75
76out vec4 out_Color;
77
78void main(void)
79{
80    vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV;
81    float t = texture2D(u_Texture, c).x;
82    out_Color = mix(pass_Background, pass_Foreground, t);
83}
Note: See TracBrowser for help on using the repository browser.