mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
refactor to update only the elements that are being drawn
This commit is contained in:
parent
735d565142
commit
9579dc0b15
@ -224,11 +224,6 @@ function love.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- update lightmap (don't need deltatime)
|
|
||||||
if lightOn then
|
|
||||||
lightWorld:update()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set shader buffer
|
-- set shader buffer
|
||||||
if bloomOn then
|
if bloomOn then
|
||||||
love.postshader.setBuffer("render")
|
love.postshader.setBuffer("render")
|
||||||
|
@ -47,9 +47,6 @@ function love.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- update lightmap (doesn't need deltatime)
|
|
||||||
lightWorld:update()
|
|
||||||
|
|
||||||
love.postshader.setBuffer("render")
|
love.postshader.setBuffer("render")
|
||||||
|
|
||||||
-- draw background
|
-- draw background
|
||||||
|
@ -610,6 +610,8 @@ function body:drawGlow()
|
|||||||
end
|
end
|
||||||
love.graphics.draw(self.img, self.x - self.ix + self.world.translate_x, self.y - self.iy + self.world.translate_y)
|
love.graphics.draw(self.img, self.x - self.ix + self.world.translate_x, self.y - self.iy + self.world.translate_y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.graphics.setShader()
|
||||||
end
|
end
|
||||||
|
|
||||||
function body:drawRefraction()
|
function body:drawRefraction()
|
||||||
|
@ -91,27 +91,12 @@ function light_world:init()
|
|||||||
self.isReflection = false
|
self.isReflection = false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update
|
|
||||||
function light_world:update()
|
|
||||||
self.last_buffer = love.graphics.getCanvas()
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
self:updateShadows()
|
|
||||||
self:updatePixelShadows()
|
|
||||||
self:updateGlow()
|
|
||||||
self:updateRefraction()
|
|
||||||
self:updateRelfection()
|
|
||||||
love.graphics.setShader()
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
love.graphics.setStencil()
|
|
||||||
love.graphics.setCanvas(self.last_buffer)
|
|
||||||
end
|
|
||||||
|
|
||||||
function light_world:updateShadows()
|
function light_world:updateShadows()
|
||||||
if not self.optionShadows or not (self.isShadows or self.isLight) then
|
if not self.optionShadows or not (self.isShadows or self.isLight) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
love.graphics.setShader(self.shader)
|
love.graphics.setShader(self.shader)
|
||||||
|
|
||||||
for i = 1, #self.lights do
|
for i = 1, #self.lights do
|
||||||
@ -143,12 +128,15 @@ function light_world:updateShadows()
|
|||||||
for i = 1, #self.lights do
|
for i = 1, #self.lights do
|
||||||
self.lights[i]:drawShine()
|
self.lights[i]:drawShine()
|
||||||
end
|
end
|
||||||
|
love.graphics.setCanvas(self.last_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:updatePixelShadows()
|
function light_world:updatePixelShadows()
|
||||||
if not self.optionPixelShadows or not self.isPixelShadows then
|
if not self.optionPixelShadows or not self.isPixelShadows then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
-- update pixel shadow
|
-- update pixel shadow
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
@ -180,12 +168,16 @@ function light_world:updatePixelShadows()
|
|||||||
love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]})
|
love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]})
|
||||||
love.graphics.rectangle("fill", self.translate_x, self.translate_y, love.graphics.getWidth(), love.graphics.getHeight())
|
love.graphics.rectangle("fill", self.translate_x, self.translate_y, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
|
love.graphics.setCanvas(self.last_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:updateGlow()
|
function light_world:updateGlow()
|
||||||
if not self.optionGlow or not self.isGlow then
|
if not self.optionGlow or not self.isGlow then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
-- create glow map
|
-- create glow map
|
||||||
self.glowMap:clear(0, 0, 0)
|
self.glowMap:clear(0, 0, 0)
|
||||||
love.graphics.setCanvas(self.glowMap)
|
love.graphics.setCanvas(self.glowMap)
|
||||||
@ -205,12 +197,15 @@ function light_world:updateGlow()
|
|||||||
for i = 1, #self.body do
|
for i = 1, #self.body do
|
||||||
self.body[i]:drawGlow()
|
self.body[i]:drawGlow()
|
||||||
end
|
end
|
||||||
|
love.graphics.setCanvas(self.last_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:updateRefraction()
|
function light_world:updateRefraction()
|
||||||
if not self.optionRefraction or not self.isRefraction then
|
if not self.optionRefraction or not self.isRefraction then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
love.graphics.setShader()
|
love.graphics.setShader()
|
||||||
-- create refraction map
|
-- create refraction map
|
||||||
self.refractionMap:clear()
|
self.refractionMap:clear()
|
||||||
@ -218,18 +213,22 @@ function light_world:updateRefraction()
|
|||||||
for i = 1, #self.body do
|
for i = 1, #self.body do
|
||||||
self.body[i]:drawRefraction()
|
self.body[i]:drawRefraction()
|
||||||
end
|
end
|
||||||
|
love.graphics.setCanvas(self.last_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:updateRelfection()
|
function light_world:updateRelfection()
|
||||||
if not self.optionReflection or not self.isReflection then
|
if not self.optionReflection or not self.isReflection then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
-- create reflection map
|
-- create reflection map
|
||||||
self.reflectionMap:clear(0, 0, 0)
|
self.reflectionMap:clear(0, 0, 0)
|
||||||
love.graphics.setCanvas(self.reflectionMap)
|
love.graphics.setCanvas(self.reflectionMap)
|
||||||
for i = 1, #self.body do
|
for i = 1, #self.body do
|
||||||
self.body[i]:drawReflection()
|
self.body[i]:drawReflection()
|
||||||
end
|
end
|
||||||
|
love.graphics.setCanvas(self.last_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:refreshScreenSize()
|
function light_world:refreshScreenSize()
|
||||||
@ -253,6 +252,8 @@ function light_world:drawShadow()
|
|||||||
if not self.optionShadows or not (self.isShadows or self.isLight) then
|
if not self.optionShadows or not (self.isShadows or self.isLight) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:updateShadows()
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
if self.blur then
|
if self.blur then
|
||||||
self.last_buffer = love.graphics.getCanvas()
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
@ -313,6 +314,7 @@ function light_world:drawPixelShadow()
|
|||||||
if not self.optionPixelShadows or not self.isPixelShadows then
|
if not self.optionPixelShadows or not self.isPixelShadows then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
self:updatePixelShadows()
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
love.graphics.setBlendMode("multiplicative")
|
love.graphics.setBlendMode("multiplicative")
|
||||||
love.graphics.setShader()
|
love.graphics.setShader()
|
||||||
@ -335,6 +337,7 @@ function light_world:drawGlow()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:updateGlow()
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
if self.glowBlur == 0.0 then
|
if self.glowBlur == 0.0 then
|
||||||
love.graphics.setBlendMode("additive")
|
love.graphics.setBlendMode("additive")
|
||||||
@ -365,6 +368,7 @@ function light_world:drawRefraction()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:updateRefraction()
|
||||||
self.last_buffer = love.graphics.getCanvas()
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
if self.last_buffer then
|
if self.last_buffer then
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
@ -386,6 +390,7 @@ function light_world:drawReflection()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:updateRelfection()
|
||||||
self.last_buffer = love.graphics.getCanvas()
|
self.last_buffer = love.graphics.getCanvas()
|
||||||
if self.last_buffer then
|
if self.last_buffer then
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
Loading…
Reference in New Issue
Block a user