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

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

neercs: some fallback code when shader model 4 isn’t available.

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