2014-04-08 17:45:21 +00:00
|
|
|
-- Example: Short Example
|
|
|
|
require "lib/postshader"
|
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()
|
|
|
|
-- 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-09-26 17:38:55 +00:00
|
|
|
lightWorld = LightWorld()
|
|
|
|
lightWorld:setAmbientColor(15, 15, 31)
|
|
|
|
lightWorld:setRefractionStrength(32.0)
|
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)
|
|
|
|
--lightMouse:setSmooth(0.01)
|
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:setShine(false)
|
|
|
|
--objectTest:setShadowType("rectangle")
|
|
|
|
--objectTest:setShadowDimension(64, 64)
|
|
|
|
objectTest:setReflection(true)
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- set background
|
|
|
|
quadScreen = love.graphics.newQuad(0, 0, love.window.getWidth(), love.window.getHeight(), 32, 24)
|
|
|
|
imgFloor = love.graphics.newImage("gfx/floor.png")
|
|
|
|
imgFloor:setWrap("repeat", "repeat")
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.update(dt)
|
|
|
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
2014-09-26 16:48:46 +00:00
|
|
|
lightMouse:setPosition(love.mouse.getX(), love.mouse.getY())
|
2014-03-23 18:10:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
|
|
|
love.postshader.setBuffer("render")
|
|
|
|
|
|
|
|
-- draw background
|
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
|
|
|
--love.graphics.draw(imgFloor, quadScreen, 0, 0)
|
|
|
|
|
|
|
|
-- draw lightmap shadows
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawShadow()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- draw scene objects
|
|
|
|
love.graphics.setColor(63, 255, 127)
|
2014-09-26 16:48:46 +00:00
|
|
|
love.graphics.circle("fill", circleTest:getX(), circleTest:getY(), circleTest:getRadius())
|
|
|
|
love.graphics.polygon("fill", rectangleTest:getPoints())
|
2014-03-23 18:10:58 +00:00
|
|
|
love.graphics.setColor(255, 255, 255)
|
|
|
|
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
|
|
|
|
|
|
|
|
--love.graphics.rectangle("fill", 128 - 32, 128 - 32, 64, 64)
|
|
|
|
|
|
|
|
-- draw lightmap shine
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawShine()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- draw pixel shadow
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawPixelShadow()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- draw glow
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawGlow()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- draw refraction
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawRefraction()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
-- draw reflection
|
2014-09-26 17:38:55 +00:00
|
|
|
lightWorld:drawReflection()
|
2014-03-23 18:10:58 +00:00
|
|
|
|
|
|
|
love.postshader.draw()
|
2014-09-26 16:48:46 +00:00
|
|
|
end
|