Created
September 4, 2012 22:22
-
-
Save 2bt/3627374 to your computer and use it in GitHub Desktop.
love2d gaussian blur test
This file contains hidden or 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 graphics = love.graphics | |
function love.load() | |
local program = ([[ | |
const float kernel[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162); | |
vec4 effect(vec4 color, sampler2D tex, vec2 tex_coords, vec2 pos) { | |
color = texture2D(tex, tex_coords) * kernel[0]; | |
for(int i = 1; i < 5; i++) { | |
color += texture2D(tex, vec2(tex_coords.x + i * %f, tex_coords.y)) * kernel[i]; | |
color += texture2D(tex, vec2(tex_coords.x - i * %f, tex_coords.y)) * kernel[i]; | |
} | |
return color; | |
} | |
]]):format(1 / graphics.getWidth(), 1 / graphics.getWidth()) | |
fx = graphics.newPixelEffect(program) | |
local program = ([[ | |
const float kernel[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162); | |
vec4 effect(vec4 color, sampler2D tex, vec2 tex_coords, vec2 pos) { | |
color = texture2D(tex, tex_coords) * kernel[0]; | |
for(int i = 1; i < 5; i++) { | |
color += texture2D(tex, vec2(tex_coords.x, tex_coords.y + i * %f)) * kernel[i]; | |
color += texture2D(tex, vec2(tex_coords.x, tex_coords.y - i * %f)) * kernel[i]; | |
} | |
return color; | |
} | |
]]):format(1 / graphics.getHeight(), 1 / graphics.getHeight()) | |
fy = graphics.newPixelEffect(program) | |
print(fx:getWarnings()) | |
print(fy:getWarnings()) | |
canvas_x = graphics.newCanvas(graphics.width, graphics.height) | |
canvas_y = graphics.newCanvas(graphics.width, graphics.height) | |
end | |
t = 0 | |
function love.draw() | |
t = t + 0.02 | |
local x = 400 + math.sin(t) * 400 | |
local y = 300 + math.sin(t * 0.8) * 300 | |
graphics.setCanvas(canvas_x) | |
graphics.push() | |
graphics.translate(x, y) | |
graphics.rotate(t * 1.3) | |
graphics.rectangle("fill", -10, -50, 20, 100) | |
graphics.pop() | |
graphics.setPixelEffect(fx) | |
graphics.setCanvas(canvas_y) | |
graphics.draw(canvas_x, 0, 0) | |
graphics.setPixelEffect(fy) | |
graphics.setCanvas(canvas_x) | |
graphics.draw(canvas_y, 0, 0) | |
graphics.setPixelEffect() | |
graphics.setCanvas() | |
graphics.draw(canvas_x, 0, 0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment