-
Notifications
You must be signed in to change notification settings - Fork 362
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
fbc0acb
commit 4a351e2
Showing
26 changed files
with
569 additions
and
20 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
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/AsciiArtFilter.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 AsciiArtFilter extends CameraFilter { | ||
private int program; | ||
|
||
public AsciiArtFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.ascii_art); | ||
} | ||
|
||
@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/CrosshatchFilter.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 CrosshatchFilter extends CameraFilter { | ||
private int program; | ||
|
||
public CrosshatchFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.crosshatch); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
defaultDraw(program, textureId, gwidth, gheight); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
app/src/main/java/cn/nekocode/camerafilter/filter/EMInterferenceFilter.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
2 changes: 0 additions & 2 deletions
2
app/src/main/java/cn/nekocode/camerafilter/filter/LegofiedFilter.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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/cn/nekocode/camerafilter/filter/LichtensteinEsqueFilter.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 LichtensteinEsqueFilter extends CameraFilter { | ||
private int program; | ||
|
||
public LichtensteinEsqueFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.lichtenstein_esque); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
defaultDraw(program, textureId, gwidth, gheight); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/cn/nekocode/camerafilter/filter/MappingFilter.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,62 @@ | ||
package cn.nekocode.camerafilter.filter; | ||
|
||
import android.content.Context; | ||
import android.opengl.GLES11Ext; | ||
import android.opengl.GLES20; | ||
|
||
import cn.nekocode.camerafilter.MyGLUtils; | ||
import cn.nekocode.camerafilter.R; | ||
|
||
/** | ||
* Created by nekocode on 16/8/6. | ||
*/ | ||
public class MappingFilter extends CameraFilter { | ||
private int program; | ||
private int texture2Id; | ||
|
||
public MappingFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.mapping); | ||
|
||
// Load the texture will need for the shader | ||
texture2Id = MyGLUtils.loadTexture(context, R.raw.tex00); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
// Use shaders | ||
GLES20.glUseProgram(program); | ||
|
||
int iResolution = GLES20.glGetUniformLocation(program, "iResolution"); | ||
// FIXME: Because we roate the texture, so we need to exchange the width and height | ||
final float res[] = {(float) gheight, (float) gwidth, 1.0f}; | ||
GLES20.glUniform3fv(iResolution, 1, res, 0); | ||
|
||
float time = ((float) (System.currentTimeMillis() - START_TIME)) / 1000.0f; | ||
int iGlobalTime = GLES20.glGetUniformLocation(program, "iGlobalTime"); | ||
GLES20.glUniform1f(iGlobalTime, time); | ||
|
||
int vPositionLocation = GLES20.glGetAttribLocation(program, "vPosition"); | ||
int vTexCoordLocation = GLES20.glGetAttribLocation(program, "vTexCoord"); | ||
int sTextureLocation = GLES20.glGetUniformLocation(program, "sTexture"); | ||
int sTexture2Location = GLES20.glGetUniformLocation(program, "sTexture2"); | ||
|
||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); | ||
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId); | ||
GLES20.glUniform1i(sTextureLocation, 0); // First layer texture | ||
|
||
GLES20.glActiveTexture(GLES20.GL_TEXTURE1); | ||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture2Id); | ||
GLES20.glUniform1i(sTexture2Location, 1); // Second layer texture | ||
|
||
GLES20.glVertexAttribPointer(vPositionLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, defaultVertexBuffer); | ||
GLES20.glVertexAttribPointer(vTexCoordLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, defaultTextureCoordBuffer); | ||
GLES20.glEnableVertexAttribArray(vPositionLocation); | ||
GLES20.glEnableVertexAttribArray(vTexCoordLocation); | ||
|
||
// Draw the texture | ||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/cn/nekocode/camerafilter/filter/MoneyFilter.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 MoneyFilter extends CameraFilter { | ||
private int program; | ||
|
||
public MoneyFilter(Context context) { | ||
super(context); | ||
|
||
// Build shaders | ||
program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.money_filter); | ||
} | ||
|
||
@Override | ||
public void draw(int textureId, int gwidth, int gheight) { | ||
defaultDraw(program, textureId, gwidth, gheight); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
app/src/main/java/cn/nekocode/camerafilter/filter/OriginalFilter.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
2 changes: 0 additions & 2 deletions
2
app/src/main/java/cn/nekocode/camerafilter/filter/PixelizeFilter.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
2 changes: 0 additions & 2 deletions
2
app/src/main/java/cn/nekocode/camerafilter/filter/TrianglesMosaicFilter.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
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,46 @@ | ||
#extension GL_OES_EGL_image_external : require | ||
precision highp float; | ||
|
||
uniform vec3 iResolution; | ||
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 --- | ||
|
||
float character(float n, vec2 p) // some compilers have the word "char" reserved | ||
{ | ||
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; | ||
} | ||
|
||
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; | ||
|
||
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)); | ||
|
||
fragColor = vec4(col, 1.0); | ||
} | ||
|
||
void main() { | ||
mainImage(gl_FragColor, texCoord * iResolution.xy); | ||
} |
Oops, something went wrong.