2021-11-20 01:14:08 +00:00
|
|
|
local gamera = require "examples/vendor/gamera"
|
2014-10-27 19:16:21 +00:00
|
|
|
local LightWorld = require "lib"
|
2021-11-20 01:14:08 +00:00
|
|
|
local objects = {}
|
|
|
|
local obj = require "examples.lib.object"
|
|
|
|
local keyboard = require "examples.lib.keyboard"
|
|
|
|
local cam, font, quadScreen, imgFloor, imgLight
|
|
|
|
local lightRange = 300
|
|
|
|
local lightDirection = 0.0
|
|
|
|
local colorAberration = 0.0
|
|
|
|
local lightWorld, mouseLight
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function load()
|
2021-11-20 01:14:08 +00:00
|
|
|
math.randomseed(love.timer.getTime())
|
|
|
|
cam = gamera.new(0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
2014-10-08 12:55:05 +00:00
|
|
|
love.graphics.setBackgroundColor(0, 0, 0)
|
2014-04-08 17:45:21 +00:00
|
|
|
love.graphics.setDefaultFilter("nearest", "nearest")
|
2021-11-20 01:14:08 +00:00
|
|
|
font = love.graphics.newImageFont("examples/img/complex/font.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"")
|
2014-04-08 17:45:21 +00:00
|
|
|
love.graphics.setFont(font)
|
2016-02-03 14:45:22 +00:00
|
|
|
quadScreen = love.graphics.newQuad(0, 0, love.graphics.getWidth() + 32, love.graphics.getHeight() + 24, 32, 24)
|
2021-11-20 01:14:08 +00:00
|
|
|
imgFloor = love.graphics.newImage("examples/img/complex/floor.png")
|
2014-04-08 17:45:21 +00:00
|
|
|
imgFloor:setWrap("repeat", "repeat")
|
2021-11-20 01:14:08 +00:00
|
|
|
imgLight = love.graphics.newImage("examples/img/complex/light.png")
|
|
|
|
lightWorld = LightWorld({ambient = {15,15,15}, refractionStrength = 16.0, reflectionVisibility = 0.75, shadowBlur = 2.0})
|
2019-09-07 11:36:40 +00:00
|
|
|
mouseLight = lightWorld:newLight(0, 0, 1, 191/ 255, 0.5, lightRange)
|
2014-09-26 16:48:46 +00:00
|
|
|
mouseLight:setGlowStrength(0.3)
|
2014-04-08 17:45:21 +00:00
|
|
|
mouseLight.z = 63
|
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function update(dt)
|
2014-04-08 17:45:21 +00:00
|
|
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
2021-11-20 01:14:08 +00:00
|
|
|
local x, y, scale = keyboard.update(dt)
|
|
|
|
cam:setScale(scale)
|
|
|
|
cam:setPosition(x, y)
|
|
|
|
local mx, my = cam:toScreen(love.mouse.getX(),love.mouse.getY())
|
|
|
|
lightWorld:setTranslation(offsetX,offsetY, scale)
|
2014-04-08 17:45:21 +00:00
|
|
|
lightDirection = lightDirection + dt
|
2021-11-20 01:14:08 +00:00
|
|
|
mouseLight:setPosition(mx, my, 1 + (math.sin(lightDirection)+1.0))
|
|
|
|
for i, o in ipairs(objects) do o:update(dt) end
|
2014-04-08 17:45:21 +00:00
|
|
|
colorAberration = math.max(0.0, colorAberration - dt * 10.0)
|
2014-10-06 21:27:41 +00:00
|
|
|
if colorAberration > 0.0 then
|
|
|
|
lightWorld.post_shader:addEffect("blur", 2.0, 2.0)
|
2019-09-07 11:36:40 +00:00
|
|
|
lightWorld.post_shader:addEffect("chromatic_aberration",
|
|
|
|
{math.sin(lightDirection * 10.0) * colorAberration, math.cos(lightDirection * 10.0) * colorAberration},
|
|
|
|
{math.cos(lightDirection * 10.0) * colorAberration, math.sin(lightDirection * 10.0) * -colorAberration},
|
2014-12-05 20:46:05 +00:00
|
|
|
{math.sin(lightDirection * 10.0) * colorAberration, math.cos(lightDirection * 10.0) * -colorAberration})
|
2014-10-06 21:27:41 +00:00
|
|
|
else
|
|
|
|
lightWorld.post_shader:removeEffect("blur")
|
2014-10-24 01:35:35 +00:00
|
|
|
lightWorld.post_shader:removeEffect("chromatic_aberration")
|
2014-10-06 21:27:41 +00:00
|
|
|
end
|
2014-12-21 18:14:46 +00:00
|
|
|
lightWorld:update(dt)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function draw()
|
2021-11-20 01:14:08 +00:00
|
|
|
cam:draw(function(l,t,w,h)
|
|
|
|
lightWorld:draw(function(l, t, w, h, s)
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
love.graphics.draw(imgFloor, quadScreen, 0,0)
|
|
|
|
for i, ob in ipairs(objects) do ob:draw() end
|
|
|
|
end)
|
|
|
|
local mx, my = cam:toScreen(love.mouse.getX(),love.mouse.getY())
|
|
|
|
love.graphics.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
|
|
|
|
end)
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
love.graphics.setColor(0, 0.5, 1)
|
|
|
|
love.graphics.print("c: chromatic abberation", 4, love.graphics.getHeight() - 20 * 6)
|
|
|
|
love.graphics.print("F1-F9: Shaders", 4, love.graphics.getHeight() - 20 * 5)
|
|
|
|
love.graphics.print("F10: Clear Bodies", 4, love.graphics.getHeight() - 20 * 4)
|
|
|
|
love.graphics.print("F11: Clear Lights", 4, love.graphics.getHeight() - 20 * 3)
|
|
|
|
love.graphics.print("Arrow Keys: Move map", 4, love.graphics.getHeight() - 20 * 2)
|
|
|
|
love.graphics.print("0-9 Keys: Add object", 4, love.graphics.getHeight() - 20 * 1)
|
|
|
|
love.graphics.setColor(1, 0.5, 0)
|
|
|
|
love.graphics.print("M.left: Add cube", love.graphics.getWidth() - 180, love.graphics.getHeight() - 20 * 3)
|
|
|
|
love.graphics.print("M.middle: Add light", love.graphics.getWidth() - 180, love.graphics.getHeight() - 20 * 2)
|
|
|
|
love.graphics.print("M.right: Add circle", love.graphics.getWidth() - 180, love.graphics.getHeight() - 20 * 1)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function mousepressed(x, y, c)
|
2021-11-20 01:14:08 +00:00
|
|
|
if c == 3 then
|
|
|
|
local light = lightWorld:newLight(x, y, math.random(), math.random(), math.random(), lightRange)
|
2014-09-26 16:48:46 +00:00
|
|
|
light:setGlowStrength(0.3)
|
2021-11-20 01:14:08 +00:00
|
|
|
if love.keyboard.isDown("rshift") or love.keyboard.isDown("lshift") then
|
|
|
|
light:setAngle(math.random(1, 5) * 0.1 * math.pi)
|
|
|
|
light:setDirection(math.random(1, 5) * 0.1 * math.pi)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
2021-11-20 01:14:08 +00:00
|
|
|
elseif c == 1 then table.insert(objects, obj.Rect:new(lightWorld, x, y, math.random(32, 64), math.random(32, 64)))
|
|
|
|
elseif c == 2 then table.insert(objects, obj.Circle:new(lightWorld, x, y, math.random(8, 32)))
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function keypressed(k, u)
|
2021-11-20 01:14:08 +00:00
|
|
|
local mx, my = cam:toScreen(love.mouse.getX(),love.mouse.getY())
|
|
|
|
if k == "f1" then lightWorld.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})
|
|
|
|
elseif k == "f2" then lightWorld.post_shader:toggleEffect("scanlines")
|
|
|
|
elseif k == "f3" then lightWorld.post_shader:toggleEffect("bloom", 2.0, 0.25)
|
|
|
|
elseif k == "f4" then lightWorld.post_shader:toggleEffect("black_and_white")
|
|
|
|
elseif k == "f5" then lightWorld.post_shader:toggleEffect("curvature")
|
|
|
|
elseif k == "f6" then lightWorld.post_shader:toggleEffect("edges")
|
|
|
|
elseif k == "f7" then lightWorld.post_shader:toggleEffect("pip")
|
|
|
|
elseif k == "f8" then lightWorld.post_shader:toggleEffect("pixellate")
|
|
|
|
elseif k == "f9" then lightWorld.post_shader:toggleEffect("waterpaint")
|
2014-04-08 17:45:21 +00:00
|
|
|
elseif k == "f10" then
|
2015-07-24 23:02:03 +00:00
|
|
|
lightWorld:clearBodies()
|
2021-11-20 01:14:08 +00:00
|
|
|
objects = {}
|
|
|
|
elseif k == "f11" then
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:clearLights()
|
2019-09-07 11:36:40 +00:00
|
|
|
mouseLight = lightWorld:newLight(0, 0, 1, 191/255, 0.5, lightRange)
|
2014-09-26 16:48:46 +00:00
|
|
|
mouseLight:setGlowStrength(0.3)
|
2021-11-20 01:14:08 +00:00
|
|
|
elseif k == "1" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/ape", mx, my, "image"))
|
|
|
|
elseif k == "2" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/chest", mx, my))
|
|
|
|
elseif k == "3" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/cone", mx, my, "circle"))
|
|
|
|
elseif k == "4" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/cube", mx, my))
|
|
|
|
elseif k == "5" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/cylinder", mx, my, "circle"))
|
|
|
|
elseif k == "6" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/screen1", mx, my))
|
|
|
|
elseif k == "7" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/screen2", mx, my))
|
|
|
|
elseif k == "8" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/screen3", mx, my))
|
|
|
|
elseif k == "9" then table.insert(objects, obj.ImageObject:new(lightWorld, "examples/img/complex/tile", mx, my))
|
|
|
|
elseif k == "0" then table.insert(objects, obj.Refraction:new(lightWorld, "examples/img/complex/water", mx, my))
|
|
|
|
elseif k == "c" then colorAberration = 3.0
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
2014-09-26 16:48:46 +00:00
|
|
|
end
|
2021-11-10 01:15:14 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
load = load,
|
|
|
|
update = update,
|
|
|
|
draw = draw,
|
|
|
|
keypressed = keypressed,
|
|
|
|
mousepressed = mousepressed,
|
|
|
|
}
|