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
|
-- 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
|
||||||
|
16
lib/util.lua
16
lib/util.lua
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user