2014-04-08 17:45:21 +00:00
|
|
|
-- Example: Short Example
|
2014-10-27 19:16:21 +00:00
|
|
|
local LightWorld = require "lib"
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
function love.load()
|
2014-10-08 12:55:05 +00:00
|
|
|
testShader = 0
|
2014-10-22 02:48:19 +00:00
|
|
|
x = 0
|
|
|
|
y = 0
|
2014-11-28 15:20:00 +00:00
|
|
|
z = 1
|
2014-09-30 22:19:37 +00:00
|
|
|
scale = 1
|
2014-10-24 01:35:35 +00:00
|
|
|
colorAberration = 0.0
|
2014-03-23 18:10:58 +00:00
|
|
|
-- load images
|
2014-11-28 16:14:53 +00:00
|
|
|
image = love.graphics.newImage("examples/gfx/machine2.png")
|
|
|
|
image_normal = love.graphics.newImage("examples/gfx/cone_normal.png")
|
|
|
|
normal = love.graphics.newImage("examples/gfx/refraction_normal.png")
|
|
|
|
glow = love.graphics.newImage("examples/gfx/machine2_glow.png")
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- create light world
|
2014-10-03 00:32:31 +00:00
|
|
|
lightWorld = LightWorld({
|
2014-10-24 02:41:52 +00:00
|
|
|
ambient = {55,55,55},
|
2014-12-11 02:42:04 +00:00
|
|
|
refractionStrength = 32.0,
|
|
|
|
reflectionVisibility = 0.75,
|
2014-10-03 00:32:31 +00:00
|
|
|
})
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- create light
|
2014-09-26 17:38:55 +00:00
|
|
|
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
|
2014-09-26 16:48:46 +00:00
|
|
|
lightMouse:setGlowStrength(0.3)
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- create shadow bodys
|
2014-09-26 17:38:55 +00:00
|
|
|
circleTest = lightWorld:newCircle(256, 256, 16)
|
|
|
|
rectangleTest = lightWorld:newRectangle(512, 512, 64, 64)
|
2014-12-03 13:31:09 +00:00
|
|
|
local px, py, pw, ph = 100, 200, 20, 50
|
|
|
|
polygonTest = lightWorld:newPolygon(
|
|
|
|
px, py,
|
|
|
|
px+pw, py,
|
|
|
|
px+pw, py+ph,
|
|
|
|
px-50, py+ph)
|
2014-09-26 20:52:16 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
imageTest = lightWorld:newImage(image, 64, 64, 24, 6)
|
2014-09-26 16:48:46 +00:00
|
|
|
imageTest:setNormalMap(image_normal)
|
|
|
|
imageTest:setGlowMap(glow)
|
|
|
|
imageTest:setOffset(12, -10)
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- create body object
|
2014-09-26 20:52:16 +00:00
|
|
|
objectTest = lightWorld:newRefraction(normal, 64, 64, 128, 128)
|
2014-09-26 16:48:46 +00:00
|
|
|
objectTest:setReflection(true)
|
2014-03-23 18:10:58 +00:00
|
|
|
end
|
|
|
|
|
2014-10-08 12:55:05 +00:00
|
|
|
function love.keypressed(k)
|
|
|
|
if k == "1" then
|
2014-10-24 01:35:35 +00:00
|
|
|
lightWorld.post_shader:toggleEffect("four_colors", {15, 56, 15}, {48, 98, 48}, {139, 172, 15}, {155, 188, 15})
|
2014-10-08 12:55:05 +00:00
|
|
|
elseif k == "2" then
|
|
|
|
lightWorld.post_shader:toggleEffect("monochrome")
|
|
|
|
elseif k == "3" then
|
|
|
|
lightWorld.post_shader:toggleEffect("scanlines")
|
|
|
|
elseif k == "4" then
|
2014-10-24 01:35:35 +00:00
|
|
|
lightWorld.post_shader:toggleEffect("tilt_shift", 4.0)
|
2014-10-08 12:55:05 +00:00
|
|
|
elseif k == "5" then
|
|
|
|
lightWorld.post_shader:toggleEffect("bloom", 2.0, 0.25)
|
|
|
|
elseif k == "6" then
|
|
|
|
lightWorld.post_shader:toggleEffect("blur", 2.0, 2.0)
|
|
|
|
elseif k == "7" then
|
2014-10-24 01:35:35 +00:00
|
|
|
lightWorld.post_shader:toggleEffect("black_and_white")
|
|
|
|
elseif k == "8" then
|
|
|
|
lightWorld.post_shader:toggleEffect("curvature")
|
|
|
|
elseif k == "9" then
|
|
|
|
lightWorld.post_shader:toggleEffect("edges")
|
|
|
|
elseif k == "0" then
|
|
|
|
lightWorld.post_shader:toggleEffect("hdr_tv")
|
|
|
|
elseif k == "q" then
|
|
|
|
lightWorld.post_shader:toggleEffect("phosphor")
|
|
|
|
elseif k == "w" then
|
|
|
|
lightWorld.post_shader:toggleEffect("phosphorish")
|
|
|
|
elseif k == "e" then
|
|
|
|
lightWorld.post_shader:toggleEffect("pip")
|
|
|
|
elseif k == "r" then
|
|
|
|
lightWorld.post_shader:toggleEffect("pixellate")
|
|
|
|
elseif k == "t" then
|
|
|
|
lightWorld.post_shader:toggleEffect("radialblur")
|
|
|
|
elseif k == "y" then
|
|
|
|
lightWorld.post_shader:toggleEffect("waterpaint")
|
|
|
|
elseif k == "c" then
|
|
|
|
if colorAberration == 0.0 then
|
|
|
|
colorAberration = 3.0
|
|
|
|
end
|
2014-11-03 22:54:15 +00:00
|
|
|
elseif k == "f" then
|
|
|
|
lightWorld:remove(lightMouse)
|
|
|
|
elseif k == "g" then
|
|
|
|
lightWorld:remove(circleTest)
|
2014-12-03 02:26:46 +00:00
|
|
|
elseif k == "d" then
|
2014-11-03 22:54:15 +00:00
|
|
|
lightWorld:remove(rectangleTest)
|
2014-10-08 12:55:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-23 18:10:58 +00:00
|
|
|
function love.update(dt)
|
|
|
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
2014-09-30 22:19:37 +00:00
|
|
|
|
2014-10-27 18:00:17 +00:00
|
|
|
if love.keyboard.isDown("down") then
|
2014-09-30 22:19:37 +00:00
|
|
|
y = y - dt * 200
|
2014-10-27 18:00:17 +00:00
|
|
|
elseif love.keyboard.isDown("up") then
|
2014-09-30 22:19:37 +00:00
|
|
|
y = y + dt * 200
|
|
|
|
end
|
|
|
|
|
2014-10-27 18:00:17 +00:00
|
|
|
if love.keyboard.isDown("right") then
|
2014-09-30 22:19:37 +00:00
|
|
|
x = x - dt * 200
|
2014-10-27 18:00:17 +00:00
|
|
|
elseif love.keyboard.isDown("left") then
|
2014-09-30 22:19:37 +00:00
|
|
|
x = x + dt * 200
|
|
|
|
end
|
|
|
|
|
2014-12-03 02:26:46 +00:00
|
|
|
|
|
|
|
if love.keyboard.isDown("k") then
|
|
|
|
polygonTest:move(0, -(dt * 200))
|
|
|
|
elseif love.keyboard.isDown("j") then
|
|
|
|
polygonTest:move(0, (dt * 200))
|
|
|
|
end
|
|
|
|
if love.keyboard.isDown("h") then
|
|
|
|
polygonTest:move(-(dt * 200), 0)
|
|
|
|
elseif love.keyboard.isDown("l") then
|
|
|
|
polygonTest:move((dt * 200), 0)
|
|
|
|
end
|
|
|
|
|
2014-09-30 22:19:37 +00:00
|
|
|
if love.keyboard.isDown("-") then
|
|
|
|
scale = scale - 0.01
|
|
|
|
elseif love.keyboard.isDown("=") then
|
|
|
|
scale = scale + 0.01
|
|
|
|
end
|
2014-10-24 01:35:35 +00:00
|
|
|
|
|
|
|
colorAberration = math.max(0.0, colorAberration - dt * 10.0)
|
|
|
|
if colorAberration > 0.0 then
|
|
|
|
lightWorld.post_shader:addEffect("blur", 2.0, 2.0)
|
|
|
|
lightWorld.post_shader:addEffect("chromatic_aberration")
|
|
|
|
else
|
|
|
|
lightWorld.post_shader:removeEffect("blur")
|
|
|
|
lightWorld.post_shader:removeEffect("chromatic_aberration")
|
|
|
|
end
|
2014-09-30 22:19:37 +00:00
|
|
|
|
2014-11-28 15:20:00 +00:00
|
|
|
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale, z)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.mousepressed(x, y, c)
|
|
|
|
if c == "wu" then
|
|
|
|
z = z + 1
|
|
|
|
elseif c == "wd" then
|
|
|
|
z = z - 1
|
|
|
|
end
|
2014-03-23 18:10:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2014-11-30 20:24:58 +00:00
|
|
|
lightWorld:setTranslation(x, y, scale)
|
2014-10-22 02:48:19 +00:00
|
|
|
love.graphics.push()
|
|
|
|
love.graphics.translate(x, y)
|
|
|
|
love.graphics.scale(scale)
|
2014-11-30 20:24:58 +00:00
|
|
|
lightWorld:draw(function()
|
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
|
|
|
|
love.graphics.setColor(63, 255, 127)
|
|
|
|
local cx, cy = circleTest:getPosition()
|
|
|
|
love.graphics.circle("fill", cx, cy, circleTest:getRadius())
|
|
|
|
love.graphics.polygon("fill", rectangleTest:getPoints())
|
2014-12-03 02:26:46 +00:00
|
|
|
love.graphics.polygon("fill", polygonTest:getPoints())
|
2014-11-30 20:24:58 +00:00
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
|
|
|
|
end)
|
2014-10-22 02:48:19 +00:00
|
|
|
love.graphics.pop()
|
2014-10-24 18:32:12 +00:00
|
|
|
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
love.graphics.setColor(0, 0, 0, 191)
|
|
|
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 24)
|
|
|
|
love.graphics.setColor(0, 255, 0)
|
|
|
|
love.graphics.print("To toggle postshaders, use 0-9 and q->y, to scale use - and =, and to translate use arrows")
|
2014-11-28 15:20:00 +00:00
|
|
|
love.graphics.print("light z: " .. lightMouse.z, 0, 50)
|
2014-09-26 16:48:46 +00:00
|
|
|
end
|