dbf-udg
view sdr/dither.p.glsl @ 14:5be16862d1b5
minor makefile modifications
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 20 Feb 2013 05:54:36 +0200 |
parents | 5f99c4c7a9fe |
children |
line source
1 /*
2 Printblobs - typography display hack
3 Copyright (C) 2013 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 uniform sampler2D framebuf, dither_tex;
19 uniform int dither_levels, dither_size;
21 uniform float tfadein;
23 vec4 fetch_pixel(vec2 texcoord)
24 {
25 float x = step(0.5, mod(texcoord.y, 0.5) / 0.5);
26 float offs = mix(1.0 - tfadein, tfadein - 1.0, x);
27 vec2 tc = texcoord + vec2(offs, 0.0);
29 return (1.0 - step(1.0, tc.x)) * step(0.0, tc.x) * texture2D(framebuf, tc);
30 }
32 void main()
33 {
34 float levels = float(dither_levels);
36 //vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
37 vec4 pixel = fetch_pixel(gl_TexCoord[0].xy);
38 float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722));
39 float coord_shift = floor(lum * levels) / levels;
41 vec2 dsz2 = vec2(float(dither_size), float(dither_size));
43 vec2 coord = mod(gl_FragCoord.xy, dsz2) / float(dither_size);
44 coord.y = coord.y / levels + coord_shift;
45 float val = texture2D(dither_tex, coord).x;
47 const vec3 dark_col = vec3(0.043, 0.286, 0.337);
48 const vec3 bright_col = vec3(0.965, 0.778, 0.555);
50 gl_FragColor = vec4(mix(dark_col, bright_col, val), 1.0);
51 }