just some refactoring

This commit is contained in:
Tim Anema 2014-12-14 13:17:56 -05:00
parent 5208475e18
commit 297952673b
2 changed files with 18 additions and 23 deletions

View File

@ -89,7 +89,6 @@ function light_world:update(dt)
self.bodies[i]:update(dt) self.bodies[i]:update(dt)
end end
end end
for i = 1, #self.lights do for i = 1, #self.lights do
self.lights[i].is_on_screen = self.lights[i]:inRange(self.l,self.t,self.w,self.h,self.s) self.lights[i].is_on_screen = self.lights[i]:inRange(self.l,self.t,self.w,self.h,self.s)
end end
@ -99,7 +98,7 @@ function light_world:draw(cb)
util.drawto(self.render_buffer, self.l, self.t, self.s, function() util.drawto(self.render_buffer, self.l, self.t, self.s, function()
cb( self.l,self.t,self.w,self.h,self.s) cb( self.l,self.t,self.w,self.h,self.s)
_ = self.disableMaterial or self:drawMaterial( self.l,self.t,self.w,self.h,self.s) _ = self.disableMaterial or self:drawMaterial( self.l,self.t,self.w,self.h,self.s)
self:drawNormalShading( self.l,self.t,self.w,self.h,self.s) self:drawShadows( self.l,self.t,self.w,self.h,self.s)
_ = self.disableGlow or self:drawGlow( self.l,self.t,self.w,self.h,self.s) _ = self.disableGlow or self:drawGlow( self.l,self.t,self.w,self.h,self.s)
_ = self.disableRefraction or self:drawRefraction( self.l,self.t,self.w,self.h,self.s) _ = self.disableRefraction or self:drawRefraction( self.l,self.t,self.w,self.h,self.s)
_ = self.disableReflection or self:drawReflection( self.l,self.t,self.w,self.h,self.s) _ = self.disableReflection or self:drawReflection( self.l,self.t,self.w,self.h,self.s)
@ -119,7 +118,7 @@ function light_world:drawBlur(blendmode, blur, canvas, canvas2, l, t, w, h, s)
end end
-- draw normal shading -- draw normal shading
function light_world:drawNormalShading(l,t,w,h,s) function light_world:drawShadows(l,t,w,h,s)
-- create normal map -- create normal map
self.normalMap:clear() self.normalMap:clear()
util.drawto(self.normalMap, l, t, s, function() util.drawto(self.normalMap, l, t, s, function()
@ -162,12 +161,11 @@ function light_world:drawNormalShading(l,t,w,h,s)
end end
-- add in ambient color -- add in ambient color
self.normal:clear(255, 255, 255) util.drawCanvasToCanvas(self.normal2, self.normal)
util.drawCanvasToCanvas(self.normal2, self.normal, {blendmode = "alpha"}) util.drawto(self.normal, 0, 0, 1, function()
util.drawto(self.normal, l, t, s, function()
love.graphics.setBlendMode("additive") love.graphics.setBlendMode("additive")
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", -l/s, -t/s, w/s,h/s) love.graphics.rectangle("fill", 0, 0, w,h)
end) end)
light_world:drawBlur("alpha", self.shadowBlur, self.normal, self.normal2, l, t, w, h, s) light_world:drawBlur("alpha", self.shadowBlur, self.normal, self.normal2, l, t, w, h, s)

View File

@ -3,10 +3,7 @@ local util = {}
function util.drawCanvasToCanvas(canvas, other_canvas, options) function util.drawCanvasToCanvas(canvas, other_canvas, options)
options = options or {} options = options or {}
local last_buffer = love.graphics.getCanvas() util.drawto(other_canvas, 0, 0, 1, function()
love.graphics.push()
love.graphics.origin()
love.graphics.setCanvas(other_canvas)
if options["blendmode"] then if options["blendmode"] then
love.graphics.setBlendMode(options["blendmode"]) love.graphics.setBlendMode(options["blendmode"])
end end
@ -15,17 +12,17 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
end end
if options["color"] then if options["color"] then
love.graphics.setColor(unpack(options["color"])) love.graphics.setColor(unpack(options["color"]))
end else
love.graphics.setColor(255,255,255) love.graphics.setColor(255,255,255)
end
love.graphics.draw(canvas,0,0) love.graphics.draw(canvas,0,0)
love.graphics.setCanvas(last_buffer)
if options["blendmode"] then if options["blendmode"] then
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
end end
if options["shader"] then if options["shader"] then
love.graphics.setShader() love.graphics.setShader()
end end
love.graphics.pop() end)
end end
function util.drawto(canvas, x, y, scale, cb) function util.drawto(canvas, x, y, scale, cb)