mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
fixe a bug in new image bodies
This commit is contained in:
parent
01aa79e819
commit
5e0320c4bf
@ -519,7 +519,7 @@ function love.keypressed(k, u)
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld:newImage(cone, mx, my, 24, 12, 12, 16)
|
||||
phyLight[phyCnt]:setNormalMap(cone_normal)
|
||||
phyLight[phyCnt]:setShadowType("circle", 12, 0, -8)
|
||||
phyLight[phyCnt]:setShadowType("circle", 12)
|
||||
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])
|
||||
|
@ -1,4 +1,3 @@
|
||||
require 'lib/postshader'
|
||||
-- Example: Short Example
|
||||
local gamera = require "vendor/gamera"
|
||||
local LightWorld = require "lib/light_world"
|
||||
|
@ -45,7 +45,7 @@ function body:init(id, type, ...)
|
||||
self.ix = self.imgWidth * 0.5
|
||||
self.iy = self.imgHeight * 0.5
|
||||
end
|
||||
self:setShadowType('rectangle', args[4] or self.imgWidth, args[5] or self.imgHeight)
|
||||
self:setShadowType('rectangle', args[4] or self.imgWidth, args[5] or self.imgHeight, args[6], args[7])
|
||||
self.reflective = true
|
||||
elseif self.type == "refraction" then
|
||||
self:initNormal(...)
|
||||
|
@ -23,12 +23,13 @@ function light:init(x, y, r, g, b, range)
|
||||
self.glowSize = 0.1
|
||||
self.glowStrength = 0.0
|
||||
self.visible = true
|
||||
self:refresh()
|
||||
self:refresh(1)
|
||||
end
|
||||
|
||||
function light:refresh()
|
||||
self.shadow = love.graphics.newCanvas()
|
||||
self.shine = love.graphics.newCanvas()
|
||||
function light:refresh(scale)
|
||||
local w, h = love.window.getWidth(), love.window.getHeight()
|
||||
self.shadow = love.graphics.newCanvas(w, h)
|
||||
self.shine = love.graphics.newCanvas(w, h)
|
||||
end
|
||||
|
||||
-- set position
|
||||
|
@ -26,6 +26,7 @@ local class = require(_PACKAGE..'/class')
|
||||
local Light = require(_PACKAGE..'/light')
|
||||
local Body = require(_PACKAGE..'/body')
|
||||
local normal_map = require(_PACKAGE..'/normal_map')
|
||||
require(_PACKAGE..'/postshader')
|
||||
|
||||
local light_world = class()
|
||||
|
||||
@ -56,7 +57,7 @@ function light_world:init(options)
|
||||
options = options or {}
|
||||
for k, v in pairs(options) do self[k] = v end
|
||||
|
||||
self:refreshScreenSize()
|
||||
self:refreshScreenSize(1)
|
||||
end
|
||||
|
||||
function light_world:drawBlur(blendmode, blur, canvas, canvas2, l, t, w, h)
|
||||
@ -206,39 +207,44 @@ function light_world:updateRelfection(l,t,w,h)
|
||||
love.graphics.setCanvas(self.render_buffer)
|
||||
end
|
||||
|
||||
function light_world:refreshScreenSize()
|
||||
self.render_buffer = love.graphics.newCanvas()
|
||||
self.shadow = love.graphics.newCanvas()
|
||||
self.shadow2 = love.graphics.newCanvas()
|
||||
self.pixelShadow = love.graphics.newCanvas()
|
||||
self.pixelShadow2 = love.graphics.newCanvas()
|
||||
self.shine = love.graphics.newCanvas()
|
||||
self.shine2 = love.graphics.newCanvas()
|
||||
self.normalMap = love.graphics.newCanvas()
|
||||
self.glowMap = love.graphics.newCanvas()
|
||||
self.glowMap2 = love.graphics.newCanvas()
|
||||
self.refractionMap = love.graphics.newCanvas()
|
||||
self.refractionMap2 = love.graphics.newCanvas()
|
||||
self.reflectionMap = love.graphics.newCanvas()
|
||||
self.reflectionMap2 = love.graphics.newCanvas()
|
||||
function light_world:refreshScreenSize(scale)
|
||||
local w, h = love.window.getWidth(), love.window.getHeight()
|
||||
self.scale = scale
|
||||
self.render_buffer = love.graphics.newCanvas(w, h)
|
||||
self.shadow = love.graphics.newCanvas(w, h)
|
||||
self.shadow2 = love.graphics.newCanvas(w, h)
|
||||
self.pixelShadow = love.graphics.newCanvas(w, h)
|
||||
self.pixelShadow2 = love.graphics.newCanvas(w, h)
|
||||
self.shine = love.graphics.newCanvas(w, h)
|
||||
self.shine2 = love.graphics.newCanvas(w, h)
|
||||
self.normalMap = love.graphics.newCanvas(w, h)
|
||||
self.glowMap = love.graphics.newCanvas(w, h)
|
||||
self.glowMap2 = love.graphics.newCanvas(w, h)
|
||||
self.refractionMap = love.graphics.newCanvas(w, h)
|
||||
self.refractionMap2 = love.graphics.newCanvas(w, h)
|
||||
self.reflectionMap = love.graphics.newCanvas(w, h)
|
||||
self.reflectionMap2 = love.graphics.newCanvas(w, h)
|
||||
|
||||
self.blurv:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.blurh:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.refractionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.reflectionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.blurv:send("screen", {w, h})
|
||||
self.blurh:send("screen", {w, h})
|
||||
self.refractionShader:send("screen", {w, h})
|
||||
self.reflectionShader:send("screen", {w, h})
|
||||
|
||||
for i = 1, #self.lights do
|
||||
self.lights[i]:refresh()
|
||||
self.lights[i]:refresh(scale)
|
||||
end
|
||||
end
|
||||
|
||||
function light_world:draw(l,t,w,h,s)
|
||||
l,t,w,h,s = (l or 0), (t or 0), (w or love.graphics.getWidth()), (h or love.graphics.getHeight()), s or 1
|
||||
|
||||
if s ~= self.scale then
|
||||
--self:refreshScreenSize(s)
|
||||
end
|
||||
|
||||
local last_buffer = love.graphics.getCanvas()
|
||||
love.graphics.setCanvas(self.render_buffer)
|
||||
|
||||
print(s)
|
||||
love.graphics.push()
|
||||
love.graphics.scale(1/s)
|
||||
sl, st, sw, sh = (l*s), (t*s), (w*s), (h*s)
|
||||
|
@ -24,6 +24,8 @@ SOFTWARE.
|
||||
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
|
||||
local class = require(_PACKAGE..'/class')
|
||||
|
||||
local post_shader = class()
|
||||
|
||||
LOVE_POSTSHADER_BUFFER_RENDER = love.graphics.newCanvas()
|
||||
LOVE_POSTSHADER_BUFFER_BACK = love.graphics.newCanvas()
|
||||
LOVE_POSTSHADER_LAST_BUFFER = nil
|
||||
@ -33,7 +35,7 @@ LOVE_POSTSHADER_BLURH = love.graphics.newShader(_PACKAGE.."/shad
|
||||
LOVE_POSTSHADER_CONTRAST = love.graphics.newShader(_PACKAGE.."/shaders/contrast.glsl")
|
||||
LOVE_POSTSHADER_CHROMATIC_ABERRATION = love.graphics.newShader(_PACKAGE.."/shaders/chromatic_aberration.glsl")
|
||||
LOVE_POSTSHADER_FOUR_COLOR = love.graphics.newShader(_PACKAGE.."/shaders/four_colors.glsl")
|
||||
LOVE_POSTSHADER_MONOCHROM = love.graphics.newShader(_PACKAGE.."/shaders/monochrom.glsl")
|
||||
LOVE_POSTSHADER_MONOCHROM = love.graphics.newShader(_PACKAGE.."/shaders/monochrome.glsl")
|
||||
LOVE_POSTSHADER_SCANLINES = love.graphics.newShader(_PACKAGE.."/shaders/scanlines.glsl")
|
||||
LOVE_POSTSHADER_TILT_SHIFT = love.graphics.newShader(_PACKAGE.."/shaders/tilt_shift.glsl")
|
||||
|
||||
@ -52,11 +54,11 @@ love.postshader.addEffect = function(shader, ...)
|
||||
args = {...}
|
||||
LOVE_POSTSHADER_LAST_BUFFER = love.graphics.getCanvas()
|
||||
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
||||
if shader == "bloom" then
|
||||
-- Bloom Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
LOVE_POSTSHADER_BLURV:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
LOVE_POSTSHADER_BLURH:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
LOVE_POSTSHADER_BLURV:send("steps", args[1] or 2.0)
|
||||
@ -81,6 +83,8 @@ love.postshader.addEffect = function(shader, ...)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
elseif shader == "blur" then
|
||||
-- Blur Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
LOVE_POSTSHADER_BLURV:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
LOVE_POSTSHADER_BLURH:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
LOVE_POSTSHADER_BLURV:send("steps", args[1] or 2.0)
|
||||
@ -91,16 +95,32 @@ love.postshader.addEffect = function(shader, ...)
|
||||
|
||||
love.graphics.setShader(LOVE_POSTSHADER_BLURH)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
elseif shader == "chromatic" then
|
||||
-- Chromatic Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
LOVE_POSTSHADER_CHROMATIC_ABERRATION:send("redStrength", {args[1] or 0.0, args[2] or 0.0})
|
||||
LOVE_POSTSHADER_CHROMATIC_ABERRATION:send("greenStrength", {args[3] or 0.0, args[4] or 0.0})
|
||||
LOVE_POSTSHADER_CHROMATIC_ABERRATION:send("blueStrength", {args[5] or 0.0, args[6] or 0.0})
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setShader(LOVE_POSTSHADER_CHROMATIC_ABERRATION)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
elseif shader == "4colors" then
|
||||
-- 4 Color Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
for i = 1, 4 do
|
||||
for k = 1, 3 do
|
||||
args[i][k] = args[i][k] / 255.0
|
||||
@ -109,8 +129,16 @@ love.postshader.addEffect = function(shader, ...)
|
||||
LOVE_POSTSHADER_FOUR_COLOR:send("palette", args[1], args[2], args[3], args[4])
|
||||
love.graphics.setShader(LOVE_POSTSHADER_FOUR_COLOR)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
elseif shader == "monochrom" then
|
||||
-- Monochrom Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
for i = 1, 3 do
|
||||
if args[i] then
|
||||
args[i] = args[i] / 255.0
|
||||
@ -121,15 +149,31 @@ love.postshader.addEffect = function(shader, ...)
|
||||
LOVE_POSTSHADER_MONOCHROM:send("time", args[5] or love.timer.getTime())
|
||||
love.graphics.setShader(LOVE_POSTSHADER_MONOCHROM)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
elseif shader == "scanlines" then
|
||||
-- Scanlines Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
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("time", args[2] or love.timer.getTime())
|
||||
love.graphics.setShader(LOVE_POSTSHADER_SCANLINES)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_RENDER)
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
elseif shader == "tiltshift" then
|
||||
-- Blur Shader
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
LOVE_POSTSHADER_BLURH:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
LOVE_POSTSHADER_BLURV:send("steps", args[1] or 2.0)
|
||||
LOVE_POSTSHADER_BLURH:send("steps", args[1] or 2.0)
|
||||
@ -143,9 +187,7 @@ love.postshader.addEffect = function(shader, ...)
|
||||
LOVE_POSTSHADER_TILT_SHIFT:send("imgBuffer", LOVE_POSTSHADER_BUFFER_RENDER)
|
||||
love.graphics.setShader(LOVE_POSTSHADER_TILT_SHIFT)
|
||||
love.graphics.draw(LOVE_POSTSHADER_BUFFER_BACK)
|
||||
end
|
||||
|
||||
if shader ~= "bloom" then
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setCanvas(LOVE_POSTSHADER_LAST_BUFFER)
|
||||
love.graphics.setShader()
|
||||
|
Loading…
Reference in New Issue
Block a user