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

Last change on this file since 2154 was 2154, checked in by sam, 10 years ago

neercs: if shaders don't support integer attributes, pass them as vectors
of ubytes; foreground colour already works.

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