MV River mixing into poison swamp

I'm working on a map where a river (grass maze) joins a poison swamp, but as far as I know there's no autotile or anything that can seamlessly connect the two together.

Here's the section of the map, cropped to align to the tile boundaries:

temp1.png


I need something that will work in that layout. An autotile would be great, of course, since it's more generically useful and would allow me to tweak the layout later if I wanted to; but simply editing the transition directly into the above image to produce something that can be added as a special case to the A5 or B sheet, or even as an event placed on top, would also be acceptable.

Note: The water in the above image is an animated autotile, and I was considering trying to animate the swamp too (I already moved it into the A1 sheet, but haven't yet gotten to transferring the animated bubbles from World_A1), so it would be cool if the transition could also be animated. However, I can make do with a non-animated one.

EDIT: I would like to note that the precise location of the boundary between swamp and water does not need to be exactly as in my posted image. In fact, it may look better if you see the water flowing around the corner a little. Think of it as the current flowing down and to the left – the water is flowing in from the top, the poison is flowing in from the right, and the mixture is flowing out to the left.
If you don't mind a bit of drawing with PIXI Graphics and layering and assuming you are only doing this for visual purposes (doesn't damage the player, etc), you could go this route (and since the water is already autotile, the animation stays on there):
s1.png


You can increase the blur if you want as well from 12 to 16 and/or the quality of the blur from 4 to 8 for a better transition. (example: new PIXI.filters.BlurFilter(16, 8))

s2.png


This is just the script call to call the function at the beginning of the map.

s3.png


Here is where the event is located since the PIXI Graphic is anchored to this event's sprite location.


Edit: If it is just the very small area where the tiles meet that you want to have the transition point, you should be able to blur that area a bit. I don't have any poison swamp tiles that can connect with the normal water. I'll do a bit more testing and report back.
That's an interesting idea… for this map I actually made the swamp impassable (it's supposed to be more a river of toxic stuff), so it doesn't damage the player. The blur in your example doesn't look great, but it's at least a bit better than a hard line.

It looks like that does lose a few things though:

  • The bubbles
  • Opaqueness of the fluid (you can now see the ground below it)

Which I guess is obvious from the fact that you're dynamically modding the water rather than using the poison swamp tiles.

EDIT: I would like to note that the precise location of the boundary between swamp and water does not need to be exactly as in my posted image. In fact, it may look better if you see the water flowing around the corner a little. Think of it as the current flowing down and to the left – the water is flowing in from the top, the poison is flowing in from the right, and the mixture is flowing out to the left.

(Since that's actually a pretty important detail, I edited it into the opening post as well. Good thing no-one came along and made an edit where it's flowing right…)
That's an interesting idea… for this map I actually made the swamp impassable (it's supposed to be more a river of toxic stuff), so it doesn't damage the player. The blur in your example doesn't look great, but it's at least a bit better than a hard line.

It looks like that does lose a few things though:

  • The bubbles
  • Opaqueness of the fluid (you can now see the ground below it)

Which I guess is obvious from the fact that you're dynamically modding the water rather than using the poison swamp tiles.

EDIT: I would like to note that the precise location of the boundary between swamp and water does not need to be exactly as in my posted image. In fact, it may look better if you see the water flowing around the corner a little. Think of it as the current flowing down and to the left – the water is flowing in from the top, the poison is flowing in from the right, and the mixture is flowing out to the left.

(Since that's actually a pretty important detail, I edited it into the opening post as well. Good thing no-one came along and made an edit where it's flowing right…)
I had an old function somewhere that allowed me to change tiles and take a quick snapshot of the area where the tiles were and then change back - not sure on the speed of it but it might work. I could also create a new layer from there and then blend it into the water.

Or, I could just index and get the tile directly and draw it into its own bitmap and add it to the scene.

Currently busy but will check out when I get back home.
Alright, this is what I have so far. Is it worth it? Considering I had to write new functions/methods to:
- find the normal water tile ids
- save the tile ids and the tile positions from the array
- replace the tile ids with the poison tile ids
- take a bitmap map screenshot that is specific to the area in question
- replace the poison tile ids with the original water tile ids
- add a gradient mask to the bitmap screenshot of those tiles
- add everything to the scene to create the proper grading of the fade between the water tiles and the poison tile bitmap image

... Not sure if it is worth it. It is doable though! haha.

@bass2yang I'm considering whether a variation on this approach is worth it, but I'm not even 100% sure what you did.

- find the normal water tile ids
- save the tile ids and the tile positions from the array
- replace the tile ids with the poison tile ids
What does this mean, exactly? Is this something you did in the console to figure out the exact data to plug in, or is it something that would go into a plugin file?

- take a bitmap map screenshot that is specific to the area in question
- replace the poison tile ids with the original water tile ids
Based on this, it sounds like you:

  1. filled the area to be blended with swamp tiles
  2. took a screenshot
  3. filled the same area with water tiles instead

Is that correct?

- add a gradient mask to the bitmap screenshot of those tiles
This phrasing makes it sound like you edited the image in an image editor to make the alpha channel be a gradient, but that doesn't fit with the fact that I can see the alpha mask in your video. Is there a good reason not to do that? I can't help wondering if that would make things simpler, but on the other hand, in your previous post you were using a blur function, so I'm not sure if it's the same.

- add everything to the scene to create the proper grading of the fade between the water tiles and the poison tile bitmap image
Does "add to scene" refer to adding an element in code, or placing and configuring an event in the editor?

Also, I have now animated the poison swamp as well. Does that cause problems for your approach? Maybe I'd need 3 screenshots, one for each animation frame?

Lastly, would you mind posting some of the code as text, rather than screenshots? That way I don't have to carefully type it in to try it out.
Yeah, it probably wouldn't work the way you want with what I was doing.

You can use $gameMap.tileId(x, y, z) to get the tile id of the specific tile on the map. X and Y are the coordinates and z is the layer index.

I actually am drawing the gradient inside the canvas using code instead of making a graphic with a graphics editor like Aesprite/etc. The blur function was just a quick way to see if it would work since we were just adding a layer of "purple" to the water instead of using the actual poison tiles.

I think the function I wrote for the gradient would be the only thing worth exploring - everything else just complicates it further and probably isn't practical, especially if you have the tiles animated. If not, then my apologies for not being able to help out much more in this area.

This is the gradient you see in my video (in terms of the mask, black is transparent, grey is a mix, and white is opaque):
JavaScript:
function createGradient(x, y, width, height) {
    const bitmap   = new Bitmap(width, height);
    const canvas   = document.createElement('canvas');
    const ctx      = canvas.getContext('2d', {willReadFrequently: true});
    const gradient = ctx.createLinearGradient(0, 0, 0, height);
    canvas.setAttribute('width' , width );
    canvas.setAttribute('height', height);

    gradient.addColorStop(0.25, 'black');
    gradient.addColorStop(0.65, 'gray' );
    gradient.addColorStop(0.95, 'white');

    ctx.fillStyle = gradient;
    ctx.fillRect(x, y, width, height);

    const c = ctx.getImageData(0, 0, width, height);
    bitmap.context.putImageData(c, 0, 0);

    return new Sprite(bitmap);
}

If you want to see the gradient in the scene, you can add it by using:
JavaScript:
const scene = SceneManager._scene._spriteset;
const sprite = createGradient(0, 0, 192, 192);
scene.addChild(sprite);

Example:
To use it as a mask, we can test it out on the player's sprite:
JavaScript:
const player = SceneManager._scene._spriteset._characterSprites.find(c =>
    c._character === $gamePlayer);
const sprite = createGradient(0, 0, 48, 48);
player.addChild(sprite);
sprite.anchor.set(0.5, 1);
player.mask = sprite;

You can make this gradient any size and add as a child to any sprite/picture/container/etc and also use it as a mask.
Hmm… it seems like this approach probably would not work too well for me then. It does give me a few ideas, but they're mostly more complicated, so I'm not sure if I'll get to them. I guess this does give me something to fall back on if I can't work out anything better…
What kind of transition do you want? Do you want them to blur together? What about a little waterfall foam? The idea I had was to copy the deep water tile, remove the deep water and lay it over the swamp, and let the light water border be the transition.
That's a good question, and I'm kind of unsure. I think a simple horizontal line transition, even blurred, isn't that great, though it's better blurred than not. The idea would be that they're meeting and mixing together, and the mixture (predominantly poison) is continuing on to the left. I'm not really sure what that would look like; I have this vague image of "fingers" of one fluid reaching out into the other, but I'm not sure if that even makes sense.

The idea I had was to copy the deep water tile, remove the deep water and lay it over the swamp, and let the light water border be the transition.
This is definitely not like the vague image I have in mind, but it's probably better than a hard line… and I suppose it could maybe make sense (physically speaking) if the toxic fluid is a lot more viscous than the water…
It seems like making what I actually envisioned is a lot of work for minimal gain, so I decided to just cover up the hard edge with the waterfall effect. This is the result:

temp.png


Since I now have 2 more areas with a similar boundary, it's helpful that I came up with a general solution.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/river-mixing-into-poison-swamp.179860/