mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
some proper refactoring so shine and shadows code are separate
This commit is contained in:
parent
e9a98dbcee
commit
5474b11c50
@ -17,7 +17,7 @@ function love.load()
|
||||
lightWorld = LightWorld({
|
||||
drawBackground = drawBackground,
|
||||
drawForground = drawForground,
|
||||
ambient = {15,15,15},
|
||||
ambient = {55,55,55},
|
||||
refractionStrength = 32.0,
|
||||
reflectionVisibility = 0.75,
|
||||
})
|
||||
|
@ -387,7 +387,7 @@ function body:setShadowType(type, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function body:shadowStencil()
|
||||
function body:stencil()
|
||||
if self.shadowType == "circle" then
|
||||
love.graphics.circle("fill", self.x - self.ox, self.y - self.oy, self.radius)
|
||||
elseif self.shadowType == "rectangle" then
|
||||
|
@ -176,25 +176,25 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
||||
end
|
||||
end)
|
||||
|
||||
love.graphics.setStencil()
|
||||
love.graphics.setShader()
|
||||
util.drawCanvasToCanvas(self.shadow, canvas, {blendmode = "additive"})
|
||||
end
|
||||
end
|
||||
|
||||
function light:drawShine(l,t,w,h,s,bodies,canvas)
|
||||
if self.visible then
|
||||
--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.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.shadow, canvas, {blendmode = "additive"})
|
||||
end
|
||||
end
|
||||
|
||||
function light:drawShine(canvas)
|
||||
if self.visible then
|
||||
util.drawCanvasToCanvas(self.shine, canvas)
|
||||
util.drawCanvasToCanvas(self.shine, canvas, {blendmode = "additive"})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -152,10 +152,8 @@ function light_world:drawShine(l,t,w,h,s)
|
||||
love.graphics.setColor(unpack(self.ambient))
|
||||
love.graphics.setBlendMode("alpha")
|
||||
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
|
||||
self.lights[i]:drawShine(self.shine)
|
||||
self.lights[i]:drawShine(l,t,w,h,s,self.body,self.shine)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -11,20 +11,20 @@ function stencils.shadow(geometry, bodies)
|
||||
-- underneath shadows
|
||||
for i = 1, #bodies do
|
||||
if not bodies[i].castsNoShadow then
|
||||
bodies[i]:shadowStencil()
|
||||
bodies[i]:stencil()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function stencils.colorShadow(bodies)
|
||||
function stencils.shine(bodies)
|
||||
return function()
|
||||
for i = 1, #bodies do
|
||||
if bodies[i].shine and
|
||||
(bodies[i].glowStrength == 0.0 or
|
||||
(bodies[i].type == "image" and not bodies[i].normal))
|
||||
then
|
||||
bodies[i]:shadowStencil()
|
||||
bodies[i]:stencil()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user