In the game I'm developing, rooms can be of various sizes, which means I need to vary the size of the floor texture appropriately.
The way I've solved this problem is to generate a Texture2D programatically, and set each pixel to be transparent (or not) as appropriate appropriately.
I get something like this:

Where, if you look at the top left, you'll clearly see the pixel artifacts from the floor texture against the dark blue background.
When I run into this with static textures, the fix is simple. Set the Texture's wrapmode to clamp instead of repeat. But when I try to do that programatically... (and change nothing else!) I get this:

I'm not quite sure what's happening, or why setting the wrapMode changes the results so markedly. Anyway I can avoid the pixel artifacts? I suppose it's possible to add an extra border around the generated texture (so that all edges can be transparent), but that doesn't seem a particularly clean solution.
Code is here:
void DebugFloorTextureMerge()
{
//sizeVector makes up the rectangle circumscribing the room's parallelagram
Vector2 sizeVector = new Vector2(roomBounds.topRight.x - roomBounds.bottomLeft.x, roomBounds.topLeft.y - roomBounds.bottomLeft.y);
//get the texture of the filled sprite
Texture2D patternTexture = (Texture2D) floorTexture.image;
//make a new texture of the size of the room.
Texture2D fillTexture = new Texture2D( (int) sizeVector.x, (int) sizeVector.y, TextureFormat.ARGB32, false);
//COMMENTING THIS LINE OUT MAKES THE TEXTURE WORK WITH ARTIFACTS
fillTexture.wrapMode = TextureWrapMode.Clamp;
//LEAVING IT IN MAKES THE FOLLOWING CODE WORTHLESS
int patternX = 0, patternY = 0;
Vector2 pointVector;
Color transparent = new Color(0,0,0,0);
for(int x = 0; x < sizeVector.x; x++)
{
for(int y = 0; y < sizeVector.y; y++)
{
pointVector = new Vector2(x,y);
if(roomBounds.Contains(pointVector))
{
//get the next pixel
fillTexture.SetPixel(x,y, patternTexture.GetPixel(patternX, patternY));
}
else
{
//pixel was not in the room, so set it to transparent.
fillTexture.SetPixel(x,y, transparent);
//resultx = x; resulty = y;
}
//increment the pattern counter and reset if necessary.
//if you only increment this when Contains is true, you'll warp the texture
patternY++;
if(patternY >= floorTexture.fillSize.y) patternY = 0;
}
//increment the pattern counter and reset if necessary.
//also reset y, so the pattern will line up properly.
patternY = 0;
patternX++;
if(patternX >= floorTexture.fillSize.x) patternX = 0;
}
//set the PixelChanges.
fillTexture.Apply();
}


floorTexture.filterMode = FilterMode.Point)? \$\endgroup\$