Git Product home page Git Product logo

Comments (5)

guyzk avatar guyzk commented on July 22, 2024

+1

from videffects.

drbeermann avatar drbeermann commented on July 22, 2024

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.

jsjjkfc avatar jsjjkfc commented on July 22, 2024

i am also wondering how to add a customed effect.....

from videffects.

Hsanka6 avatar Hsanka6 commented on July 22, 2024

+1

from videffects.

CarGuo avatar CarGuo commented on July 22, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.