Light, a shadow system for LÖVE

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Light, a shadow system for LÖVE

Post 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..
Attachments
light.love
DEMO
(19.13 KiB) Downloaded 694 times
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

Re: Light, a shadow system for LÖVE

Post 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.
User avatar
drikdrok
Prole
Posts: 36
Joined: Sun Mar 15, 2015 9:53 am
Contact:

Re: Light, a shadow system for LÖVE

Post 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...
Last edited by drikdrok on Wed Oct 12, 2016 7:01 pm, edited 1 time in total.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Light, a shadow system for LÖVE

Post 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.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
drikdrok
Prole
Posts: 36
Joined: Sun Mar 15, 2015 9:53 am
Contact:

Re: Light, a shadow system for LÖVE

Post 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 :)!
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Light, a shadow system for LÖVE

Post 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 :)
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Light, a shadow system for LÖVE

Post by alberto_lara »

This is actually pretty cool, terrific work!
User avatar
AC Vis
Prole
Posts: 9
Joined: Thu Aug 20, 2015 2:35 am

Re: Light, a shadow system for LÖVE

Post 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?
User avatar
Foogles
Prole
Posts: 14
Joined: Thu Feb 18, 2016 5:33 pm

Re: Light, a shadow system for LÖVE

Post 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?
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Light, a shadow system for LÖVE

Post by NightKawata »

my favorite part is that the screenshot looks like a 1990s game ad
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests