Create a simple circular light effect (2D, no OpenGL)

I want to create an effect of a circular light - no projections, no OpenGL, thank you - in my game, much like the Zelda:

I was able to create the effect with a single light source. I have a dark surface and one with a transparent gradient circle that I blend on the first using SDL_BLENDMODE_NONE, then I blend the dark texture into the screen:

The problem is that, when I have two of them, the intersection if mixed:

So, my idea is to create an image with a white circle using gradient to transparent, and subtract the alpha, in my black surface, from the white pixels in the image.
But I could not figure out how to do that. I tried different combinations of custom blend, and still I am unable to do so.

So, in short my question is:
Given a dark texture, I want to use custom blend to make transparent all white pixels from a second texture, respecting its alpha level. Do anyone knows how to do that?

Thanks in advance.

For this, you only to draw the light once. You draw the lights to the black overlay that has SDL_BLENDMODE_MOD for its blend mode and SDL_BLENDMODE_ADD for the lights. When you are done with all your lights, just render the black overlay last.

1 Like

Works like a charm. Thanks a lot.

1 Like