1.效果图
2.fragment shader
public static final String PIXELATION_FRAGMENT_SHADER = "" +
"precision highp float;\n" +
"varying vec2 textureCoordinate;\n" +
"uniform float imageWidthFactor;\n" +
"uniform float imageHeightFactor;\n" +
"uniform sampler2D inputImageTexture;\n" +
"uniform float pixel;\n" +
"void main()\n" +
"{\n" +
" vec2 uv = textureCoordinate.xy;\n" +
" float dx = pixel * imageWidthFactor;\n" +
" float dy = pixel * imageHeightFactor;\n" +
" vec2 coord = vec2(dx * floor(uv.x / dx), dy * floor(uv.y / dy));\n" +
" vec3 tc = texture2D(inputImageTexture, coord).xyz;\n" +
" gl_FragColor = vec4(tc, 1.0);\n" +
"}";
3.原理
透过floor,限制像素的块的大小。