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 -- draw normal shading
function light_world:drawShadows(l,t,w,h,s) function light_world:drawShadows(l,t,w,h,s)
-- create normal map love.graphics.setCanvas( self.normalMap )
util.drawto(self.normalMap, l, t, s, function()
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas()
util.drawto(self.normalMap, l, t, s, function()
for i = 1, #self.bodies do for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then if self.bodies[i]:isVisible() then
self.bodies[i]:drawNormal() 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) local angle = light.direction - (light.angle / 2.0)
love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle) love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle)
end) end)
love.graphics.setStencilTest("greater",0)
love.graphics.stencil(function() love.graphics.stencil(function()
love.graphics.setShader(self.image_mask) love.graphics.setShader(self.image_mask)
-- TODO:invert mask
for k = 1, #self.bodies do for k = 1, #self.bodies do
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
self.bodies[k]:drawStencil() self.bodies[k]:drawStencil()
@ -146,6 +147,7 @@ function light_world:drawShadows(l,t,w,h,s)
end end
love.graphics.setShader() love.graphics.setShader()
end) end)
love.graphics.setStencilTest("equal", 0)
for k = 1, #self.bodies do for k = 1, #self.bodies do
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
self.bodies[k]:drawShadow(light) 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}) self.post_shader:drawBlur(self.shadow_buffer, {self.shadowBlur})
util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiply"}) util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiply"})
love.graphics.setStencilTest()
end end
-- draw material -- draw material

View File

@ -18,33 +18,29 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
end end
if options["stencil"] then if options["stencil"] then
love.graphics.stencil(options["stencil"]) love.graphics.stencil(options["stencil"])
love.graphics.setStencilTest("greater",0)
end end
if options["istencil"] then if options["istencil"] then
love.graphics.stencil(options["istencil"]) love.graphics.stencil(options["istencil"])
--TODO: invert map love.graphics.setStencilTest("equal", 0)
end end
if options["color"] then if options["color"] then
love.graphics.setColor(unpack(options["color"])) love.graphics.setColor(unpack(options["color"]))
else else
love.graphics.setColor(255,255,255) love.graphics.setColor(255,255,255)
end end
--TODO: not really sure if this is right if love.graphics.getCanvas() ~= canvas then
love.graphics.setCanvas()
love.graphics.draw(canvas,0,0) love.graphics.draw(canvas,0,0)
love.graphics.setCanvas(canvas) end
if options["blendmode"] then if options["blendmode"] then
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
end end
if options["shader"] then if options["shader"] then
love.graphics.setShader() love.graphics.setShader()
end end
if options["stencil"] then if options["stencil"] or options["istencil"] 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
--love.graphics.setInvertedStencil() --love.graphics.setInvertedStencil()
love.graphics.setStencilTest()
end end
end) end)
end end