SFML community forums

Help => Graphics => Topic started by: Allptraum on August 09, 2016, 06:35:31 pm

Title: Only render Parts of a sf::sprite | Light sources?
Post by: Allptraum on August 09, 2016, 06:35:31 pm
Hey. I want to implement light sources in my game. I want to lay a complete blank sprite (exactly the window size)
over the game.
Is it possible to create masks for the light (like a white circle wich fades out) as a texture and to say, that the black sprite wont render over the lightmasks? (i dont mean with the intersect function. the pixels of the black sprite wich doesnt cover the mask should render).

I'm open for other ideas to implement light sources.
Title: Re: Only render Parts of a sf::sprite | Light sources?
Post by: DarkRoku12 on August 09, 2016, 08:05:49 pm
If you want to render a part of a texture dynamically you need to use shaders.

Check the sf::Shader (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Shader.php) class and the sf::Shader tutorial (http://www.sfml-dev.org/tutorials/2.3/graphics-shader.php).

You also will need a shader tutorial (http://www.google.com/search?q=fragment+shader+tutorial).

Or try to implement LTBL/LTBL2 (http://en.sfml-dev.org/forums/index.php?topic=16895.0).
Title: Re: Only render Parts of a sf::sprite | Light sources?
Post by: Hapax on August 12, 2016, 04:03:59 am
You may also find using sf::BlendMode (http://www.sfml-dev.org/documentation/2.4.0/structsf_1_1BlendMode.php) useful. It can be used to blend/overlay during drawing or used to cut/crop using a render texture.

If you draw a black rectangle containing a white circle using BlendMultiply, it will leave the circle part as it was and change the rest to black.

Maybe using a the Radial Gradient Shader (https://github.com/SFML/SFML/wiki/Source%3A-Radial-Gradient-Shader) will help if you're looking for smoother light/spotlight masks.