├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── nekocode │ │ └── camerafilter │ │ ├── CameraRenderer.java │ │ ├── MainActivity.java │ │ ├── MyGLUtils.java │ │ ├── RenderBuffer.java │ │ └── filter │ │ ├── AsciiArtFilter.java │ │ ├── BasicDeformFilter.java │ │ ├── BlackAndWhiteFilter.java │ │ ├── BlueorangeFilter.java │ │ ├── CameraFilter.java │ │ ├── CartoonFilter.java │ │ ├── CastingFilter.java │ │ ├── ChromaticAberrationFilter.java │ │ ├── ContrastFilter.java │ │ ├── CrackedFilter.java │ │ ├── CrosshatchFilter.java │ │ ├── EMInterferenceFilter.java │ │ ├── EdgeDetectionFilter.java │ │ ├── GrayFilter.java │ │ ├── HexagonMosaicFilter.java │ │ ├── JFAVoronoiFilter.java │ │ ├── LegofiedFilter.java │ │ ├── LichtensteinEsqueFilter.java │ │ ├── MappingFilter.java │ │ ├── MirrorFilter.java │ │ ├── MoneyFilter.java │ │ ├── NegativeFilter.java │ │ ├── NoiseWarpFilter.java │ │ ├── NostalgiaFilter.java │ │ ├── OriginalFilter.java │ │ ├── PixelizeFilter.java │ │ ├── PolygonizationFilter.java │ │ ├── RefractionFilter.java │ │ ├── ReliefFilter.java │ │ ├── SwirlFilter.java │ │ ├── TileMosaicFilter.java │ │ ├── TrianglesMosaicFilter.java │ │ ├── TripleFilter.java │ │ └── WaterReflectionFilter.java │ └── res │ ├── menu │ └── filter.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── raw │ ├── ascii_art.fsh │ ├── basic_deform.fsh │ ├── black_and_white.fsh │ ├── blue_orange.fsh │ ├── cartoon.fsh │ ├── casting.fsh │ ├── chromatic_aberration.fsh │ ├── contrast.fsh │ ├── cracked.fsh │ ├── crosshatch.fsh │ ├── edge_detection.fsh │ ├── em_interference.fsh │ ├── gray.fsh │ ├── hexagon_mosaic.fsh │ ├── legofied.fsh │ ├── lichtenstein_esque.fsh │ ├── mapping.fsh │ ├── mirror.fsh │ ├── money_filter.fsh │ ├── negative.fsh │ ├── noise_warp.fsh │ ├── nostalgia.fsh │ ├── original.fsh │ ├── original_rtt.fsh │ ├── pixelize.fsh │ ├── polygonization.fsh │ ├── refraction.fsh │ ├── relief.fsh │ ├── swirl.fsh │ ├── tex00.jpg │ ├── tex07.jpg │ ├── tex11.png │ ├── tile_mosaic.fsh │ ├── triangles_mosaic.fsh │ ├── triple.fsh │ ├── vertext.vsh │ ├── voronoi.fsh │ ├── voronoi_buf_a.fsh │ ├── voronoi_buf_b.fsh │ ├── voronoi_buf_c.fsh │ └── water_reflection.fsh │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── art ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png ├── 18.png ├── 19.png ├── 2.png ├── 20.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | *.iml 10 | *.apk 11 | *.jobf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CameraFilter 2 | [![Apache 2.0 License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0.html) 3 | 4 | Realtime camera filters. Process frames by OpenGL shaders. 5 | 6 | **[Download the apk](https://github.com/nekocode/CameraFilter/releases)** to have a try. 7 | 8 | ## Filters 9 | 10 | Thanks to the original authors of the shader codes. I just port them from webgl to opengl es. 11 | 12 | | Filter | Preview | Filter | Preview | 13 | | :----- | :------ | :----- | :------ | 14 | | [Edge Detection](https://www.shadertoy.com/view/Xtd3W7) | ![](art/1.png) | [Pixelize](https://www.shadertoy.com/view/4lXXDH) | ![](art/2.png)| 15 | | [EM Interference](https://www.shadertoy.com/view/lsXSWl) | ![](art/3.png)| [Triangles Mosaic](https://www.shadertoy.com/view/4d2SWy) | ![](art/4.png) | 16 | | [Legofied](https://www.shadertoy.com/view/XtBSzy) | ![](art/5.png) | [Tile Mosaic](https://www.shadertoy.com/view/MtfXRN) | ![](art/6.png) | 17 | | [Blueorange](https://www.shadertoy.com/view/MslGzr) | ![](art/7.png) | [Chromatic Aberration](https://www.shadertoy.com/view/Mds3zn) | ![](art/8.png) | 18 | | [Basic Deform](https://www.shadertoy.com/view/XdsGzH) | ![](art/9.png) | [Contrast](https://www.shadertoy.com/view/Xdf3RN) | ![](art/10.png) | 19 | | [NoiseWarp](https://www.shadertoy.com/view/4sX3RN) | ![](art/11.png) | [Refraction](https://www.shadertoy.com/view/MsX3zN) | ![](art/12.png) | 20 | | [Mapping](https://www.shadertoy.com/view/XsX3R7) | ![](art/13.png) | [Crosshatch](https://www.shadertoy.com/view/MdX3Dr) | ![](art/14.png) | 21 | | [Lichtenstein-esque](https://www.shadertoy.com/view/Mdf3zS) | ![](art/15.png) | [Ascii Art](https://www.shadertoy.com/view/lssGDj) | ![](art/16.png) | 22 | | [Money Filter](https://www.shadertoy.com/view/XlsXDN) | ![](art/17.png) | [Cracked](https://www.shadertoy.com/view/XdBSzW) | ![](art/18.png) | 23 | | [Polygonization](https://www.shadertoy.com/view/4lsXR7) | ![](art/19.png) | [JFA Voronoi](https://www.shadertoy.com/view/4sy3W3) | ![](art/20.png) | 24 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion "28.0.3" 6 | 7 | defaultConfig { 8 | applicationId "cn.nekocode.camerafilter" 9 | minSdkVersion 15 10 | targetSdkVersion 27 11 | versionCode 212 12 | versionName "2.4" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: "libs", include: ["*.jar"]) 24 | implementation "com.android.support:appcompat-v7:27.1.1" 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/CameraRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter; 17 | 18 | import android.content.Context; 19 | import android.graphics.SurfaceTexture; 20 | import android.hardware.Camera; 21 | import android.opengl.GLES11Ext; 22 | import android.opengl.GLES20; 23 | import android.util.Log; 24 | import android.util.Pair; 25 | import android.util.SparseArray; 26 | import android.view.TextureView; 27 | 28 | import java.io.IOException; 29 | 30 | import javax.microedition.khronos.egl.EGL10; 31 | import javax.microedition.khronos.egl.EGLConfig; 32 | import javax.microedition.khronos.egl.EGLContext; 33 | import javax.microedition.khronos.egl.EGLDisplay; 34 | import javax.microedition.khronos.egl.EGLSurface; 35 | 36 | import cn.nekocode.camerafilter.filter.AsciiArtFilter; 37 | import cn.nekocode.camerafilter.filter.BasicDeformFilter; 38 | import cn.nekocode.camerafilter.filter.BlackAndWhiteFilter; 39 | import cn.nekocode.camerafilter.filter.BlueorangeFilter; 40 | import cn.nekocode.camerafilter.filter.CameraFilter; 41 | import cn.nekocode.camerafilter.filter.CartoonFilter; 42 | import cn.nekocode.camerafilter.filter.CastingFilter; 43 | import cn.nekocode.camerafilter.filter.ChromaticAberrationFilter; 44 | import cn.nekocode.camerafilter.filter.ContrastFilter; 45 | import cn.nekocode.camerafilter.filter.CrackedFilter; 46 | import cn.nekocode.camerafilter.filter.CrosshatchFilter; 47 | import cn.nekocode.camerafilter.filter.EMInterferenceFilter; 48 | import cn.nekocode.camerafilter.filter.EdgeDetectionFilter; 49 | import cn.nekocode.camerafilter.filter.GrayFilter; 50 | import cn.nekocode.camerafilter.filter.HexagonMosaicFilter; 51 | import cn.nekocode.camerafilter.filter.JFAVoronoiFilter; 52 | import cn.nekocode.camerafilter.filter.LegofiedFilter; 53 | import cn.nekocode.camerafilter.filter.LichtensteinEsqueFilter; 54 | import cn.nekocode.camerafilter.filter.MappingFilter; 55 | import cn.nekocode.camerafilter.filter.MirrorFilter; 56 | import cn.nekocode.camerafilter.filter.MoneyFilter; 57 | import cn.nekocode.camerafilter.filter.NegativeFilter; 58 | import cn.nekocode.camerafilter.filter.NoiseWarpFilter; 59 | import cn.nekocode.camerafilter.filter.NostalgiaFilter; 60 | import cn.nekocode.camerafilter.filter.OriginalFilter; 61 | import cn.nekocode.camerafilter.filter.PixelizeFilter; 62 | import cn.nekocode.camerafilter.filter.PolygonizationFilter; 63 | import cn.nekocode.camerafilter.filter.RefractionFilter; 64 | import cn.nekocode.camerafilter.filter.ReliefFilter; 65 | import cn.nekocode.camerafilter.filter.SwirlFilter; 66 | import cn.nekocode.camerafilter.filter.TileMosaicFilter; 67 | import cn.nekocode.camerafilter.filter.TrianglesMosaicFilter; 68 | import cn.nekocode.camerafilter.filter.TripleFilter; 69 | import cn.nekocode.camerafilter.filter.WaterReflectionFilter; 70 | 71 | /** 72 | * @author nekocode (nekocode.cn@gmail.com) 73 | */ 74 | public class CameraRenderer implements Runnable, TextureView.SurfaceTextureListener { 75 | private static final String TAG = "CameraRenderer"; 76 | private static final int EGL_OPENGL_ES2_BIT = 4; 77 | private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; 78 | private static final int DRAW_INTERVAL = 1000 / 30; 79 | 80 | private Thread renderThread; 81 | private Context context; 82 | private SurfaceTexture surfaceTexture; 83 | private int gwidth, gheight; 84 | 85 | private EGLDisplay eglDisplay; 86 | private EGLSurface eglSurface; 87 | private EGLContext eglContext; 88 | private EGL10 egl10; 89 | 90 | private Camera camera; 91 | private SurfaceTexture cameraSurfaceTexture; 92 | private int cameraTextureId; 93 | private CameraFilter selectedFilter; 94 | private int selectedFilterId = R.id.filter0; 95 | private SparseArray cameraFilterMap = new SparseArray<>(); 96 | 97 | public CameraRenderer(Context context) { 98 | this.context = context; 99 | } 100 | 101 | @Override 102 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { 103 | } 104 | 105 | @Override 106 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 107 | gwidth = -width; 108 | gheight = -height; 109 | } 110 | 111 | @Override 112 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 113 | if (camera != null) { 114 | camera.stopPreview(); 115 | camera.release(); 116 | } 117 | if (renderThread != null && renderThread.isAlive()) { 118 | renderThread.interrupt(); 119 | } 120 | CameraFilter.release(); 121 | 122 | return true; 123 | } 124 | 125 | @Override 126 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 127 | if (renderThread != null && renderThread.isAlive()) { 128 | renderThread.interrupt(); 129 | } 130 | renderThread = new Thread(this); 131 | 132 | surfaceTexture = surface; 133 | gwidth = -width; 134 | gheight = -height; 135 | 136 | // Open camera 137 | Pair backCamera = getBackCamera(); 138 | final int backCameraId = backCamera.second; 139 | camera = Camera.open(backCameraId); 140 | 141 | // Start rendering 142 | renderThread.start(); 143 | } 144 | 145 | public void setSelectedFilter(int id) { 146 | selectedFilterId = id; 147 | selectedFilter = cameraFilterMap.get(id); 148 | if (selectedFilter != null) 149 | selectedFilter.onAttach(); 150 | } 151 | 152 | @Override 153 | public void run() { 154 | initGL(surfaceTexture); 155 | 156 | // Setup camera filters map 157 | cameraFilterMap.append(R.id.filter0, new OriginalFilter(context)); 158 | cameraFilterMap.append(R.id.filter1, new EdgeDetectionFilter(context)); 159 | cameraFilterMap.append(R.id.filter2, new PixelizeFilter(context)); 160 | cameraFilterMap.append(R.id.filter3, new EMInterferenceFilter(context)); 161 | cameraFilterMap.append(R.id.filter4, new TrianglesMosaicFilter(context)); 162 | cameraFilterMap.append(R.id.filter5, new LegofiedFilter(context)); 163 | cameraFilterMap.append(R.id.filter6, new TileMosaicFilter(context)); 164 | cameraFilterMap.append(R.id.filter7, new BlueorangeFilter(context)); 165 | cameraFilterMap.append(R.id.filter8, new ChromaticAberrationFilter(context)); 166 | cameraFilterMap.append(R.id.filter9, new BasicDeformFilter(context)); 167 | cameraFilterMap.append(R.id.filter10, new ContrastFilter(context)); 168 | cameraFilterMap.append(R.id.filter11, new NoiseWarpFilter(context)); 169 | cameraFilterMap.append(R.id.filter12, new RefractionFilter(context)); 170 | cameraFilterMap.append(R.id.filter13, new MappingFilter(context)); 171 | cameraFilterMap.append(R.id.filter14, new CrosshatchFilter(context)); 172 | cameraFilterMap.append(R.id.filter15, new LichtensteinEsqueFilter(context)); 173 | cameraFilterMap.append(R.id.filter16, new AsciiArtFilter(context)); 174 | cameraFilterMap.append(R.id.filter17, new MoneyFilter(context)); 175 | cameraFilterMap.append(R.id.filter18, new CrackedFilter(context)); 176 | cameraFilterMap.append(R.id.filter19, new PolygonizationFilter(context)); 177 | cameraFilterMap.append(R.id.filter20, new JFAVoronoiFilter(context)); 178 | cameraFilterMap.append(R.id.filter21, new BlackAndWhiteFilter(context)); 179 | cameraFilterMap.append(R.id.filter22, new GrayFilter(context)); 180 | cameraFilterMap.append(R.id.filter23, new NegativeFilter(context)); 181 | cameraFilterMap.append(R.id.filter24, new NostalgiaFilter(context)); 182 | cameraFilterMap.append(R.id.filter25, new CastingFilter(context)); 183 | cameraFilterMap.append(R.id.filter26, new ReliefFilter(context)); 184 | cameraFilterMap.append(R.id.filter27, new SwirlFilter(context)); 185 | cameraFilterMap.append(R.id.filter28, new HexagonMosaicFilter(context)); 186 | cameraFilterMap.append(R.id.filter29, new MirrorFilter(context)); 187 | cameraFilterMap.append(R.id.filter30, new TripleFilter(context)); 188 | cameraFilterMap.append(R.id.filter31, new CartoonFilter(context)); 189 | cameraFilterMap.append(R.id.filter32, new WaterReflectionFilter(context)); 190 | setSelectedFilter(selectedFilterId); 191 | 192 | // Create texture for camera preview 193 | cameraTextureId = MyGLUtils.genTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); 194 | cameraSurfaceTexture = new SurfaceTexture(cameraTextureId); 195 | 196 | // Start camera preview 197 | try { 198 | camera.setPreviewTexture(cameraSurfaceTexture); 199 | camera.startPreview(); 200 | } catch (IOException ioe) { 201 | // Something bad happened 202 | } 203 | 204 | // Render loop 205 | while (!Thread.currentThread().isInterrupted()) { 206 | try { 207 | if (gwidth < 0 && gheight < 0) 208 | GLES20.glViewport(0, 0, gwidth = -gwidth, gheight = -gheight); 209 | 210 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 211 | 212 | // Update the camera preview texture 213 | synchronized (this) { 214 | cameraSurfaceTexture.updateTexImage(); 215 | } 216 | 217 | // Draw camera preview 218 | selectedFilter.draw(cameraTextureId, gwidth, gheight); 219 | 220 | // Flush 221 | GLES20.glFlush(); 222 | egl10.eglSwapBuffers(eglDisplay, eglSurface); 223 | 224 | Thread.sleep(DRAW_INTERVAL); 225 | 226 | } catch (InterruptedException e) { 227 | Thread.currentThread().interrupt(); 228 | } 229 | } 230 | 231 | cameraSurfaceTexture.release(); 232 | GLES20.glDeleteTextures(1, new int[]{cameraTextureId}, 0); 233 | } 234 | 235 | private void initGL(SurfaceTexture texture) { 236 | egl10 = (EGL10) EGLContext.getEGL(); 237 | 238 | eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); 239 | if (eglDisplay == EGL10.EGL_NO_DISPLAY) { 240 | throw new RuntimeException("eglGetDisplay failed " + 241 | android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); 242 | } 243 | 244 | int[] version = new int[2]; 245 | if (!egl10.eglInitialize(eglDisplay, version)) { 246 | throw new RuntimeException("eglInitialize failed " + 247 | android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); 248 | } 249 | 250 | int[] configsCount = new int[1]; 251 | EGLConfig[] configs = new EGLConfig[1]; 252 | int[] configSpec = { 253 | EGL10.EGL_RENDERABLE_TYPE, 254 | EGL_OPENGL_ES2_BIT, 255 | EGL10.EGL_RED_SIZE, 8, 256 | EGL10.EGL_GREEN_SIZE, 8, 257 | EGL10.EGL_BLUE_SIZE, 8, 258 | EGL10.EGL_ALPHA_SIZE, 8, 259 | EGL10.EGL_DEPTH_SIZE, 0, 260 | EGL10.EGL_STENCIL_SIZE, 0, 261 | EGL10.EGL_NONE 262 | }; 263 | 264 | EGLConfig eglConfig = null; 265 | if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) { 266 | throw new IllegalArgumentException("eglChooseConfig failed " + 267 | android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); 268 | } else if (configsCount[0] > 0) { 269 | eglConfig = configs[0]; 270 | } 271 | if (eglConfig == null) { 272 | throw new RuntimeException("eglConfig not initialized"); 273 | } 274 | 275 | int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; 276 | eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); 277 | eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfig, texture, null); 278 | 279 | if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { 280 | int error = egl10.eglGetError(); 281 | if (error == EGL10.EGL_BAD_NATIVE_WINDOW) { 282 | Log.e(TAG, "eglCreateWindowSurface returned EGL10.EGL_BAD_NATIVE_WINDOW"); 283 | return; 284 | } 285 | throw new RuntimeException("eglCreateWindowSurface failed " + 286 | android.opengl.GLUtils.getEGLErrorString(error)); 287 | } 288 | 289 | if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { 290 | throw new RuntimeException("eglMakeCurrent failed " + 291 | android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); 292 | } 293 | } 294 | 295 | private Pair getBackCamera() { 296 | Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); 297 | final int numberOfCameras = Camera.getNumberOfCameras(); 298 | 299 | for (int i = 0; i < numberOfCameras; ++i) { 300 | Camera.getCameraInfo(i, cameraInfo); 301 | if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { 302 | return new Pair<>(cameraInfo, i); 303 | } 304 | } 305 | return null; 306 | } 307 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter; 17 | 18 | import android.Manifest; 19 | import android.content.pm.PackageManager; 20 | import android.graphics.Bitmap; 21 | import android.os.Bundle; 22 | import android.os.Environment; 23 | import android.support.v4.app.ActivityCompat; 24 | import android.support.v4.content.ContextCompat; 25 | import android.support.v7.app.AppCompatActivity; 26 | import android.view.GestureDetector; 27 | import android.view.Menu; 28 | import android.view.MenuItem; 29 | import android.view.MotionEvent; 30 | import android.view.TextureView; 31 | import android.view.View; 32 | import android.widget.FrameLayout; 33 | import android.widget.Toast; 34 | 35 | import java.io.File; 36 | import java.io.FileNotFoundException; 37 | import java.io.FileOutputStream; 38 | import java.io.IOException; 39 | import java.io.OutputStream; 40 | import java.text.SimpleDateFormat; 41 | import java.util.ArrayList; 42 | import java.util.Arrays; 43 | import java.util.Date; 44 | 45 | /** 46 | * @author nekocode (nekocode.cn@gmail.com) 47 | */ 48 | public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener { 49 | private static final int REQUEST_CAMERA_PERMISSION = 101; 50 | private FrameLayout container; 51 | private CameraRenderer renderer; 52 | private TextureView textureView; 53 | private int filterId = R.id.filter0; 54 | private int mCurrentFilterId = 0; 55 | 56 | String[] TITLES = {"Original", "EdgeDectection", "Pixelize", 57 | "EMInterference", "TrianglesMosaic", "Legofied", 58 | "TileMosaic", "Blueorange", "ChromaticAberration", 59 | "BasicDeform", "Contrast", "NoiseWarp", "Refraction", 60 | "Mapping", "Crosshatch", "LichtensteinEsque", 61 | "AsciiArt", "MoneyFilter", "Cracked", "Polygonization", 62 | "JFAVoronoi", "BlackAndWhite", "Gray", "Negative", 63 | "Nostalgia", "Casting", "Relief", "Swirl", "HexagonMosaic", 64 | "Mirror", "Triple", "Cartoon", "WaterReflection" 65 | }; 66 | 67 | Integer[] FILTER_RES_IDS = {R.id.filter0, R.id.filter1, R.id.filter2, R.id.filter3, R.id.filter4, 68 | R.id.filter5, R.id.filter6, R.id.filter7, R.id.filter8, R.id.filter9, R.id.filter10, 69 | R.id.filter11, R.id.filter12, R.id.filter13, R.id.filter14, R.id.filter15, R.id.filter16, 70 | R.id.filter17, R.id.filter18, R.id.filter19, R.id.filter20, 71 | R.id.filter21, R.id.filter22, R.id.filter23, R.id.filter24, 72 | R.id.filter25, R.id.filter26, R.id.filter27, R.id.filter28, 73 | R.id.filter29, R.id.filter30, R.id.filter31, R.id.filter32}; 74 | 75 | ArrayList mFilterArray = new ArrayList<>(Arrays.asList(FILTER_RES_IDS)); 76 | 77 | GestureDetector mGestureDetector; 78 | 79 | @Override 80 | protected void onCreate(Bundle savedInstanceState) { 81 | super.onCreate(savedInstanceState); 82 | setContentView(container = new FrameLayout(this)); 83 | setTitle(TITLES[mCurrentFilterId]); 84 | 85 | 86 | if (ContextCompat.checkSelfPermission(this, 87 | Manifest.permission.CAMERA) 88 | != PackageManager.PERMISSION_GRANTED) { 89 | 90 | // Should we show an explanation? 91 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { 92 | Toast.makeText(this, "Camera access is required.", Toast.LENGTH_SHORT).show(); 93 | 94 | } else { 95 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 96 | REQUEST_CAMERA_PERMISSION); 97 | } 98 | 99 | } else { 100 | setupCameraPreviewView(); 101 | } 102 | 103 | mGestureDetector = new GestureDetector(this, this); 104 | } 105 | 106 | @Override 107 | public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 108 | switch (requestCode) { 109 | case REQUEST_CAMERA_PERMISSION: { 110 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 111 | setupCameraPreviewView(); 112 | } 113 | } 114 | } 115 | } 116 | 117 | void setupCameraPreviewView() { 118 | renderer = new CameraRenderer(this); 119 | textureView = new TextureView(this); 120 | container.addView(textureView); 121 | textureView.setSurfaceTextureListener(renderer); 122 | 123 | // textureView.setOnTouchListener(this); 124 | textureView.setOnTouchListener(new View.OnTouchListener() { 125 | @Override 126 | public boolean onTouch(View view, MotionEvent motionEvent) { 127 | mGestureDetector.onTouchEvent(motionEvent); 128 | return true; 129 | } 130 | }); 131 | 132 | textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { 133 | @Override 134 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 135 | renderer.onSurfaceTextureSizeChanged(null, v.getWidth(), v.getHeight()); 136 | } 137 | }); 138 | } 139 | 140 | @Override 141 | public boolean onCreateOptionsMenu(Menu menu) { 142 | getMenuInflater().inflate(R.menu.filter, menu); 143 | return true; 144 | } 145 | 146 | @Override 147 | public boolean onOptionsItemSelected(MenuItem item) { 148 | filterId = item.getItemId(); 149 | 150 | // TODO: need tidy up 151 | if (filterId == R.id.capture) { 152 | Toast.makeText(this, 153 | capture() ? "The capture has been saved to your sdcard root path." : 154 | "Save failed!", 155 | Toast.LENGTH_SHORT).show(); 156 | return true; 157 | } 158 | 159 | setTitle(item.getTitle()); 160 | 161 | if (renderer != null) 162 | renderer.setSelectedFilter(filterId); 163 | mCurrentFilterId = mFilterArray.indexOf(filterId); 164 | return true; 165 | } 166 | 167 | private boolean capture() { 168 | String mPath = genSaveFileName(getTitle().toString() + "_", ".png"); 169 | File imageFile = new File(mPath); 170 | if (imageFile.exists()) { 171 | imageFile.delete(); 172 | } 173 | 174 | // create bitmap screen capture 175 | Bitmap bitmap = textureView.getBitmap(); 176 | OutputStream outputStream = null; 177 | 178 | try { 179 | outputStream = new FileOutputStream(imageFile); 180 | bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream); 181 | outputStream.flush(); 182 | outputStream.close(); 183 | 184 | } catch (FileNotFoundException e) { 185 | e.printStackTrace(); 186 | return false; 187 | } catch (IOException e) { 188 | e.printStackTrace(); 189 | return false; 190 | } 191 | 192 | return true; 193 | } 194 | 195 | private String genSaveFileName(String prefix, String suffix) { 196 | Date date = new Date(); 197 | SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyyMMdd_hhmmss"); 198 | String timeString = dateformat1.format(date); 199 | String externalPath = Environment.getExternalStorageDirectory().toString(); 200 | return externalPath + "/" + prefix + timeString + suffix; 201 | } 202 | 203 | @Override 204 | public boolean onDown(MotionEvent motionEvent) { 205 | 206 | return false; 207 | } 208 | 209 | @Override 210 | public void onShowPress(MotionEvent motionEvent) { 211 | 212 | } 213 | 214 | @Override 215 | public boolean onSingleTapUp(MotionEvent motionEvent) { 216 | return false; 217 | } 218 | 219 | @Override 220 | public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { 221 | return false; 222 | } 223 | 224 | @Override 225 | public void onLongPress(MotionEvent motionEvent) { 226 | 227 | } 228 | 229 | @Override 230 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 231 | float velocity = Math.abs(velocityX) > Math.abs(velocityY) ? velocityX : velocityY; 232 | int step = velocity > 0 ? -1 : 1; 233 | mCurrentFilterId = circleLoop(TITLES.length, mCurrentFilterId, step); 234 | setTitle(TITLES[mCurrentFilterId]); 235 | if (renderer != null) { 236 | renderer.setSelectedFilter(FILTER_RES_IDS[mCurrentFilterId]); 237 | } 238 | return true; 239 | } 240 | 241 | private int circleLoop(int size, int currentPos, int step) { 242 | if (step == 0) { 243 | return currentPos; 244 | } 245 | 246 | if (step > 0) { 247 | if (currentPos + step >= size) { 248 | return (currentPos + step) % size; 249 | } else { 250 | return currentPos + step; 251 | } 252 | } else { 253 | if (currentPos + step < 0) { 254 | return currentPos + step + size; 255 | } else { 256 | return currentPos + step; 257 | } 258 | } 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/MyGLUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter; 17 | 18 | import android.content.Context; 19 | import android.content.res.Resources; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.opengl.GLES11Ext; 23 | import android.opengl.GLES20; 24 | import android.opengl.GLUtils; 25 | import android.util.Log; 26 | 27 | import java.io.ByteArrayOutputStream; 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | 31 | import javax.microedition.khronos.opengles.GL10; 32 | 33 | /** 34 | * @author nekocode (nekocode.cn@gmail.com) 35 | */ 36 | public class MyGLUtils { 37 | private static final String TAG = "MyGLUtils"; 38 | 39 | public static int genTexture() { 40 | return genTexture(GLES20.GL_TEXTURE_2D); 41 | } 42 | 43 | public static int genTexture(int textureType) { 44 | int[] genBuf = new int[1]; 45 | GLES20.glGenTextures(1, genBuf, 0); 46 | GLES20.glBindTexture(textureType, genBuf[0]); 47 | 48 | // Set texture default draw parameters 49 | if (textureType == GLES11Ext.GL_TEXTURE_EXTERNAL_OES) { 50 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); 51 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 52 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); 53 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); 54 | 55 | } else { 56 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); 57 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 58 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); 59 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); 60 | } 61 | 62 | return genBuf[0]; 63 | } 64 | 65 | public static int loadTexture(final Context context, final int resourceId, int[] size) { 66 | final int texId = genTexture(); 67 | 68 | if (texId != 0) { 69 | final BitmapFactory.Options options = new BitmapFactory.Options(); 70 | options.inScaled = false; // No pre-scaling 71 | options.inJustDecodeBounds = true; 72 | 73 | // Just decode bounds 74 | BitmapFactory.decodeResource(context.getResources(), resourceId, options); 75 | 76 | // Set return size 77 | size[0] = options.outWidth; 78 | size[1] = options.outHeight; 79 | 80 | // Decode 81 | options.inJustDecodeBounds = false; 82 | Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options); 83 | 84 | // Load the bitmap into the bound texture. 85 | GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); 86 | 87 | // Recycle the bitmap, since its data has been loaded into OpenGL. 88 | bitmap.recycle(); 89 | } 90 | 91 | return texId; 92 | } 93 | 94 | public static int buildProgram(Context context, int vertexSourceRawId, int fragmentSourceRawId) { 95 | return buildProgram(getStringFromRaw(context, vertexSourceRawId), 96 | getStringFromRaw(context, fragmentSourceRawId)); 97 | } 98 | 99 | public static int buildProgram(String vertexSource, String fragmentSource) { 100 | final int vertexShader = buildShader(GLES20.GL_VERTEX_SHADER, vertexSource); 101 | if (vertexShader == 0) { 102 | return 0; 103 | } 104 | 105 | final int fragmentShader = buildShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); 106 | if (fragmentShader == 0) { 107 | return 0; 108 | } 109 | 110 | final int program = GLES20.glCreateProgram(); 111 | if (program == 0) { 112 | return 0; 113 | } 114 | 115 | GLES20.glAttachShader(program, vertexShader); 116 | GLES20.glAttachShader(program, fragmentShader); 117 | GLES20.glLinkProgram(program); 118 | 119 | return program; 120 | } 121 | 122 | public static int buildShader(int type, String shaderSource) { 123 | final int shader = GLES20.glCreateShader(type); 124 | if (shader == 0) { 125 | return 0; 126 | } 127 | 128 | GLES20.glShaderSource(shader, shaderSource); 129 | GLES20.glCompileShader(shader); 130 | 131 | int[] status = new int[1]; 132 | GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, status, 0); 133 | if (status[0] == 0) { 134 | Log.e(TAG, GLES20.glGetShaderInfoLog(shader)); 135 | GLES20.glDeleteShader(shader); 136 | return 0; 137 | } 138 | 139 | return shader; 140 | } 141 | 142 | private static String getStringFromRaw(Context context, int id) { 143 | String str; 144 | try { 145 | Resources r = context.getResources(); 146 | InputStream is = r.openRawResource(id); 147 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 148 | int i = is.read(); 149 | while (i != -1) { 150 | baos.write(i); 151 | i = is.read(); 152 | } 153 | 154 | str = baos.toString(); 155 | is.close(); 156 | } catch (IOException e) { 157 | str = ""; 158 | } 159 | 160 | return str; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/RenderBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter; 17 | 18 | import android.opengl.GLES20; 19 | 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.IntBuffer; 23 | 24 | import javax.microedition.khronos.opengles.GL10; 25 | 26 | /** 27 | * @author nekocode (nekocode.cn@gmail.com) 28 | */ 29 | public class RenderBuffer { 30 | private int texId = 0; 31 | private int activeTexUnit = 0; 32 | private int renderBufferId = 0; 33 | private int frameBufferId = 0; 34 | 35 | private int width, height; 36 | 37 | public RenderBuffer(int width, int height, int activeTexUnit) { 38 | this.width = width; 39 | this.height = height; 40 | this.activeTexUnit = activeTexUnit; 41 | int[] genbuf = new int[1]; 42 | 43 | // Generate and bind 2d texture 44 | GLES20.glActiveTexture(activeTexUnit); 45 | texId = MyGLUtils.genTexture(); 46 | IntBuffer texBuffer = 47 | ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); 48 | GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texBuffer); 49 | 50 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); 51 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 52 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); 53 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); 54 | 55 | // Generate frame buffer 56 | GLES20.glGenFramebuffers(1, genbuf, 0); 57 | frameBufferId = genbuf[0]; 58 | // Bind frame buffer 59 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); 60 | 61 | // Generate render buffer 62 | GLES20.glGenRenderbuffers(1, genbuf, 0); 63 | renderBufferId = genbuf[0]; 64 | // Bind render buffer 65 | GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferId); 66 | GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); 67 | 68 | unbind(); 69 | } 70 | 71 | public int getTexId() { 72 | return texId; 73 | } 74 | 75 | public int getWidth() { 76 | return width; 77 | } 78 | 79 | public int getHeight() { 80 | return height; 81 | } 82 | 83 | public int getActiveTexUnit() { 84 | return activeTexUnit; 85 | } 86 | 87 | public void bind() { 88 | GLES20.glViewport(0, 0, width, height); 89 | 90 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); 91 | GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, 92 | GLES20.GL_TEXTURE_2D, texId, 0); 93 | GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, 94 | GLES20.GL_RENDERBUFFER, renderBufferId); 95 | } 96 | 97 | public void unbind() { 98 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/AsciiArtFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class AsciiArtFilter extends CameraFilter { 28 | private int program; 29 | 30 | public AsciiArtFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.ascii_art); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/BasicDeformFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class BasicDeformFilter extends CameraFilter { 28 | private int program; 29 | 30 | public BasicDeformFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.basic_deform); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/BlackAndWhiteFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class BlackAndWhiteFilter extends CameraFilter { 28 | private int program; 29 | 30 | public BlackAndWhiteFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.black_and_white); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/BlueorangeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class BlueorangeFilter extends CameraFilter { 28 | private int program; 29 | 30 | public BlueorangeFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.blue_orange); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/CameraFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES11Ext; 20 | import android.opengl.GLES20; 21 | import android.support.annotation.CallSuper; 22 | 23 | import java.nio.ByteBuffer; 24 | import java.nio.ByteOrder; 25 | import java.nio.FloatBuffer; 26 | 27 | import cn.nekocode.camerafilter.MyGLUtils; 28 | import cn.nekocode.camerafilter.R; 29 | import cn.nekocode.camerafilter.RenderBuffer; 30 | 31 | /** 32 | * @author nekocode (nekocode.cn@gmail.com) 33 | */ 34 | public abstract class CameraFilter { 35 | static final float SQUARE_COORDS[] = { 36 | 1.0f, -1.0f, 37 | -1.0f, -1.0f, 38 | 1.0f, 1.0f, 39 | -1.0f, 1.0f, 40 | }; 41 | static final float TEXTURE_COORDS[] = { 42 | 1.0f, 0.0f, 43 | 0.0f, 0.0f, 44 | 1.0f, 1.0f, 45 | 0.0f, 1.0f, 46 | }; 47 | static FloatBuffer VERTEX_BUF, TEXTURE_COORD_BUF; 48 | static int PROGRAM = 0; 49 | 50 | private static final int BUF_ACTIVE_TEX_UNIT = GLES20.GL_TEXTURE8; 51 | private static RenderBuffer CAMERA_RENDER_BUF; 52 | 53 | private static final float ROATED_TEXTURE_COORDS[] = { 54 | 1.0f, 0.0f, 55 | 1.0f, 1.0f, 56 | 0.0f, 0.0f, 57 | 0.0f, 1.0f, 58 | }; 59 | private static FloatBuffer ROATED_TEXTURE_COORD_BUF; 60 | 61 | final long START_TIME = System.currentTimeMillis(); 62 | int iFrame = 0; 63 | 64 | public CameraFilter(Context context) { 65 | // Setup default Buffers 66 | if (VERTEX_BUF == null) { 67 | VERTEX_BUF = ByteBuffer.allocateDirect(SQUARE_COORDS.length * 4) 68 | .order(ByteOrder.nativeOrder()).asFloatBuffer(); 69 | VERTEX_BUF.put(SQUARE_COORDS); 70 | VERTEX_BUF.position(0); 71 | } 72 | 73 | if (TEXTURE_COORD_BUF == null) { 74 | TEXTURE_COORD_BUF = ByteBuffer.allocateDirect(TEXTURE_COORDS.length * 4) 75 | .order(ByteOrder.nativeOrder()).asFloatBuffer(); 76 | TEXTURE_COORD_BUF.put(TEXTURE_COORDS); 77 | TEXTURE_COORD_BUF.position(0); 78 | } 79 | 80 | if (ROATED_TEXTURE_COORD_BUF == null) { 81 | ROATED_TEXTURE_COORD_BUF = ByteBuffer.allocateDirect(ROATED_TEXTURE_COORDS.length * 4) 82 | .order(ByteOrder.nativeOrder()).asFloatBuffer(); 83 | ROATED_TEXTURE_COORD_BUF.put(ROATED_TEXTURE_COORDS); 84 | ROATED_TEXTURE_COORD_BUF.position(0); 85 | } 86 | 87 | if (PROGRAM == 0) { 88 | PROGRAM = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.original_rtt); 89 | } 90 | } 91 | 92 | @CallSuper 93 | public void onAttach() { 94 | iFrame = 0; 95 | } 96 | 97 | final public void draw(int cameraTexId, int canvasWidth, int canvasHeight) { 98 | // TODO move? 99 | // Create camera render buffer 100 | if (CAMERA_RENDER_BUF == null || 101 | CAMERA_RENDER_BUF.getWidth() != canvasWidth || 102 | CAMERA_RENDER_BUF.getHeight() != canvasHeight) { 103 | CAMERA_RENDER_BUF = new RenderBuffer(canvasWidth, canvasHeight, BUF_ACTIVE_TEX_UNIT); 104 | } 105 | 106 | // Use shaders 107 | GLES20.glUseProgram(PROGRAM); 108 | 109 | int iChannel0Location = GLES20.glGetUniformLocation(PROGRAM, "iChannel0"); 110 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0); 111 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTexId); 112 | GLES20.glUniform1i(iChannel0Location, 0); 113 | 114 | int vPositionLocation = GLES20.glGetAttribLocation(PROGRAM, "vPosition"); 115 | GLES20.glEnableVertexAttribArray(vPositionLocation); 116 | GLES20.glVertexAttribPointer(vPositionLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, VERTEX_BUF); 117 | 118 | int vTexCoordLocation = GLES20.glGetAttribLocation(PROGRAM, "vTexCoord"); 119 | GLES20.glEnableVertexAttribArray(vTexCoordLocation); 120 | GLES20.glVertexAttribPointer(vTexCoordLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, ROATED_TEXTURE_COORD_BUF); 121 | 122 | // Render to texture 123 | CAMERA_RENDER_BUF.bind(); 124 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 125 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 126 | CAMERA_RENDER_BUF.unbind(); 127 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 128 | 129 | onDraw(CAMERA_RENDER_BUF.getTexId(), canvasWidth, canvasHeight); 130 | 131 | iFrame++; 132 | } 133 | 134 | abstract void onDraw(int cameraTexId, int canvasWidth, int canvasHeight); 135 | 136 | void setupShaderInputs(int program, int[] iResolution, int[] iChannels, int[][] iChannelResolutions) { 137 | setupShaderInputs(program, VERTEX_BUF, TEXTURE_COORD_BUF, iResolution, iChannels, iChannelResolutions); 138 | } 139 | 140 | void setupShaderInputs(int program, FloatBuffer vertex, FloatBuffer textureCoord, int[] iResolution, int[] iChannels, int[][] iChannelResolutions) { 141 | GLES20.glUseProgram(program); 142 | 143 | int iResolutionLocation = GLES20.glGetUniformLocation(program, "iResolution"); 144 | GLES20.glUniform3fv(iResolutionLocation, 1, 145 | FloatBuffer.wrap(new float[]{(float) iResolution[0], (float) iResolution[1], 1.0f})); 146 | 147 | float time = ((float) (System.currentTimeMillis() - START_TIME)) / 1000.0f; 148 | int iGlobalTimeLocation = GLES20.glGetUniformLocation(program, "iGlobalTime"); 149 | GLES20.glUniform1f(iGlobalTimeLocation, time); 150 | 151 | int iFrameLocation = GLES20.glGetUniformLocation(program, "iFrame"); 152 | GLES20.glUniform1i(iFrameLocation, iFrame); 153 | 154 | int vPositionLocation = GLES20.glGetAttribLocation(program, "vPosition"); 155 | GLES20.glEnableVertexAttribArray(vPositionLocation); 156 | GLES20.glVertexAttribPointer(vPositionLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, vertex); 157 | 158 | int vTexCoordLocation = GLES20.glGetAttribLocation(program, "vTexCoord"); 159 | GLES20.glEnableVertexAttribArray(vTexCoordLocation); 160 | GLES20.glVertexAttribPointer(vTexCoordLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoord); 161 | 162 | for (int i = 0; i < iChannels.length; i++) { 163 | int sTextureLocation = GLES20.glGetUniformLocation(program, "iChannel" + i); 164 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i); 165 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, iChannels[i]); 166 | GLES20.glUniform1i(sTextureLocation, i); 167 | } 168 | 169 | float _iChannelResolutions[] = new float[iChannelResolutions.length * 3]; 170 | for (int i = 0; i < iChannelResolutions.length; i++) { 171 | _iChannelResolutions[i * 3] = iChannelResolutions[i][0]; 172 | _iChannelResolutions[i * 3 + 1] = iChannelResolutions[i][1]; 173 | _iChannelResolutions[i * 3 + 2] = 1.0f; 174 | } 175 | 176 | int iChannelResolutionLocation = GLES20.glGetUniformLocation(program, "iChannelResolution"); 177 | GLES20.glUniform3fv(iChannelResolutionLocation, 178 | _iChannelResolutions.length, FloatBuffer.wrap(_iChannelResolutions)); 179 | } 180 | 181 | public static void release() { 182 | PROGRAM = 0; 183 | CAMERA_RENDER_BUF = null; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/CartoonFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class CartoonFilter extends CameraFilter { 28 | private int program; 29 | 30 | public CartoonFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.cartoon); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/CastingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class CastingFilter extends CameraFilter { 28 | private int program; 29 | 30 | public CastingFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.casting); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/ChromaticAberrationFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class ChromaticAberrationFilter extends CameraFilter { 28 | private int program; 29 | 30 | public ChromaticAberrationFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.chromatic_aberration); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/ContrastFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class ContrastFilter extends CameraFilter { 28 | private int program; 29 | 30 | public ContrastFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.contrast); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/CrackedFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class CrackedFilter extends CameraFilter { 28 | private int program; 29 | 30 | public CrackedFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.cracked); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/CrosshatchFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class CrosshatchFilter extends CameraFilter { 28 | private int program; 29 | 30 | public CrosshatchFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.crosshatch); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/EMInterferenceFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class EMInterferenceFilter extends CameraFilter { 28 | private int program; 29 | 30 | public EMInterferenceFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.em_interference); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/EdgeDetectionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class EdgeDetectionFilter extends CameraFilter { 28 | private int program; 29 | 30 | public EdgeDetectionFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.edge_detection); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/GrayFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class GrayFilter extends CameraFilter { 28 | private int program; 29 | 30 | public GrayFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.gray); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/HexagonMosaicFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class HexagonMosaicFilter extends CameraFilter { 28 | private int program; 29 | 30 | public HexagonMosaicFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.hexagon_mosaic); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/JFAVoronoiFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | import cn.nekocode.camerafilter.RenderBuffer; 24 | 25 | /** 26 | * @author nekocode (nekocode.cn@gmail.com) 27 | */ 28 | public class JFAVoronoiFilter extends CameraFilter { 29 | private int programImg; 30 | private int programA; 31 | private int programB; 32 | private int programC; 33 | 34 | private RenderBuffer bufA; 35 | private RenderBuffer bufB; 36 | private RenderBuffer bufC; 37 | 38 | public JFAVoronoiFilter(Context context) { 39 | super(context); 40 | 41 | // Build shaders 42 | programImg = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.voronoi); 43 | programA = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.voronoi_buf_a); 44 | programB = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.voronoi_buf_b); 45 | programC = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.voronoi_buf_c); 46 | } 47 | 48 | @Override 49 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 50 | // TODO move? 51 | if (bufA == null || bufA.getWidth() != canvasWidth || bufB.getHeight() != canvasHeight) { 52 | // Create new textures for buffering 53 | bufA = new RenderBuffer(canvasWidth, canvasHeight, GLES20.GL_TEXTURE4); 54 | bufB = new RenderBuffer(canvasWidth, canvasHeight, GLES20.GL_TEXTURE5); 55 | bufC = new RenderBuffer(canvasWidth, canvasHeight, GLES20.GL_TEXTURE6); 56 | } 57 | 58 | // Render to buf a 59 | setupShaderInputs(programA, 60 | new int[]{canvasWidth, canvasHeight}, 61 | new int[]{cameraTexId, bufA.getTexId()}, 62 | new int[][]{new int[]{canvasWidth, canvasHeight}, new int[]{canvasWidth, canvasHeight}}); 63 | bufA.bind(); 64 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 65 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 66 | bufA.unbind(); 67 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 68 | 69 | 70 | // Render to buf b 71 | setupShaderInputs(programB, 72 | new int[]{canvasWidth, canvasHeight}, 73 | new int[]{bufB.getTexId(), bufA.getTexId()}, 74 | new int[][]{new int[]{canvasWidth, canvasHeight}, new int[]{canvasWidth, canvasHeight}}); 75 | bufB.bind(); 76 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 77 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 78 | bufB.unbind(); 79 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 80 | 81 | 82 | // Render to buf c 83 | setupShaderInputs(programC, 84 | new int[]{canvasWidth, canvasHeight}, 85 | new int[]{bufC.getTexId(), bufB.getTexId()}, 86 | new int[][]{new int[]{canvasWidth, canvasHeight}, new int[]{canvasWidth, canvasHeight}}); 87 | bufC.bind(); 88 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 89 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 90 | bufC.unbind(); 91 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 92 | 93 | 94 | // Render to screen 95 | setupShaderInputs(programImg, 96 | new int[]{canvasWidth, canvasHeight}, 97 | new int[]{bufC.getTexId(), bufA.getTexId()}, 98 | new int[][]{new int[]{canvasWidth, canvasHeight}, new int[]{canvasWidth, canvasHeight}}); 99 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/LegofiedFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class LegofiedFilter extends CameraFilter { 28 | private int program; 29 | 30 | public LegofiedFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.legofied); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/LichtensteinEsqueFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class LichtensteinEsqueFilter extends CameraFilter { 28 | private int program; 29 | 30 | public LichtensteinEsqueFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.lichtenstein_esque); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/MappingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class MappingFilter extends CameraFilter { 28 | private int program; 29 | private int texture2Id; 30 | 31 | public MappingFilter(Context context) { 32 | super(context); 33 | 34 | // Build shaders 35 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.mapping); 36 | 37 | // Load the texture will need for the shader 38 | texture2Id = MyGLUtils.loadTexture(context, R.raw.tex00, new int[2]); 39 | } 40 | 41 | @Override 42 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 43 | setupShaderInputs(program, 44 | new int[]{canvasWidth, canvasHeight}, 45 | new int[]{cameraTexId, texture2Id}, 46 | new int[][]{}); 47 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/MirrorFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class MirrorFilter extends CameraFilter { 28 | private int program; 29 | 30 | public MirrorFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.mirror); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/MoneyFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class MoneyFilter extends CameraFilter { 28 | private int program; 29 | 30 | public MoneyFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.money_filter); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/NegativeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class NegativeFilter extends CameraFilter { 28 | private int program; 29 | 30 | public NegativeFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.negative); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/NoiseWarpFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class NoiseWarpFilter extends CameraFilter { 28 | private int program; 29 | 30 | public NoiseWarpFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.noise_warp); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/NostalgiaFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class NostalgiaFilter extends CameraFilter { 28 | private int program; 29 | 30 | public NostalgiaFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.nostalgia); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/OriginalFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class OriginalFilter extends CameraFilter { 28 | private int program; 29 | 30 | public OriginalFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.original); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/PixelizeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class PixelizeFilter extends CameraFilter { 28 | private int program; 29 | 30 | public PixelizeFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.pixelize); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/PolygonizationFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class PolygonizationFilter extends CameraFilter { 28 | private int program; 29 | 30 | public PolygonizationFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.polygonization); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/RefractionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class RefractionFilter extends CameraFilter { 28 | private int program; 29 | private int texture2Id; 30 | 31 | public RefractionFilter(Context context) { 32 | super(context); 33 | 34 | // Build shaders 35 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.refraction); 36 | 37 | // Load the texture will need for the shader 38 | texture2Id = MyGLUtils.loadTexture(context, R.raw.tex11, new int[2]); 39 | } 40 | 41 | @Override 42 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 43 | setupShaderInputs(program, 44 | new int[]{canvasWidth, canvasHeight}, 45 | new int[]{cameraTexId, texture2Id}, 46 | new int[][]{}); 47 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/ReliefFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class ReliefFilter extends CameraFilter { 28 | private int program; 29 | 30 | public ReliefFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.relief); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/SwirlFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class SwirlFilter extends CameraFilter { 28 | private int program; 29 | 30 | public SwirlFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.swirl); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/TileMosaicFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class TileMosaicFilter extends CameraFilter { 28 | private int program; 29 | 30 | public TileMosaicFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.tile_mosaic); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/TrianglesMosaicFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 nekocode 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author nekocode (nekocode.cn@gmail.com) 26 | */ 27 | public class TrianglesMosaicFilter extends CameraFilter { 28 | private int program; 29 | 30 | public TrianglesMosaicFilter(Context context) { 31 | super(context); 32 | 33 | // Build shaders 34 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.triangles_mosaic); 35 | } 36 | 37 | @Override 38 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 39 | setupShaderInputs(program, 40 | new int[]{canvasWidth, canvasHeight}, 41 | new int[]{cameraTexId}, 42 | new int[][]{}); 43 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/TripleFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class TripleFilter extends CameraFilter { 28 | private int program; 29 | 30 | public TripleFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.triple); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/cn/nekocode/camerafilter/filter/WaterReflectionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 winston 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package cn.nekocode.camerafilter.filter; 17 | 18 | import android.content.Context; 19 | import android.opengl.GLES20; 20 | 21 | import cn.nekocode.camerafilter.MyGLUtils; 22 | import cn.nekocode.camerafilter.R; 23 | 24 | /** 25 | * @author winston (1054669137@qq.com) 26 | */ 27 | public class WaterReflectionFilter extends CameraFilter { 28 | private int program; 29 | 30 | public WaterReflectionFilter(Context context) { 31 | super(context); 32 | program = MyGLUtils.buildProgram(context, R.raw.vertext, R.raw.water_reflection); 33 | } 34 | 35 | @Override 36 | public void onDraw(int cameraTexId, int canvasWidth, int canvasHeight) { 37 | setupShaderInputs(program, 38 | new int[]{canvasWidth, canvasHeight}, 39 | new int[]{cameraTexId}, 40 | new int[][]{}); 41 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/menu/filter.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | 59 | 60 | 64 | 65 | 69 | 70 | 74 | 75 | 79 | 80 | 84 | 85 | 89 | 90 | 94 | 95 | 99 | 100 | 104 | 105 | 109 | 110 | 114 | 115 | 119 | 120 | 124 | 125 | 129 | 130 | 134 | 135 | 139 | 140 | 144 | 145 | 149 | 150 | 154 | 155 | 159 | 160 | 164 | 165 | 169 | 170 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/raw/ascii_art.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | // referenced the method of bitmap of iq : https://www.shadertoy.com/view/4dfXWj 9 | 10 | #define r iResolution.xy 11 | #define t iGlobalTime 12 | 13 | #define zoom 2. 14 | 15 | #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.)); } 16 | 17 | float gray(vec3 _i) 18 | { 19 | return (_i.x+_i.y+_i.z)/3.; 20 | } 21 | 22 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 23 | { 24 | vec2 uv = vec2(floor(fragCoord.x/8./zoom)*8.*zoom,floor(fragCoord.y/12./zoom)*12.*zoom)/r; 25 | ivec2 pos = ivec2(mod(fragCoord.x/zoom,8.),mod(fragCoord.y/zoom,12.)); 26 | vec4 tex = texture2D(iChannel0,uv); 27 | float cha = 0.; 28 | 29 | { 30 | float g = gray(tex.xyz); 31 | if( g < .125 ) 32 | { 33 | P(11,0,0,0,0,0,0,0,0); 34 | P(10,0,0,0,0,0,0,0,0); 35 | P(9,0,0,0,0,0,0,0,0); 36 | P(8,0,0,0,0,0,0,0,0); 37 | P(7,0,0,0,0,0,0,0,0); 38 | P(6,0,0,0,0,0,0,0,0); 39 | P(5,0,0,0,0,0,0,0,0); 40 | P(4,0,0,0,0,0,0,0,0); 41 | P(3,0,0,0,0,0,0,0,0); 42 | P(2,0,0,0,0,0,0,0,0); 43 | P(1,0,0,0,0,0,0,0,0); 44 | P(0,0,0,0,0,0,0,0,0); 45 | } 46 | else if( g < .25 ) // . 47 | { 48 | P(11,0,0,0,0,0,0,0,0); 49 | P(10,0,0,0,0,0,0,0,0); 50 | P(9,0,0,0,0,0,0,0,0); 51 | P(8,0,0,0,0,0,0,0,0); 52 | P(7,0,0,0,0,0,0,0,0); 53 | P(6,0,0,0,0,0,0,0,0); 54 | P(5,0,0,0,0,0,0,0,0); 55 | P(4,0,0,0,1,1,0,0,0); 56 | P(3,0,0,0,1,1,0,0,0); 57 | P(2,0,0,0,0,0,0,0,0); 58 | P(1,0,0,0,0,0,0,0,0); 59 | P(0,0,0,0,0,0,0,0,0); 60 | } 61 | else if( g < .375 ) // , 62 | { 63 | P(11,0,0,0,0,0,0,0,0); 64 | P(10,0,0,0,0,0,0,0,0); 65 | P(9,0,0,0,0,0,0,0,0); 66 | P(8,0,0,0,0,0,0,0,0); 67 | P(7,0,0,0,0,0,0,0,0); 68 | P(6,0,0,0,0,0,0,0,0); 69 | P(5,0,0,0,0,0,0,0,0); 70 | P(4,0,0,0,1,1,0,0,0); 71 | P(3,0,0,0,1,1,0,0,0); 72 | P(2,0,0,0,0,1,0,0,0); 73 | P(1,0,0,0,1,0,0,0,0); 74 | P(0,0,0,0,0,0,0,0,0); 75 | } 76 | else if( g < .5 ) // - 77 | { 78 | P(11,0,0,0,0,0,0,0,0); 79 | P(10,0,0,0,0,0,0,0,0); 80 | P(9,0,0,0,0,0,0,0,0); 81 | P(8,0,0,0,0,0,0,0,0); 82 | P(7,0,0,0,0,0,0,0,0); 83 | P(6,1,1,1,1,1,1,1,0); 84 | P(5,0,0,0,0,0,0,0,0); 85 | P(4,0,0,0,0,0,0,0,0); 86 | P(3,0,0,0,0,0,0,0,0); 87 | P(2,0,0,0,0,0,0,0,0); 88 | P(1,0,0,0,0,0,0,0,0); 89 | P(0,0,0,0,0,0,0,0,0); 90 | } 91 | else if(g < .625 ) // + 92 | { 93 | P(11,0,0,0,0,0,0,0,0); 94 | P(10,0,0,0,0,0,0,0,0); 95 | P(9,0,0,0,1,0,0,0,0); 96 | P(8,0,0,0,1,0,0,0,0); 97 | P(7,0,0,0,1,0,0,0,0); 98 | P(6,1,1,1,1,1,1,1,0); 99 | P(5,0,0,0,1,0,0,0,0); 100 | P(4,0,0,0,1,0,0,0,0); 101 | P(3,0,0,0,1,0,0,0,0); 102 | P(2,0,0,0,0,0,0,0,0); 103 | P(1,0,0,0,0,0,0,0,0); 104 | P(0,0,0,0,0,0,0,0,0); 105 | } 106 | else if(g < .75 ) // * 107 | { 108 | P(11,0,0,0,0,0,0,0,0); 109 | P(10,0,0,0,1,0,0,0,0); 110 | P(9,1,0,0,1,0,0,1,0); 111 | P(8,0,1,0,1,0,1,0,0); 112 | P(7,0,0,1,1,1,0,0,0); 113 | P(6,0,0,0,1,0,0,0,0); 114 | P(5,0,0,1,1,1,0,0,0); 115 | P(4,0,1,0,1,0,1,0,0); 116 | P(3,1,0,0,1,0,0,1,0); 117 | P(2,0,0,0,1,0,0,0,0); 118 | P(1,0,0,0,0,0,0,0,0); 119 | P(0,0,0,0,0,0,0,0,0); 120 | } 121 | else if(g < .875 ) // # 122 | { 123 | P(11,0,0,0,0,0,0,0,0); 124 | P(10,0,0,1,0,0,1,0,0); 125 | P(9,0,0,1,0,0,1,0,0); 126 | P(8,1,1,1,1,1,1,1,0); 127 | P(7,0,0,1,0,0,1,0,0); 128 | P(6,0,0,1,0,0,1,0,0); 129 | P(5,0,1,0,0,1,0,0,0); 130 | P(4,0,1,0,0,1,0,0,0); 131 | P(3,1,1,1,1,1,1,1,0); 132 | P(2,0,1,0,0,1,0,0,0); 133 | P(1,0,1,0,0,1,0,0,0); 134 | P(0,0,0,0,0,0,0,0,0); 135 | } 136 | else // @ 137 | { 138 | P(11,0,0,0,0,0,0,0,0); 139 | P(10,0,0,1,1,1,1,0,0); 140 | P(9,0,1,0,0,0,0,1,0); 141 | P(8,1,0,0,0,1,1,1,0); 142 | P(7,1,0,0,1,0,0,1,0); 143 | P(6,1,0,0,1,0,0,1,0); 144 | P(5,1,0,0,1,0,0,1,0); 145 | P(4,1,0,0,1,0,0,1,0); 146 | P(3,1,0,0,1,1,1,1,0); 147 | P(2,0,1,0,0,0,0,0,0); 148 | P(1,0,0,1,1,1,1,1,0); 149 | P(0,0,0,0,0,0,0,0,0); 150 | } 151 | } 152 | 153 | vec3 col = vec3(1.); 154 | fragColor = vec4(cha*col,1.); 155 | } 156 | 157 | void main() { 158 | mainImage(gl_FragColor, texCoord * iResolution.xy); 159 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/basic_deform.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 9 | { 10 | float stongth = 0.3; 11 | vec2 uv = fragCoord.xy; 12 | float waveu = sin((uv.y + iGlobalTime) * 20.0) * 0.5 * 0.05 * stongth; 13 | fragColor = texture2D(iChannel0, uv + vec2(waveu, 0)); 14 | } 15 | 16 | void main() { 17 | mainImage(gl_FragColor, texCoord); 18 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/black_and_white.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 mask = texture2D(iChannel0, fragCoord); 10 | float color = (mask.r + mask.g + mask.b) / 3.0; 11 | color = step(0.5, color); 12 | vec4 tempColor = vec4(color, color, color, 1.0); 13 | fragColor = tempColor; 14 | } 15 | 16 | void main() { 17 | mainImage(gl_FragColor, texCoord); 18 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/blue_orange.fsh: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 9 | { 10 | vec2 uv = fragCoord.xy; 11 | 12 | vec3 tex = texture2D( iChannel0, uv ).rgb; 13 | float shade = dot(tex, vec3(0.333333)); 14 | 15 | vec3 col = mix(vec3(0.1, 0.36, 0.8) * (1.0-2.0*abs(shade-0.5)), vec3(1.06, 0.8, 0.55), 1.0-shade); 16 | 17 | fragColor = vec4(col,1.0); 18 | } 19 | 20 | void main() { 21 | mainImage(gl_FragColor, texCoord); 22 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/cartoon.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 color = texture2D(iChannel0, fragCoord); 10 | float newR = abs(color.r + color.g * 2.0 - color.b) * color.r; 11 | float newG = abs(color.r + color.b * 2.0 - color.g) * color.r; 12 | float newB = abs(color.r + color.b * 2.0 - color.g) * color.g; 13 | vec4 newColor = vec4(newR, newG, newB, 1.0); 14 | fragColor = newColor; 15 | } 16 | 17 | void main() { 18 | mainImage(gl_FragColor, texCoord); 19 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/casting.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 mask = texture2D(iChannel0, fragCoord); 10 | vec4 tempColor = vec4(mask.r*0.5/(mask.g + mask.b + 0.01), 11 | mask.g*0.5/(mask.r + mask.b + 0.01), 12 | mask.b*0.5/(mask.r + mask.g + 0.01), 13 | 1.0); 14 | fragColor = tempColor; 15 | } 16 | 17 | void main() { 18 | mainImage(gl_FragColor, texCoord); 19 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/chromatic_aberration.fsh: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 9 | { 10 | vec2 uv = fragCoord.xy; 11 | 12 | float amount = 0.0; 13 | 14 | amount = (1.0 + sin(iGlobalTime*6.0)) * 0.5; 15 | amount *= 1.0 + sin(iGlobalTime*16.0) * 0.5; 16 | amount *= 1.0 + sin(iGlobalTime*19.0) * 0.5; 17 | amount *= 1.0 + sin(iGlobalTime*27.0) * 0.5; 18 | amount = pow(amount, 3.0); 19 | 20 | amount *= 0.05; 21 | 22 | vec3 col; 23 | col.r = texture2D( iChannel0, vec2(uv.x+amount,uv.y) ).r; 24 | col.g = texture2D( iChannel0, uv ).g; 25 | col.b = texture2D( iChannel0, vec2(uv.x-amount,uv.y) ).b; 26 | 27 | col *= (1.0 - amount * 0.5); 28 | 29 | fragColor = vec4(col,1.0); 30 | } 31 | 32 | 33 | void main() { 34 | mainImage(gl_FragColor, texCoord); 35 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/contrast.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | float remap(float value, float inputMin, float inputMax, float outputMin, float outputMax) 9 | { 10 | return (value - inputMin) * ((outputMax - outputMin) / (inputMax - inputMin)) + outputMin; 11 | } 12 | 13 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 14 | { 15 | vec2 uv = fragCoord.xy; 16 | float normalizedContrast = 1.0; 17 | float contrast = remap(normalizedContrast, 0.0, 1.0, 0.2 /*min*/, 4.0 /*max*/); 18 | 19 | vec4 srcColor = texture2D(iChannel0, uv); 20 | vec4 dstColor = vec4((srcColor.rgb - vec3(0.5)) * contrast + vec3(0.5), 1.0); 21 | fragColor = clamp(dstColor, 0.0, 1.0); 22 | } 23 | 24 | void main() { 25 | mainImage(gl_FragColor, texCoord); 26 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/cracked.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | float rnd(vec2 s) 9 | { 10 | return 1.-2.*fract(sin(s.x*253.13+s.y*341.41)*589.19); 11 | } 12 | 13 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 14 | { 15 | vec2 p=(fragCoord.xy*2.-iResolution.xy)/iResolution.x; 16 | 17 | vec2 v=vec2(1E3); 18 | vec2 v2=vec2(1E4); 19 | vec2 center=vec2(.1,-.5); 20 | for(int c=0;c<30;c++) 21 | { 22 | float angle=floor(rnd(vec2(float(c),387.44))*16.)*3.1415*.4-.5; 23 | float dist=pow(rnd(vec2(float(c),78.21)),2.)*.5; 24 | vec2 vc=vec2(center.x+cos(angle)*dist+rnd(vec2(float(c),349.3))*7E-3, 25 | center.y+sin(angle)*dist+rnd(vec2(float(c),912.7))*7E-3); 26 | if(length(vc-p) 0.1 ) 73 | tex = tex * ( 1.0 / brightestChannel ); 74 | else 75 | tex.rgb = vec3(1.0,1.0,1.0); 76 | #endif // COLOUR_HATCHES 77 | 78 | if (brightness < hatch_1) 79 | { 80 | if (mod(fragCoord.x + fragCoord.y, density) <= width) 81 | { 82 | #ifdef COLOUR_HATCHES 83 | res = vec3(tex.rgb * hatch_1_brightness); 84 | #else 85 | res = vec3(hatch_1_brightness); 86 | #endif 87 | } 88 | } 89 | 90 | if (brightness < hatch_2) 91 | { 92 | if (mod(fragCoord.x - fragCoord.y, density) <= width) 93 | { 94 | #ifdef COLOUR_HATCHES 95 | res = vec3(tex.rgb * hatch_2_brightness); 96 | #else 97 | res = vec3(hatch_2_brightness); 98 | #endif 99 | } 100 | } 101 | 102 | if (brightness < hatch_3) 103 | { 104 | if (mod(fragCoord.x + fragCoord.y - (density*0.5), density) <= width) 105 | { 106 | #ifdef COLOUR_HATCHES 107 | res = vec3(tex.rgb * hatch_3_brightness); 108 | #else 109 | res = vec3(hatch_3_brightness); 110 | #endif 111 | } 112 | } 113 | 114 | if (brightness < hatch_4) 115 | { 116 | if (mod(fragCoord.x - fragCoord.y - (density*0.5), density) <= width) 117 | { 118 | #ifdef COLOUR_HATCHES 119 | res = vec3(tex.rgb * hatch_4_brightness); 120 | #else 121 | res = vec3(hatch_4_brightness); 122 | #endif 123 | } 124 | } 125 | 126 | vec2 p = fragCoord.xy; 127 | 128 | // simple sobel edge detection, 129 | // borrowed and tweaked from jmk's "edge glow" filter, here: 130 | // https://www.shadertoy.com/view/Mdf3zr 131 | float gx = 0.0; 132 | gx += -1.0 * lookup(p, -1.0, -1.0); 133 | gx += -2.0 * lookup(p, -1.0, 0.0); 134 | gx += -1.0 * lookup(p, -1.0, 1.0); 135 | gx += 1.0 * lookup(p, 1.0, -1.0); 136 | gx += 2.0 * lookup(p, 1.0, 0.0); 137 | gx += 1.0 * lookup(p, 1.0, 1.0); 138 | 139 | float gy = 0.0; 140 | gy += -1.0 * lookup(p, -1.0, -1.0); 141 | gy += -2.0 * lookup(p, 0.0, -1.0); 142 | gy += -1.0 * lookup(p, 1.0, -1.0); 143 | gy += 1.0 * lookup(p, -1.0, 1.0); 144 | gy += 2.0 * lookup(p, 0.0, 1.0); 145 | gy += 1.0 * lookup(p, 1.0, 1.0); 146 | 147 | // hack: use g^2 to conceal noise in the video 148 | float g = gx*gx + gy*gy; 149 | res *= (1.0-g); 150 | 151 | fragColor = vec4(res, 1.0); 152 | } 153 | 154 | void main() { 155 | mainImage(gl_FragColor, texCoord * iResolution.xy); 156 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/edge_detection.fsh: -------------------------------------------------------------------------------- 1 | #extension GL_OES_standard_derivatives : enable 2 | precision mediump float; 3 | 4 | uniform vec3 iResolution; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 9 | { 10 | vec2 uv = fragCoord.xy; 11 | vec4 color = texture2D(iChannel0, fragCoord); 12 | float gray = length(color.rgb); 13 | fragColor = vec4(vec3(step(0.06, length(vec2(dFdx(gray), dFdy(gray))))), 1.0); 14 | } 15 | 16 | void main() { 17 | mainImage(gl_FragColor, texCoord); 18 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/em_interference.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | float rng2(vec2 seed) 9 | { 10 | return fract(sin(dot(seed * floor(iGlobalTime * 12.), vec2(127.1,311.7))) * 43758.5453123); 11 | } 12 | 13 | float rng(float seed) 14 | { 15 | return rng2(vec2(seed, 1.0)); 16 | } 17 | 18 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 19 | { 20 | vec2 uv = fragCoord.xy; 21 | vec2 blockS = floor(uv * vec2(24., 9.)); 22 | vec2 blockL = floor(uv * vec2(8., 4.)); 23 | 24 | float r = rng2(uv); 25 | vec3 noise = (vec3(r, 1. - r, r / 2. + 0.5) * 1.0 - 2.0) * 0.08; 26 | 27 | float lineNoise = pow(rng2(blockS), 8.0) * pow(rng2(blockL), 3.0) - pow(rng(7.2341), 17.0) * 2.; 28 | 29 | vec4 col1 = texture2D(iChannel0, uv); 30 | vec4 col2 = texture2D(iChannel0, uv + vec2(lineNoise * 0.05 * rng(5.0), 0)); 31 | vec4 col3 = texture2D(iChannel0, uv - vec2(lineNoise * 0.05 * rng(31.0), 0)); 32 | 33 | fragColor = vec4(vec3(col1.x, col2.y, col3.z) + noise, 1.0); 34 | } 35 | 36 | void main() { 37 | mainImage(gl_FragColor, texCoord); 38 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/gray.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 mask = texture2D(iChannel0, fragCoord); 10 | float color = (mask.r + mask.g + mask.b) /3.0; 11 | vec4 tempColor =vec4(color, color, color,1.0); 12 | fragColor = tempColor; 13 | } 14 | 15 | void main() { 16 | mainImage(gl_FragColor, texCoord); 17 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/hexagon_mosaic.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | const float mosaicSize = 0.03; 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 10 | { 11 | float length = mosaicSize; 12 | float TR = 0.866025; 13 | 14 | float x = texCoord.x; 15 | float y = texCoord.y; 16 | 17 | int wx = int(x / 1.5 / length); 18 | int wy = int(y / TR / length); 19 | vec2 v1, v2, vn; 20 | 21 | if (wx/2 * 2 == wx) { 22 | if (wy/2 * 2 == wy) { 23 | //(0,0),(1,1) 24 | v1 = vec2(length * 1.5 * float(wx), length * TR * float(wy)); 25 | v2 = vec2(length * 1.5 * float(wx + 1), length * TR * float(wy + 1)); 26 | } else { 27 | //(0,1),(1,0) 28 | v1 = vec2(length * 1.5 * float(wx), length * TR * float(wy + 1)); 29 | v2 = vec2(length * 1.5 * float(wx + 1), length * TR * float(wy)); 30 | } 31 | }else { 32 | if (wy/2 * 2 == wy) { 33 | //(0,1),(1,0) 34 | v1 = vec2(length * 1.5 * float(wx), length * TR * float(wy + 1)); 35 | v2 = vec2(length * 1.5 * float(wx + 1), length * TR * float(wy)); 36 | } else { 37 | //(0,0),(1,1) 38 | v1 = vec2(length * 1.5 * float(wx), length * TR * float(wy)); 39 | v2 = vec2(length * 1.5 * float(wx + 1), length * TR * float(wy + 1)); 40 | } 41 | } 42 | 43 | float s1 = sqrt(pow(v1.x - x, 2.0) + pow(v1.y - y, 2.0)); 44 | float s2 = sqrt(pow(v2.x - x, 2.0) + pow(v2.y - y, 2.0)); 45 | if (s1 < s2) { 46 | vn = v1; 47 | } else { 48 | vn = v2; 49 | } 50 | vec4 color = texture2D(iChannel0, vn); 51 | 52 | fragColor = color; 53 | } 54 | 55 | void main () { 56 | mainImage(gl_FragColor, texCoord); 57 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/legofied.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | float c = 0.02; //amout of blocks = c*iResolution.x 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ){ 10 | //blocked pixel coordinate 11 | vec2 middle = floor(fragCoord*c+.5)/c; 12 | 13 | vec3 color = texture2D(iChannel0, middle/iResolution.xy).rgb; 14 | 15 | //lego block effects 16 | //stud 17 | float dis = distance(fragCoord,middle)*c*2.; 18 | if(dis<.65&&dis>.55){ 19 | color *= dot(vec2(0.707),normalize(fragCoord-middle))*.5+1.; 20 | } 21 | 22 | //side shadow 23 | vec2 delta = abs(fragCoord-middle)*c*2.; 24 | float sdis = max(delta.x,delta.y); 25 | if(sdis>.9){ 26 | color *= .8; 27 | } 28 | 29 | fragColor = vec4(color,1.0); 30 | } 31 | 32 | void main() { 33 | mainImage(gl_FragColor, texCoord*iResolution.xy); 34 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/lichtenstein_esque.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | // Size of the quad in pixels 9 | const float size = 15.0; 10 | 11 | // Radius of the circle 12 | const float radius = size * 0.5; 13 | 14 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 15 | { 16 | // Current quad in pixels 17 | vec2 quadPos = floor(fragCoord.xy / size) * size; 18 | // Normalized quad position 19 | vec2 quad = quadPos/iResolution.xy; 20 | // Center of the quad 21 | vec2 quadCenter = (quadPos + size/2.0); 22 | // Distance to quad center 23 | float dist = length(quadCenter - fragCoord.xy); 24 | 25 | vec4 texel = texture2D(iChannel0, quad); 26 | if (dist > radius) 27 | { 28 | fragColor = vec4(0.25); 29 | } 30 | else 31 | { 32 | fragColor = texel; 33 | } 34 | } 35 | 36 | 37 | void main() { 38 | mainImage(gl_FragColor, texCoord*iResolution.xy); 39 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/mapping.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | uniform sampler2D iChannel1; 7 | varying vec2 texCoord; 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 10 | { 11 | 12 | vec2 pos = fragCoord.xy; 13 | vec2 uv2 = vec2( fragCoord.xy / iResolution.xy ); 14 | vec4 sound = texture2D( iChannel0, uv2 ); 15 | pos.x = pos.x + 150.0 * sound.r; 16 | pos.y = pos.y + 150.0 * sound.b; 17 | vec2 uv = pos / iResolution.xy; 18 | 19 | vec4 col = texture2D( iChannel1, uv ); 20 | 21 | col.a += 1.0 - sin( col.x - col.y + iGlobalTime * 0.1 ); 22 | 23 | fragColor = col * sound.r; 24 | } 25 | 26 | void main() { 27 | mainImage(gl_FragColor, texCoord * iResolution.xy); 28 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/mirror.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 10 | { 11 | vec2 flipCoord = vec2(1.0-fragCoord.x, fragCoord.y); 12 | if(flipCoord.x >= 0.5){ 13 | fragColor = texture2D(iChannel0, vec2( flipCoord.x - 0.5, flipCoord.y )); 14 | } else { 15 | fragColor = texture2D(iChannel0, vec2( 0.5 - flipCoord.x,flipCoord.y )); 16 | } 17 | } 18 | 19 | void main() { 20 | mainImage(gl_FragColor, texCoord); 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/raw/money_filter.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | 9 | // Money filter by Giacomo Preciado 10 | // Based on: "Free Engraved Illustration Effect Action for Photoshop" - http://snip.ly/j0gq 11 | // e-mail: giacomo@kyrie.pe 12 | // website: http://kyrie.pe 13 | 14 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 15 | { 16 | vec2 xy = fragCoord.xy / iResolution.yy; 17 | 18 | float amplitud = 0.03; 19 | float frecuencia = 10.0; 20 | float gris = 1.0; 21 | float divisor = 8.0 / iResolution.y; 22 | float grosorInicial = divisor * 0.2; 23 | 24 | const int kNumPatrones = 6; 25 | 26 | // x: seno del angulo, y: coseno del angulo, z: factor de suavizado 27 | vec3 datosPatron[kNumPatrones]; 28 | datosPatron[0] = vec3(-0.7071, 0.7071, 3.0); // -45 29 | datosPatron[1] = vec3(0.0, 1.0, 0.6); // 0 30 | datosPatron[2] = vec3(0.0, 1.0, 0.5); // 0 31 | datosPatron[3] = vec3(1.0, 0.0, 0.4); // 90 32 | datosPatron[4] = vec3(1.0, 0.0, 0.3); // 90 33 | datosPatron[5] = vec3(0.0, 1.0, 0.2); // 0 34 | 35 | vec4 color = texture2D(iChannel0, vec2(fragCoord.x / iResolution.x, xy.y)); 36 | fragColor = color; 37 | 38 | for(int i = 0; i < kNumPatrones; i++) 39 | { 40 | float coseno = datosPatron[i].x; 41 | float seno = datosPatron[i].y; 42 | 43 | vec2 punto = vec2( 44 | xy.x * coseno - xy.y * seno, 45 | xy.x * seno + xy.y * coseno 46 | ); 47 | 48 | float grosor = grosorInicial * float(i + 1); 49 | float dist = mod(punto.y + grosor * 0.5 - sin(punto.x * frecuencia) * amplitud, divisor); 50 | float brillo = 0.3 * color.r + 0.4 * color.g + 0.3 * color.b; 51 | 52 | if(dist < grosor && brillo < 0.75 - 0.12 * float(i)) 53 | { 54 | // Suavizado 55 | float k = datosPatron[i].z; 56 | float x = (grosor - dist) / grosor; 57 | float fx = abs((x - 0.5) / k) - (0.5 - k) / k; 58 | gris = min(fx, gris); 59 | } 60 | } 61 | 62 | fragColor = vec4(gris, gris, gris, 1.0); 63 | } 64 | 65 | void main() { 66 | mainImage(gl_FragColor, texCoord*iResolution.xy); 67 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/negative.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 mask = texture2D(iChannel0, fragCoord); 10 | vec4 color =vec4(1.0-mask.r, 1.0-mask.g, 1.0-mask.r,1.0); 11 | fragColor = color; 12 | } 13 | 14 | void main() { 15 | mainImage(gl_FragColor, texCoord); 16 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/noise_warp.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | float mod289(float x) 9 | { 10 | return x - floor(x * (1.0 / 289.0)) * 289.0; 11 | } 12 | 13 | vec4 mod289(vec4 x) 14 | { 15 | return x - floor(x * (1.0 / 289.0)) * 289.0; 16 | } 17 | 18 | vec4 perm(vec4 x) 19 | { 20 | return mod289(((x * 34.0) + 1.0) * x); 21 | } 22 | 23 | float noise3d(vec3 p) 24 | { 25 | vec3 a = floor(p); 26 | vec3 d = p - a; 27 | d = d * d * (3.0 - 2.0 * d); 28 | 29 | vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); 30 | vec4 k1 = perm(b.xyxy); 31 | vec4 k2 = perm(k1.xyxy + b.zzww); 32 | 33 | vec4 c = k2 + a.zzzz; 34 | vec4 k3 = perm(c); 35 | vec4 k4 = perm(c + 1.0); 36 | 37 | vec4 o1 = fract(k3 * (1.0 / 41.0)); 38 | vec4 o2 = fract(k4 * (1.0 / 41.0)); 39 | 40 | vec4 o3 = o2 * d.z + o1 * (1.0 - d.z); 41 | vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); 42 | 43 | return o4.y * d.y + o4.x * (1.0 - d.y); 44 | } 45 | 46 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 47 | { 48 | vec2 uv = fragCoord.xy; 49 | float v1 = noise3d(vec3(uv * 10.0, 0.0)); 50 | float v2 = noise3d(vec3(uv * 10.0, 1.0)); 51 | 52 | vec4 color = texture2D(iChannel0, uv + vec2(v1, v2) * 0.1); 53 | fragColor = color; 54 | } 55 | 56 | void main() { 57 | mainImage(gl_FragColor, texCoord); 58 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/nostalgia.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 8 | { 9 | vec4 mask = texture2D(iChannel0, fragCoord); 10 | vec4 tempColor = vec4(0.393 * mask.r + 0.769 * mask.g + 0.189 * mask.b, 11 | 0.349 * mask.r + 0.686 * mask.g + 0.168 * mask.b, 12 | 0.272 * mask.r + 0.534 * mask.g + 0.131 * mask.b, 1.0); 13 | fragColor = tempColor; 14 | } 15 | 16 | void main() { 17 | mainImage(gl_FragColor, texCoord); 18 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/original.fsh: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | varying vec2 texCoord; 4 | uniform sampler2D iChannel0; 5 | 6 | void main() { 7 | gl_FragColor = texture2D(iChannel0, texCoord); 8 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/original_rtt.fsh: -------------------------------------------------------------------------------- 1 | #extension GL_OES_EGL_image_external : require 2 | precision mediump float; 3 | 4 | varying vec2 texCoord; 5 | uniform samplerExternalOES iChannel0; 6 | 7 | void main() { 8 | gl_FragColor = texture2D(iChannel0, texCoord); 9 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/pixelize.fsh: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | #define S (iResolution.x / 6e1) // The cell size. 8 | 9 | void mainImage(out vec4 c, vec2 p) 10 | { 11 | c = texture2D(iChannel0, floor((p + .5) / S) * S / iResolution.xy); 12 | } 13 | 14 | void main() { 15 | mainImage(gl_FragColor, texCoord*iResolution.xy); 16 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/polygonization.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform float iGlobalTime; 5 | uniform sampler2D iChannel0; 6 | varying vec2 texCoord; 7 | 8 | vec2 hash2( vec2 p ) 9 | { 10 | // procedural white noise 11 | return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); 12 | } 13 | 14 | vec2 voronoi( in vec2 x ) 15 | { 16 | vec2 n = floor(x); 17 | vec2 f = fract(x); 18 | 19 | //---------------------------------- 20 | // regular voronoi 21 | //---------------------------------- 22 | vec2 mg, mr; 23 | 24 | float md = 8.0; 25 | for( int j=-1; j<=1; j++ ) 26 | for( int i=-1; i<=1; i++ ) 27 | { 28 | vec2 g = vec2(float(i),float(j)); 29 | vec2 o = hash2( n + g ); 30 | vec2 r = g + o - f; 31 | float d = dot(r,r); 32 | 33 | if( d 0.333 && fragCoord.y<= 0.666){ 14 | fragColor = texture2D(iChannel0, fragCoord); 15 | }else{ 16 | fragColor = texture2D(iChannel0, vec2(fragCoord.x,fragCoord.y - 0.333)); 17 | } 18 | } 19 | 20 | void main() { 21 | mainImage(gl_FragColor, texCoord); 22 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/vertext.vsh: -------------------------------------------------------------------------------- 1 | attribute vec2 vPosition; 2 | attribute vec2 vTexCoord; 3 | varying vec2 texCoord; 4 | 5 | void main() { 6 | texCoord = vTexCoord; 7 | gl_Position = vec4 ( vPosition.x, vPosition.y, 0.0, 1.0 ); 8 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/voronoi.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform int iFrame; 4 | uniform vec3 iResolution; 5 | uniform vec3 iChannelResolution[2]; 6 | uniform float iGlobalTime; 7 | uniform sampler2D iChannel0; 8 | uniform sampler2D iChannel1; 9 | varying vec2 texCoord; 10 | 11 | 12 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 13 | { 14 | vec2 uv = fragCoord.xy / iResolution.xy; 15 | 16 | #if 0 // debug feature extraction 17 | 18 | fragColor = texture2D(iChannel1, uv).wwww; 19 | 20 | #else 21 | 22 | vec4 cell = texture2D(iChannel0, uv); 23 | vec2 cell_uv = cell.xy; 24 | vec4 video = texture2D(iChannel1, cell_uv); 25 | vec2 dcell = cell_uv * iChannelResolution[0].xy - fragCoord.xy; 26 | float len = length(dcell); 27 | vec3 color = video.xyz * (.9 + len*.005); 28 | fragColor = vec4(color, 1.); 29 | 30 | #endif 31 | } 32 | 33 | void main() { 34 | mainImage(gl_FragColor, texCoord*iResolution.xy); 35 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/voronoi_buf_a.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform int iFrame; 4 | uniform vec3 iResolution; 5 | uniform vec3 iChannelResolution[2]; 6 | uniform float iGlobalTime; 7 | uniform sampler2D iChannel0; 8 | uniform sampler2D iChannel1; 9 | varying vec2 texCoord; 10 | 11 | // A super simple video source with feature detection 12 | 13 | float grayScale(vec4 c) { return c.x*.29 + c.y*.58 + c.z*.13; } 14 | 15 | //============================================================ 16 | vec4 GenerateSeed (in vec2 fragCoord) 17 | { 18 | vec2 uv = fragCoord / iResolution.xy; 19 | vec3 dataStep = vec3( vec2(1.) / iChannelResolution[0].xy, 0.); 20 | 21 | vec4 fragColor = texture2D( iChannel0, uv ); 22 | 23 | float d = grayScale(fragColor); 24 | float dL = grayScale(texture2D( iChannel0, uv - dataStep.xz )); 25 | float dR = grayScale(texture2D( iChannel0, uv + dataStep.xz )); 26 | float dU = grayScale(texture2D( iChannel0, uv - dataStep.zy )); 27 | float dD = grayScale(texture2D( iChannel0, uv + dataStep.zy )); 28 | float w = float( d*0.99 > max(max(dL, dR), max(dU, dD)) ); 29 | 30 | w = max(w, texture2D( iChannel1, uv ).w*.9); // get some from previous frame 31 | 32 | fragColor.w = w; 33 | 34 | return fragColor; 35 | } 36 | 37 | //============================================================ 38 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 39 | { 40 | fragColor = GenerateSeed(fragCoord); 41 | } 42 | 43 | 44 | void main() { 45 | mainImage(gl_FragColor, texCoord*iResolution.xy); 46 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/voronoi_buf_b.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform int iFrame; 4 | uniform vec3 iResolution; 5 | uniform vec3 iChannelResolution[2]; 6 | uniform float iGlobalTime; 7 | uniform sampler2D iChannel0; 8 | uniform sampler2D iChannel1; 9 | varying vec2 texCoord; 10 | 11 | 12 | // how many JFA steps to do. 2^c_maxSteps is max image size on x and y 13 | const float c_maxSteps = 10.0; 14 | 15 | //============================================================ 16 | vec4 StepJFA (in vec2 fragCoord, in float level) 17 | { 18 | float stepwidth = floor(exp2(c_maxSteps - 1. - level)+0.5); 19 | 20 | float bestDistance = 9999.0; 21 | vec2 bestCoord = vec2(0.0); 22 | 23 | for (int y = -1; y <= 1; ++y) { 24 | for (int x = -1; x <= 1; ++x) { 25 | vec2 sampleCoord = fragCoord + vec2(x,y) * stepwidth; 26 | 27 | vec4 data = texture2D( iChannel0, sampleCoord / iChannelResolution[0].xy); 28 | vec2 seedCoord = data.xy * iChannelResolution[0].xy; 29 | float dist = length(seedCoord - fragCoord); 30 | if ((seedCoord.x != 0.0 || seedCoord.y != 0.0) && dist < bestDistance) 31 | { 32 | bestDistance = dist; 33 | bestCoord = seedCoord; 34 | } 35 | } 36 | } 37 | 38 | return vec4(bestCoord / iChannelResolution[0].xy, 0.0, 0.0); 39 | } 40 | 41 | //============================================================ 42 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 43 | { 44 | float fFrame = float(iFrame); 45 | float level = mod(fFrame,c_maxSteps); 46 | if (level < .5) { 47 | if (texture2D(iChannel1, fragCoord / iResolution.xy).w > .5) 48 | fragColor = vec4(fragCoord / iChannelResolution[0].xy, 0.0, 0.0); 49 | else 50 | fragColor = vec4(0.0); 51 | return; 52 | } 53 | 54 | fragColor = StepJFA(fragCoord, level); 55 | } 56 | 57 | 58 | void main() { 59 | mainImage(gl_FragColor, texCoord*iResolution.xy); 60 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/voronoi_buf_c.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform int iFrame; 4 | uniform vec3 iResolution; 5 | uniform vec3 iChannelResolution[2]; 6 | uniform float iGlobalTime; 7 | uniform sampler2D iChannel0; 8 | uniform sampler2D iChannel1; 9 | varying vec2 texCoord; 10 | 11 | // A secondary buffer to get clean Voronoi every N-th frame 12 | 13 | // this must be in sync with JFA algorithm constant 14 | const float c_maxSteps = 10.0; 15 | 16 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 17 | { 18 | vec2 uv = fragCoord.xy / iResolution.xy; 19 | if (mod(float(iFrame+1),c_maxSteps) < .5) { 20 | fragColor = texture2D(iChannel1, uv); // update to new voronoi cell 21 | } else { 22 | fragColor = texture2D(iChannel0, uv); // no change 23 | } 24 | } 25 | 26 | 27 | void main() { 28 | mainImage(gl_FragColor, texCoord*iResolution.xy); 29 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/water_reflection.fsh: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | uniform vec3 iResolution; 4 | uniform sampler2D iChannel0; 5 | varying vec2 texCoord; 6 | 7 | float waterLevel = 0.5; 8 | float waveAmplitude = 0.01; 9 | 10 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 11 | { 12 | if(fragCoord.y >= waterLevel){ 13 | fragColor = texture2D(iChannel0, fragCoord); 14 | }else{ 15 | fragColor = texture2D(iChannel0,vec2(fragCoord.x + fract(sin(dot(fragCoord.xy ,vec2(12.9898,78.233))) * 43758.5453) * waveAmplitude, 16 | 2.0 * waterLevel - fragCoord.y)); 17 | } 18 | } 19 | 20 | void main() { 21 | mainImage(gl_FragColor, texCoord); 22 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #646464 4 | #646464 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CameraFilter 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /art/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/1.png -------------------------------------------------------------------------------- /art/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/10.png -------------------------------------------------------------------------------- /art/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/11.png -------------------------------------------------------------------------------- /art/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/12.png -------------------------------------------------------------------------------- /art/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/13.png -------------------------------------------------------------------------------- /art/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/14.png -------------------------------------------------------------------------------- /art/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/15.png -------------------------------------------------------------------------------- /art/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/16.png -------------------------------------------------------------------------------- /art/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/17.png -------------------------------------------------------------------------------- /art/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/18.png -------------------------------------------------------------------------------- /art/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/19.png -------------------------------------------------------------------------------- /art/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/2.png -------------------------------------------------------------------------------- /art/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/20.png -------------------------------------------------------------------------------- /art/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/3.png -------------------------------------------------------------------------------- /art/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/4.png -------------------------------------------------------------------------------- /art/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/5.png -------------------------------------------------------------------------------- /art/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/6.png -------------------------------------------------------------------------------- /art/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/7.png -------------------------------------------------------------------------------- /art/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/8.png -------------------------------------------------------------------------------- /art/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/art/9.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | google() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:3.4.0' 8 | } 9 | } 10 | 11 | allprojects { 12 | repositories { 13 | jcenter() 14 | google() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/CameraFilter/0062da6aea0a70868d2ed46f4572c9f7d5cf941c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jun 01 14:43:03 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------