Finding textures within a texture atlas

Hello,

I am having some issues with texture atlases. How exactly do you tell a model that its texture is on a certain part of the atlas? Can or should it be done with a script, or is it a matter of exporting the model with its UVs already in the right place, instead of always exporting in the standard U1V1 space?

Thank you

I don’t know a way to do that in Unity although maybe it is possible. I take it into Maya LT and highlight the area I want to see in the UV editor and then move it or whatever I need to do with it. You could do it in Blender as well.

Right, and within unity, how exactly do you specify the range of a texture atlas? Say, for example, for a 4x4 atlas in UV space, how do you tell the engine that you want that square to be fitted to that UV range? Every time I tried it always sets it to the 1x1 space regardless, so how is that dealt with? Would setting the tiling to 0.25/0.25 on that 4x4 atlas be the proper way to do it?

Totally out of my experience. lol

I make models with a modeling program, UV them with the modeling program, use the proper UV space, send them to Unity and they work. I imagine you need to just do your models in another program.

Tiling has to do with how many times the texture is tiled.

Are you making models or are you trying to UV textures within Unity? I am 99% sure you have to do that in a modeling program.

Maybe I didn’t explain myself clearly enough. I will try to rephrase what I meant.

Imagine I have a texture atlas, an 8196x8196 texture, that contains 16 different textures, for 16 different objects that use the same material. So, you have 4 rows of 2048x2048 textures in a single image that was put together in photoshop.

If you take a texture like that and apply it straight to an object, all of those 16 textures will be projected onto the first square in UV space. It makes sense, since all the computer sees is a square texture, and by default, it will assign that square to the U1V1 square, like it should. However, your object will look like a mess, since all of

However, if you go in the material options and set the tiling to 0,25/0,25, the texture will take up 4x more space on each axis, so, whatever texture is at the bottom left corner of the big 8K texture will be projected correctly to the object, as long as that object’s UVs are in the deafult UV space.

What I am asking is this:

Is this the way a texture atlas is supposed to work? Adjusting the tiling, then, altering the position of each object’s UV shell in Max, Maya, or whatever, and applying the same material to all objects that use the atlas’ textures? It does in fact work, I have tested it, but I am not sure if this is the right way to do it, or if using this method, the 8K texture is loaded for every single object.

Or, is there a way to tell where in the texture atlas a certain object’s texture is, via script, without changing each object’s UV shells’ position in Maya, and without adjusting the tiling parameter? Am I even supposed to pack the textures together externally, or should that be done in Unity as well, via Texture2D.PackTextures ?

Thanks

You have to create the UVs in a modeling program and place them on the correct texture. That is the only way I know how to do it and I would be amazed if you could do that in Unity alone.

I am wondering if you are looking at the UV and seeing four squares and thinking you can put everything in all four squares. You need to put it in the upper right corner. If you put it somewhere else, it won’t work. Your entire atlas needs to go where this one is going in the example below.

So, take your model into Maya or whatever, use the edit UV options, highlight the UVs you want to move, then using the tools, move the UVs on the edit UV window. Put them where you want them, check your model to make sure they look good, then scale or move again until they look right to you.

If your model does not already have UVs in place, you need to create those in the 3d modeling program. Every one is different…In Maya, I highlight the area, such as a wall or a window or the entire model if they share a texture, and then use the appropriate method to create the UV, planar if flat, cylinder, automatic, etc. The UV’s are created and they you do the above to move them to the appropriate place on your texture. Make sure you assign the texture to the model so you can see it while you work.

It isn’t that hard although it seems like it is until you try it. :slight_smile:

Hope that helps.

2DtexturesPack will only pack several textures. It will not assign the UVs. You need to do that in an external program.

No, it does work. I am new to unity, but I’ve been working with Maya for a long time now. Most 3D applications, be it modeling software, engines or 3D painting apps, will recognize any UV shell on positive UV space, not just on the “top right square”. Anything above or to the right of that square is valid, even unity is fine with this. You don’t need to restrict shells to just one square, as long as a single shell doesn’t cross over a border between two UV spaces.

The only thing I am doing differently from you is that I am using more space instead of just the deafult square, so I need to reduce the tiling on the main texture so that it covers a bigger area. Maya has a UV range setting for textures in its place2Dtexture nodes, but unity does not, so you have to compensate with the tiling.

I just find it faster to map every model to the top right square, instead of fitting them all in there at once.

But in essence, you did answer my question, so, is that it? Nothing special about an atlas script-wise?

I have only used Maya with Unity, so my responses were only based on that. Whether you can use it otherwise is not something I know anything about.

Nothing special about the atlas script-wise. Just use it as your texture in the inspector and place it on the model or export the model with the textures and it should do that automatically.

I think I understand now where you are coming from. I was confused, not sure if you were a completely newbie who knew nothing about modeling or someone who was so advanced that I had no information to give you. :slight_smile:

I think you have it now though. Just use the top right square for Unity and it should be fine.

Edit: Unity will ALSO read anything outside of that square, if you are using a tiled texture. So with a tiled texture, you can make the UV as big as you want as long as the tiled texture is within that square. But with an atlas, you are not tiling it. If you are using a tiled texture, you don’t need any special scripts either.

1 Like

Alright, thank you for your help!

@VonDark , I did edit and add tiled texture info. I wonder if that is what you are trying to do?