顶点着色器
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"
;