Tiling a tile from texture atlas to a quad of a bigger mesh?

Basically the same as the title.
I have a system that generates a mesh from a 3D grid and optimizes the number of vertices by combining quads with same tile type. Something like a minecraft chunk generation. But the tile texture is stretched over the quad, and is not tiled properly.

I cant just use tile and offset node in shader or use default tiling settings of a lit material because the material uses a Texture atlas and as far as I understand tiling just scales UV and as a result it will point on a different tile texture of a texture atlas.

How do I fix it?
Here is a reference:



The atlas is a 256x256 image and the rest of it is white for future tiles.

To anyone curious I found a solution. Just use Texture2DArray instead of regular Texture2D. I also use vertexColor channel to keep info about the size of a quad. So the final shader looks like this: