Building light map from primitives worked great on small scale, but the only problem is drawing darkness to fill everything around.
You could use a "post-processing"-style setup and draw to an intermediate step and then draw all the light stuff together at once.
This would be something like:
- create a render texture that covers the entire part you want to draw (likely just the entire window but this can be modified e.g. if you're using double-pixels, you could use a half-size rendertexture)
- fill it with black (that's all the dark parts sorted right away!)
- draw your lights to the render texture (can be coloured but white is normal light; can also have transparency and likely should to allow overlapping lights), adding them together (blendmode: add)
- draw the render texture to the window with some sort of filter (blendmode: multiply is the simplest but a shader may do a better job if you use coloured lights)
Worked like a charm, code is bellow so others can use it. Colors seems to be fine too, but I'll need to create something like campfire to test it for sure. Do you have snippet/manual for that shader so I can compare the results?
int main()
{
sf::Vector2f resolution = { 500, 500 };
sf::RenderWindow window(sf::VideoMode(resolution.x, resolution.y), "LightExample", sf::Style::Close);
sf::RenderTexture texture;
texture.create(resolution.x, resolution.y);
sf::CircleShape light(80.f, 8);
light.setFillColor(sf::Color(250, 250, 250, 250));
light.setPosition(250, 250);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
return 0;
}
}
texture.clear(sf::Color( 0, 0, 0, 250));
texture.draw(triangle, sf::BlendAdd);
sf::Sprite renderTextureSprite(texture.getTexture());
window.clear();
window.draw(renderTextureSprite, sf::RenderStates(sf::BlendMultiply));
window.display();
}
}