Skip to content

Instantly share code, notes, and snippets.

@2bt
Created September 4, 2012 22:22
Show Gist options
  • Select an option

  • Save 2bt/3627374 to your computer and use it in GitHub Desktop.

Select an option

Save 2bt/3627374 to your computer and use it in GitHub Desktop.

Revisions

  1. twobit created this gist Sep 4, 2012.
    67 changes: 67 additions & 0 deletions main.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    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