minor fixes over stencil

This commit is contained in:
leokaplan 2016-02-04 17:33:22 +01:00
parent 85d4fbbba7
commit eeb9d91747
2 changed files with 13 additions and 14 deletions

View File

@ -107,9 +107,10 @@ end
-- draw normal shading
function light_world:drawShadows(l,t,w,h,s)
-- create normal map
love.graphics.setCanvas( self.normalMap )
love.graphics.clear()
love.graphics.setCanvas()
util.drawto(self.normalMap, l, t, s, function()
love.graphics.clear()
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

View File

@ -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()
love.graphics.draw(canvas,0,0)
love.graphics.setCanvas(canvas)
if love.graphics.getCanvas() ~= canvas then
love.graphics.draw(canvas,0,0)
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