SFML community forums

Help => Graphics => Topic started by: Robustprogram on June 30, 2014, 06:54:30 am

Title: Light and Shadow Blending
Post by: Robustprogram on June 30, 2014, 06:54:30 am
I have a poorly pieced shadow system and I am just wondering how to blend both the shadows and light together as I have absolutely no idea how to blend it together. Any help will be appreciated :D
Title: Re: Light and Shadow Blending
Post by: Robustprogram on June 30, 2014, 07:11:19 am
Btw this is the best I could do with render Textures ...

I am hopeless XD
Title: Re: Light and Shadow Blending
Post by: Nexus on June 30, 2014, 08:02:05 am
What have you tried exactly?

Have you already had a look at existing libraries like Let There Be Light or GLLight2D?
Title: Re: Light and Shadow Blending
Post by: Robustprogram on June 30, 2014, 09:06:41 am
I tried to use the SFML standard blendmodes by having the lights get drawn onto a rendertexture with blendmode Add for the light and Multiply for the shadow. I then applied the rendertexture to a sprite and I draw the sprite with no other blendmodes.

Also I had a look at both libraries you posted but both of them use OpenGL and that is going to open up more problems as I haven't worked with OpenGL before and just ran into problems when I ran some tests with OpenGL.
Title: Re: Light and Shadow Blending
Post by: Nexus on June 30, 2014, 10:27:09 pm
I have not worked with those two libraries, but don't they abstract from OpenGL?

Also, there are meanwhile far more blendmodes than the four in SFML 2.1. Check out the latest master branch if you're interested.
Title: Re: Light and Shadow Blending
Post by: Lee R on July 01, 2014, 01:06:15 am
Simplest to implement:
http://en.sfml-dev.org/forums/index.php?topic=14154.msg99530#msg99530

Complicated but potentially more efficient:
Use the shadow geometry to clip the light geometry and accumulate the lights in a single render texture using additive blending, then apply that render texture to the scene using multiplicative blending.

http://www.redblobgames.com/articles/visibility/
Title: Re: Light and Shadow Blending
Post by: Robustprogram on July 01, 2014, 04:57:02 am
@Lee R. Holy crap, thanks for the tip as I have finally implemented a shadow system now :D
But speaking on clipping, how do we clip in sfml. One thing I was interested in was it possible to clip the area from displaying the light at all.

But still thanks for the example as it really helped me