-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nekocode
committed
Aug 8, 2016
1 parent
364126d
commit 55c1cf8
Showing
9 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/cn/nekocode/camerafilter/filter/CrackedFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cn.nekocode.camerafilter.filter; | ||
|
||
import android.content.Context; | ||
|
||
import cn.nekocode.camerafilter.MyGLUtils; | ||
import cn.nekocode.camerafilter.R; | ||
|
||
/** | ||
* Created by nekocode on 16/8/6. | ||
*/ | ||
public class CrackedFilter extends CameraFilter { | ||
private int program; | ||
|
||
public CrackedFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.cracked); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
defaultDraw(program, textureId, gwidth, gheight); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/cn/nekocode/camerafilter/filter/PolygonizationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cn.nekocode.camerafilter.filter; | ||
|
||
import android.content.Context; | ||
|
||
import cn.nekocode.camerafilter.MyGLUtils; | ||
import cn.nekocode.camerafilter.R; | ||
|
||
/** | ||
* Created by nekocode on 16/8/6. | ||
*/ | ||
public class PolygonizationFilter extends CameraFilter { | ||
private int program; | ||
|
||
public PolygonizationFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.polygonization); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
defaultDraw(program, textureId, gwidth, gheight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#extension GL_OES_EGL_image_external : require | ||
precision highp float; | ||
|
||
uniform vec3 iResolution; | ||
uniform float iGlobalTime; | ||
uniform samplerExternalOES sTexture; | ||
varying vec2 texCoord; | ||
|
||
float rnd(vec2 s) | ||
{ | ||
return 1.-2.*fract(sin(s.x*253.13+s.y*341.41)*589.19); | ||
} | ||
|
||
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | ||
{ | ||
vec2 p=(fragCoord.xy*2.-iResolution.xy)/iResolution.x; | ||
|
||
vec2 v=vec2(1E3); | ||
vec2 v2=vec2(1E4); | ||
vec2 center=vec2(.1,-.5); | ||
for(int c=0;c<30;c++) | ||
{ | ||
float angle=floor(rnd(vec2(float(c),387.44))*16.)*3.1415*.4-.5; | ||
float dist=pow(rnd(vec2(float(c),78.21)),2.)*.5; | ||
vec2 vc=vec2(center.x+cos(angle)*dist+rnd(vec2(float(c),349.3))*7E-3, | ||
center.y+sin(angle)*dist+rnd(vec2(float(c),912.7))*7E-3); | ||
if(length(vc-p)<length(v-p)) | ||
{ | ||
v2=v; | ||
v=vc; | ||
} | ||
else if(length(vc-p)<length(v2-p)) | ||
{ | ||
v2=vc; | ||
} | ||
} | ||
|
||
float col=abs(length(dot(p-v,normalize(v-v2)))-length(dot(p-v2,normalize(v-v2))))+.002*length(p-center); | ||
col=7E-4/col; | ||
if(length(v-v2)<4E-3)col=0.; | ||
// if(length(v-p)<4E-3)col=1E-6; | ||
if(col<.3)col=0.; | ||
vec4 tex=texture2D(sTexture,(fragCoord.xy)/iResolution.xy+rnd(v)*.02); | ||
fragColor=col*vec4(vec3(1.-tex.xyz),1.)+(1.-col)*tex; | ||
} | ||
|
||
void main() { | ||
mainImage(gl_FragColor, texCoord * iResolution.xy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#extension GL_OES_EGL_image_external : require | ||
precision highp float; | ||
|
||
uniform vec3 iResolution; | ||
uniform float iGlobalTime; | ||
uniform samplerExternalOES sTexture; | ||
varying vec2 texCoord; | ||
|
||
vec2 hash2( vec2 p ) | ||
{ | ||
// procedural white noise | ||
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); | ||
} | ||
|
||
vec2 voronoi( in vec2 x ) | ||
{ | ||
vec2 n = floor(x); | ||
vec2 f = fract(x); | ||
|
||
//---------------------------------- | ||
// regular voronoi | ||
//---------------------------------- | ||
vec2 mg, mr; | ||
|
||
float md = 8.0; | ||
for( int j=-1; j<=1; j++ ) | ||
for( int i=-1; i<=1; i++ ) | ||
{ | ||
vec2 g = vec2(float(i),float(j)); | ||
vec2 o = hash2( n + g ); | ||
vec2 r = g + o - f; | ||
float d = dot(r,r); | ||
|
||
if( d<md ) | ||
{ | ||
md = d; | ||
mr = r; | ||
mg = g; | ||
} | ||
} | ||
|
||
return mr; | ||
} | ||
|
||
vec3 VoronoiColor(float steps, vec2 p, vec2 uv) | ||
{ | ||
vec2 c = voronoi( steps*p ); | ||
|
||
vec2 uv1 = uv; | ||
uv1.x += c.x/steps; | ||
uv1.y += c.y/steps * iResolution.x/iResolution.y; | ||
|
||
return texture2D(sTexture, vec2(uv1.x, uv1.y)).xyz; | ||
} | ||
|
||
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | ||
{ | ||
vec2 p = fragCoord.xy/iResolution.xx; | ||
vec2 uv = fragCoord.xy / iResolution.xy; | ||
|
||
vec3 color = vec3(0.0,0.0,0.0); | ||
for (float i=0.0; i<4.0; i+=1.0) | ||
{ | ||
float steps = 30.0*pow(2.0,i); | ||
color += VoronoiColor(steps, p, uv); | ||
} | ||
|
||
fragColor = vec4(color*0.25,1.0); | ||
} | ||
|
||
void main() { | ||
mainImage(gl_FragColor, texCoord * iResolution.xy); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.