Hello,
I recently tried to write simple light system and after hour of very satisfying prototyping I encountered a problem which I can't solve to this day.
My idea was to create completely black, opaque mask (default state, darkness) and for each light create one render texture. At the end I would have to combine everything and just draw on top of game. Simple enough, I prepared lights (gradient circle with opaque color in the center and the same color, but transparent on the edges), and drew them on transparent masks. Places blocked by obstacles I made transparent again. After combining everything with standard sf::BlendAdd result looks very promising (first attachment) but it doesn't show any background. Ok, it's completely understandable, 255 is opaque so adding can't give transparent mask. I changed blend mode to reverse subtract
sf::BlendMode masksCombining = sf::BlendAdd;
masksCombining.colorEquation = sf::BlendMode::Add;
masksCombining.alphaEquation = sf::BlendMode::ReverseSubtract;
finalMask.draw(maskSprite, masksCombining);
and opacity works perfect, but it changes vivid colors into Tim Burton works... Also high intensity of light causes colors to whiten.
And this is the problem I can't get around. I've read a lot about blending, tried multiple permutations of factors and equations and nothing. I just can imagine how it should be done to preserve colors and change opacity at the same time. Maybe I should change default masks colors to different values? If this is the solution, what are these values?
I'm looking forward to your respones,
frogi16