I’m trying to implement the Marching Squares Algorithm to reproduce the Oxygen Not Included style terrain bumps. In order to do this, I am using a tilemap where each tile has a sprite that has its TextureCoordinates adjusted depending on where it is in the world, so it will look like one continuous object (as shown in ONI). Then, to apply the bumpy edges I am using a mask and multiplying the color of each pixel by the mask. To make a black edge the mask has black color, to remove the texture the mask is transparent, to keep the texture the mask is white.
There are several ways to apply a mask though, and I’m nervous about performance problems with all of them and trying to pick the best one before spending the time to implement them completely.
The Blend State/Function only works if the render target has nothing else on it, otherwise I will subtract out previously drawn stuff. This means I would have to switch render targets for every texture that I want to do this for. 10-15 target switches seems bad.
The other way to do this would be a pixel shader so the mask can get applied to the sprite before it gets drawn. While I can accomplish this with a single shader, I don’t know how to switch the mask TextureCoordinate that the shader is using for each sprite while batched. If I switch to SpriteSortMode.Immediate, then this is easy, but it would be a big performance hit.
Is there a performant way of doing either of those two solutions?
Are there other solutions?
Related:
Oxygen Not Included Tiling
Oxygen Not Included. Notice how they have a continuous texture that they have subtracted from, and then for different textures, just render on top of each other.
My testing mask: