Tile a cropped texture in atlas/texture grid

Hello, everyone.

I hope you can help me with this issue I’m trying to solve. I have texture grid with a few normal maps like so:

Now, what I want is to be able to crop one of these textures inside the material and then tile them as if they were individual textures. I can easily crop the texture using UV coordinates manipulation.

The problem is I don’t know how to tile this after. I’ve been told by some to use Clamp, but I’m not sure how that would work. When I try to clamp the coordinates, they just break.

Is there any recommendation you could give me to achieve this?
Thanks in advance.

i’m assuming you wanna do some form of detail normals? you gotta do some shader math to get the correct uvs for the detail map from an atlas.

the ideal solution would be to put them in a 3d stack or a slice array of 2d textures, so you can id them on the z axis and use the xy system for the uvs.

the z axis interpolator gotta be nuked. just thoughts.

1 Like

Agreed, separate textures sampled via an array is the way to go. But if you must atlas them in the same file, you can use a flipbook material function to easily break them apart or inspect it to see how it’s done.

Thank you. I did analyze the Flipbook material function and I managed to “extract” a version of what I wanted. However, now there’s another problem: seams.

Seams appear everywhere. I managed to minimize them a bit by using the ComputeMipLevels material function, but it’s not fully getting rid of them. At least now it looks good at a distance.

This is caused by mip mapping. Set the tex sampler to manually derive mip maps. This will add a ddx and ddy input. Use the ddx and ddy nodes with an unaltered coordinate node as the inputs, and this will fix the seams.
Essentially because your texture coordinate system is non-linear, you’re screwing up the ability for the automatic mipmapping to calculate the correct level.

Do you mean like this?

It doesn’t seem to be working as expected. The texture gets tiled in a weird way as you can see in the preview. Do I have to do it in a different way? Sorry if I misinterpreted what you said.

well… the filtering will never work unless you clamp the uvs and manually sample the other edge.

picture:

if you sample the orange region you have to take the samples from the blu edge. the default bilinear or anisotropic filter does not do that. it samples the edge pixel of the red lined texture. that’s what creates the seams. also… if you sample pixels in the blu region it will automaticly sample from the left most edge. default texture filtering with automatic repetition. not good for solid color atlases.

flipbook will not do that either. flipbook is more or less meant or vfx atlases like particle effects. the edges are usually not seen, due to transparency.

1 Like

Almost. You need to add DDX and DDY nodes in between the coordinates and the input.

The texture now appears as expected, but I still get the seams as you can see in this image with the material applied.

Any remaining seams will be from the issue glitchered mentioned when using automatically generated mipmaps, since the texture will de-res itself and blur into the neighboring textures. Its possible to fix this by manually creating your own mip maps, for example.
But again, the simpler way is to just create a texture array instead of an atlas.
You gain nothing that I can think of from using an atlas instead of an array.

1 Like

Thanks for the input and thank you to @glitchered as well. I will post my current solution for anyone who stumbles upon this thread at some point.

For those looking for a solution, do the following.

Create a new material function like in this image:

Then use it to input the UVs to your texture. In the Material Function’s UVs, pass it an already tiled texture coordinate for the desired tiling of the subtexture.

Set your texture sample’s MipValueMode to Derivative and pass it a Tex Coord through the DDX and DDY nodes to the corresponding inputs in the texture sample.

You can do both! Use a flipbook-texture as a layer inside a texture-atlas. Append to the regular flipbook output the layer-ID.

I use this for an animated raindrops layer.

And to the OP, yes, much easier to just pass a layer ID vs funky UV-math.

As an aside, there seems to be an incidental space-savings feature to texture-arrays as well, so there is that…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.