Dynamic lighting and shadows

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
fruitcup
Prole
Posts: 2
Joined: Tue Jul 15, 2014 11:12 am

Dynamic lighting and shadows

Post by fruitcup »

Hi, I wanted to share my lights.

Image
Image
Image
Image
Image
Image
Image
Image
Image
It's pretty simple:

Code: Select all

For every light
  For every block
     Iterate over edges of block, calculating the shadow for each edge
     Draw the shadows to the inverted stencil
  Turn on shader and additive blending
  Draw a fullscreen rectangle (shader renders the light with some simple math)
Change blending mode to multiply
Render every block with color
It's all runs smoothly, even with many lights and many Box2D bodies.

I just wanted to share and see what you guys think :D

Well I just saw this: viewtopic.php?f=5&t=77418

Code on GitHub in case anyone wants to see:
https://github.com/jacobbrunson/Love-Lights

Here's a standalone .love if you want it:
https://github.com/jacobbrunson/Love-Li ... ights.love

Controls:
  • Left-Click: Place light
  • Right-Click: Drag block
  • A/D: Cycle light hue
  • W/S: Change light sizes
  • Z: Remove light
  • F: Spawn blocks
  • R: Remove blocks
  • G: Toggle gravity
  • Arrow keys: Move blocks
And shameless plug, I also made this in Java and WebGL:
https://github.com/jacobbrunson/BasicLighting
http://jacobbrunson.me/lights.html
Last edited by fruitcup on Tue Jul 15, 2014 9:15 pm, edited 3 times 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: Dynamic lighting and shadows

Post by Ranguna259 »

Really nice, what fps do you get ?
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.
fruitcup
Prole
Posts: 2
Joined: Tue Jul 15, 2014 11:12 am

Re: Dynamic lighting and shadows

Post by fruitcup »

Ranguna259 wrote:Really nice, what fps do you get ?
Hmm I just tested it. I get a solid 60 w/ 10 lights and 100 bodies, and also with 25 lights and 8o bodies

All of the code is currently optimized for readability so there's likely performance loss there. Also most of this is computed on the CPU. I might try moving all of it over to a shader to make it more robust.

Would you normally do math (like calculating the position of shadows) inside a shader? Or should that stay on the CPU?

Edit:
Well I just saw this: viewtopic.php?f=5&t=77418

So I am now quitting and putting my code on GitHub in case anyone wants to see:
https://github.com/jacobbrunson/Love-Lights

Here's a standalone .love if you want it:
https://github.com/jacobbrunson/Love-Li ... ights.love

And shameless plug, I also made this in Java and WebGL:
https://github.com/jacobbrunson/BasicLighting
http://jacobbrunson.me/lights.html
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Dynamic lighting and shadows

Post by Ranguna259 »

Disable vsync and check the FPS, lights on the CPU are very resource intensive so I want to know how much is shader based lightning better than CPU lightning.
Last edited by Ranguna259 on Wed Jul 16, 2014 12:02 am, edited 1 time in total.
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
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Dynamic lighting and shadows

Post by rmcode »

fruitcup wrote: So I am now quitting and putting my code on GitHub in case anyone wants to see:
https://github.com/jacobbrunson/Love-Lights
No need to quit. There is enough LÖVE for everyone two lighting engines.
Post Reply

Who is online

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