split the update method up into components, easier to understand

This commit is contained in:
Tim Anema 2014-09-27 12:59:51 -04:00
parent 3502fe7d3e
commit 8115657d11

View File

@ -261,70 +261,76 @@ end
-- draw shadow -- draw shadow
function light_world:drawShadow() function light_world:drawShadow()
if self.optionShadows and (self.isShadows or self.isLight) then if not self.optionShadows or not (self.isShadows or self.isLight) then
love.graphics.setColor(255, 255, 255) return
if self.blur then
self.last_buffer = love.graphics.getCanvas()
self.blurv:send("steps", self.blur)
self.blurh:send("steps", self.blur)
love.graphics.setBlendMode("alpha")
love.graphics.setCanvas(self.shadow2)
love.graphics.setShader(self.blurv)
love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.shadow)
love.graphics.setShader(self.blurh)
love.graphics.draw(self.shadow2, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.last_buffer)
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
else
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
end
end end
end love.graphics.setColor(255, 255, 255)
-- draw shine if self.blur then
function light_world:drawShine() self.last_buffer = love.graphics.getCanvas()
if self.optionShadows and self.isShadows then self.blurv:send("steps", self.blur)
love.graphics.setColor(255, 255, 255) self.blurh:send("steps", self.blur)
if self.blur and false then love.graphics.setBlendMode("alpha")
self.last_buffer = love.graphics.getCanvas() love.graphics.setCanvas(self.shadow2)
self.blurv:send("steps", self.blur) love.graphics.setShader(self.blurv)
self.blurh:send("steps", self.blur) love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha") love.graphics.setCanvas(self.shadow)
love.graphics.setCanvas(self.shine2) love.graphics.setShader(self.blurh)
love.graphics.setShader(self.blurv) love.graphics.draw(self.shadow2, self.translate_x, self.translate_y)
love.graphics.draw(self.shine, self.translate_x, self.translate_y) love.graphics.setCanvas(self.last_buffer)
love.graphics.setCanvas(self.shine)
love.graphics.setShader(self.blurh)
love.graphics.draw(self.shine2, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.last_buffer)
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shine, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
else
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shine, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
end
end
end
-- draw pixel shadow
function light_world:drawPixelShadow()
if self.optionPixelShadows and self.isPixelShadows then
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("multiplicative") love.graphics.setBlendMode("multiplicative")
love.graphics.setShader() love.graphics.setShader()
love.graphics.draw(self.pixelShadow, self.translate_x, self.translate_y) love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
else
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
end end
end end
-- draw shine
function light_world:drawShine()
if not self.optionShadows or not self.isShadows then
return
end
love.graphics.setColor(255, 255, 255)
if self.blur and false then
self.last_buffer = love.graphics.getCanvas()
self.blurv:send("steps", self.blur)
self.blurh:send("steps", self.blur)
love.graphics.setBlendMode("alpha")
love.graphics.setCanvas(self.shine2)
love.graphics.setShader(self.blurv)
love.graphics.draw(self.shine, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.shine)
love.graphics.setShader(self.blurh)
love.graphics.draw(self.shine2, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.last_buffer)
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shine, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
else
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.shine, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
end
end
-- draw pixel shadow
function light_world:drawPixelShadow()
if not self.optionPixelShadows or not self.isPixelShadows then
return
end
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("multiplicative")
love.graphics.setShader()
love.graphics.draw(self.pixelShadow, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
end
-- draw material -- draw material
function light_world:drawMaterial() function light_world:drawMaterial()
love.graphics.setShader(self.materialShader) love.graphics.setShader(self.materialShader)
@ -333,83 +339,94 @@ function light_world:drawMaterial()
end end
love.graphics.setShader() love.graphics.setShader()
end end
-- draw glow -- draw glow
function light_world:drawGlow() function light_world:drawGlow()
if self.optionGlow and self.isGlow then if not self.optionGlow or not self.isGlow then
love.graphics.setColor(255, 255, 255) return
if self.glowBlur == 0.0 then end
love.graphics.setBlendMode("additive")
love.graphics.setShader() love.graphics.setColor(255, 255, 255)
love.graphics.draw(self.glowMap, self.translate_x, self.translate_y) if self.glowBlur == 0.0 then
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("additive")
else love.graphics.setShader()
self.blurv:send("steps", self.glowBlur) love.graphics.draw(self.glowMap, self.translate_x, self.translate_y)
self.blurh:send("steps", self.glowBlur) love.graphics.setBlendMode("alpha")
self.last_buffer = love.graphics.getCanvas() else
love.graphics.setBlendMode("additive") self.blurv:send("steps", self.glowBlur)
self.glowMap2:clear() self.blurh:send("steps", self.glowBlur)
love.graphics.setCanvas(self.glowMap2) self.last_buffer = love.graphics.getCanvas()
love.graphics.setShader(self.blurv) love.graphics.setBlendMode("additive")
love.graphics.draw(self.glowMap, self.translate_x, self.translate_y) self.glowMap2:clear()
love.graphics.setCanvas(self.glowMap) love.graphics.setCanvas(self.glowMap2)
love.graphics.setShader(self.blurh) love.graphics.setShader(self.blurv)
love.graphics.draw(self.glowMap2, self.translate_x, self.translate_y) love.graphics.draw(self.glowMap, self.translate_x, self.translate_y)
love.graphics.setCanvas(self.last_buffer) love.graphics.setCanvas(self.glowMap)
love.graphics.setShader() love.graphics.setShader(self.blurh)
love.graphics.draw(self.glowMap, self.translate_x, self.translate_y) love.graphics.draw(self.glowMap2, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha") love.graphics.setCanvas(self.last_buffer)
end love.graphics.setShader()
love.graphics.draw(self.glowMap, self.translate_x, self.translate_y)
love.graphics.setBlendMode("alpha")
end end
end end
-- draw refraction -- draw refraction
function light_world:drawRefraction() function light_world:drawRefraction()
if self.optionRefraction and self.isRefraction then if not self.optionRefraction or not self.isRefraction then
self.last_buffer = love.graphics.getCanvas() return
if self.last_buffer then end
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("alpha") self.last_buffer = love.graphics.getCanvas()
love.graphics.setCanvas(self.refractionMap2) if self.last_buffer then
love.graphics.draw(self.last_buffer, self.translate_x, self.translate_y) love.graphics.setColor(255, 255, 255)
love.graphics.setCanvas(self.last_buffer) love.graphics.setBlendMode("alpha")
self.refractionShader:send("backBuffer", self.refractionMap2) love.graphics.setCanvas(self.refractionMap2)
self.refractionShader:send("refractionStrength", self.refractionStrength) love.graphics.draw(self.last_buffer, self.translate_x, self.translate_y)
love.graphics.setShader(self.refractionShader) love.graphics.setCanvas(self.last_buffer)
love.graphics.draw(self.refractionMap, self.translate_x, self.translate_y) self.refractionShader:send("backBuffer", self.refractionMap2)
love.graphics.setShader() self.refractionShader:send("refractionStrength", self.refractionStrength)
end love.graphics.setShader(self.refractionShader)
love.graphics.draw(self.refractionMap, self.translate_x, self.translate_y)
love.graphics.setShader()
end end
end end
-- draw reflection -- draw reflection
function light_world:drawReflection() function light_world:drawReflection()
if self.optionReflection and self.isReflection then if not self.optionReflection or not self.isReflection then
self.last_buffer = love.graphics.getCanvas() return
if self.last_buffer then end
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("alpha") self.last_buffer = love.graphics.getCanvas()
love.graphics.setCanvas(self.reflectionMap2) if self.last_buffer then
love.graphics.draw(self.last_buffer, self.translate_x, self.translate_y) love.graphics.setColor(255, 255, 255)
love.graphics.setCanvas(self.last_buffer) love.graphics.setBlendMode("alpha")
self.reflectionShader:send("backBuffer", self.reflectionMap2) love.graphics.setCanvas(self.reflectionMap2)
self.reflectionShader:send("reflectionStrength", self.reflectionStrength) love.graphics.draw(self.last_buffer, self.translate_x, self.translate_y)
self.reflectionShader:send("reflectionVisibility", self.reflectionVisibility) love.graphics.setCanvas(self.last_buffer)
love.graphics.setShader(self.reflectionShader) self.reflectionShader:send("backBuffer", self.reflectionMap2)
love.graphics.draw(self.reflectionMap, self.translate_x, self.translate_y) self.reflectionShader:send("reflectionStrength", self.reflectionStrength)
love.graphics.setShader() self.reflectionShader:send("reflectionVisibility", self.reflectionVisibility)
end love.graphics.setShader(self.reflectionShader)
love.graphics.draw(self.reflectionMap, self.translate_x, self.translate_y)
love.graphics.setShader()
end end
end end
-- new light -- new light
function light_world:newLight(x, y, red, green, blue, range) function light_world:newLight(x, y, red, green, blue, range)
self.lights[#self.lights + 1] = Light(self, x, y, red, green, blue, range) self.lights[#self.lights + 1] = Light(self, x, y, red, green, blue, range)
self.isLight = true self.isLight = true
return self.lights[#self.lights] return self.lights[#self.lights]
end end
-- clear lights -- clear lights
function light_world:clearLights() function light_world:clearLights()
self.lights = {} self.lights = {}
self.isLight = false self.isLight = false
self.changed = true self.changed = true
end end
-- clear objects -- clear objects
function light_world:clearBodys() function light_world:clearBodys()
self.body = {} self.body = {}
@ -420,41 +437,50 @@ function light_world:clearBodys()
self.isRefraction = false self.isRefraction = false
self.isReflection = false self.isReflection = false
end end
-- set offset -- set offset
function light_world:setTranslation(translateX, translateY) function light_world:setTranslation(translateX, translateY)
self.translate_x = translateX self.translate_x = translateX
self.translate_y = translateY self.translate_y = translateY
end end
-- set ambient color -- set ambient color
function light_world:setAmbientColor(red, green, blue) function light_world:setAmbientColor(red, green, blue)
self.ambient = {red, green, blue} self.ambient = {red, green, blue}
end end
-- set ambient red -- set ambient red
function light_world:setAmbientRed(red) function light_world:setAmbientRed(red)
self.ambient[1] = red self.ambient[1] = red
end end
-- set ambient green -- set ambient green
function light_world:setAmbientGreen(green) function light_world:setAmbientGreen(green)
self.ambient[2] = green self.ambient[2] = green
end end
-- set ambient blue -- set ambient blue
function light_world:setAmbientBlue(blue) function light_world:setAmbientBlue(blue)
self.ambient[3] = blue self.ambient[3] = blue
end end
-- set normal invert -- set normal invert
function light_world:setNormalInvert(invert) function light_world:setNormalInvert(invert)
self.normalInvert = invert self.normalInvert = invert
end end
-- set blur -- set blur
function light_world:setBlur(blur) function light_world:setBlur(blur)
self.blur = blur self.blur = blur
self.changed = true self.changed = true
end end
-- set blur -- set blur
function light_world:setShadowBlur(blur) function light_world:setShadowBlur(blur)
self.blur = blur self.blur = blur
self.changed = true self.changed = true
end end
-- set buffer -- set buffer
function light_world:setBuffer(buffer) function light_world:setBuffer(buffer)
if buffer == "render" then if buffer == "render" then