Lighting and Shadow System

Showcase your libraries, tools and other projects that help your fellow love users.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Lighting and Shadow System

Post by argh »

Update: 2014/02/02 I am going to change to add an additive lighting system

Update: 2014/02/03 Working subtractive lighting system

https://gist.github.com/seanpackham/8727943

Original Post

Hi all, first post here. I want to start by saying Love2D is by far the easiest and quickest 2D framework I have encountered and it is due to the great community and authors. Thank you for all that you have done!

I have been implementing lighting and shadows for a prototype I am making http://forums.tigsource.com/index.php?topic=38448.0 but have hit a wall. I am not too clued up on blend modes, stencils and cavanses and this is currently where I am:

Image

I have been following these great resources:
  1. http://forums.tigsource.com/index.php?topic=8803.0
  2. http://experimentalized.blogspot.com/20 ... sting.html
  3. http://lwjgl.org/forum/index.php/topic,5203.0.html
  4. https://github.com/DrAgonmoray/BasicLighting/
trying to emulate these looks:
  1. http://www.youtube.com/watch?v=nSf1MpsWKig
  2. http://www.youtube.com/watch?v=Gy9tvA9AlSg (user oysi93 implemented his lighting in love2d)
I also saw that löve user styves http://love2d.org/forums/memberlist.php ... e&u=134530 is working on a lighting system http://love2d.org/forums/viewtopic.php? ... 90#p161226.

I have completed the shadow generation, and in the code have drawn the shadow polygons with an alpha to demonstrate multiple shadows overlapping but generally they should be opaque. I have included a port, with some minor changes, of the fragment shader from resource link 4 above.

I have not been able to correctly blend the various states (geometry/background, shadows, lights).

I was wondering if any lövers out there could give me some advice? Perhaps a lightmask solution is easier than using a shader...

Here is a gist of the code https://gist.github.com/seanpackham/8727943

Thanks :)
Last edited by argh on Mon Feb 03, 2014 8:27 am, edited 3 times in total.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Need Help with Almost Complete Lighting and Shadow Syste

Post by argh »

Updated 2014/02/03 Removed embeeded code and added link to gist.

Thanks to the reddit user http://www.reddit.com/user/naughty who answered my question http://www.reddit.com/r/love2d/comments ... hting_and/ with an algorithm and updated code sample, I now have a finished lighting prototype :)

Image

Here's a link to the devlog post http://forums.tigsource.com/index.php?t ... #msg990401

Code in a gist https://gist.github.com/seanpackham/8727943
Last edited by argh on Mon Feb 03, 2014 8:25 am, 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: Complete Lighting and Shadow System!

Post by Ranguna259 »

Shadows should stop when they find another object, in your code shadows just keep on going until they hit a wall.
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
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: Complete Lighting and Shadow System!

Post by verilog »

Hi argh!
Just wanted to say that your prototype is looking sweet, man! Thanks for the links and keep it up!
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Complete Lighting and Shadow System!

Post by argh »

Ranguna259 wrote:Shadows should stop when they find another object, in your code shadows just keep on going until they hit a wall.
Yip to be more realistic they should stop when hitting objects. The problem is the performance plummets if you need to think of each shadow behaving like a light, potentially being split into many sub shadows. Any thoughts or suggestions how this could be done efficiently?
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Complete Lighting and Shadow System!

Post by argh »

verilog wrote:Hi argh!
Just wanted to say that your prototype is looking sweet, man! Thanks for the links and keep it up!
Thanks for the encouragement :)
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Complete Lighting and Shadow System!

Post by Ranguna259 »

argh wrote: Yip to be more realistic they should stop when hitting objects. The problem is the performance plummets if you need to think of each shadow behaving like a light, potentially being split into many sub shadows. Any thoughts or suggestions how this could be done efficiently?
I haven't seen how your code works but could you tell me really quickly how yur algorithem works ? is it additive (do you draw the light) or subtractive (do you draw the shadows) ? Here's an exemple of an additive like light.

Oh and nice work so far :3
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.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Complete Lighting and Shadow System!

Post by argh »

Thanks, it's subtractive. I see the additive approach will have more realistic results. Thanks for the link, I'll try and implement it. I also found this approach http://www.catalinzima.com/2010/07/my-t ... d-shadows/
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Lighting and Shadow System

Post by Ranguna259 »

That's a similar aproach to this one. I'm actually trying to reproduce that effect and I'm currently looking for a rectangle to polar and a polar to rectangle shader.
Since you draw the shadows how do you set their limit ? Do they stop once they reach a certain distance from the light source or when they hit the screen borders ?
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.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Complete Lighting and Shadow System!

Post by Germanunkol »

Ranguna259 wrote: Here's an exemple of an additive like light.
That's an amazing post, thanks for sharing! I love the interacitve examples... really neat!
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 80 guests