dbf-udg

annotate sdr/dither.p.glsl @ 12:1abbed71e9c9

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