mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
split the update method up into components, easier to understand
This commit is contained in:
parent
08e50a7b2a
commit
3502fe7d3e
@ -105,8 +105,23 @@ function light_world:update()
|
|||||||
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
love.graphics.setBlendMode("alpha")
|
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)
|
||||||
|
self.changed = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function light_world:updateShadows()
|
||||||
|
if not self.optionShadows or not (self.isShadows or self.isLight) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if self.optionShadows and (self.isShadows or self.isLight) then
|
|
||||||
love.graphics.setShader(self.shader)
|
love.graphics.setShader(self.shader)
|
||||||
|
|
||||||
for i = 1, #self.lights do
|
for i = 1, #self.lights do
|
||||||
@ -139,7 +154,10 @@ function light_world:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.optionPixelShadows and self.isPixelShadows then
|
function light_world:updatePixelShadows()
|
||||||
|
if not self.optionPixelShadows or not self.isPixelShadows then
|
||||||
|
return
|
||||||
|
end
|
||||||
-- update pixel shadow
|
-- update pixel shadow
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
@ -173,7 +191,10 @@ function light_world:update()
|
|||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.optionGlow and self.isGlow then
|
function light_world:updateGlow()
|
||||||
|
if not self.optionGlow or not self.isGlow then
|
||||||
|
return
|
||||||
|
end
|
||||||
-- 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)
|
||||||
@ -195,7 +216,10 @@ function light_world:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.optionRefraction and self.isRefraction then
|
function light_world:updateRefraction()
|
||||||
|
if not self.optionRefraction or not self.isRefraction then
|
||||||
|
return
|
||||||
|
end
|
||||||
love.graphics.setShader()
|
love.graphics.setShader()
|
||||||
-- create refraction map
|
-- create refraction map
|
||||||
self.refractionMap:clear()
|
self.refractionMap:clear()
|
||||||
@ -205,7 +229,10 @@ function light_world:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.optionReflection and self.isReflection then
|
function light_world:updateRelfection()
|
||||||
|
if not self.optionReflection or not self.isReflection then
|
||||||
|
return
|
||||||
|
end
|
||||||
-- create reflection map
|
-- create reflection map
|
||||||
if self.changed then
|
if self.changed then
|
||||||
self.reflectionMap:clear(0, 0, 0)
|
self.reflectionMap:clear(0, 0, 0)
|
||||||
@ -216,14 +243,6 @@ function light_world:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setShader()
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
love.graphics.setStencil()
|
|
||||||
love.graphics.setCanvas(self.last_buffer)
|
|
||||||
|
|
||||||
self.changed = false
|
|
||||||
end
|
|
||||||
|
|
||||||
function light_world:refreshScreenSize()
|
function light_world:refreshScreenSize()
|
||||||
self.shadow = love.graphics.newCanvas()
|
self.shadow = love.graphics.newCanvas()
|
||||||
self.shadow2 = love.graphics.newCanvas()
|
self.shadow2 = love.graphics.newCanvas()
|
||||||
@ -239,6 +258,7 @@ function light_world:refreshScreenSize()
|
|||||||
self.pixelShadow = love.graphics.newCanvas()
|
self.pixelShadow = love.graphics.newCanvas()
|
||||||
self.pixelShadow2 = love.graphics.newCanvas()
|
self.pixelShadow2 = love.graphics.newCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw shadow
|
-- draw shadow
|
||||||
function light_world:drawShadow()
|
function light_world:drawShadow()
|
||||||
if self.optionShadows and (self.isShadows or self.isLight) then
|
if self.optionShadows and (self.isShadows or self.isLight) then
|
||||||
|
Loading…
Reference in New Issue
Block a user