diff --git a/README.md b/README.md index b4add28..119deda 100644 --- a/README.md +++ b/README.md @@ -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) | \ No newline at end of file +| Legofied | https://www.shadertoy.com/view/XtBSzy# | ![](art/5.png) | +| TileMosaic | https://www.shadertoy.com/view/MtfXRN | ![](art/6.png) | \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8ae55f5..92de5dc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,10 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/cn/nekocode/camerafilter/filter/CameraFilter.java b/app/src/main/java/cn/nekocode/camerafilter/filter/CameraFilter.java index 0624c23..1eacbc6 100644 --- a/app/src/main/java/cn/nekocode/camerafilter/filter/CameraFilter.java +++ b/app/src/main/java/cn/nekocode/camerafilter/filter/CameraFilter.java @@ -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; @@ -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; diff --git a/app/src/main/res/raw/edge_detection.fsh b/app/src/main/res/raw/edge_detection.fsh index c6198a9..8671887 100644 --- a/app/src/main/res/raw/edge_detection.fsh +++ b/app/src/main/res/raw/edge_detection.fsh @@ -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); } \ No newline at end of file diff --git a/app/src/main/res/raw/em_interference.fsh b/app/src/main/res/raw/em_interference.fsh index 03dabc0..f33d2c4 100644 --- a/app/src/main/res/raw/em_interference.fsh +++ b/app/src/main/res/raw/em_interference.fsh @@ -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.)); @@ -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); } \ No newline at end of file diff --git a/app/src/main/res/raw/legofied.fsh b/app/src/main/res/raw/legofied.fsh index 7870d8b..0bec1e2 100644 --- a/app/src/main/res/raw/legofied.fsh +++ b/app/src/main/res/raw/legofied.fsh @@ -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 diff --git a/app/src/main/res/raw/pixelize.fsh b/app/src/main/res/raw/pixelize.fsh index f364d9e..31e1742 100644 --- a/app/src/main/res/raw/pixelize.fsh +++ b/app/src/main/res/raw/pixelize.fsh @@ -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); } \ No newline at end of file diff --git a/app/src/main/res/raw/tile_mosaic.fsh b/app/src/main/res/raw/tile_mosaic.fsh index 0012cbf..8e1a41a 100644 --- a/app/src/main/res/raw/tile_mosaic.fsh +++ b/app/src/main/res/raw/tile_mosaic.fsh @@ -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); @@ -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)); } diff --git a/app/src/main/res/raw/triangles_mosaic.fsh b/app/src/main/res/raw/triangles_mosaic.fsh index 42276ed..68e8073 100644 --- a/app/src/main/res/raw/triangles_mosaic.fsh +++ b/app/src/main/res/raw/triangles_mosaic.fsh @@ -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); } \ No newline at end of file diff --git a/art/6.png b/art/6.png new file mode 100644 index 0000000..ae2127e Binary files /dev/null and b/art/6.png differ