defold / sample-lights-and-shadows

Example of how to achieve pixel perfect shadows in a 2D view
MIT License
31 stars 5 forks source link

Fix falloff curve calculation #9

Closed haath closed 1 year ago

haath commented 1 year ago

Hey,

I noticed in light_quad.fp that the radial light intensity value, which should have been affecting only the alpha channel of the color, was in fact being multiplied with all components of the color. Because of this, when I tried to implement ambient lighting, this weird circular dark spot around the light would get created, since the ambient light was also being multiplied with the light's intensity.

After the fix, you can see that the radial falloff now works properly, the light becomes gradually less dense until it blends perfectly with the ambient light.

Before: image

After: image

I also took this opportunity to properly hookup the falloff property, it wasn't used before and it was hard-coded to 1.


Note that in the examples above I am not using this repo as an asset. Instead I have incorporated these ideas into my own rendering pipeline. In this sample there's probably no falloff issue, since you rely on Multiply blend modes to hide elements. But this issue does appear when you take the light as a render target, and multiply it with another render target on a quad.

britzl commented 1 year ago

Thank you for the PR! Can you update it with the latest from master?

haath commented 1 year ago

Done!