source: trunk/src/gpu/tile.lolfx @ 1846

Last change on this file since 1846 was 1846, checked in by sam, 9 years ago

gpu: get rid of the inline 2D shader and create "tile.lolfx".

File size: 3.7 KB
Line 
1-- GLSL.Vert --
2
3#version 130
4
5attribute vec3 in_Position;
6attribute vec2 in_TexCoord;
7varying vec2 pass_TexCoord;
8
9uniform mat4 proj_matrix;
10uniform mat4 view_matrix;
11uniform mat4 model_matrix;
12
13void main()
14{
15    gl_Position = proj_matrix * view_matrix * model_matrix
16                * vec4(in_Position, 1.0);
17    pass_TexCoord = in_TexCoord;
18}
19
20-- GLSL.Frag --
21
22#version 130
23
24#if defined GL_ES
25precision mediump float;
26#endif
27
28uniform sampler2D in_Texture;
29varying vec2 pass_TexCoord;
30
31void main()
32{
33    vec4 col = texture2D(in_Texture, pass_TexCoord);
34//    vec4 col = vec4(0.5, 1.0, 0.0, 0.5);
35//    vec4 col = vec4(pass_TexCoord * 4.0, 0.0, 0.25);
36
37#if 0
38    float mul = 2.0;
39#   if 1
40    vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));
41    float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);
42    float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);
43    float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);
44    float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);
45    float dx3 = mod(floor(gl_FragCoord.x * 0.25), 2.0);
46    float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);
47    float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);
48    t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;
49    t2 = t1;
50    t3 = t1;
51#   else
52    float rand = sin(gl_FragCoord.x * 1.23456) * 123.456
53               + cos(gl_FragCoord.y * 2.34567) * 789.012;
54    float t1 = mod(sin(rand) * 17.13043, 1.0);
55    float t2 = mod(sin(rand) * 27.13043, 1.0);
56    float t3 = mod(sin(rand) * 37.13043, 1.0);
57#   endif
58    float fracx = fract(col.x * mul);
59    float fracy = fract(col.y * mul);
60    float fracz = fract(col.z * mul);
61    fracx = fracx > t1 ? 1.0 : 0.0;
62    fracy = fracy > t2 ? 1.0 : 0.0;
63    fracz = fracz > t3 ? 1.0 : 0.0;
64    col.x = (floor(col.x * mul) + fracx) / mul;
65    col.y = (floor(col.y * mul) + fracy) / mul;
66    col.z = (floor(col.z * mul) + fracz) / mul;
67#endif
68    gl_FragColor = col;
69}
70
71-- HLSL.Vert --
72
73void main(float4 in_Position : POSITION,
74          float2 in_TexCoord : TEXCOORD0,
75          uniform float4x4 proj_matrix,
76          uniform float4x4 view_matrix,
77          uniform float4x4 model_matrix,
78          out float2 out_TexCoord : TEXCOORD0,
79          out float4 out_Position : POSITION)
80{
81    out_Position = mul(proj_matrix, mul(view_matrix, mul(model_matrix, in_Position)));
82    out_TexCoord = in_TexCoord;
83}
84
85-- HLSL.Frag --
86
87void main(float2 in_TexCoord : TEXCOORD0,
88#if 0
89          float4 in_FragCoord : WPOS,
90#endif
91          uniform sampler2D tex,
92          out float4 out_FragColor : COLOR)
93{
94    float4 col = tex2D(tex, in_TexCoord);
95#if 0
96    float mul = 2.0;
97    float t1, t2, t3;
98#   if 1
99    float dx1 = frac(in_FragCoord.x * 0.5) * 2.0;
100    float dy1 = frac(in_FragCoord.y * 0.5) * 2.0;
101    t1 = frac((3.0 * dx1 + 2.0 * dy1) / 4.0) * 4.0;
102    float dx2 = frac(floor(in_FragCoord.x * 0.5) * 0.5) * 2.0;
103    float dy2 = frac(floor(in_FragCoord.y * 0.5) * 0.5) * 2.0;
104    t2 = frac((3.0 * dx2 + 2.0 * dy2) / 4.0) * 4.0;
105    float dx3 = frac(floor(in_FragCoord.x * 0.25) * 0.5) * 2.0;
106    float dy3 = frac(floor(in_FragCoord.y * 0.25) * 0.5) * 2.0;
107    t3 = frac((3.0 * dx3 + 2.0 * dy3) / 4.0) * 4.0;
108    t1 = (1.0 + 4.0 * t1 + t2) / 17.0;
109    t2 = t1;
110    t3 = t1;
111#   else
112    float rand = sin(in_FragCoord.x * 1.23456) * 123.456
113               + cos(in_FragCoord.y * 2.34567) * 789.012;
114    t1 = frac(sin(rand) * 17.13043);
115    t2 = frac(sin(rand) * 27.13043);
116    t3 = frac(sin(rand) * 37.13043);
117#   endif
118    float fracx = frac(col.x * mul);
119    float fracy = frac(col.y * mul);
120    float fracz = frac(col.z * mul);
121    fracx = fracx > t1 ? 1.0 : 0.0;
122    fracy = fracy > t2 ? 1.0 : 0.0;
123    fracz = fracz > t3 ? 1.0 : 0.0;
124    col.x = (floor(col.x * mul) + fracx) / mul;
125    col.y = (floor(col.y * mul) + fracy) / mul;
126    col.z = (floor(col.z * mul) + fracz) / mul;
127#endif
128    out_FragColor = col;
129}
130
Note: See TracBrowser for help on using the repository browser.