SFML community forums
General => SFML projects => Topic started 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)
-
That looks really cool! :)
Hiw does it handle multiple light sources?
-
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
-
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!
-
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!
-
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
-
Looks nice! How many lights and light blockers can it handle?
-
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.
-
Hey that looks cool. But can i choose refresh rate of the light? For example make it update 10 per second?
-
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 .
-
That sounds pretty cool, i should check it out.