Using images as an alpha mask

I'm looking for a script that allows you to treat a picture as an alpha mask.


For example, you take a black and white picture and then you place it over another picture. Any parts of the picture covered by black pixels in the mask will be rendered transparent and any parts of the picture covered by white pixels will be fully opaque. Any shade of gray in between would be used to determine partial opacity.


The script should allow me to control what picture the mask should apply to.


Preferably, this masking can be done in real-time without noticeable delays: if I move the mask around, you should see different parts of the picture appearing and disappearing.


Is there such a script?
IDK of anything like that in existence, though you could possibly do a pixel by pixel color check on the mask. 

Another possibility is to have a dark layer between the actual image and the mask, show it using negative blend mode the same with the mask, using black to show the most opaque. Not sure if this could work though, but it's the approach used by lighting systems to put holes into the dark layer. 
That is definitely going to need a DLL. No way that I can think of to do that generally lag free.
I figured the processing would need to be done outside of Ruby.


I was hoping there was some trick that I could use with the existing blend modes and sprite opacity settings to accomplish mask behavior like what Adik mentions.


I'll try the subtraction again and see if I can get anything to work there, but when I think about how it works, subtracting white pixels simply removes all color, so if you wanted to make things darker that would be an appropriate solution. An analogous solution is available to make things brighter by using addition.


But I think alpha masking couldn't be achieved using color masking since it doesn't deal with opacities?
The idea was to have a dark layer between the image and the "mask", in which the mask will simply reduce the opacity of parts of the dark layer... Like basically just applying the technique used by lighting scripts into the image. It will be pretty laggy from my experience though.
Is that how it works?


I'll have to look at it again then.


I didn't think blend mode was related to opacities but maybe they just combined it together (like how they do audio pitch...)


Oh but what if you mixed opacity and blend mode together...
That's how it seems to work, as long as the blend mode is negative (or was it subtract or something? anyway, the blend mode that isn't normal or add). You create a new sprite, create a dark bitmap for it with a negative blend mode, then blt/stretch_blt the "light" images into the positions that need to be not-dark.

Oh but what if you mixed opacity and blend mode together...
Never tried using opacity on the "lights", just on the dark layer... So I don't how what will happen. XD
I'd like to see how you do this, if you manage to get it working. I've wanted to use a mask on fogs but could never figure out how to get it to work without resorting to pixel comparison, which is just nasty 🙁

Original thread: https://forums.rpgmakerweb.com/threads/using-images-as-an-alpha-mask.36119/