1+ #version 130
2+
3+ in vec2 textureUV;
4+ in vec4 vertexColor;
5+
6+ out vec4 FragColor;
7+
8+ uniform sampler2D rteTexture;
9+ uniform sampler2D rtePalette;
10+ uniform vec4 rteColor;
11+
12+ // Pseudo random number generator.
13+ float hash( vec2 a )
14+ {
15+ return fract ( sin ( a.x * 3433.8 + a.y * 3843.98 ) * 45933.8 );
16+ }
17+
18+ // Value noise courtesy of BigWingz
19+ // check his youtube channel he has
20+ // a video of this one.
21+ // Succint version by FabriceNeyret
22+ float noise( vec2 U )
23+ {
24+ vec2 id = floor ( U );
25+ U = fract ( U );
26+ U *= U * ( 3 . - 2 . * U );
27+
28+ vec2 A = vec2 ( hash(id), hash(id + vec2 (0 ,1 )) );
29+ vec2 B = vec2 ( hash(id + vec2 (1 ,0 )), hash(id + vec2 (1 ,1 )) );
30+ vec2 C = mix ( A, B, U.x);
31+
32+ return mix ( C.x, C.y, U.y );
33+ }
34+
35+ vec4 texture2DAA(sampler2D tex, vec2 uv) {
36+ vec2 texsize = vec2 (textureSize(tex, 0 ));
37+ vec2 uv_texspace = uv * texsize;
38+ vec2 seam = floor (uv_texspace + .5 );
39+ uv_texspace = (uv_texspace - seam) / fwidth (uv_texspace) + seam;
40+ uv_texspace = clamp (uv_texspace, seam - .5 , seam + .5 );
41+ return texture(tex, uv_texspace / texsize);
42+ }
43+
44+ void main() {
45+ if (noise(gl_FragCoord .xy + textureUV) < 0.5 ) {
46+ discard ;
47+ }
48+ float red = texture2D (rteTexture, textureUV).r;
49+ vec4 color = texture2DAA(rtePalette, vec2 (red * vertexColor.r, 0.0 )) * vec4 (rteColor.rgb, rteColor.a * vertexColor.a);
50+
51+ FragColor = color;
52+ }
0 commit comments