some proper refactoring so shine and shadows code are separate

This commit is contained in:
Tim Anema 2014-10-23 22:41:52 -04:00
parent e9a98dbcee
commit 5474b11c50
5 changed files with 18 additions and 20 deletions

View File

@ -17,7 +17,7 @@ function love.load()
lightWorld = LightWorld({ lightWorld = LightWorld({
drawBackground = drawBackground, drawBackground = drawBackground,
drawForground = drawForground, drawForground = drawForground,
ambient = {15,15,15}, ambient = {55,55,55},
refractionStrength = 32.0, refractionStrength = 32.0,
reflectionVisibility = 0.75, reflectionVisibility = 0.75,
}) })

View File

@ -387,7 +387,7 @@ function body:setShadowType(type, ...)
end end
end end
function body:shadowStencil() function body:stencil()
if self.shadowType == "circle" then if self.shadowType == "circle" then
love.graphics.circle("fill", self.x - self.ox, self.y - self.oy, self.radius) love.graphics.circle("fill", self.x - self.ox, self.y - self.oy, self.radius)
elseif self.shadowType == "rectangle" then elseif self.shadowType == "rectangle" then

View File

@ -176,25 +176,25 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
end end
end) end)
-- update shine
self.shine:clear(255, 255, 255)
util.drawto(self.shine, l, t, s, function()
love.graphics.setShader(self.shader)
love.graphics.setBlendMode("alpha")
love.graphics.setStencil(stencils.colorShadow(bodies))
love.graphics.rectangle("fill", -l/s,-t/s,w/s,h/s)
end)
love.graphics.setStencil() love.graphics.setStencil()
love.graphics.setShader() love.graphics.setShader()
util.drawCanvasToCanvas(self.shadow, canvas, {blendmode = "additive"}) util.drawCanvasToCanvas(self.shadow, canvas, {blendmode = "additive"})
end end
end end
function light:drawShine(canvas) function light:drawShine(l,t,w,h,s,bodies,canvas)
if self.visible then if self.visible then
util.drawCanvasToCanvas(self.shine, canvas) --update shine
self.shine:clear(255, 255, 255)
util.drawto(self.shine, l, t, s, function()
love.graphics.setShader(self.shader)
love.graphics.setBlendMode("alpha")
love.graphics.setStencil(stencils.shine(bodies))
love.graphics.rectangle("fill", -l/s,-t/s,w/s,h/s)
end)
love.graphics.setStencil()
love.graphics.setShader()
util.drawCanvasToCanvas(self.shine, canvas, {blendmode = "additive"})
end end
end end

View File

@ -152,10 +152,8 @@ function light_world:drawShine(l,t,w,h,s)
love.graphics.setColor(unpack(self.ambient)) love.graphics.setColor(unpack(self.ambient))
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
love.graphics.rectangle("fill", -l/s, -t/s, w/s, h/s) love.graphics.rectangle("fill", -l/s, -t/s, w/s, h/s)
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("additive")
for i = 1, #self.lights do for i = 1, #self.lights do
self.lights[i]:drawShine(self.shine) self.lights[i]:drawShine(l,t,w,h,s,self.body,self.shine)
end end
end) end)

View File

@ -11,20 +11,20 @@ function stencils.shadow(geometry, bodies)
-- underneath shadows -- underneath shadows
for i = 1, #bodies do for i = 1, #bodies do
if not bodies[i].castsNoShadow then if not bodies[i].castsNoShadow then
bodies[i]:shadowStencil() bodies[i]:stencil()
end end
end end
end end
end end
function stencils.colorShadow(bodies) function stencils.shine(bodies)
return function() return function()
for i = 1, #bodies do for i = 1, #bodies do
if bodies[i].shine and if bodies[i].shine and
(bodies[i].glowStrength == 0.0 or (bodies[i].glowStrength == 0.0 or
(bodies[i].type == "image" and not bodies[i].normal)) (bodies[i].type == "image" and not bodies[i].normal))
then then
bodies[i]:shadowStencil() bodies[i]:stencil()
end end
end end
end end