2014-10-24 18:32:12 +00:00
|
|
|
local PostShader = require "lib/postshader"
|
2021-11-10 01:15:14 +00:00
|
|
|
local colorAberration = 0
|
|
|
|
local post_shader, render_buffer
|
|
|
|
local img
|
2014-10-24 18:32:12 +00:00
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function load()
|
2014-10-24 18:32:12 +00:00
|
|
|
post_shader = PostShader()
|
2016-04-26 13:23:11 +00:00
|
|
|
render_buffer = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
|
2021-11-20 01:14:08 +00:00
|
|
|
img = love.graphics.newImage("examples/img/postshaders/kingscard.jpeg")
|
2014-10-24 18:32:12 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function keypressed(k)
|
2014-10-24 18:32:12 +00:00
|
|
|
if k == "1" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("four_colors", {0.05, 0.21, 0.05}, {0.18, 0.38, 0.18}, {0.54, 0.67, 0.05}, {0.60, 0.73, 0.05})
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "2" then
|
|
|
|
post_shader:toggleEffect("monochrome")
|
|
|
|
elseif k == "3" then
|
|
|
|
post_shader:toggleEffect("scanlines")
|
|
|
|
elseif k == "4" then
|
|
|
|
post_shader:toggleEffect("tilt_shift", 4.0)
|
|
|
|
elseif k == "5" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("bloom", 2.0, 0.25)
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "6" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("blur", 10.0, 10.0)
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "7" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("black_and_white")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "8" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("curvature")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "9" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("edges")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "0" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("hdr_tv")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "q" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("phosphor")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "w" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("phosphorish")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "e" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("pip")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "r" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("pixellate")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "t" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("radialblur")
|
2014-10-24 18:32:12 +00:00
|
|
|
elseif k == "y" then
|
2021-11-10 01:15:14 +00:00
|
|
|
post_shader:toggleEffect("waterpaint")
|
|
|
|
elseif k == "c" then
|
|
|
|
colorAberration = 3.0
|
|
|
|
post_shader:addEffect("blur", 2.0, 2.0)
|
|
|
|
post_shader:addEffect("chromatic_aberration")
|
2014-10-24 18:32:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function update(dt)
|
|
|
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
|
|
|
colorAberration = math.max(0.0, colorAberration - dt * 10.0)
|
|
|
|
if colorAberration <= 0.0 then
|
|
|
|
post_shader:removeEffect("blur")
|
|
|
|
post_shader:removeEffect("chromatic_aberration")
|
|
|
|
end
|
2014-10-24 18:32:12 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function draw()
|
2014-10-24 18:32:12 +00:00
|
|
|
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
2021-11-10 01:15:14 +00:00
|
|
|
love.graphics.setCanvas(render_buffer)
|
|
|
|
love.graphics.clear()
|
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
love.graphics.draw(img, 250, 100, 0, 0.5)
|
2014-10-24 18:32:12 +00:00
|
|
|
love.graphics.setCanvas()
|
|
|
|
post_shader:drawWith(render_buffer)
|
|
|
|
love.graphics.setBlendMode("alpha")
|
2021-11-10 01:15:14 +00:00
|
|
|
love.graphics.setColor(0, 0, 0, 0.74)
|
2014-10-24 18:32:12 +00:00
|
|
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 24)
|
2021-11-10 01:15:14 +00:00
|
|
|
love.graphics.setColor(0, 1, 0)
|
|
|
|
love.graphics.print("To toggle postshaders, use 0-9 and q->y, c for chromatic aberration")
|
2014-10-24 18:32:12 +00:00
|
|
|
end
|
2021-11-10 01:15:14 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
load = load,
|
|
|
|
update = update,
|
|
|
|
draw = draw,
|
|
|
|
keypressed = keypressed,
|
|
|
|
}
|