GLSL 模糊

顶点着色器

    private final String mVertexShader = "uniform mat4 uMVPMatrix;\n"
            + "uniform mat4 uSTMatrix;\n"
            + "attribute vec4 aPosition;\n"
            + "attribute vec4 aTextureCoord;\n"
                    + "attribute vec4 a_color;\n"

            + "varying vec2 vTextureCoord;\n"
            + "varying vec4 v_fragmentColor;\n"
            + "void main() {\n"
                +"v_fragmentColor = a_color;\n"
            + "  gl_Position = uMVPMatrix * aPosition;\n"
            + "  vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n"
            + "}\n";

片段着色器

    String guss =
        "#extension GL_OES_EGL_image_external : require\n" +
            "uniform samplerExternalOES sTexture;\n" +
            "varying vec2 vTextureCoord;\n" +
             "varying vec4 v_fragmentColor;\n" +
        "vec4 blur(vec2 p)\n" +
        "{\n" +
        "vec4 col = vec4(0.0);\n" +
        "vec2 unit = vec2(0.01, 0.01);\n" +
        "float r = 2.0;\n" +
        "float sampleStep = r / 8.0; \n" +
        "float count = 0.0;\n" +
        "for(float x = -r; x < r; x += sampleStep)\n" +
        "{\n" +
        "  for(float y = -r; y < r; y += sampleStep)\n" +
        "    {\n" +
        "      float weight = (r - abs(x)) * (r - abs(y));\n" +
        "      col += texture2D(sTexture, p + vec2(x * unit.x, y * unit.y)) * weight;\n" +
        "      count += weight;\n" +
        "    }\n" +
        "}\n" +
            "return col/count;\n" +
            "}\n" +
        "void main(void)\n" +
        "{\n" +
            "vec4 col = blur(vTextureCoord);\n" +
            "gl_FragColor =  col;\n" +
        "}\n"
        ;

顶点着色器

    private final String mVertexShader = "uniform mat4 uMVPMatrix;\n"
            + "uniform mat4 uSTMatrix;\n"
            + "attribute vec4 aPosition;\n"
            + "attribute vec4 aTextureCoord;\n"
            + "varying vec2 vTextureCoord;\n"
            + "void main() {\n"
            + "  gl_Position = uMVPMatrix * aPosition;\n"
            + "  vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n"
            + "}\n";

片段着色器

        String s =
                "#extension GL_OES_EGL_image_external : require\n" +
                        "precision mediump float;\n" +
                "uniform samplerExternalOES sTexture;\n" +
                "varying vec2 vTextureCoord;\n" +
                "const float blurSize = "+ blur + "/800.0;\n" +
                "const float weightSum = 70.0 + 2.0 * (1.0 + 8.0 + 28.0 + 56.0);\n" +
                "\n" +
                "void main(void)\n" +
                "{\n" +
                "   vec4 sum = vec4(0.0);\n" +
                "\n" +
                "if(vTextureCoord.y < 0.9)\n"+
                "{\n" +
                "   sum += c(sTexture, vec2(vTextureCoord.x - 4.0*blurSize, vTextureCoord.y)) * 1.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x - 3.0*blurSize, vTextureCoord.y)) * 8.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x - 2.0*blurSize, vTextureCoord.y)) * 28.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x - blurSize, vTextureCoord.y)) * 56.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x, vTextureCoord.y)) * 70.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x + blurSize, vTextureCoord.y)) * 56.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x + 2.0*blurSize, vTextureCoord.y)) * 28.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x + 3.0*blurSize, vTextureCoord.y)) * 8.0 / weightSum;\n" +
                "   sum += texture2D(sTexture, vec2(vTextureCoord.x + 4.0*blurSize, vTextureCoord.y)) * 1.0 / weightSum;\n" +
                "\n" +
                "   gl_FragColor = sum;\n" +
//                "  gl_FragColor = texture2D(sTexture, vec2(vTextureCoord.x, vTextureCoord.y));\n" +
                "}\n" +
                "else\n" +
                "{\n" +
                 "  gl_FragColor = texture2D(sTexture, vec2(vTextureCoord.x, vTextureCoord.y));\n" +
                "}\n" +
                "}";

片段着色器 上下各20%

    String guss =
        "#extension GL_OES_EGL_image_external : require\n" +
            "uniform samplerExternalOES sTexture;\n" +
            "varying vec2 vTextureCoord;\n" +
             "varying vec4 v_fragmentColor;\n" +
        "vec4 blur(vec2 p)\n" +
        "{\n" +
        "vec4 col = vec4(0.0);\n" +
        "vec2 unit = vec2(0.01, 0.01);\n" +
        "float r = 2.0;\n" +
        "float sampleStep = r / 8.0; \n" +
        "float count = 0.0;\n" +
        "for(float x = -r; x < r; x += sampleStep)\n" +
        "{\n" +
        "  for(float y = -r; y < r; y += sampleStep)\n" +
        "    {\n" +
        "      float weight = (r - abs(x)) * (r - abs(y));\n" +
        "      col += texture2D(sTexture, p + vec2(x * unit.x, y * unit.y)) * weight;\n" +
        "      count += weight;\n" +
        "    }\n" +
        "}\n" +
            "return col/count;\n" +
            "}\n" +
        "void main(void)\n" +
        "{\n" +
            "vec4 col;\n" +
            "if(vTextureCoord.y < 0.2)\n" +
            "{\n" +
            "col = blur(vTextureCoord);\n" +
            "gl_FragColor =  col;\n" +
            "}\n" +
            "else if(vTextureCoord.y > 0.8)\n" +
            "{\n" +
            "col = blur(vTextureCoord);\n" +
            "gl_FragColor =  col;\n" +
            "}\n" +
            "else\n" +
            "{\n" +
            "gl_FragColor =  texture2D(sTexture, vTextureCoord);\n" +
            "}\n" +
//            "vec4 col = blur(vTextureCoord);\n" +
//            "gl_FragColor =  col;\n" +
//            "gl_FragColor =  texture2D(sTexture, vTextureCoord);\n" +
        "}\n"
        ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值