Solarus Forum

Solarus => Development => Topic started by: Porksteak on June 01, 2018, 05:43:21 am

Title: how can you draw similarly to the light_manager
Post by: Porksteak on June 01, 2018, 05:43:21 am
How can you make a drawable while using the light manager? Basically what I want to do is have a dark room, and rather than lighting a torch making the room lit, it would make a circle of light surrounding the torch. How can I do this?
Title: Re: how can you draw similarly to the light_manager
Post by: Diarandor on June 01, 2018, 03:04:19 pm
1) With shaders, when Solarus v1.6 is released,
or
2) With a black surface that has a (semi)transparent circle in the middle.
Title: Re: how can you draw similarly to the light_manager
Post by: llamazing on June 01, 2018, 03:50:36 pm
Light manager? Is that script someone wrote?

What you want to use is blend modes, specifically the multiply blend mode.

If you think of black as a value of 0 and white as a value of 1, if you multiply any color by black it becomes black and if you multiply by white it is unchanged. Shades of grey will thus darken the image where the closer to black it is the darker it will get.

So then start with a black surface (or perhaps dark grey if you still want the darkened part of the room to be slightly visible). Next you'll want to draw white circles wherever a torch is visible. You have two options here:

Then all you have to do is draw that black surface with white circles overlaid on top of the game's surface, and be sure to use the multiply blend mode. Regardless of which option you used above, the result will be the black surface will have black pixels at the darkest spots, white pixels at the brightest spots and shades of grey in between. The best option would be creating a menu to draw the black surface on top of the game surface.

The tricky part is updating the image as the player moves. Once again you have two options:
Title: Re: how can you draw similarly to the light_manager
Post by: Diarandor on June 01, 2018, 04:56:06 pm
Yeah, I forgot option "3) Using blend modes."

It is not announced yet, but std::gregwar (who is developping shaders) made some experimental shaders allowing several dynamic light sources with shadows on the hero (and other entities). It works also with moving light sources, and looked awesomly awesome. Those shaders will be usable with Solarus v1.6 when he shares the code.