Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Candle - 2D basic lighting for SFML  (Read 12797 times)

0 Members and 1 Guest are viewing this topic.

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Candle - 2D basic lighting for SFML
« 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
Full documentation: https://miguelmj.github.io/Candle

Sharing knowledge is a high human value!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #1 on: September 26, 2020, 09:28:16 am »
That looks really cool! :)

Hiw does it handle multiple light sources?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #2 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
Sharing knowledge is a high human value!

splavacado100

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #3 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!

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #4 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!
Sharing knowledge is a high human value!

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #5 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

Sharing knowledge is a high human value!

sidewinder

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Candle - 2D basic lighting for SFML
« Reply #6 on: February 17, 2021, 09:45:16 pm »
Looks nice! How many lights and light blockers can it handle?

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #7 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.
Sharing knowledge is a high human value!

KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #8 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?

MiguelMJ

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #9 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 .
Sharing knowledge is a high human value!

KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Re: Candle - 2D basic lighting for SFML
« Reply #10 on: March 24, 2021, 02:47:01 pm »
That sounds pretty cool, i should check it out.