Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upPixelate Filter is Busted #4
Comments
This comment has been minimized.
This comment has been minimized.
Hi! Do you have any fix ready or would you be able to help us fix it? Martin |
This comment has been minimized.
This comment has been minimized.
does anyone have a fix for the pixelate filter? really want to use this in a project. |
This comment has been minimized.
This comment has been minimized.
i modified the Ascii filter to fix this.. you can replace the filter in filter.js with this as a quick hack function PixelateFilter()
{
PIXI.Filter.call(this,
// vertex shader
"#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",
// fragment shader
"#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nuniform vec4 filterArea;\nuniform float pixelSize;\nuniform sampler2D uSampler;\n\nvec2 mapCoord( vec2 coord )\n{\n coord *= filterArea.xy;\n coord += filterArea.zw;\n\n return coord;\n}\n\nvec2 unmapCoord( vec2 coord )\n{\n coord -= filterArea.zw;\n coord /= filterArea.xy;\n\n return coord;\n}\n\nvec2 pixelate(vec2 coord, vec2 size)\n{\n return floor( coord / size ) * size;\n}\n\nvec2 getMod(vec2 coord, vec2 size)\n{\n return mod( coord , size) / size;\n}\n\nfloat character(float n, vec2 p)\n{\n p = floor(p*vec2(4.0, -4.0) + 2.5);\n if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)\n {\n if (int(mod(n/exp2(p.x + 5.0*p.y), 2.0)) == 1) return 1.0;\n }\n return 0.0;\n}\n\nvoid main()\n{\n vec2 coord = mapCoord(vTextureCoord);\n\n // get the rounded color..\n vec2 pixCoord = pixelate(coord, vec2(pixelSize));\n pixCoord = unmapCoord(pixCoord);\n\n vec4 color = texture2D(uSampler, pixCoord);\n\n // determine the character to use\n float gray = (color.r + color.g + color.b) / 3.0;\n\n float n = 65536.0; // .\n if (gray > 0.2) n = 65600.0; // :\n if (gray > 0.3) n = 332772.0; // *\n if (gray > 0.4) n = 15255086.0; // o\n if (gray > 0.5) n = 23385164.0; // &\n if (gray > 0.6) n = 15252014.0; // 8\n if (gray > 0.7) n = 13199452.0; // @\n if (gray > 0.8) n = 11512810.0; // #\n\n // get the mod..\n vec2 modd = getMod(coord, vec2(pixelSize));\n\n gl_FragColor = color;\n\n}"
);
this.pixelSize = 4;
}
PixelateFilter.prototype = Object.create(PIXI.Filter.prototype);
PixelateFilter.prototype.constructor = PixelateFilter;
module.exports = PixelateFilter;
Object.defineProperties(PixelateFilter.prototype, {
/**
* This a point that describes the size of the blocks.
* x is the width of the block and y is the height.
*
* @member {PIXI.Point}
* @memberof PIXI.filters.PixelateFilter#
*/
pixelSize: {
get: function ()
{
return this.uniforms.pixelSize;
},
set: function (value)
{
this.uniforms.pixelSize = value;
}
}
});
},{}],9:[function(require,module,exports){ |
This comment has been minimized.
This comment has been minimized.
@jeff-gold-marblemedia , you sir, are awesome. Thank you for the quick fix on the pixelate filter |
This comment has been minimized.
This comment has been minimized.
@jeff-gold-marblemedia would welcome a Pull request if you could put something together. |
this commit fixes `PixelateFilter` per the code that @jeff-gold-marblemedia posted in pixijs#4, which is cribbed from `AsciiFilter`. I'm sad to admit that I don't yet know enough about GL or shaders to describe why this works or why the original implementation was broken. I was able to trim down some unused code that was copied from `AsciiFilter` where `gray` was being assigned to a variable but never used.
this commit fixes `PixelateFilter` per the code that @jeff-gold-marblemedia posted in pixijs#4, which is cribbed from `AsciiFilter`. I'm sad to admit that I don't yet know enough about GL or shaders to describe why this works or why the original implementation was broken. I was able to trim down some unused code that was copied from `AsciiFilter` where `gray` was being assigned to a variable but never used.
This comment has been minimized.
This comment has been minimized.
hi maintainers, see #23 if this is something that you still want – hope to learn more about webGL and shaders in the near future. |
this commit fixes `PixelateFilter` per the code that @jeff-gold-marblemedia posted in pixijs#4, which is cribbed from `AsciiFilter`. I'm sad to admit that I don't yet know enough about GL or shaders to describe why this works or why the original implementation was broken.
this commit fixes `PixelateFilter` per the code that @jeff-gold-marblemedia posted in pixijs#4, which is cribbed from `AsciiFilter`. I'm sad to admit that I don't yet know enough about GL or shaders to describe why this works or why the original implementation was broken.
If you see the demos, the PixelateFilter doesn't appear to be operating correctly. Shows up as a solid block instead of pixelated image. http://pixijs.github.io/pixi-filters/examples/