Page 7 of 15

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

Posted: Thu Dec 18, 2014 1:54 pm
by giann
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.

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

Posted: Thu Dec 18, 2014 2:11 pm
by joedono
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.

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

Posted: Fri Dec 19, 2014 2:07 pm
by soulaymenc
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?

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

Posted: Fri Dec 19, 2014 2:18 pm
by giann
Sounds like a canvas not being cleared.

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

Posted: Sat Dec 20, 2014 3:57 am
by drunken_thor
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

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

Posted: Sat Dec 20, 2014 3:59 am
by drunken_thor
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.

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

Posted: Sat Dec 20, 2014 4:04 am
by drunken_thor
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.)

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

Posted: Sat Dec 20, 2014 10:06 am
by soulaymenc
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 :)

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

Posted: Sun Dec 21, 2014 1:52 pm
by giann
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.)
Shadows are not blurred anymore.
Also bloom is not working even though drawBloom is called.

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

Posted: Sun Dec 21, 2014 5:09 pm
by drunken_thor
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?