GPUImagePixellateFilter for round part of an image?
Hi,
is it difficult to write a filter like GPUImagePixellateFilter which only pixelates a round part of a image (with a given center and a given radius)?
Is there perhaps an easy way to achieve this with the existing GPUImagePixellateFilter filter as well?
Thanks for your answer.
I'll try to write a modified filter.
Hi again,
I tried to modify the shader and basically it works fine. The only problem is that the pixelated area is oval but I'd like to have an area where you can see every 'pixel' as a rectangle.
Perhaps someone could help me to modify my shader. This is my code so far:
void main() { highp vec2 textureCoordinateToUse = textureCoordinate; highp float dist = distance(center, textureCoordinate); textureCoordinateToUse -= center; if (dist < radius) { highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel); highp vec2 samplePos = textureCoordinateToUse - mod(textureCoordinateToUse, sampleDivisor); textureCoordinateToUse = samplePos; } textureCoordinateToUse += center; gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse); } );
The elliptical nature of the pixellated region is due to the fact that I use a 0-1.0 coordinate space for the texture coordinates in both X and Y, despite the different pixel dimensions for those two directions. You'll need to account for this, possibly by scaling the Y texture coordinate by the ratio of width / height of the filter frame. You could feed in a uniform to do this.
I also use an orthographic projection matrix in my transform filter to do something similar, but I'm not sure if that would be the right approach here.
Right now, there is no way to do this with the standard filters. However, you could do this by creating a modified variant of the pixellation filter that checks whether the current coordinate is within your circle and if so applies the pixellation effect. If outside the circle, just use the input pixel color without any pixellation.
Look at the bump filter for how to determine if a pixel is within a certain radius of a center point. The math in the fragment shader isn't too difficult, and it should be relatively easy to modify the pixellation filter to do this.
Otherwise, the mask filter and a blend could do this, but the mask filter was never fixed by the person who submitted it.