Lantern image that pierces through other pictures

I already posted about this in the general MV support section but the more I think about it and tinker with it, the more I think I may need some plugin help.


Are there any existing plugins that would do this, or should I request a new one?


Basically, I'm making custom lights in our game. I'm trying to work out just the lantern right now but eventually, each map will have a "lightmap" of sorts on top of it depending on what time of day it is (dawn, morning, dusk, night, along with the four seasons) (of course, caves will always be dark). The player is able to use the lantern on any map at any time they want except underwater. So I'm going to have pictures on top of all of the maps that have lights all over the place, and in the same picture, a screen tone depending on the time of day (independent from the screen tone option in RMMV). I need the lantern to pierce through that picture. Any darkness, any light, that the player walks through, would be negated by a small circle of light around the player as the lantern.


There are two ways this could be done, I'm not sure which is easier or if one or the other has already been created and I've missed something.


1. If a picture is on top of another picture, it overrides it on a per-pixel basis. If the lantern picture is 99 and the lightmap is 98, wherever the player is the lightmap would be overrided by 99 and you would see straight through it. Of course, the picture would actually be in a plugin so that you could have pictures function normally if need be as well.


2. There is a light map, a lantern image, and an in-engine screen tone filter set. The lightmap and the lantern image both override the screen tone if there are pixels there.


It's a complicated request and it's been boggling my mind for a while. I know that the lighting plugins here use a darkness mask and the lights override that mask and show what's beneath it, and that's pretty much what I'm looking for, just a bit more customizable. As far as I know, you can't do directional lighting or shadows with them, and they don't allow (to my knowledge) turning off lights depending on the time of day/season, they are always on. Doesn't work with changing a fireplace depending on the season and such, as it'll always be lit even if the fire isn't on which is troublesome. I mean if anybody has a remedy to fixing that it would certainly be a lot easier than what I'm doing right now, but until then I need something similar to those plugins, but more simple, as to allow more creativity.


Thanks for all of your help guys. I really appreciate it.
Ahh, I know exactly what's going on with this. An interesting new thing with MV is that images are, in a way, put into layers. Each layer can be thought of as it's own bitmap, and thats what's actually drawn to the screen. When two things are drawn to the same layer, whatever was drawn last will overwrite anything it's drawn over.


An example of this are the windows, now. If you were to modify a scene to have windows on top of each other, they won't layer, but will overwrite each other. This can be fixed with a change to how many layers are used, but that requires changing default code to make it work universally. By default, all menu scenes add windows to what it literally calls the Window Layer. While it would potentially be an easy fix to get everything on its own layer, without testing and debugging it could lead to unexpected bugs and performance issues. It will probably cause the games to use more memory as it has to start managing many more layers. 
In XP (which is the only other one I've worked with so that's my only reference xD), as far as pictures go, if you put a picture A on 1, picture B on 10, and picture C on 30, then C would be above B, and B would be above A. But if you put D on 30, then C would cease to exist.


Does MV, then, make it so if you put two pictures on 30, the second one you put there will take over the first in just that area, or does it act exactly like XP? If it does act like XP in that regard, are you saying that if there were a way to put both images on picture layer 30 it would work that way?


As far as memory usage, I'm not sure if the lighting plugins take up that much more memory, I don't think they do but I'm not sure. They seem to work with the exact thing you're talking about, as in having both the lights and the darkness mask on the same layer but the lights will always overtake it and show what's below it (with a separate color for the light too, which is nice for differentiating between fire and natural light). Is that indeed how they work (I'm referring to Orange Lighting and Terrax Lighting BTW)? Because that's exactly what I'm going for, just with events and Show Pictures rather than a plugin so I can customize it a bit more.
I couldnt tell you how to do this in the Javascript / MV engine but I can tell you how to do it on the Ruby side.  Im hoping that things are similar enough that a similar process might be used in MV.


In XP / VX / Ace, create a new Bitmap that covers the screen.  I didnt create one that covers the whole map for performance.  Set the Blend Type to 2 for Subtract.  Use fill_rect to fill the entire bitmap with an RGBA color that you want for your "Shadow".  Now, because the Blend Type is subtract,you need to "Invert" your colors when picking a color for fill_rect.  Thus, if you want a solid black shadow, then your color would be Color.new(255, 255, 255, 255) which is actually white, but due to subtract inversion from Blend Type 2, your Shadow will now appear as Black.  Next, take a Graphic that you want to use as a Lightsource and get its bitmap and use a Block Transfer to draw on the Shadowmap itself.  You can do this multiple times and manipulate the position of the graphic to suit your needs.


In Ruby versions, although you can rotate a Sprite, you cant rotate a Bitmap.  All the images that are stored in the Cache are non rotated.  I am also working on a Dynamic Lighting system, but it is for XP.  One of the things that I did to enhance the functionality of my script was to create a custom DLL for rotating bitmap images, however, I am terrible at C++.  Now, if we are really really lucky, we might be able to use this DLL file to rotate Bitmaps in MV as well, but I highly doublt it will work.


In the end, you may end up with some very very nice looking effects, similar to what is shown in the following Animated Gifs:


LightInside.gif



PenLight.gif



PenLightH.gif



SpotLight.gif



You can download my Prototype Demo to take a look at the source code, which may or may not help since XP is ruby based and MV is Javascript based.  Concepts may be similar enough that it could be possible.




There are a few other ways to do this:


You could create a very large picture that follows the Player around and has a "Hole" cut out in the image itself.  The image there would end up being larger than the screen otherwise you'll end up seeing the edges of the Shadow Picture if the Player is not right in the center of the screen.


I would recommend researching how to use JS features that are similar to "blt" (Block Transfer) and "stretch_blt" (Stretch Block Transfer) as using a Lightsource to cut out a hole from a Shadowmap can allow multiple "dynamic" lightsources.
@Heretic86 Thanks for your response. Unfortunately I'm not a scripter by any means, I understand a little bit and I can change a little bit but I would have no idea how to convert all of that over to MV.


Like I said as well, I'm not really looking for something super plugin intensive. It doesn't really have to be dynamic either. I'm just looking for a way to use a light/shadow map as a picture overlay as well as a lantern, and have that lantern show through the shadows and lights of the picture. It's evident you can do that exact thing with Terrax Lighting for instance, but it doesn't have certain features that I could draw in with Photoshop (like directional light and shadows). Orange Lighting also lets Terrax Lighting work with the Orange Time System, which I am also using, but it doesn't have those features either and for some reason doesn't let your turn lights off depending on the time or day/season since the lighting of an event is all dependent on the notetag of the event and if it isn't parallel process or autorun it can't run the plugin command (using a comment would probably fix this, that's what had to happen in XP as I'm sure you're aware of).


I would use the "hole" method, which I tried originally, but then the surrounding area HAS to be completely black and you can't see lights if your lantern doesn't reach that far.
I'm away from my computer and never really tinkered with a lot of MV from the editor side, I've only really worked with the code and pictures is rarely something I look at, so I don't know the precise details of that, and I'm away from my computer right now. I'll try to remember to look at it sometime but try to remind me if I forget to for a couple days. 
@Zalerinian thanks a bunch 🙂  will do!
@Zalerinian if you have a chance to check this out please do, if not no stress 🙂
Sorry, I had forgotten to check on this earlier. Pictures are all added onto one layer, aptly named _pictureLayer, in Spriteset_Base in the createPictures function. Each picture is added onto the layer and so overlapping pictures will cause those below it to be cleared. For this to be fixed, a plugin would be necessary.


edit: @Prescott
Alright I'll request a plugin for it then. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/lantern-image-that-pierces-through-other-pictures.64969/