From eeb9d917471593a248e98f4ffd7f0ee3e8c363e5 Mon Sep 17 00:00:00 2001 From: leokaplan Date: Thu, 4 Feb 2016 17:33:22 +0100 Subject: [PATCH] minor fixes over stencil --- lib/init.lua | 9 ++++++--- lib/util.lua | 18 +++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index 6120631..5738fac 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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 diff --git a/lib/util.lua b/lib/util.lua index 4dcc277..5d16bae 100644 --- a/lib/util.lua +++ b/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() - 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