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,限制像素的块的大小。
该文章展示了一个用于像素化图像的FragmentShader代码,通过`floor`函数和自定义的像素大小参数,限制每个像素块的大小,从而达到像素化效果。主要涉及浮点精度、纹理坐标和纹理采样。
1095

被折叠的 条评论
为什么被折叠?



