## Löve "Light vs. Shadow" Engine v2

giann
Prole
Posts: 42
Joined: Fri Jun 28, 2013 11:38 am

### Re: Löve "Light vs. Shadow" Engine v2

If your character cast a shadow and your light is exactly on top of it, it will block out the light.
You need to position your light just at the edge of your character image.
When you change your light direction, you also need to move the light to the opposite edge of your character image in that direction.

joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

### Re: Löve "Light vs. Shadow" Engine v2

giann wrote:If your character cast a shadow and your light is exactly on top of it, it will block out the light.
You need to position your light just at the edge of your character image.
When you change your light direction, you also need to move the light to the opposite edge of your character image in that direction.
I don't think that's the problem. The lightWorld doesn't know about the player. I didn't see the need to register the player as a body. I tried giving the light an offset so it wouldn't be directly over the player as a test, and it still disappears when pointed to the lower left.

soulaymenc
Prole
Posts: 34
Joined: Thu Jul 11, 2013 2:03 pm
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

Uhh, something wierd just happened, when I remove all light sources, when I move a sprite, it keeps redrawing and leave traces (just like when windows xp windows stops responding, and you move it with your mouse).

It only happens when I remove all lightsources. (It kinda happens with lightsources on, but the traces slowly fades away). Any idea how to fix it?
This world is so strange.

giann
Prole
Posts: 42
Joined: Fri Jun 28, 2013 11:38 am

### Re: Löve "Light vs. Shadow" Engine v2

Sounds like a canvas not being cleared.

drunken_thor
Citizen
Posts: 75
Joined: Wed Oct 01, 2014 12:14 am
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

soulaymenc wrote:Uhh, something wierd just happened, when I remove all light sources, when I move a sprite, it keeps redrawing and leave traces (just like when windows xp windows stops responding, and you move it with your mouse).

It only happens when I remove all lightsources. (It kinda happens with lightsources on, but the traces slowly fades away). Any idea how to fix it?
The main problem is that there is no background to your world. The problem is that the shadows need to be drawn to something so there needs to be a background of some sort. That is why in most of the examples it draws a rectangle to the background. if you simply draw a background rectangle it will all go away
Light_world.lua for all your lighting needs
Github

drunken_thor
Citizen
Posts: 75
Joined: Wed Oct 01, 2014 12:14 am
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

joedono wrote:I'm having a really weird issue. My top-down exploration game includes a character with a flashlight. When I start the flashlight with this code, it doesn't show up until I change the direction of the light. Then, if I try to swing the flashlight back to that direction, it vanishes again.

Code: Select all

self.flashLight:setDirection(math.pi * 3/4);
self.flashLight:setAngle(math.pi * 1/2);

However, changing the angle of the flashlight to math.pi * 3/8 seems to solve the problem, but I'd like a 45degree light if I can manage it.

I'll attach the project I have so far. Use WASD to move, the arrow keys to swing the flashlight around, and space to turn the flashlight on and off. If you try to shine the flashlight to the lower-left, it disappears when it gets there.
Please try the most recent version of the code, I just released a bunch of optimizations and one of them was to take out the complicated directional light math and use an arc stencil instead. That should clear up your issues.
Light_world.lua for all your lighting needs
Github

drunken_thor
Citizen
Posts: 75
Joined: Wed Oct 01, 2014 12:14 am
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

giann wrote:Do you think there's room for improvements in terms of performances ?
My FPS drops really quickly the more I add bodies and lights.

Edit: Another weird issue is that FPS seems to drops relative to the screen size regardless of the number of lights/bodies.

800x450: 50fps
1280x720: 20fps
with the same number of lights/bodies
Please try the most recent version of the code. Through testing I realized that stenciling narrows the amount of area that shaders are applied, so by stenciling the area of each light I was able to get significant speed boosts. HOWEVER I have found that you still need to be wise how you use your lights and use of objects. Things turn out nice with a few lights and large shadow bodies (walls.)
Light_world.lua for all your lighting needs
Github

soulaymenc
Prole
Posts: 34
Joined: Thu Jul 11, 2013 2:03 pm
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

drunken_thor wrote:The main problem is that there is no background to your world. The problem is that the shadows need to be drawn to something so there needs to be a background of some sort. That is why in most of the examples it draws a rectangle to the background. if you simply draw a background rectangle it will all go away
Oh I actually noticed that, but on image objects backgrounds, never though of rectangles, this solves the issue, thank you
This world is so strange.

giann
Prole
Posts: 42
Joined: Fri Jun 28, 2013 11:38 am

### Re: Löve "Light vs. Shadow" Engine v2

drunken_thor wrote:
giann wrote:Do you think there's room for improvements in terms of performances ?
My FPS drops really quickly the more I add bodies and lights.

Edit: Another weird issue is that FPS seems to drops relative to the screen size regardless of the number of lights/bodies.

800x450: 50fps
1280x720: 20fps
with the same number of lights/bodies
Please try the most recent version of the code. Through testing I realized that stenciling narrows the amount of area that shaders are applied, so by stenciling the area of each light I was able to get significant speed boosts. HOWEVER I have found that you still need to be wise how you use your lights and use of objects. Things turn out nice with a few lights and large shadow bodies (walls.)
Also bloom is not working even though drawBloom is called.

drunken_thor
Citizen
Posts: 75
Joined: Wed Oct 01, 2014 12:14 am
Contact:

### Re: Löve "Light vs. Shadow" Engine v2

giann wrote: Shadows are not blurred anymore.
Also bloom is not working even though drawBloom is called.
I have tested it all and the current code on master works for both shadow blur and bloom. can I see your code of how you are setting shadow blur and how you are setting bloom on the postshader?

Also any mention of optimizations? Have you noticed any performance gains?
Light_world.lua for all your lighting needs
Github