# How to layer multiple terrain tile types using Marching Squares

I've done a lot of research on marching squares, including:

But I just can't seem to get my head around it for some reason.

A few questions I have just while going into the algorithm:

• Are the "blending"/"marching square" tiles the same size as the original tile?

• Do the "blending" tiles overlay the tiles POST the original render/draw? (I assume there would need to be a transparent portion of the "blending" tile for this to work)

• The second displaced grid is just completely confusing to me, is that the location where the "blending" tiles would be placed? I thought the "blend" would just be placed at the intersection (so that 1 tile "invades" the other).

Additionally, I was confused about how this would work if there were multiple terrain types.

For example, If I were to have 3 terrain types and they were laid out like this:

0 2

1 2


Where the overlap is 2 -> 1 -> 0. I believe the way I would code this is so that the 1 overlaps the 0, and then the 2 overlaps the 1 & 0. So, if I had 128 x 128 pixel tiles, I would need 32x32 blending tiles for this to work.

The "2" overlap would also end up overlapping 2 of the 32x32 "1" tiles, but I suppose I could just not draw those if they look weird..

The other option I thought of was to simply ignore either the "0" or "1" tile, and have them be converted so that only 2 different tiles could ever sit next to each other..

• Your question about grid offsets sounds like it might be helped by checking out this talk from Oskar Stålberg, where he explains the benefits of thinking about your tiles using the "dual grid". Feb 3, 2022 at 23:51
• Please let me get more details: 1) Do you understand how Marching Cubes or Marching Squares works, in general? 2) Do you need a C++ code? 3) Are you looking for the 1D outlines that encompass the regions with measure 3, measure 2, measure 1, etc.? 4) Are you looking for the 2D triangles that encompass the regions with measure 3, measure 2, measure 1, etc.? I have an existing code, but it doesn't quite do what you want: github.com/sjhalayka/Marching-Squares Feb 4, 2022 at 1:08
• @shawn_halayka 1. I'm not sure if I understand, that is why i asked those 4 questions. I haven't looked into Marching Cubes, I'm trying to do 2D terrain blending with several different tiles, so only require Marching Squares. If you do have existing code that does 2D terrain blending using Marching Squares (Important it would need to be 3+ adjacent tile types, not 2), that would be helpful Feb 4, 2022 at 1:38