2014-04-08 17:45:21 +00:00
|
|
|
-- Example: Short Example
|
2014-09-26 17:38:55 +00:00
|
|
|
local LightWorld = require "lib/light_world"
|
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-09-30 22:19:37 +00:00
|
|
|
scale = 1
|
2014-03-23 18:10:58 +00:00
|
|
|
-- load images
|
|
|
|
image = love.graphics.newImage("gfx/machine2.png")
|
|
|
|
image_normal = love.graphics.newImage("gfx/cone_normal.png")
|
|
|
|
normal = love.graphics.newImage("gfx/refraction_normal.png")
|
|
|
|
glow = love.graphics.newImage("gfx/machine2_glow.png")
|
|
|
|
|
|
|
|
-- create light world
|
2014-10-03 00:32:31 +00:00
|
|
|
lightWorld = LightWorld({
|
|
|
|
drawBackground = drawBackground,
|
2014-10-08 12:55:05 +00:00
|
|
|
drawForground = drawForground,
|
|
|
|
ambient = {15,15,15},
|
|
|
|
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-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
|
|
|
|
lightWorld.post_shader:toggleEffect("4colors", {15, 56, 15}, {48, 98, 48}, {139, 172, 15}, {155, 188, 15})
|
|
|
|
elseif k == "2" then
|
|
|
|
lightWorld.post_shader:toggleEffect("monochrome")
|
|
|
|
elseif k == "3" then
|
|
|
|
lightWorld.post_shader:toggleEffect("scanlines")
|
|
|
|
elseif k == "4" then
|
|
|
|
lightWorld.post_shader:toggleEffect("tiltshift", 4.0)
|
|
|
|
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)
|
|
|
|
--lightWorld.post_shader:addEffect("chromatic", math.sin(lightDirection * 10.0) * colorAberration, math.cos(lightDirection * 10.0) * colorAberration, math.cos(lightDirection * 10.0) * colorAberration, math.sin(lightDirection * 10.0) * -colorAberration, math.sin(lightDirection * 10.0) * colorAberration, math.cos(lightDirection * 10.0) * -colorAberration)
|
|
|
|
elseif k == "7" then
|
|
|
|
testShader = testShader + 1
|
|
|
|
lightWorld.post_shader:addEffect("test", testShader)
|
|
|
|
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
|
|
|
|
|
|
|
if love.keyboard.isDown("up") then
|
|
|
|
y = y - dt * 200
|
|
|
|
elseif love.keyboard.isDown("down") then
|
|
|
|
y = y + dt * 200
|
|
|
|
end
|
|
|
|
|
|
|
|
if love.keyboard.isDown("left") then
|
|
|
|
x = x - dt * 200
|
|
|
|
elseif love.keyboard.isDown("right") then
|
|
|
|
x = x + dt * 200
|
|
|
|
end
|
|
|
|
|
|
|
|
if love.keyboard.isDown("-") then
|
|
|
|
scale = scale - 0.01
|
|
|
|
elseif love.keyboard.isDown("=") then
|
|
|
|
scale = scale + 0.01
|
|
|
|
end
|
|
|
|
|
2014-10-22 02:48:19 +00:00
|
|
|
lightMouse:setPosition(love.mouse.getX(), love.mouse.getY())
|
2014-03-23 18:10:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2014-10-22 02:48:19 +00:00
|
|
|
love.graphics.push()
|
|
|
|
love.graphics.translate(x, y)
|
|
|
|
love.graphics.scale(scale)
|
|
|
|
lightWorld:draw(x,y,scale)
|
|
|
|
love.graphics.pop()
|
2014-09-26 16:48:46 +00:00
|
|
|
end
|
2014-10-03 00:32:31 +00:00
|
|
|
|
|
|
|
function drawBackground(l,t,w,h)
|
2014-10-23 01:55:15 +00:00
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.rectangle("fill", -l, -t, w, h)
|
2014-10-03 00:32:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function drawForground(l,t,w,h)
|
|
|
|
love.graphics.setColor(63, 255, 127)
|
|
|
|
love.graphics.circle("fill", circleTest:getX(), circleTest:getY(), circleTest:getRadius())
|
|
|
|
love.graphics.polygon("fill", rectangleTest:getPoints())
|
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
|
|
|
|
end
|
|
|
|
|