How do I fill the "empty" space in a material from a downscaled, non-tiling (clamped) texture?

Tried searching for an answer but depending on the search terms I used I primarily found topics about the Clamp material node, or how to make tiling textures look like they aren’t tiling, neither of which is what I’m after. I’m not the best at explaining so I’ve also supplied a picture of what I’m trying to achieve.

I have a texture that in which I have set the X- and Y-axis tiling methods to clamp. This seems to work as the texture does not tile when scaled down in a material. However, when scaling down a texture so that there is no “empty” room on the texture sample it seems to fill this with the color value of the closest pixel (or a process similar to this). Is there a way to either directly define what it should fill this void with, or otherwise determine what parts is and isn’t actual texture data to generate a mask?

Basically I want to generate blackness around it. Here’s an image showing what I have gotten so far, as well as a mockup of what I am trying to achieve.

Easiest way is just to make that texture ( the one you have in the bottom picture ).

Thanks for answering!

Sure, I could do that and it is the easiest way I suppose, but it kinda defeats the purpose of doing this all programmatically. Also makes the system significantly more inflexible as I would have to manually create multiple textures for various grid size (NumTilesX and NumTilesY) I end up using, as well as compensating for using multiple textures at multiple sizes if those values are modified in runtime via dynamic material instances.
[HR][/HR]
I’d assume that there would be two ways of going about this without resorting to baking it into the texture: Either finding a way to tell it “if you don’t have pixel data for this, make it black”, or being able to “measure the size of this texture scaled down, create a separate mask with a black background but a white square the size of the scaled down measurement”.

Check preserve borders mode for mipmap generation. Otherwise, directly in material, check when UVs are outside of 0-1 range and multiply output of texture by zero, if so.

Thanks for your answer Deathrey!

Interesting. Didn’t know about the Preserve Borders checkbox. Did try it out, although it ended up not making much of a difference. With that specific texture it just made everything around it white, so I switched to another texture with a bigger color difference to check. Still uses some kind of closest color (just a different algorithm I suppose) to fill the empty space.

Now getting a specific UV range seems like a much more viable method. Seeing as I scale down the texture, the areas that need to be blacked out are inside the 0-1 range, but I presume it is simply a matter of changing the input of the appropriate nodes to match the necessary UV range (i.e. 0-0.25 instead of 0-1). Don’t know why I didn’t think of multiplying by zero, but that should work.

Apologize for being a bit dense when it comes to this, materials are not my strong suit (but I am trying to learn): How would I go about doing the isolation of an UV range in such way? I’m looking at various nodes and experimenting to see if I can find anyone that does the job, but still can’t make heads or tails of it.