Adding a mask to a fog bitmap

I'm using my XP Style Fog script to add moving fog to a map. But I only want to see it in the low-lying areas, which means I need a way to mask or punch out shapes in the plane on which the fog is drawn.


Is that even possible? I can't do it to the bitmap itself, because it'll be repeated across the map, and the mask needs to be applied to a different part of the bitmap each frame because the fog is moving.
Could you use Unlimited Graphically Layered Maps and make a layer above the fog with the high-lands and whatever will be above the fog?
No, because the player needs to walk both below AND above the fog, as they climb higher into the mountains.
How about changing the z-value of the fog depending on the player's location, or using a switch or variable and setting the value appropriately using player touch events.


I would implement elevation and use something to specify the elevation of the map (like a height map) but that's really only practical if you're planning to implement really bumpy mountain ranges with multiple layers of elevation each with different effects.


If it's just a simple "high" or "low" kind of thing you could probably get away with just placing events or region tiles all over the place to adjust the fog sprite or however it's implemented.
I may know of one possible way though there may be easy ways.

If you have a paint program that has layer capiblity you could make an image of the each map you want to use.

Add a second layer over that with your fog bitmap in that layer.

on the first layer use something like a lasso select on areas you don't want in the fog layer.

back on second (fog) layer delete the areas you don't want.

After you have done this use Gaussian blur at very small setting to remove edges where you deleted.

Save the new fog bitmap something that would make you know which map it belongs too.

Then in your script you will need to check the map_id and have it assign which fog bitmap you want to use for that map. (Unsure about how to code this part but I believe I have seen scripts that can check the map_id).
If it's just a simple "high" or "low" kind of thing you could probably get away with just placing events or region tiles all over the place to adjust the fog sprite or however it's implemented.
Instead of placing events all over the place I think you could handle that with one event in each map setting it to parallel prossess with two variables one for player(map X) and one for player(map Y). Then use a script to show and hide the fog based on the players location (you could probalbly do this with events too). However doing this you would still have a fog bitmap that would show in places that you might want higher than the fog (like the tips of high mountains).
I can't do that - the fog is moving, so any cut-away areas would not stay where they need to be.


Changing the z value won't work either, because the fog needs to be displayed in front of some tiles, and behind others.


The best I can think of at the moment is using player touch events to reduce the opacity as you get higher. This MIGHT solve the problem for one map, but in imagining possibilities, I've already thought of 3 other maps where the same trick wouldn't work 🙁


I think this'll be a backburner project 🙁
Another way is to use the double-tilemap trick by creating a second tilemap and copying tiles that should be on the "upper layer" over, while drawing the fog in between the two tilemaps.

Upper map LayerFog LayerLower map LayerThen it would appear that the fog is moving over certain tiles and under other tiles, and you'd only have to deal with the moving fog rather than trying to figure out how to actually draw fog "behind" certain tiles like the fog rolling behind a tree instead of in front of a tree, which sounds incredibly complex because if you want to place parts of the fog image BETWEEN say an A-tile and a B-tile.You could probably use a static image for the upper layer as well if a tilemap is too expensive on performance.

Then figure out how to deal with character sprites.

Original thread: https://forums.rpgmakerweb.com/threads/adding-a-mask-to-a-fog-bitmap.18799/