• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Creating 'lighting' with blend modes?

R

Rosieu

Guest
Hi again everyone!

I'm not entirely sure this is the correct spot to be asking this, but it seems like my best bet, so apologies if I missed the appropriate spot for this thread! :)

I was wondering if there is a way using blend modes and the draw function to create a 'lighting' effect? It's something I have seen done before (and done myself) on Photoshop, and something I have done in Scirra's Construct 2, but I haven't been able to pull it off in gamemaker as yet?

Basically, I'm looking for a way that allows a sprite to be drawn in such a way, using a blend mode, so that it kind of 'negates' black wherever it overlaps it. Anywhere / any items not in the corona of light would thus be black, while anything within the light would be 'illuminated' and thus show their proper colours, etc.

Sorry about how brief my question is, I don't exactly have any more info to add, I'm kinda fuzzy on how to approach the entire issue, so any help is greatly appreciated! :)

I hope you all have a great day!
 

CMAllen

Member
Yes, but you need to rethink the way you're creating the effect. bm_subtract is quite literal in its design. Subtracting a white, fully opaque pixel from anything will result in a black, fully transparent pixel. bm_add does the opposite. A black, fully transparent pixel adds nothing to the final pixel. So, to 'block out' and apply shadows to your application surface (like a night-time effect), you could draw your 'lighted areas' in their inverted color values (so for the final lighted area to have a red hue, red would be 0, while green and blue would be 1) to a transparent or opaque white surface, then draw that surface in bm_subtract to the application surface. The white areas are subtracted, resulting in black, the lighted areas remain unchanged or take on the hue of their intended lighting color. And the alpha values don't matter, because the application surface does not have an alpha channel.

Note: other advanced blend modes can simplify the process, but they are not universally supported across all platforms.
 
Top