Created
August 3, 2012 05:20
-
-
Save randrews/3244637 to your computer and use it in GitHub Desktop.
A pixelation shader for Love
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local shader = love.graphics.newPixelEffect [[ | |
extern vec2 size; | |
extern number factor; | |
vec4 effect(vec4 color, Image img, vec2 texture_coords, vec2 pixel_coords){ | |
vec2 tc = floor(texture_coords * size / factor) * factor / size; | |
return Texel(img, tc); | |
} | |
]] | |
love.graphics.setPixelEffect(shader) | |
local image = love.graphics.newImage('maggie.jpg') -- Put in whatever image you want here | |
local t = 0 | |
function love.draw() | |
love.graphics.draw(image, 0, 0) | |
end | |
function love.update(dt) | |
t = t + dt | |
shader:send('factor', math.abs(math.sin(t)) * 32) | |
shader:send('size', {image:getWidth(), image:getHeight()}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment