mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
finished refactor so that there are no more globals to the light world
This commit is contained in:
parent
d58fd39f7f
commit
f2b9d62efe
@ -1,6 +1,6 @@
|
|||||||
-- Example: Complex Example
|
-- Example: Complex Example
|
||||||
require "lib/postshader"
|
require "lib/postshader"
|
||||||
require "lib/light_world"
|
local LightWorld = require "lib/light_world"
|
||||||
|
|
||||||
function initScene()
|
function initScene()
|
||||||
-- physic world
|
-- physic world
|
||||||
@ -89,11 +89,11 @@ function love.load()
|
|||||||
-- light world
|
-- light world
|
||||||
lightRange = 400
|
lightRange = 400
|
||||||
lightSmooth = 1.0
|
lightSmooth = 1.0
|
||||||
lightWorld = love.light.newWorld()
|
lightWorld = LightWorld()
|
||||||
lightWorld.setAmbientColor(15, 15, 31)
|
lightWorld:setAmbientColor(15, 15, 31)
|
||||||
lightWorld.setRefractionStrength(16.0)
|
lightWorld:setRefractionStrength(16.0)
|
||||||
lightWorld.setReflectionVisibility(0.75)
|
lightWorld:setReflectionVisibility(0.75)
|
||||||
mouseLight = lightWorld.newLight(0, 0, 255, 191, 127, lightRange)
|
mouseLight = lightWorld:newLight(0, 0, 255, 191, 127, lightRange)
|
||||||
mouseLight:setGlowStrength(0.3)
|
mouseLight:setGlowStrength(0.3)
|
||||||
mouseLight:setSmooth(lightSmooth)
|
mouseLight:setSmooth(lightSmooth)
|
||||||
mouseLight.z = 63
|
mouseLight.z = 63
|
||||||
@ -174,15 +174,15 @@ function love.update(dt)
|
|||||||
|
|
||||||
if offsetX ~= offsetOldX or offsetY ~= offsetOldY then
|
if offsetX ~= offsetOldX or offsetY ~= offsetOldY then
|
||||||
offsetChanged = true
|
offsetChanged = true
|
||||||
for i = 2, lightWorld.getLightCount() do
|
for i = 2, lightWorld:getLightCount() do
|
||||||
lightWorld.setLightPosition(i, lightWorld.getLightX(i) + (offsetX - offsetOldX), lightWorld.getLightY(i) + (offsetY - offsetOldY))
|
lightWorld:setLightPosition(i, lightWorld:getLightX(i) + (offsetX - offsetOldX), lightWorld:getLightY(i) + (offsetY - offsetOldY))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
offsetChanged = false
|
offsetChanged = false
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, lightWorld.getLightCount() do
|
for i = 1, lightWorld:getLightCount() do
|
||||||
lightWorld.setLightDirection(i, lightDirection)
|
lightWorld:setLightDirection(i, lightDirection)
|
||||||
end
|
end
|
||||||
|
|
||||||
tileX = tileX + dt * 32.0
|
tileX = tileX + dt * 32.0
|
||||||
@ -225,7 +225,7 @@ end
|
|||||||
function love.draw()
|
function love.draw()
|
||||||
-- update lightmap (don't need deltatime)
|
-- update lightmap (don't need deltatime)
|
||||||
if lightOn then
|
if lightOn then
|
||||||
lightWorld.update()
|
lightWorld:update()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set shader buffer
|
-- set shader buffer
|
||||||
@ -265,7 +265,7 @@ function love.draw()
|
|||||||
|
|
||||||
-- draw lightmap shadows
|
-- draw lightmap shadows
|
||||||
if lightOn and not normalOn then
|
if lightOn and not normalOn then
|
||||||
lightWorld.drawShadow()
|
lightWorld:drawShadow()
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, phyCnt do
|
for i = 1, phyCnt do
|
||||||
@ -280,7 +280,7 @@ function love.draw()
|
|||||||
|
|
||||||
-- draw lightmap shine
|
-- draw lightmap shine
|
||||||
if lightOn and not normalOn then
|
if lightOn and not normalOn then
|
||||||
lightWorld.drawShine()
|
lightWorld:drawShine()
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
@ -298,24 +298,24 @@ function love.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not normalOn then
|
if not normalOn then
|
||||||
lightWorld.drawMaterial()
|
lightWorld:drawMaterial()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw pixel shadow
|
-- draw pixel shadow
|
||||||
if lightOn and not normalOn then
|
if lightOn and not normalOn then
|
||||||
lightWorld.drawPixelShadow()
|
lightWorld:drawPixelShadow()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw glow
|
-- draw glow
|
||||||
if lightOn and not normalOn then
|
if lightOn and not normalOn then
|
||||||
lightWorld.drawGlow()
|
lightWorld:drawGlow()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw reflection
|
-- draw reflection
|
||||||
lightWorld.drawReflection()
|
lightWorld:drawReflection()
|
||||||
|
|
||||||
-- draw refraction
|
-- draw refraction
|
||||||
lightWorld.drawRefraction()
|
lightWorld:drawRefraction()
|
||||||
|
|
||||||
love.graphics.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
|
love.graphics.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
|
||||||
|
|
||||||
@ -438,15 +438,15 @@ end
|
|||||||
function love.mousepressed(x, y, c)
|
function love.mousepressed(x, y, c)
|
||||||
if c == "m" then
|
if c == "m" then
|
||||||
-- add light
|
-- add light
|
||||||
local r = lightWorld.getLightCount() % 3
|
local r = lightWorld:getLightCount() % 3
|
||||||
local light
|
local light
|
||||||
|
|
||||||
if r == 0 then
|
if r == 0 then
|
||||||
light = lightWorld.newLight(x, y, 31, 127, 63, lightRange)
|
light = lightWorld:newLight(x, y, 31, 127, 63, lightRange)
|
||||||
elseif r == 1 then
|
elseif r == 1 then
|
||||||
light = lightWorld.newLight(x, y, 127, 63, 31, lightRange)
|
light = lightWorld:newLight(x, y, 127, 63, 31, lightRange)
|
||||||
else
|
else
|
||||||
light = lightWorld.newLight(x, y, 31, 63, 127, lightRange)
|
light = lightWorld:newLight(x, y, 31, 63, 127, lightRange)
|
||||||
end
|
end
|
||||||
light:setSmooth(lightSmooth)
|
light:setSmooth(lightSmooth)
|
||||||
light:setGlowStrength(0.3)
|
light:setGlowStrength(0.3)
|
||||||
@ -454,7 +454,7 @@ function love.mousepressed(x, y, c)
|
|||||||
-- add rectangle
|
-- add rectangle
|
||||||
math.randomseed(love.timer.getTime())
|
math.randomseed(love.timer.getTime())
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newPolygon()
|
phyLight[phyCnt] = lightWorld:newPolygon()
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, x, y, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, x, y, "dynamic")
|
||||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, math.random(32, 64), math.random(32, 64))
|
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, math.random(32, 64), math.random(32, 64))
|
||||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||||
@ -464,7 +464,7 @@ function love.mousepressed(x, y, c)
|
|||||||
math.randomseed(love.timer.getTime())
|
math.randomseed(love.timer.getTime())
|
||||||
cRadius = math.random(8, 32)
|
cRadius = math.random(8, 32)
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newCircle(x, y, cRadius)
|
phyLight[phyCnt] = lightWorld:newCircle(x, y, cRadius)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, x, y, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, x, y, "dynamic")
|
||||||
phyShape[phyCnt] = love.physics.newCircleShape(0, 0, cRadius)
|
phyShape[phyCnt] = love.physics.newCircleShape(0, 0, cRadius)
|
||||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||||
@ -498,7 +498,7 @@ function love.keypressed(k, u)
|
|||||||
if shadowBlur > 8.0 then
|
if shadowBlur > 8.0 then
|
||||||
shadowBlur = 0.0
|
shadowBlur = 0.0
|
||||||
end
|
end
|
||||||
lightWorld.setBlur(shadowBlur)
|
lightWorld:setBlur(shadowBlur)
|
||||||
elseif k == "f6" or k == "b" then
|
elseif k == "f6" or k == "b" then
|
||||||
bloomOn = math.max(0.25, bloomOn * 2.0)
|
bloomOn = math.max(0.25, bloomOn * 2.0)
|
||||||
if bloomOn > 1.0 then
|
if bloomOn > 1.0 then
|
||||||
@ -513,7 +513,7 @@ function love.keypressed(k, u)
|
|||||||
if glowBlur > 8.0 then
|
if glowBlur > 8.0 then
|
||||||
glowBlur = 0.0
|
glowBlur = 0.0
|
||||||
end
|
end
|
||||||
lightWorld.setGlowStrength(glowBlur)
|
lightWorld:setGlowStrength(glowBlur)
|
||||||
elseif k == "f10" then
|
elseif k == "f10" then
|
||||||
effectOn = effectOn + 1.0
|
effectOn = effectOn + 1.0
|
||||||
if effectOn > 4.0 then
|
if effectOn > 4.0 then
|
||||||
@ -521,17 +521,17 @@ function love.keypressed(k, u)
|
|||||||
end
|
end
|
||||||
elseif k == "f11" then
|
elseif k == "f11" then
|
||||||
physicWorld:destroy()
|
physicWorld:destroy()
|
||||||
lightWorld.clearBodys()
|
lightWorld:clearBodys()
|
||||||
initScene()
|
initScene()
|
||||||
elseif k == "f12" then
|
elseif k == "f12" then
|
||||||
lightWorld.clearLights()
|
lightWorld:clearLights()
|
||||||
mouseLight = lightWorld.newLight(0, 0, 255, 191, 127, lightRange)
|
mouseLight = lightWorld:newLight(0, 0, 255, 191, 127, lightRange)
|
||||||
mouseLight:setGlowStrength(0.3)
|
mouseLight:setGlowStrength(0.3)
|
||||||
mouseLight:setSmooth(lightSmooth)
|
mouseLight:setSmooth(lightSmooth)
|
||||||
elseif k == "1" then
|
elseif k == "1" then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(circle, mx, my)
|
phyLight[phyCnt] = lightWorld:newImage(circle, mx, my)
|
||||||
phyLight[phyCnt]:setNormalMap(circle_normal)
|
phyLight[phyCnt]:setNormalMap(circle_normal)
|
||||||
phyLight[phyCnt]:setShadowType("circle", 16)
|
phyLight[phyCnt]:setShadowType("circle", 16)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -539,11 +539,11 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif k == "2" then
|
elseif k == "2" then
|
||||||
local r = lightWorld.getBodyCount() % 2
|
local r = lightWorld:getBodyCount() % 2
|
||||||
if r == 0 then
|
if r == 0 then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(cone, mx, my, 24, 12, 12, 16)
|
phyLight[phyCnt] = lightWorld:newImage(cone, mx, my, 24, 12, 12, 16)
|
||||||
phyLight[phyCnt]:setNormalMap(cone_normal)
|
phyLight[phyCnt]:setNormalMap(cone_normal)
|
||||||
phyLight[phyCnt]:setShadowType("circle", 12, 0, -8)
|
phyLight[phyCnt]:setShadowType("circle", 12, 0, -8)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -553,7 +553,7 @@ function love.keypressed(k, u)
|
|||||||
elseif r == 1 then
|
elseif r == 1 then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(chest, mx, my, 32, 24, 16, 0)
|
phyLight[phyCnt] = lightWorld:newImage(chest, mx, my, 32, 24, 16, 0)
|
||||||
phyLight[phyCnt]:setNormalMap(chest_normal)
|
phyLight[phyCnt]:setNormalMap(chest_normal)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 32, 24)
|
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 32, 24)
|
||||||
@ -562,9 +562,9 @@ function love.keypressed(k, u)
|
|||||||
end
|
end
|
||||||
elseif k == "3" then
|
elseif k == "3" then
|
||||||
-- add image
|
-- add image
|
||||||
local r = lightWorld.getBodyCount() % #material
|
local r = lightWorld:getBodyCount() % #material
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(ape, mx, my, 160, 128, 80, 64)
|
phyLight[phyCnt] = lightWorld:newImage(ape, mx, my, 160, 128, 80, 64)
|
||||||
phyLight[phyCnt]:setNormalMap(ape_normal)
|
phyLight[phyCnt]:setNormalMap(ape_normal)
|
||||||
if r == 3 then
|
if r == 3 then
|
||||||
phyLight[phyCnt]:setGlowMap(ape_glow)
|
phyLight[phyCnt]:setGlowMap(ape_glow)
|
||||||
@ -577,10 +577,10 @@ function love.keypressed(k, u)
|
|||||||
phyLight[phyCnt]:setShadowType("image", 0, -16, 0.0)
|
phyLight[phyCnt]:setShadowType("image", 0, -16, 0.0)
|
||||||
elseif k == "4" then
|
elseif k == "4" then
|
||||||
-- add glow image
|
-- add glow image
|
||||||
local r = lightWorld.getBodyCount() % 5
|
local r = lightWorld:getBodyCount() % 5
|
||||||
if r == 0 then
|
if r == 0 then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(machine, mx, my, 32, 24, 16, 0)
|
phyLight[phyCnt] = lightWorld:newImage(machine, mx, my, 32, 24, 16, 0)
|
||||||
phyLight[phyCnt]:setNormalMap(machine_normal)
|
phyLight[phyCnt]:setNormalMap(machine_normal)
|
||||||
phyLight[phyCnt]:setGlowMap(machine_glow)
|
phyLight[phyCnt]:setGlowMap(machine_glow)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -589,7 +589,7 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif r == 1 then
|
elseif r == 1 then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(machine2, mx, my, 24, 12, 12, -4)
|
phyLight[phyCnt] = lightWorld:newImage(machine2, mx, my, 24, 12, 12, -4)
|
||||||
phyLight[phyCnt]:setNormalMap(machine2_normal)
|
phyLight[phyCnt]:setNormalMap(machine2_normal)
|
||||||
phyLight[phyCnt]:setGlowMap(machine2_glow)
|
phyLight[phyCnt]:setGlowMap(machine2_glow)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -598,7 +598,7 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif r == 2 then
|
elseif r == 2 then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(led, mx, my, 32, 6, 16, -8)
|
phyLight[phyCnt] = lightWorld:newImage(led, mx, my, 32, 6, 16, -8)
|
||||||
phyLight[phyCnt]:setNormalMap(led_normal)
|
phyLight[phyCnt]:setNormalMap(led_normal)
|
||||||
phyLight[phyCnt]:setGlowMap(led_glow)
|
phyLight[phyCnt]:setGlowMap(led_glow)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -607,7 +607,7 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif r == 3 then
|
elseif r == 3 then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(led2, mx, my, 32, 6, 16, -8)
|
phyLight[phyCnt] = lightWorld:newImage(led2, mx, my, 32, 6, 16, -8)
|
||||||
phyLight[phyCnt]:setNormalMap(led_normal)
|
phyLight[phyCnt]:setNormalMap(led_normal)
|
||||||
phyLight[phyCnt]:setGlowMap(led_glow2)
|
phyLight[phyCnt]:setGlowMap(led_glow2)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -616,7 +616,7 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif r == 4 then
|
elseif r == 4 then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(led3, mx, my, 32, 6, 16, -8)
|
phyLight[phyCnt] = lightWorld:newImage(led3, mx, my, 32, 6, 16, -8)
|
||||||
phyLight[phyCnt]:setNormalMap(led_normal)
|
phyLight[phyCnt]:setNormalMap(led_normal)
|
||||||
phyLight[phyCnt]:setGlowMap(led_glow3)
|
phyLight[phyCnt]:setGlowMap(led_glow3)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -627,7 +627,7 @@ function love.keypressed(k, u)
|
|||||||
elseif k == "5" then
|
elseif k == "5" then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(cone_large, mx, my, 24, 128, 12, 64)
|
phyLight[phyCnt] = lightWorld:newImage(cone_large, mx, my, 24, 128, 12, 64)
|
||||||
phyLight[phyCnt]:setNormalMap(cone_large_normal)
|
phyLight[phyCnt]:setNormalMap(cone_large_normal)
|
||||||
phyLight[phyCnt]:setShadowType("image", 0, -6, 0.0)
|
phyLight[phyCnt]:setShadowType("image", 0, -6, 0.0)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -637,7 +637,7 @@ function love.keypressed(k, u)
|
|||||||
elseif k == "6" then
|
elseif k == "6" then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(blopp, mx, my, 42, 16, 21, 0)
|
phyLight[phyCnt] = lightWorld:newImage(blopp, mx, my, 42, 16, 21, 0)
|
||||||
phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient")
|
phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient")
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(0.5)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -647,7 +647,7 @@ function love.keypressed(k, u)
|
|||||||
elseif k == "7" then
|
elseif k == "7" then
|
||||||
-- add image
|
-- add image
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newImage(tile, mx, my)
|
phyLight[phyCnt] = lightWorld:newImage(tile, mx, my)
|
||||||
phyLight[phyCnt]:setHeightMap(tile_normal, 2.0)
|
phyLight[phyCnt]:setHeightMap(tile_normal, 2.0)
|
||||||
phyLight[phyCnt]:setGlowMap(tile_glow)
|
phyLight[phyCnt]:setGlowMap(tile_glow)
|
||||||
phyLight[phyCnt]:setShadow(false)
|
phyLight[phyCnt]:setShadow(false)
|
||||||
@ -659,7 +659,7 @@ function love.keypressed(k, u)
|
|||||||
elseif k == "8" then
|
elseif k == "8" then
|
||||||
-- add rectangle
|
-- add rectangle
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newPolygon()
|
phyLight[phyCnt] = lightWorld:newPolygon()
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(0.5)
|
||||||
phyLight[phyCnt]:setGlowStrength(1.0)
|
phyLight[phyCnt]:setGlowStrength(1.0)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
@ -676,7 +676,7 @@ function love.keypressed(k, u)
|
|||||||
math.randomseed(love.timer.getTime())
|
math.randomseed(love.timer.getTime())
|
||||||
cRadius = math.random(8, 32)
|
cRadius = math.random(8, 32)
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newCircle(mx, my, cRadius)
|
phyLight[phyCnt] = lightWorld:newCircle(mx, my, cRadius)
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(0.5)
|
||||||
phyLight[phyCnt]:setGlowStrength(1.0)
|
phyLight[phyCnt]:setGlowStrength(1.0)
|
||||||
math.randomseed(phyCnt)
|
math.randomseed(phyCnt)
|
||||||
@ -689,19 +689,19 @@ function love.keypressed(k, u)
|
|||||||
phyFixture[phyCnt]:setRestitution(0.5)
|
phyFixture[phyCnt]:setRestitution(0.5)
|
||||||
elseif k == "0" then
|
elseif k == "0" then
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld.newRefraction(refraction_normal, mx, my)
|
phyLight[phyCnt] = lightWorld:newRefraction(refraction_normal, mx, my)
|
||||||
phyLight[phyCnt]:setReflection(true)
|
phyLight[phyCnt]:setReflection(true)
|
||||||
elseif k == "l" then
|
elseif k == "l" then
|
||||||
-- add light
|
-- add light
|
||||||
local r = lightWorld.getLightCount() % 3
|
local r = lightWorld:getLightCount() % 3
|
||||||
local light
|
local light
|
||||||
|
|
||||||
if r == 0 then
|
if r == 0 then
|
||||||
light = lightWorld.newLight(mx, my, 31, 127, 63, lightRange)
|
light = lightWorld:newLight(mx, my, 31, 127, 63, lightRange)
|
||||||
elseif r == 1 then
|
elseif r == 1 then
|
||||||
light = lightWorld.newLight(mx, my, 127, 63, 31, lightRange)
|
light = lightWorld:newLight(mx, my, 127, 63, 31, lightRange)
|
||||||
else
|
else
|
||||||
light = lightWorld.newLight(mx, my, 31, 63, 127, lightRange)
|
light = lightWorld:newLight(mx, my, 31, 63, 127, lightRange)
|
||||||
end
|
end
|
||||||
light.setSmooth(lightSmooth)
|
light.setSmooth(lightSmooth)
|
||||||
light.setGlowStrength(0.3)
|
light.setGlowStrength(0.3)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Example: Short Example
|
-- Example: Short Example
|
||||||
require "lib/postshader"
|
require "lib/postshader"
|
||||||
require "lib/light_world"
|
local LightWorld = require "lib/light_world"
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
-- load images
|
-- load images
|
||||||
@ -10,25 +10,25 @@ function love.load()
|
|||||||
glow = love.graphics.newImage("gfx/machine2_glow.png")
|
glow = love.graphics.newImage("gfx/machine2_glow.png")
|
||||||
|
|
||||||
-- create light world
|
-- create light world
|
||||||
lightWorld = love.light.newWorld()
|
lightWorld = LightWorld()
|
||||||
lightWorld.setAmbientColor(15, 15, 31)
|
lightWorld:setAmbientColor(15, 15, 31)
|
||||||
lightWorld.setRefractionStrength(32.0)
|
lightWorld:setRefractionStrength(32.0)
|
||||||
|
|
||||||
-- create light
|
-- create light
|
||||||
lightMouse = lightWorld.newLight(0, 0, 255, 127, 63, 300)
|
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
|
||||||
lightMouse:setGlowStrength(0.3)
|
lightMouse:setGlowStrength(0.3)
|
||||||
--lightMouse:setSmooth(0.01)
|
--lightMouse:setSmooth(0.01)
|
||||||
|
|
||||||
-- create shadow bodys
|
-- create shadow bodys
|
||||||
circleTest = lightWorld.newCircle(256, 256, 16)
|
circleTest = lightWorld:newCircle(256, 256, 16)
|
||||||
rectangleTest = lightWorld.newRectangle(512, 512, 64, 64)
|
rectangleTest = lightWorld:newRectangle(512, 512, 64, 64)
|
||||||
imageTest = lightWorld.newImage(image, 64, 64, 24, 6)
|
imageTest = lightWorld:newImage(image, 64, 64, 24, 6)
|
||||||
imageTest:setNormalMap(image_normal)
|
imageTest:setNormalMap(image_normal)
|
||||||
imageTest:setGlowMap(glow)
|
imageTest:setGlowMap(glow)
|
||||||
imageTest:setOffset(12, -10)
|
imageTest:setOffset(12, -10)
|
||||||
|
|
||||||
-- create body object
|
-- create body object
|
||||||
objectTest = lightWorld.newBody("refraction", normal, 64, 64, 128, 128)
|
objectTest = lightWorld:newBody("refraction", normal, 64, 64, 128, 128)
|
||||||
--objectTest:setShine(false)
|
--objectTest:setShine(false)
|
||||||
--objectTest:setShadowType("rectangle")
|
--objectTest:setShadowType("rectangle")
|
||||||
--objectTest:setShadowDimension(64, 64)
|
--objectTest:setShadowDimension(64, 64)
|
||||||
@ -47,7 +47,7 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- update lightmap (doesn't need deltatime)
|
-- update lightmap (doesn't need deltatime)
|
||||||
lightWorld.update()
|
lightWorld:update()
|
||||||
|
|
||||||
love.postshader.setBuffer("render")
|
love.postshader.setBuffer("render")
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ function love.draw()
|
|||||||
--love.graphics.draw(imgFloor, quadScreen, 0, 0)
|
--love.graphics.draw(imgFloor, quadScreen, 0, 0)
|
||||||
|
|
||||||
-- draw lightmap shadows
|
-- draw lightmap shadows
|
||||||
lightWorld.drawShadow()
|
lightWorld:drawShadow()
|
||||||
|
|
||||||
-- draw scene objects
|
-- draw scene objects
|
||||||
love.graphics.setColor(63, 255, 127)
|
love.graphics.setColor(63, 255, 127)
|
||||||
@ -69,19 +69,19 @@ function love.draw()
|
|||||||
--love.graphics.rectangle("fill", 128 - 32, 128 - 32, 64, 64)
|
--love.graphics.rectangle("fill", 128 - 32, 128 - 32, 64, 64)
|
||||||
|
|
||||||
-- draw lightmap shine
|
-- draw lightmap shine
|
||||||
lightWorld.drawShine()
|
lightWorld:drawShine()
|
||||||
|
|
||||||
-- draw pixel shadow
|
-- draw pixel shadow
|
||||||
lightWorld.drawPixelShadow()
|
lightWorld:drawPixelShadow()
|
||||||
|
|
||||||
-- draw glow
|
-- draw glow
|
||||||
lightWorld.drawGlow()
|
lightWorld:drawGlow()
|
||||||
|
|
||||||
-- draw refraction
|
-- draw refraction
|
||||||
lightWorld.drawRefraction()
|
lightWorld:drawRefraction()
|
||||||
|
|
||||||
-- draw reflection
|
-- draw reflection
|
||||||
lightWorld.drawReflection()
|
lightWorld:drawReflection()
|
||||||
|
|
||||||
love.postshader.draw()
|
love.postshader.draw()
|
||||||
end
|
end
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -121,7 +121,7 @@ love.postshader.addEffect = function(shader, ...)
|
|||||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
||||||
elseif shader == "scanlines" then
|
elseif shader == "scanlines" then
|
||||||
-- Scanlines Shader
|
-- Scanlines Shader
|
||||||
LOVE_POSTSHADER_SCANLINES:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
--LOVE_POSTSHADER_SCANLINES:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||||
LOVE_POSTSHADER_SCANLINES:send("strength", args[1] or 2.0)
|
LOVE_POSTSHADER_SCANLINES:send("strength", args[1] or 2.0)
|
||||||
LOVE_POSTSHADER_SCANLINES:send("time", args[2] or love.timer.getTime())
|
LOVE_POSTSHADER_SCANLINES:send("time", args[2] or love.timer.getTime())
|
||||||
love.graphics.setShader(LOVE_POSTSHADER_SCANLINES)
|
love.graphics.setShader(LOVE_POSTSHADER_SCANLINES)
|
||||||
|
14
main.lua
14
main.lua
@ -7,7 +7,7 @@
|
|||||||
-- Updated by Dresenpai
|
-- Updated by Dresenpai
|
||||||
|
|
||||||
require "lib/postshader"
|
require "lib/postshader"
|
||||||
require "lib/light_world"
|
local LightWorld = require "lib/light_world"
|
||||||
|
|
||||||
exf = {}
|
exf = {}
|
||||||
exf.current = nil
|
exf.current = nil
|
||||||
@ -72,8 +72,8 @@ function exf.draw()
|
|||||||
|
|
||||||
exf.list:draw()
|
exf.list:draw()
|
||||||
|
|
||||||
lightWorld.update()
|
lightWorld:update()
|
||||||
lightWorld.drawShadow()
|
lightWorld:drawShadow()
|
||||||
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
love.graphics.draw(exf.bigball, 800 - 128, 600 - 128, love.timer.getTime(), 1, 1, exf.bigball:getWidth() * 0.5, exf.bigball:getHeight() * 0.5)
|
love.graphics.draw(exf.bigball, 800 - 128, 600 - 128, love.timer.getTime(), 1, 1, exf.bigball:getWidth() * 0.5, exf.bigball:getHeight() * 0.5)
|
||||||
@ -179,15 +179,15 @@ function exf.resume()
|
|||||||
love.window.setTitle("LOVE Example Browser")
|
love.window.setTitle("LOVE Example Browser")
|
||||||
|
|
||||||
-- create light world
|
-- create light world
|
||||||
lightWorld = love.light.newWorld()
|
lightWorld = LightWorld()
|
||||||
lightWorld.setAmbientColor(127, 127, 127)
|
lightWorld:setAmbientColor(127, 127, 127)
|
||||||
|
|
||||||
-- create light
|
-- create light
|
||||||
lightMouse = lightWorld.newLight(0, 0, 255, 127, 63, 500)
|
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 500)
|
||||||
lightMouse:setSmooth(2)
|
lightMouse:setSmooth(2)
|
||||||
|
|
||||||
-- create shadow bodys
|
-- create shadow bodys
|
||||||
circleTest = lightWorld.newCircle(800 - 128, 600 - 128, 46)
|
circleTest = lightWorld:newCircle(800 - 128, 600 - 128, 46)
|
||||||
end
|
end
|
||||||
|
|
||||||
function inside(mx, my, x, y, w, h)
|
function inside(mx, my, x, y, w, h)
|
||||||
|
Loading…
Reference in New Issue
Block a user