Add glow light.
2
conf.lua
@ -13,7 +13,7 @@ function love.conf(t)
|
||||
t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
|
||||
t.window.fullscreen = false -- Enable fullscreen (boolean)
|
||||
t.window.fullscreentype = "normal" -- Standard fullscreen or desktop fullscreen mode (string)
|
||||
t.window.vsync = false -- Enable vertical sync (boolean)
|
||||
t.window.vsync = true -- Enable vertical sync (boolean)
|
||||
t.window.fsaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
|
||||
t.window.display = 1 -- Index of the monitor to show the window in (number)
|
||||
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean). Added in 0.9.1
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
BIN
gfx/chest_normal.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
BIN
gfx/font.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
gfx/machine.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
gfx/machine2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 988 B |
BIN
gfx/machine2_normal.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
gfx/machine_glow.png
Normal file
After Width: | Height: | Size: 979 B |
BIN
gfx/machine_normal.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
150
light.lua
@ -18,13 +18,18 @@ function love.light.newWorld()
|
||||
o.poly = {}
|
||||
o.img = {}
|
||||
o.shadow = love.graphics.newCanvas()
|
||||
o.shadow2 = love.graphics.newCanvas()
|
||||
o.shine = love.graphics.newCanvas()
|
||||
o.normalMap = love.graphics.newCanvas()
|
||||
o.glowMap = love.graphics.newCanvas()
|
||||
o.glowMap2 = love.graphics.newCanvas()
|
||||
o.isGlowBlur = false
|
||||
o.pixelShadow = love.graphics.newCanvas()
|
||||
o.pixelShadow2 = love.graphics.newCanvas()
|
||||
o.shader = love.graphics.newShader("shader/poly_shadow.glsl")
|
||||
o.shader2 = love.graphics.newShader("shader/pixel_self_shadow.glsl")
|
||||
o.changed = true
|
||||
o.blur = true
|
||||
o.blur = 2.0
|
||||
-- update
|
||||
o.update = function()
|
||||
LOVE_LIGHT_LAST_BUFFER = love.graphics.getCanvas()
|
||||
@ -58,8 +63,8 @@ function love.light.newWorld()
|
||||
o.lights[i].glowStrength
|
||||
}
|
||||
|
||||
if curLightX+curLightRange > 0 and curLightX-curLightRange < love.graphics.getWidth()
|
||||
and curLightY+curLightRange > 0 and curLightY-curLightRange < love.graphics.getHeight()
|
||||
if curLightX + curLightRange > 0 and curLightX - curLightRange < love.graphics.getWidth()
|
||||
and curLightY + curLightRange > 0 and curLightY - curLightRange < love.graphics.getHeight()
|
||||
then
|
||||
local lightposrange = {curLightX, love.graphics.getHeight() - curLightY, curLightRange}
|
||||
LOVE_LIGHT_CURRENT = o.lights[i]
|
||||
@ -88,6 +93,10 @@ function love.light.newWorld()
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
|
||||
lightsOnScreen = lightsOnScreen + 1
|
||||
|
||||
o.lights[i].visible = true
|
||||
else
|
||||
o.lights[i].visible = false
|
||||
end
|
||||
|
||||
o.lights[i].changed = o.changed
|
||||
@ -105,35 +114,46 @@ function love.light.newWorld()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.setBlendMode("additive")
|
||||
for i = 1, #o.lights do
|
||||
if o.lights[i].visible then
|
||||
love.graphics.draw(o.lights[i].shadow)
|
||||
end
|
||||
end
|
||||
o.isShadowBlur = false
|
||||
end
|
||||
|
||||
-- update shine
|
||||
love.graphics.setCanvas(o.shine)
|
||||
love.graphics.setColor(unpack(o.ambient))
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
love.graphics.setColor(255,255,255)
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.setBlendMode("additive")
|
||||
for i = 1, #o.lights do
|
||||
if o.lights[i].visible then
|
||||
love.graphics.draw(o.lights[i].shine)
|
||||
end
|
||||
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
o.pixelShadow:clear()
|
||||
math.randomseed(2)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setCanvas(o.pixelShadow)
|
||||
|
||||
for i = 1, #o.img do
|
||||
if o.img[i].normal then
|
||||
love.graphics.draw(o.img[i].normal, o.img[i].x - o.img[i].ox2, o.img[i].y - o.img[i].oy2)
|
||||
end
|
||||
end
|
||||
|
||||
-- update pixel shadow
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
||||
-- create normal map
|
||||
if o.changed then
|
||||
o.normalMap:clear()
|
||||
love.graphics.setShader()
|
||||
love.graphics.setCanvas(o.normalMap)
|
||||
for i = 1, #o.img do
|
||||
if o.img[i].normal then
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(o.img[i].normal, o.img[i].x - o.img[i].ox2, o.img[i].y - o.img[i].oy2)
|
||||
else
|
||||
love.graphics.setColor(127, 127, 255)
|
||||
love.graphics.rectangle("fill", o.img[i].x - o.img[i].ox2, o.img[i].y - o.img[i].oy2, o.img[i].imgWidth, o.img[i].imgHeight)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
o.pixelShadow2:clear()
|
||||
love.graphics.setCanvas(o.pixelShadow2)
|
||||
love.graphics.setBlendMode("additive")
|
||||
@ -145,6 +165,7 @@ function love.light.newWorld()
|
||||
o.ambient[3] / 255.0
|
||||
}
|
||||
for i = 1, #o.lights do
|
||||
if o.lights[i].visible then
|
||||
local curLightColor = {
|
||||
o.lights[i].red / 255.0,
|
||||
o.lights[i].green / 255.0,
|
||||
@ -155,7 +176,8 @@ function love.light.newWorld()
|
||||
o.shader2:send("lightColor", curLightColor)
|
||||
o.shader2:send("lightAmbient", curLightAmbient)
|
||||
o.shader2:send("lightSmooth", {o.lights[i].smooth})
|
||||
love.graphics.draw(o.pixelShadow)
|
||||
love.graphics.draw(o.normalMap)
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setShader()
|
||||
@ -164,6 +186,18 @@ function love.light.newWorld()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.draw(o.pixelShadow2)
|
||||
|
||||
-- create glow map
|
||||
if o.changed then
|
||||
o.glowMap:clear(0, 0, 0)
|
||||
love.graphics.setCanvas(o.glowMap)
|
||||
for i = 1, #o.img do
|
||||
if o.img[i].glow then
|
||||
love.graphics.draw(o.img[i].glow, o.img[i].x - o.img[i].ox2, o.img[i].y - o.img[i].oy2)
|
||||
end
|
||||
end
|
||||
o.isGlowBlur = false
|
||||
end
|
||||
|
||||
love.graphics.setShader()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setStencil()
|
||||
@ -176,12 +210,15 @@ function love.light.newWorld()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
if o.blur then
|
||||
LOVE_LIGHT_LAST_BUFFER = love.graphics.getCanvas()
|
||||
LOVE_LIGHT_BLURV:send("steps", o.blur)
|
||||
LOVE_LIGHT_BLURH:send("steps", o.blur)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(o.shadow)
|
||||
love.graphics.setCanvas(o.shadow2)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURV)
|
||||
love.graphics.draw(o.shadow)
|
||||
love.graphics.setCanvas(o.shadow)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURH)
|
||||
love.graphics.draw(o.shadow)
|
||||
love.graphics.draw(o.shadow2)
|
||||
love.graphics.setCanvas(LOVE_LIGHT_LAST_BUFFER)
|
||||
love.graphics.setBlendMode("multiplicative")
|
||||
love.graphics.setShader()
|
||||
@ -205,24 +242,37 @@ function love.light.newWorld()
|
||||
-- draw pixel shadow
|
||||
o.drawPixelShadow = function()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
if o.blur and false then
|
||||
LOVE_LIGHT_LAST_BUFFER = love.graphics.getCanvas()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(o.pixelShadow)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURV)
|
||||
love.graphics.draw(o.pixelShadow)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURH)
|
||||
love.graphics.draw(o.pixelShadow)
|
||||
love.graphics.setCanvas(LOVE_LIGHT_LAST_BUFFER)
|
||||
love.graphics.setBlendMode("multiplicative")
|
||||
love.graphics.setShader()
|
||||
love.graphics.draw(o.pixelShadow)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
end
|
||||
-- draw glow
|
||||
o.drawGlow = function()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
if o.isGlowBlur then
|
||||
love.graphics.setBlendMode("additive")
|
||||
love.graphics.setShader()
|
||||
love.graphics.draw(o.glowMap)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
else
|
||||
love.graphics.setBlendMode("multiplicative")
|
||||
love.graphics.setShader()
|
||||
love.graphics.draw(o.pixelShadow)
|
||||
LOVE_LIGHT_BLURV:send("steps", 1.0)
|
||||
LOVE_LIGHT_BLURH:send("steps", 1.0)
|
||||
LOVE_LIGHT_LAST_BUFFER = love.graphics.getCanvas()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(o.glowMap2)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURV)
|
||||
love.graphics.draw(o.glowMap)
|
||||
love.graphics.setCanvas(o.glowMap)
|
||||
love.graphics.setShader(LOVE_LIGHT_BLURH)
|
||||
love.graphics.draw(o.glowMap2)
|
||||
love.graphics.setCanvas(LOVE_LIGHT_LAST_BUFFER)
|
||||
love.graphics.setBlendMode("additive")
|
||||
love.graphics.setShader()
|
||||
love.graphics.draw(o.glowMap)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
||||
o.isGlowBlur = true
|
||||
end
|
||||
end
|
||||
-- new light
|
||||
@ -234,12 +284,14 @@ function love.light.newWorld()
|
||||
-- clear lights
|
||||
o.clearLights = function()
|
||||
o.lights = {}
|
||||
o.changed = true
|
||||
end
|
||||
-- clear objects
|
||||
o.clearObjects = function()
|
||||
o.poly = {}
|
||||
o.circle = {}
|
||||
o.img = {}
|
||||
o.changed = true
|
||||
end
|
||||
-- set ambient color
|
||||
o.setAmbientColor = function(red, green, blue)
|
||||
@ -294,6 +346,18 @@ function love.light.newWorld()
|
||||
o.getPoints = function(n)
|
||||
return unpack(o.poly[n].data)
|
||||
end
|
||||
-- set light position
|
||||
o.setLightPosition = function(n, x, y)
|
||||
o.lights[n].setPosition(x, y)
|
||||
end
|
||||
-- set light x
|
||||
o.setLightX = function(n, x)
|
||||
o.lights[n].setX(x)
|
||||
end
|
||||
-- set light y
|
||||
o.setLightY = function(n, y)
|
||||
o.lights[n].setY(y)
|
||||
end
|
||||
-- get light count
|
||||
o.getLightCount = function()
|
||||
return #o.lights
|
||||
@ -326,6 +390,7 @@ function love.light.newLight(p, x, y, red, green, blue, range)
|
||||
o.glowSize = 0.1
|
||||
o.glowStrength = 0.0
|
||||
o.changed = true
|
||||
o.visible = true
|
||||
-- set position
|
||||
o.setPosition = function(x, y)
|
||||
if x ~= o.x or y ~= o.y then
|
||||
@ -334,6 +399,20 @@ function love.light.newLight(p, x, y, red, green, blue, range)
|
||||
o.changed = true
|
||||
end
|
||||
end
|
||||
-- set x
|
||||
o.setX = function(x)
|
||||
if x ~= o.x then
|
||||
o.x = x
|
||||
o.changed = true
|
||||
end
|
||||
end
|
||||
-- set y
|
||||
o.setY = function(y)
|
||||
if y ~= o.y then
|
||||
o.y = y
|
||||
o.changed = true
|
||||
end
|
||||
end
|
||||
-- set color
|
||||
o.setColor = function(red, green, blue)
|
||||
o.red = red
|
||||
@ -549,6 +628,7 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
|
||||
o.id = #p.img
|
||||
o.img = img
|
||||
o.normal = nil
|
||||
o.glow = nil
|
||||
o.x = x
|
||||
o.y = y
|
||||
o.width = width or img:getWidth()
|
||||
@ -557,6 +637,8 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
|
||||
o.oy = o.height / 2.0
|
||||
o.ox2 = ox or o.width / 2.0
|
||||
o.oy2 = oy or o.height / 2.0
|
||||
o.imgWidth = img:getWidth()
|
||||
o.imgHeight = img:getHeight()
|
||||
o.shine = true
|
||||
p.changed = true
|
||||
o.data = {
|
||||
@ -611,9 +693,13 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
|
||||
o.img = img
|
||||
end
|
||||
-- set normal
|
||||
o.setNormal = function(normal)
|
||||
o.setNormalMap = function(normal)
|
||||
o.normal = normal
|
||||
end
|
||||
-- set normal
|
||||
o.setGlowMap = function(glow)
|
||||
o.glow = glow
|
||||
end
|
||||
-- get type
|
||||
o.getType = function()
|
||||
return "image"
|
||||
|
220
main.lua
@ -24,11 +24,6 @@ function initScene()
|
||||
wall4.shape = love.physics.newRectangleShape(0, 0, 800, 10)
|
||||
wall4.fixture = love.physics.newFixture(wall4.body, wall4.shape)
|
||||
|
||||
myPoly1 = lightWorld.newPolygon(wall1.body:getWorldPoints(wall1.shape:getPoints()))
|
||||
myPoly2 = lightWorld.newPolygon(wall2.body:getWorldPoints(wall2.shape:getPoints()))
|
||||
myPoly3 = lightWorld.newPolygon(wall3.body:getWorldPoints(wall3.shape:getPoints()))
|
||||
myPoly4 = lightWorld.newPolygon(wall4.body:getWorldPoints(wall4.shape:getPoints()))
|
||||
|
||||
phyCnt = 0
|
||||
phyLight = {}
|
||||
phyBody = {}
|
||||
@ -39,55 +34,63 @@ end
|
||||
function love.load()
|
||||
love.graphics.setBackgroundColor(0, 0, 0)
|
||||
love.graphics.setDefaultFilter("nearest", "nearest")
|
||||
quadScreen = love.graphics.newQuad(0, 0, love.window.getWidth(), love.window.getHeight(), 32, 32)
|
||||
imgFloor = love.graphics.newImage("floor.png")
|
||||
|
||||
-- load image font
|
||||
font = love.graphics.newImageFont("gfx/font.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"")
|
||||
love.graphics.setFont(font)
|
||||
|
||||
-- set background
|
||||
quadScreen = love.graphics.newQuad(0, 0, love.window.getWidth() + 32, love.window.getHeight() + 24, 32, 24)
|
||||
imgFloor = love.graphics.newImage("gfx/floor.png")
|
||||
imgFloor:setWrap("repeat", "repeat")
|
||||
|
||||
circle = love.graphics.newImage "circle.png"
|
||||
circle_normal = love.graphics.newImage "circle_normal.png"
|
||||
cone = love.graphics.newImage "cone.png"
|
||||
cone_normal = love.graphics.newImage "cone_normal.png"
|
||||
chest = love.graphics.newImage "chest.png"
|
||||
chest_normal = love.graphics.newImage "chest_normal.png"
|
||||
-- load image examples
|
||||
circle = love.graphics.newImage "gfx/circle.png"
|
||||
circle_normal = love.graphics.newImage "gfx/circle_normal.png"
|
||||
cone = love.graphics.newImage "gfx/cone.png"
|
||||
cone_normal = love.graphics.newImage "gfx/cone_normal.png"
|
||||
chest = love.graphics.newImage "gfx/chest.png"
|
||||
chest_normal = love.graphics.newImage "gfx/chest_normal.png"
|
||||
machine = love.graphics.newImage "gfx/machine.png"
|
||||
machine_normal = love.graphics.newImage "gfx/machine_normal.png"
|
||||
machine_glow = love.graphics.newImage "gfx/machine_glow.png"
|
||||
machine2 = love.graphics.newImage "gfx/machine2.png"
|
||||
machine2_normal = love.graphics.newImage "gfx/machine2_normal.png"
|
||||
machine2_glow = love.graphics.newImage "gfx/machine2_glow.png"
|
||||
|
||||
-- light world
|
||||
lightRange = 400
|
||||
lightRange = 300
|
||||
lightSmooth = 1.0
|
||||
lightWorld = love.light.newWorld()
|
||||
lightWorld.setAmbientColor(15, 15, 31)
|
||||
mouseLight = lightWorld.newLight(0, 0, 255, 127, 63, lightRange)
|
||||
mouseLight.setGlowStrength(0.3)
|
||||
mouseLight.setSmooth(lightSmooth)
|
||||
|
||||
-- init physic world
|
||||
initScene()
|
||||
|
||||
helpOn = true
|
||||
helpOn = false
|
||||
physicOn = false
|
||||
lightOn = true
|
||||
gravityOn = 1
|
||||
shadowBlurOn = true
|
||||
shadowBlur = 2.0
|
||||
bloomOn = true
|
||||
textureOn = true
|
||||
|
||||
offsetX = 0.0
|
||||
offsetY = 0.0
|
||||
offsetOldX = 0.0
|
||||
offsetOldY = 0.0
|
||||
offsetChanged = false
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
love.window.setTitle("FPS:" .. love.timer.getFPS())
|
||||
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
||||
mouseLight.setPosition(love.mouse.getX(), love.mouse.getY())
|
||||
mx = love.mouse.getX()
|
||||
my = love.mouse.getY()
|
||||
|
||||
for i = 1, phyCnt do
|
||||
if phyBody[i]:isAwake() then
|
||||
if phyLight[i].getType() == "polygon" then
|
||||
phyLight[i].setPoints(phyBody[i]:getWorldPoints(phyShape[i]:getPoints()))
|
||||
elseif phyLight[i].getType() == "circle" then
|
||||
phyLight[i].setPosition(phyBody[i]:getX(), phyBody[i]:getY())
|
||||
elseif phyLight[i].getType() == "image" then
|
||||
phyLight[i].setPosition(phyBody[i]:getX(), phyBody[i]:getY())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if love.keyboard.isDown("w") then
|
||||
for i = 1, phyCnt do
|
||||
phyBody[i]:applyForce(0, -2000)
|
||||
@ -108,17 +111,57 @@ function love.update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
if love.keyboard.isDown("up") then
|
||||
offsetY = offsetY + dt * 200
|
||||
elseif love.keyboard.isDown("down") then
|
||||
offsetY = offsetY - dt * 200
|
||||
end
|
||||
|
||||
if love.keyboard.isDown("left") then
|
||||
offsetX = offsetX + dt * 200
|
||||
elseif love.keyboard.isDown("right") then
|
||||
offsetX = offsetX - dt * 200
|
||||
end
|
||||
|
||||
if offsetX ~= offsetOldX or offsetY ~= offsetOldY then
|
||||
offsetChanged = true
|
||||
for i = 2, lightWorld.getLightCount() do
|
||||
lightWorld.setLightPosition(i, lightWorld.getLightX(i) + (offsetX - offsetOldX), lightWorld.getLightY(i) + (offsetY - offsetOldY))
|
||||
end
|
||||
else
|
||||
offsetChanged = false
|
||||
end
|
||||
|
||||
for i = 1, phyCnt do
|
||||
if phyBody[i]:isAwake() or offsetChanged then
|
||||
if offsetChanged then
|
||||
phyBody[i]:setX(phyBody[i]:getX() + (offsetX - offsetOldX))
|
||||
phyBody[i]:setY(phyBody[i]:getY() + (offsetY - offsetOldY))
|
||||
end
|
||||
if phyLight[i].getType() == "polygon" then
|
||||
phyLight[i].setPoints(phyBody[i]:getWorldPoints(phyShape[i]:getPoints()))
|
||||
elseif phyLight[i].getType() == "circle" then
|
||||
phyLight[i].setPosition(phyBody[i]:getX(), phyBody[i]:getY())
|
||||
elseif phyLight[i].getType() == "image" then
|
||||
phyLight[i].setPosition(phyBody[i]:getX(), phyBody[i]:getY())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if physicOn then
|
||||
physicWorld:update(dt)
|
||||
end
|
||||
|
||||
-- update lightmap
|
||||
if lightOn then
|
||||
lightWorld.update(dt)
|
||||
end
|
||||
offsetOldX = offsetX
|
||||
offsetOldY = offsetY
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
-- update lightmap (don't need deltatime)
|
||||
if lightOn then
|
||||
lightWorld.update()
|
||||
end
|
||||
|
||||
-- set shader buffer
|
||||
if bloomOn then
|
||||
love.postshader.setBuffer("render")
|
||||
@ -127,7 +170,7 @@ function love.draw()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
if textureOn then
|
||||
love.graphics.draw(imgFloor, quadScreen)
|
||||
love.graphics.draw(imgFloor, quadScreen, offsetX % 32 - 32, offsetY % 24 - 24)
|
||||
else
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
end
|
||||
@ -151,76 +194,89 @@ function love.draw()
|
||||
end
|
||||
|
||||
for i = 1, phyCnt do
|
||||
love.graphics.setColor(191 + math.sin(i) * 63, 191 + math.cos(i) * 63, 191 + math.tan(i) * 63)
|
||||
if phyLight[i].getType() == "image" then
|
||||
love.graphics.setColor(223 + math.sin(i) * 31, 223 + math.cos(i) * 31, 223 + math.tan(i) * 31)
|
||||
love.graphics.draw(phyLight[i].img, phyLight[i].x - phyLight[i].ox2, phyLight[i].y - phyLight[i].oy2)
|
||||
end
|
||||
end
|
||||
|
||||
-- draw pixel shadow
|
||||
if lightOn then
|
||||
lightWorld.drawPixelShadow()
|
||||
end
|
||||
|
||||
-- draw glow
|
||||
if lightOn then
|
||||
lightWorld.drawGlow()
|
||||
end
|
||||
|
||||
-- draw help
|
||||
if helpOn then
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setColor(0, 0, 0, 191)
|
||||
love.graphics.rectangle("fill", 8, 8, 210, 16 * 16)
|
||||
love.graphics.setColor(0, 127, 255)
|
||||
love.graphics.print("WASD: Move objects", 16, 16)
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 44)
|
||||
love.graphics.rectangle("fill", 0, love.graphics.getHeight() - 68, 240, 68)
|
||||
love.graphics.rectangle("fill", love.graphics.getWidth() - 244, love.graphics.getHeight() - 84, 244, 84)
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F1: Help on", 16, 32)
|
||||
love.graphics.print("F1: Help (on)", 4 + 152 * 0, 4)
|
||||
if physicOn then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F2: Physic on", 16, 48)
|
||||
love.graphics.print("F2: Physic (on)", 4 + 152 * 1, 4)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F2: Physic off", 16, 48)
|
||||
love.graphics.print("F2: Physic (off)", 4 + 152 * 1, 4)
|
||||
end
|
||||
if lightOn then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F3: Light on", 16, 64)
|
||||
love.graphics.print("F3: Light (on)", 4 + 152 * 2, 4)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F3: Light off", 16, 64)
|
||||
love.graphics.print("F3: Light (off)", 4 + 152 * 2, 4)
|
||||
end
|
||||
if gravityOn == 1.0 then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F4: Gravity on", 16, 80)
|
||||
love.graphics.print("F4: Gravity (on)", 4 + 152 * 3, 4)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F4: Gravity off", 16, 80)
|
||||
love.graphics.print("F4: Gravity (off)", 4 + 152 * 3, 4)
|
||||
end
|
||||
if shadowBlurOn then
|
||||
if shadowBlur >= 1.0 then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F5: Shadowblur on", 16, 96)
|
||||
love.graphics.print("F5: Shadowblur (" .. shadowBlur .. ")", 4 + 152 * 4, 4)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F5: Shadowblur off", 16, 96)
|
||||
love.graphics.print("F5: Shadowblur (off)", 4 + 152 * 4, 4)
|
||||
end
|
||||
if bloomOn then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F6: Bloom on", 16, 112)
|
||||
love.graphics.print("F6: Bloom on", 4 + 152 * 0, 4 + 20 * 1)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F6: Bloom off", 16, 112)
|
||||
love.graphics.print("F6: Bloom off", 4 + 152 * 0, 4 + 20 * 1)
|
||||
end
|
||||
if textureOn then
|
||||
love.graphics.setColor(0, 255, 0)
|
||||
love.graphics.print("F7: Texture on", 16, 128)
|
||||
love.graphics.print("F7: Texture on", 4 + 152 * 1, 4 + 20 * 1)
|
||||
else
|
||||
love.graphics.setColor(255, 0, 0)
|
||||
love.graphics.print("F7: Texture off", 16, 128)
|
||||
love.graphics.print("F7: Texture off", 4 + 152 * 1, 4 + 20 * 1)
|
||||
end
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.print("F11: Clear objects", 16, 144)
|
||||
love.graphics.print("F12: Clear lights", 16, 160)
|
||||
love.graphics.print("M.left: Add cube", 16, 176)
|
||||
love.graphics.print("M.middle: Add light", 16, 192)
|
||||
love.graphics.print("M.right: Add circle", 16, 208)
|
||||
love.graphics.print("M.scroll: Change smooth", 16, 224)
|
||||
love.graphics.print("1-3: Add image", 16, 240)
|
||||
love.graphics.setColor(255, 0, 255)
|
||||
love.graphics.print("F11: Clear obj.", 4 + 152 * 3, 4 + 20 * 1)
|
||||
love.graphics.print("F12: Clear lights", 4 + 152 * 4, 4 + 20 * 1)
|
||||
love.graphics.setColor(0, 127, 255)
|
||||
love.graphics.print("WASD Keys: Move objects", 4, love.graphics.getHeight() - 20 * 3)
|
||||
love.graphics.print("Arrow Keys: Move map", 4, love.graphics.getHeight() - 20 * 2)
|
||||
love.graphics.print("1-5 Keys: Add image", 4, love.graphics.getHeight() - 20 * 1)
|
||||
love.graphics.setColor(255, 127, 0)
|
||||
love.graphics.print("M.left: Add cube", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 4)
|
||||
love.graphics.print("M.middle: Add light", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 3)
|
||||
love.graphics.print("M.right: Add circle", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 2)
|
||||
love.graphics.print("M.scroll: Change smooth", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 1)
|
||||
love.graphics.setColor(255, 127, 0)
|
||||
else
|
||||
love.graphics.setColor(255, 255, 255, 63)
|
||||
love.graphics.print("F1: Help", 8, 8)
|
||||
love.graphics.setColor(255, 255, 255, 191)
|
||||
love.graphics.print("F1: Help", 4, 4)
|
||||
end
|
||||
|
||||
-- draw shader
|
||||
@ -262,12 +318,16 @@ function love.mousepressed(x, y, c)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
phyFixture[phyCnt]:setRestitution(0.5)
|
||||
elseif c == "wu" then
|
||||
if lightSmooth < 4.0 then
|
||||
lightSmooth = lightSmooth * 1.1
|
||||
mouseLight.setSmooth(lightSmooth)
|
||||
end
|
||||
elseif c == "wd" then
|
||||
if lightSmooth > 0.5 then
|
||||
lightSmooth = lightSmooth / 1.1
|
||||
mouseLight.setSmooth(lightSmooth)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(k, u)
|
||||
@ -282,8 +342,11 @@ function love.keypressed(k, u)
|
||||
gravityOn = 1 - gravityOn
|
||||
physicWorld:setGravity(0, gravityOn * 9.81 * 64)
|
||||
elseif k == "f5" then
|
||||
shadowBlurOn = not shadowBlurOn
|
||||
lightWorld.setBlur(shadowBlurOn)
|
||||
shadowBlur = math.max(1, shadowBlur * 2.0)
|
||||
if shadowBlur > 8.0 then
|
||||
shadowBlur = 0.0
|
||||
end
|
||||
lightWorld.setBlur(shadowBlur)
|
||||
elseif k == "f6" then
|
||||
bloomOn = not bloomOn
|
||||
elseif k == "f7" then
|
||||
@ -296,11 +359,12 @@ function love.keypressed(k, u)
|
||||
lightWorld.clearLights()
|
||||
mouseLight = lightWorld.newLight(0, 0, 255, 127, 63, lightRange)
|
||||
mouseLight.setGlowStrength(0.3)
|
||||
mouseLight.setSmooth(lightSmooth)
|
||||
elseif k == "1" then
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(circle, mx, my)
|
||||
phyLight[phyCnt].setNormal(circle_normal)
|
||||
phyLight[phyCnt].setNormalMap(circle_normal)
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 32, 32)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
@ -309,19 +373,39 @@ function love.keypressed(k, u)
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(cone, mx, my, 24, 12, 12, 28)
|
||||
phyLight[phyCnt].setNormal(cone_normal)
|
||||
phyLight[phyCnt].setNormalMap(cone_normal)
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 25, 32)
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 24, 32)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
phyFixture[phyCnt]:setRestitution(0.5)
|
||||
elseif k == "3" then
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(chest, mx, my, 32, 24, 16, 36)
|
||||
phyLight[phyCnt].setNormal(chest_normal)
|
||||
phyLight[phyCnt].setNormalMap(chest_normal)
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 32, 24)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
phyFixture[phyCnt]:setRestitution(0.5)
|
||||
elseif k == "4" then
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(machine, mx, my, 32, 24, 16, 36)
|
||||
phyLight[phyCnt].setNormalMap(machine_normal)
|
||||
phyLight[phyCnt].setGlowMap(machine_glow)
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 32, 24)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
phyFixture[phyCnt]:setRestitution(0.5)
|
||||
elseif k == "5" then
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(machine2, mx, my, 24, 12, 12, 28)
|
||||
phyLight[phyCnt].setNormalMap(machine2_normal)
|
||||
phyLight[phyCnt].setGlowMap(machine2_glow)
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 24, 32)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
phyFixture[phyCnt]:setRestitution(0.5)
|
||||
end
|
||||
end
|
@ -46,6 +46,8 @@ love.postshader.draw = function(shader)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
elseif shader == "blur" then
|
||||
-- Blur Shader
|
||||
LOVE_POSTSHADER_BLURV:send("steps", 2.0)
|
||||
LOVE_POSTSHADER_BLURH:send("steps", 2.0)
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
extern vec2 screen = vec2(800.0, 600.0);
|
||||
extern float steps = 2.0;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
||||
vec4 col = Texel(texture, texture_coords);
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y + pSize.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * 2));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y + pSize.y * 2));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * 3));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y + pSize.y * 3));
|
||||
col = col / 7.0;
|
||||
for(int i = 1; i <= steps; i++) {
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * i));
|
||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y + pSize.y * i));
|
||||
}
|
||||
col = col / (steps * 2.0 + 1.0);
|
||||
return vec4(col.r, col.g, col.b, 1.0);
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
extern vec2 screen = vec2(800.0, 600.0);
|
||||
extern float steps = 2.0;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
||||
vec4 col = Texel(texture, texture_coords);
|
||||
col = col + Texel(texture, vec2(texture_coords.x - pSize.x, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x + pSize.x, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x - pSize.x * 2, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x + pSize.x * 2, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x - pSize.x * 3, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x + pSize.x * 3, texture_coords.y));
|
||||
col = col / 7.0;
|
||||
for(int i = 1; i <= steps; i++) {
|
||||
col = col + Texel(texture, vec2(texture_coords.x - pSize.x * i, texture_coords.y));
|
||||
col = col + Texel(texture, vec2(texture_coords.x + pSize.x * i, texture_coords.y));
|
||||
}
|
||||
col = col / (steps * 2.0 + 1.0);
|
||||
return vec4(col.r, col.g, col.b, 1.0);
|
||||
}
|
@ -14,8 +14,8 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
|
||||
float att = 1 - distance / lightRange;
|
||||
|
||||
if(distance < lightRange && pixel.a > 0.0) {
|
||||
return vec4(vec3(clamp(1 - dot(normal, lightDirection), 0.0, 1.0)) * lightColor * pow(att, lightSmooth) + lightAmbient, 1.0);
|
||||
if(pixel.a > 0.0 && distance < lightRange) {
|
||||
return vec4(vec3(clamp((1 - dot(normal, lightDirection)) * pow(att, lightSmooth * 4.0), 0.0, 1.0)) * lightColor + lightAmbient, 1.0);
|
||||
} else if(pixel.a == 0.0) {
|
||||
return vec4(0.0);
|
||||
} else {
|
||||
|