SFML community forums

General => SFML projects => Topic started by: MiguelMJ on September 26, 2020, 03:04:52 am

Title: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on September 26, 2020, 03:04:52 am
Candle - 2D lighting for SFML
Hello! I recently created a library implementing some basic algorithms of shadow casting and field of view. It is easy to integrate, it has no dependencies other than SFML itself and it's open for further development. The code comes with a demo to test the main features, which are dynamic lights, fog and shadows. Any feedback is appreciated, thank you!

Code: https://github.com/MiguelMJ/Candle (https://github.com/MiguelMJ/Candle)
Full documentation: https://miguelmj.github.io/Candle (https://miguelmj.github.io/Candle)

(https://raw.githubusercontent.com/MiguelMJ/Candle/master/doc/img/demo.gif)
Title: Re: Candle - 2D basic lighting for SFML
Post by: eXpl0it3r on September 26, 2020, 09:28:16 am
That looks really cool! :)

Hiw does it handle multiple light sources?
Title: Re: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on September 26, 2020, 02:23:58 pm
Each light source cast its light independently against the shadow casting segments and borders of the area, to calculate the area they iluminate.

Then they pierce the fog with an alpha substracting blending mode and then are drawn with the Add blend mode. This way, different light source actually accumulate.

But all of this happens under the hood, the different lights integrate seamlessly with a single draw call!  ;D
Title: Re: Candle - 2D basic lighting for SFML
Post by: splavacado100 on December 11, 2020, 03:44:58 am
This looks amazing, I hope you don't mind if if I use it for my game haha. Once I get I better grasp of how it works, I'd love to help contribute to it with the different lights and more realistic lighting and such. Really cool stuff!
Title: Re: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on December 18, 2020, 12:12:46 pm
Of course! Use it how you want. You don't need to give credit, but it would be appreciated anyways  ;D. Right now I can't work much on it because of university  :-\  but I can review pull requests and answer issues. When I have some time I'm definitely going to get back to work on it.

And thanks!
Title: Re: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on February 16, 2021, 11:43:23 pm
I'm glad to announce that the next version of Candle is here! Candle v1.0 is a complete revamp of the original one, with even easier integration, new light types and more customizable light sources and fog areas. It is also better optimized. It also has more and better documentation and a series of tutorials to make it easier to use.

Source code: https://github.com/MiguelMJ/Candle
Official documentation: https://miguelmj.github.io/Candle
Tutorials: https://miguelmj.github.io/Candle/tutorials.html

Title: Re: Candle - 2D basic lighting for SFML
Post by: sidewinder on February 17, 2021, 09:45:16 pm
Looks nice! How many lights and light blockers can it handle?
Title: Re: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on February 18, 2021, 05:25:16 pm
It depends on the disposition, as lights with a lot of edges (light blockers) in range would have larger computations to perform. I've not done exhaustive testing, but I know that it can handle several dozens of each one without problem.
With the demo program you can test the performance in your own machine, btw  ;D.
Title: Re: Candle - 2D basic lighting for SFML
Post by: KRS on March 20, 2021, 10:31:25 am
Hey that looks cool. But can i choose refresh rate of the light? For example make it update 10 per second?
Title: Re: Candle - 2D basic lighting for SFML
Post by: MiguelMJ on March 24, 2021, 01:23:39 pm
To update the light you call castLight, so you can refresh it whenever you want. If you don't want to do it every frame, you could use a timer with sf::Time and sf::Clock, for example  ;D .
Title: Re: Candle - 2D basic lighting for SFML
Post by: KRS on March 24, 2021, 02:47:01 pm
That sounds pretty cool, i should check it out.