Skip to content

Commit

Permalink
Update ascii art filter
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Aug 8, 2016
1 parent 4a351e2 commit f420ae1
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 25 deletions.
164 changes: 139 additions & 25 deletions app/src/main/res/raw/ascii_art.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,153 @@ uniform float iGlobalTime;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

// Bitmap to ASCII (not really) fragment shader by movAX13h, September 2013
// --- This shader is now used in Pixi JS ---
// referenced the method of bitmap of iq : https://www.shadertoy.com/view/4dfXWj

float character(float n, vec2 p) // some compilers have the word "char" reserved
#define r iResolution.xy
#define t iGlobalTime

#define zoom 2.

#define P(id,a,b,c,d,e,f,g,h) if( id == int(pos.y) ){ int pa = a+2*(b+2*(c+2*(d+2*(e+2*(f+2*(g+2*(h))))))); cha = floor(mod(float(pa)/pow(2.,float(pos.x)-1.),2.)); }

float gray(vec3 _i)
{
p = floor(p*vec2(4.0, -4.0) + 2.5);
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
{
if (int(mod(n/exp2(p.x + 5.0*p.y), 2.0)) == 1) return 1.0;
}
return 0.0;
return (_i.x+_i.y+_i.z)/3.;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy;
vec3 col = texture2D(sTexture, floor(uv/8.0)*8.0/iResolution.xy).rgb;
vec2 uv = vec2(floor(fragCoord.x/8./zoom)*8.*zoom,floor(fragCoord.y/12./zoom)*12.*zoom)/r;
ivec2 pos = ivec2(mod(fragCoord.x/zoom,8.),mod(fragCoord.y/zoom,12.));
vec4 tex = texture2D(sTexture,uv);
float cha = 0.;

float gray = (col.r + col.g + col.b)/3.0;

float n = 65536.0; // .
if (gray > 0.2) n = 65600.0; // :
if (gray > 0.3) n = 332772.0; // *
if (gray > 0.4) n = 15255086.0; // o
if (gray > 0.5) n = 23385164.0; // &
if (gray > 0.6) n = 15252014.0; // 8
if (gray > 0.7) n = 13199452.0; // @
if (gray > 0.8) n = 11512810.0; // #

vec2 p = mod(uv/10.0, 2.0) - vec2(1.0);
col = gray*vec3(character(n, p));
{
float g = gray(tex.xyz);
if( g < .125 )
{
P(11,0,0,0,0,0,0,0,0);
P(10,0,0,0,0,0,0,0,0);
P(9,0,0,0,0,0,0,0,0);
P(8,0,0,0,0,0,0,0,0);
P(7,0,0,0,0,0,0,0,0);
P(6,0,0,0,0,0,0,0,0);
P(5,0,0,0,0,0,0,0,0);
P(4,0,0,0,0,0,0,0,0);
P(3,0,0,0,0,0,0,0,0);
P(2,0,0,0,0,0,0,0,0);
P(1,0,0,0,0,0,0,0,0);
P(0,0,0,0,0,0,0,0,0);
}
else if( g < .25 ) // .
{
P(11,0,0,0,0,0,0,0,0);
P(10,0,0,0,0,0,0,0,0);
P(9,0,0,0,0,0,0,0,0);
P(8,0,0,0,0,0,0,0,0);
P(7,0,0,0,0,0,0,0,0);
P(6,0,0,0,0,0,0,0,0);
P(5,0,0,0,0,0,0,0,0);
P(4,0,0,0,1,1,0,0,0);
P(3,0,0,0,1,1,0,0,0);
P(2,0,0,0,0,0,0,0,0);
P(1,0,0,0,0,0,0,0,0);
P(0,0,0,0,0,0,0,0,0);
}
else if( g < .375 ) // ,
{
P(11,0,0,0,0,0,0,0,0);
P(10,0,0,0,0,0,0,0,0);
P(9,0,0,0,0,0,0,0,0);
P(8,0,0,0,0,0,0,0,0);
P(7,0,0,0,0,0,0,0,0);
P(6,0,0,0,0,0,0,0,0);
P(5,0,0,0,0,0,0,0,0);
P(4,0,0,0,1,1,0,0,0);
P(3,0,0,0,1,1,0,0,0);
P(2,0,0,0,0,1,0,0,0);
P(1,0,0,0,1,0,0,0,0);
P(0,0,0,0,0,0,0,0,0);
}
else if( g < .5 ) // -
{
P(11,0,0,0,0,0,0,0,0);
P(10,0,0,0,0,0,0,0,0);
P(9,0,0,0,0,0,0,0,0);
P(8,0,0,0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1,1,1,1,0,0);
P(9,0,1,0,0,0,0,1,0);
P(8,1,0,0,0,1,1,1,0);
P(7,1,0,0,1,0,0,1,0);
P(6,1,0,0,1,0,0,1,0);
P(5,1,0,0,1,0,0,1,0);
P(4,1,0,0,1,0,0,1,0);
P(3,1,0,0,1,1,1,1,0);
P(2,0,1,0,0,0,0,0,0);
P(1,0,0,1,1,1,1,1,0);
P(0,0,0,0,0,0,0,0,0);
}
}

fragColor = vec4(col, 1.0);
vec3 col = vec3(1.);
fragColor = vec4(cha*col,1.);
}

void main() {
Expand Down
Binary file modified art/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f420ae1

Please sign in to comment.