mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
minor fixes over stencil
This commit is contained in:
parent
85d4fbbba7
commit
eeb9d91747
@ -107,9 +107,10 @@ end
|
||||
|
||||
-- draw normal shading
|
||||
function light_world:drawShadows(l,t,w,h,s)
|
||||
-- create normal map
|
||||
util.drawto(self.normalMap, l, t, s, function()
|
||||
love.graphics.setCanvas( self.normalMap )
|
||||
love.graphics.clear()
|
||||
love.graphics.setCanvas()
|
||||
util.drawto(self.normalMap, l, t, s, function()
|
||||
for i = 1, #self.bodies do
|
||||
if self.bodies[i]:isVisible() then
|
||||
self.bodies[i]:drawNormal()
|
||||
@ -136,9 +137,9 @@ function light_world:drawShadows(l,t,w,h,s)
|
||||
local angle = light.direction - (light.angle / 2.0)
|
||||
love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle)
|
||||
end)
|
||||
love.graphics.setStencilTest("greater",0)
|
||||
love.graphics.stencil(function()
|
||||
love.graphics.setShader(self.image_mask)
|
||||
-- TODO:invert mask
|
||||
for k = 1, #self.bodies do
|
||||
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
|
||||
self.bodies[k]:drawStencil()
|
||||
@ -146,6 +147,7 @@ function light_world:drawShadows(l,t,w,h,s)
|
||||
end
|
||||
love.graphics.setShader()
|
||||
end)
|
||||
love.graphics.setStencilTest("equal", 0)
|
||||
for k = 1, #self.bodies do
|
||||
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
|
||||
self.bodies[k]:drawShadow(light)
|
||||
@ -178,6 +180,7 @@ function light_world:drawShadows(l,t,w,h,s)
|
||||
|
||||
self.post_shader:drawBlur(self.shadow_buffer, {self.shadowBlur})
|
||||
util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiply"})
|
||||
love.graphics.setStencilTest()
|
||||
end
|
||||
|
||||
-- draw material
|
||||
|
16
lib/util.lua
16
lib/util.lua
@ -18,33 +18,29 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
|
||||
end
|
||||
if options["stencil"] then
|
||||
love.graphics.stencil(options["stencil"])
|
||||
love.graphics.setStencilTest("greater",0)
|
||||
end
|
||||
if options["istencil"] then
|
||||
love.graphics.stencil(options["istencil"])
|
||||
--TODO: invert map
|
||||
love.graphics.setStencilTest("equal", 0)
|
||||
end
|
||||
if options["color"] then
|
||||
love.graphics.setColor(unpack(options["color"]))
|
||||
else
|
||||
love.graphics.setColor(255,255,255)
|
||||
end
|
||||
--TODO: not really sure if this is right
|
||||
love.graphics.setCanvas()
|
||||
if love.graphics.getCanvas() ~= canvas then
|
||||
love.graphics.draw(canvas,0,0)
|
||||
love.graphics.setCanvas(canvas)
|
||||
end
|
||||
if options["blendmode"] then
|
||||
love.graphics.setBlendMode("alpha")
|
||||
end
|
||||
if options["shader"] then
|
||||
love.graphics.setShader()
|
||||
end
|
||||
if options["stencil"] then
|
||||
--TODO: check if commenting this is really ok
|
||||
--love.graphics.stencil()
|
||||
end
|
||||
if options["istencil"] then
|
||||
--TODO: check if commenting this is really ok
|
||||
if options["stencil"] or options["istencil"] then
|
||||
--love.graphics.setInvertedStencil()
|
||||
love.graphics.setStencilTest()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user