Skip to content

Commit

Permalink
Update filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Aug 7, 2016
1 parent e2be951 commit f795e28
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 38 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Realtime camera filters. Process frames by OpenGL shaders.
| Title | Live Demo | Preview |
| :---- | :-------- | :------ |
| Edge Detection | https://www.shadertoy.com/view/Xtd3W7# | ![](art/1.png)|
| Pixelize | https://www.shadertoy.com/view/4syXD1 | ![](art/2.png)|
| Pixelize | https://www.shadertoy.com/view/4lXXDH# | ![](art/2.png)|
| EM Interference | https://www.shadertoy.com/view/lsXSWl# | ![](art/3.png)|
| Triangles Mosaic | https://www.shadertoy.com/view/4d2SWy | ![](art/4.png) |
| Legofied | https://www.shadertoy.com/view/XtBSzy# | ![](art/5.png) |
| Legofied | https://www.shadertoy.com/view/XtBSzy# | ![](art/5.png) |
| TileMosaic | https://www.shadertoy.com/view/MtfXRN | ![](art/6.png) |
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public abstract class CameraFilter {
Context context;

private static final float squareCoords[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, 1.0f,
-1.0f, 1.0f,
};
private static final float textureCoords[] = {
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
};
private static FloatBuffer defaultVertexBuffer, defaultTextureCoordBuffer;

Expand Down Expand Up @@ -53,7 +53,8 @@ void defaultDraw(int program, int textureId, int gwidth, int gheight) {
GLES20.glUseProgram(program);

int iResolution = GLES20.glGetUniformLocation(program, "iResolution");
final float res[] = {(float) gwidth, (float) gheight, 1.0f};
// 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;
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/res/raw/edge_detection.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ uniform vec3 iResolution;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

void main() {
vec4 color = texture2D(sTexture, texCoord);
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy;
vec4 color = texture2D(sTexture, fragCoord);
float gray = length(color.rgb);
gl_FragColor = vec4(vec3(step(0.06, length(vec2(dFdx(gray), dFdy(gray))))), 1.0);
// gl_FragColor = vec4(vec3(pow(length(vec2(dFdx(gray), dFdy(gray))), .5)), 1.0);
fragColor = vec4(vec3(step(0.06, length(vec2(dFdx(gray), dFdy(gray))))), 1.0);
}

void main() {
mainImage(gl_FragColor, texCoord);
}
17 changes: 12 additions & 5 deletions app/src/main/res/raw/em_interference.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ uniform float iGlobalTime;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

float rng2(vec2 seed) {
float rng2(vec2 seed)
{
return fract(sin(dot(seed * floor(iGlobalTime * 12.), vec2(127.1,311.7))) * 43758.5453123);
}

float rng(float seed) {
float rng(float seed)
{
return rng2(vec2(seed, 1.0));
}

void main() {
vec2 uv = texCoord.xy;
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy;
vec2 blockS = floor(uv * vec2(24., 9.));
vec2 blockL = floor(uv * vec2(8., 4.));

Expand All @@ -29,5 +32,9 @@ void main() {
vec4 col2 = texture2D(sTexture, uv + vec2(lineNoise * 0.05 * rng(5.0), 0));
vec4 col3 = texture2D(sTexture, uv - vec2(lineNoise * 0.05 * rng(31.0), 0));

gl_FragColor = vec4(vec3(col1.x, col2.y, col3.z) + noise, 1.0);
fragColor = vec4(vec3(col1.x, col2.y, col3.z) + noise, 1.0);
}

void main() {
mainImage(gl_FragColor, texCoord);
}
2 changes: 1 addition & 1 deletion app/src/main/res/raw/legofied.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ uniform vec3 iResolution;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

float c = 0.03; //amout of blocks = c*iResolution.x
float c = 0.02; //amout of blocks = c*iResolution.x

void mainImage( out vec4 fragColor, in vec2 fragCoord ){
//blocked pixel coordinate
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/res/raw/pixelize.fsh
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#extension GL_OES_EGL_image_external : require
#extension GL_OES_standard_derivatives : enable
#define PIXEL_SIZE 10.0
precision mediump float;

uniform vec3 iResolution;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

void main() {
vec2 uv = texCoord.xy;

float dx = PIXEL_SIZE / 500.0;
float dy = PIXEL_SIZE / 275.0;
void mainImage(out vec4 f,vec2 u)
{
vec2 r = iResolution.xy;
f = texture2D(sTexture,ceil(u / (r.x/1e2)) * r.x/1e2 / r);
}

uv.x = dx * floor(uv.x / dx);
uv.y = dy * floor(uv.y / dy);

gl_FragColor = texture2D(sTexture, uv);
void main() {
mainImage(gl_FragColor, texCoord*iResolution.xy);
}
5 changes: 3 additions & 2 deletions app/src/main/res/raw/tile_mosaic.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
const float textureSamplesCount = 3.0;
const float textureEdgeOffset = 0.005;
const float borderSize = 1.0;
const float size = 2.0;
const float size = 0.5;

float tileSize = minTileSize + floor(size * (maxTileSize - minTileSize));
tileSize += mod(tileSize, 2.0);
Expand All @@ -37,7 +37,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
vec2 pixelNumber = floor(fragCoord - (tileNumber * tileSize));
pixelNumber = mod(pixelNumber + borderSize, tileSize);

float pixelBorder = step(pixelNumber.x, borderSize) * step(pixelNumber.y, borderSize) * step(borderSize * 2.0 + 1.0, tileSize);
float pixelBorder = step(min(pixelNumber.x, pixelNumber.y), borderSize) * step(borderSize * 2.0 + 1.0, tileSize);
//float pixelBorder = step(pixelNumber.x, borderSize) * step(pixelNumber.y, borderSize) * step(borderSize * 2.0 + 1.0, tileSize);

fragColor *= pow(fragColor, vec4(pixelBorder));
}
Expand Down
21 changes: 13 additions & 8 deletions app/src/main/res/raw/triangles_mosaic.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ uniform vec3 iResolution;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;

vec2 tile_num = vec2(40.0, 20.0);
vec2 tile_num = vec2(40.0,20.0);

void main() {
vec2 uv = texCoord.xy;
vec2 uv2 = floor(uv*tile_num)/tile_num;
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy;
vec2 uv2 = floor(uv*tile_num)/tile_num;
uv -= uv2;
uv *= tile_num;
gl_FragColor = texture2D(sTexture, uv2 + vec2(step(1.0-uv.y,uv.x)/(2.0*tile_num.x),
//0,
step(uv.x,uv.y)/(2.0*tile_num.y)
fragColor = texture2D( sTexture, uv2 + vec2(step(1.0-uv.y,uv.x)/(2.0*tile_num.x),
//0,
step(uv.x,uv.y)/(2.0*tile_num.y)
//0
));
) );
}

void main() {
mainImage(gl_FragColor, texCoord);
}
Binary file added art/6.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 f795e28

Please sign in to comment.