Comments (5)
+1
from videffects.
I have a version of a blur filter working, but it's pretty inefficient right now, using a full 5x5 gaussian blur. I'd like to do much bigger kernels, but the performance is going to be pretty bad, especially on older phones.
I would love to hear if there is a suggestion for how I could create a down-sampled SurfaceView that would take up the whole viewport when displayed. This would reduce the number of pixels the fragment shader has to run over significantly, while still providing pretty good quality because of the low-pass nature of the blur filter. I'm not as familiar with the Android view architecture to do this however.
from videffects.
i am also wondering how to add a customed effect.....
from videffects.
+1
from videffects.
public class GaussianBlurEffect implements ShaderInterface {
public final static int TYPEX = 1;
public final static int TYPEY = 2;
public final static int TYPEXY = 3;
private float radius = 1.0f;
private String blurTypeString = "vec2(1.0,0.0)";
/**
* Initialize Effect
*/
public GaussianBlurEffect(float radius) {
this.radius = radius;
}
public GaussianBlurEffect(float radius, int blurType) {
this.radius = radius;
switch (blurType) {
case TYPEX:
blurTypeString = "vec2(1.0,0.0)";
break;
case TYPEY:
blurTypeString = "vec2(0.0,1.0)";
break;
case TYPEXY:
blurTypeString = "vec2(1.0,1.0)";
break;
}
}
@Override
public String getShader(GLSurfaceView mGlSurfaceView) {
return "#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"const float resolution=1024.0;\n" +
"const float radius = " + radius + ";\n" +
"vec2 dir =" + blurTypeString + "; //若为x模糊,可传入(1.0,0.0) y模糊 (0.0,1.0)\n" +
"\n" +
"void main() {\n" +
" //this will be our RGBA sum\n" +
" vec4 sum = vec4(0.0);\n" +
" \n" +
" //our original texcoord for this fragment\n" +
" vec2 tc = vTextureCoord;\n" +
" \n" +
" //the amount to blur, i.e. how far off center to sample from \n" +
" //1.0 -> blur by one pixel\n" +
" //2.0 -> blur by two pixels, etc.\n" +
" float blur = radius/resolution; \n" +
" \n" +
" //the direction of our blur\n" +
" //(1.0, 0.0) -> x-axis blur\n" +
" //(0.0, 1.0) -> y-axis blur\n" +
" float hstep = dir.x;\n" +
" float vstep = dir.y;\n" +
" \n" +
" \n" +
" //apply blurring, using a 9-tap filter with predefined gaussian weights\n" +
" \n" +
" sum += texture2D(sTexture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;\n" +
" sum += texture2D(sTexture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;\n" +
" sum += texture2D(sTexture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;\n" +
" sum += texture2D(sTexture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;\n" +
" \n" +
" sum += texture2D(sTexture, vec2(tc.x, tc.y)) * 0.2270270270;\n" +
" \n" +
" sum += texture2D(sTexture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;\n" +
" sum += texture2D(sTexture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;\n" +
" sum += texture2D(sTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;\n" +
" sum += texture2D(sTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;\n" +
"\n" +
" vec4 cc= texture2D(sTexture,vTextureCoord );\n" +
"\n" +
" //discard alpha for our simple demo, multiply by vertex color and return\n" +
" gl_FragColor =vec4(sum.rgb, cc.a);\n" +
"}";
}
}
from videffects.
Related Issues (20)
- How to save video? HOT 1
- CRASH | When trying to Save Video. HOT 6
- How can i save video with filter ? HOT 1
- Hi,Thanks for this open source library. I am looking for if you can add Old VHS effects in this.
- video aspect ratio issue HOT 2
- Unable to load video from gallery HOT 36
- Save video on Sdcard after effect
- Saving effected video in sdcard . Effect issue .
- Saving effected video in sdcard . Effect issue channel mixer!
- After Video processing video is faster. how to fix that ? HOT 3
- glDrawArrays: glError 1282
- Save Video with effects : plan HOT 3
- How to create Color channel mixers for different filters ?
- how to add media controller in video surface view ?
- VideoSurfaceView shows as black on android 9
- how to save video without AssetFileDescriptor HOT 3
- how to apply effects because i found only 3 filters in this code.
- apply Effects as Filters?
- Applying denoising shaders
- apply filters to a single frame in code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from videffects.