Page 1 of 2

Light, a shadow system for LÖVE

Posted: Fri Feb 12, 2016 9:47 pm
by Ranguna259
I know there are lots of shadow libraries out there but I wanted to make my own, here it is, light.
The code's on github.

Image

This library allows you to add shadows to your game, it currently supports translation given that you provide a big enough canvas to draw all the lights, I'm planning on optimizing it since you need to load a full map to add just a few lights into it so it's not very efficient, the code is based on this tutorial and works pretty well.

All the docs are on github, if you find any bugs then please post them there or here.
Thanks for reading :megagrin:

Controls for the demo:
Middle mouse button to add a light.
That's all..

Re: Light, a shadow system for LÖVE

Posted: Sat Feb 13, 2016 11:53 am
by whitebear
Wow, this works really well. Even under some stress test didn't seem to slow down. got to about 70+ lightsources until I saw fps drop.

Re: Light, a shadow system for LÖVE

Posted: Sat Feb 13, 2016 5:34 pm
by drikdrok
This looks really nice! I noticed that this does not Work with cameras like hump. What would a solution to that be? I suspect it has something to do with the canvas. But i have never worked with the love canvas before...

Re: Light, a shadow system for LÖVE

Posted: Sat Feb 13, 2016 6:15 pm
by Ranguna259
whitebear wrote:Wow, this works really well. Even under some stress test didn't seem to slow down. got to about 70+ lightsources until I saw fps drop.
Thanks, I'm pretty proud of the render method myself since it can handle a lot of lights before it reaches a bottleneck state. It's really efficient given that the scene canvas is small enough.
drikdrok wrote:This looks really nice! I noticed that this does not Work with cameras like hump. What be would a solution to that be? I suspect it has something to do with the canvas. But i have never worked the love canvas before...
Yeah, light doesn't work with most camera libs.. I don't know how they work but essencialy .generateShadows() only renderes shadows to the scene that is provided, so first you need to draw your scene into a canvas instead of drawing it direcly to the screen, then pass that canvas to .generateShadows() and draw the output and the scene canvas, here's how you save thing into a canvas:

Code: Select all

function love.load()
  scene = love.graphics.newCanvas()
end

function love.draw()
  love.graphics.setCanvas()
    love.graphics.clear()
    
    --draw everything in here
    
  love.graphics.setCanvas()
   
  love.graphics.draw(light.generateShadows(scene)
  love.graphics.draw(scene)
end
I'll look into this after I'm done with the next update.

Re: Light, a shadow system for LÖVE

Posted: Sat Feb 13, 2016 6:46 pm
by drikdrok
Ranguna259 wrote:
whitebear wrote:Wow, this works really well. Even under some stress test didn't seem to slow down. got to about 70+ lightsources until I saw fps drop.
Thanks, I'm pretty proud of the render method myself since it can handle a lot of lights before it reaches a bottleneck state. It's really efficient given that the scene canvas is small enough.
drikdrok wrote:This looks really nice! I noticed that this does not Work with cameras like hump. What be would a solution to that be? I suspect it has something to do with the canvas. But i have never worked the love canvas before...
Yeah, light doesn't work with most camera libs.. I don't know how they work but essencialy .generateShadows() only renderes shadows to the scene that is provided, so first you need to draw your scene into a canvas instead of drawing it direcly to the screen, then pass that canvas to .generateShadows() and draw the output and the scene canvas, here's how you save thing into a canvas:

Code: Select all

function love.load()
  scene = love.graphics.newCanvas()
end

function love.draw()
  love.graphics.setCanvas()
    love.graphics.clear()
    
    --draw everything in here
    
  love.graphics.setCanvas()
   
  love.graphics.draw(light.generateShadows(scene)
  love.graphics.draw(scene)
end
I'll look into this after I'm done with the next update.
Thank you very much! I will look for a solution too :)!

Re: Light, a shadow system for LÖVE

Posted: Sat Feb 13, 2016 7:45 pm
by Ranguna259
drikdrok wrote:Thank you very much! I will look for a solution too :)!
You are welcome, if you find anything post here or PM me :)

Re: Light, a shadow system for LÖVE

Posted: Sun Feb 14, 2016 4:17 pm
by alberto_lara
This is actually pretty cool, terrific work!

Re: Light, a shadow system for LÖVE

Posted: Thu Feb 18, 2016 4:54 pm
by AC Vis
I love how simple this is to use. It would be great if it worked with a camera system...to my knowledge, which is limited, I can't recall a lighting/shadow system for Love that does work with cameras. Which means there is no workaround?

Re: Light, a shadow system for LÖVE

Posted: Thu Feb 18, 2016 5:40 pm
by Foogles
This looks fantastic! I am making a simple arcade game without any fancy graphics. Adding some lighting may give it a less flat look.

If I use this library in my projects, is there something I should be doing to credit you for your work?

Re: Light, a shadow system for LÖVE

Posted: Thu Feb 18, 2016 6:12 pm
by NightKawata
my favorite part is that the screenshot looks like a 1990s game ad