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

Last change on this file since 2171 was 2171, checked in by sam, 7 years ago

neercs: more pre-shader4 compatibility tweaks.

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