I asked my question in a very old thread and I was suggested to make a new one.
2 be honest this is really weird... I usually find whatever I need through a simple google or youtube search. but this atlas thing is really gettin on my nerves. it's about a weak or two I'm digin google, youtube, even http://unity3d.com to find the answer related to Atlas. But all I find is Atlas generation through:
none of 'em explained the way the Atlas is applied to Unity. There's no single tutorial out there for starters. Would u explain in a simple way how this atlas works in unity. Say I wanna create a simple 512*512 Atlas in photoshop. do I have to have 4 textures with the exact 256*256 pixel and put them in photoshop and save 'em as a specific format and then replace it with original textures in unity and tweak x and y tiling?
Besides.. what kinda Mapping method should I use in 3rd party 3d modeling applications? Unwrap UVW or just UVW mapping ? I UV my model this way: Say we have a 5 story building with 5 seprate walls and I wanna tile their interior and exterior faces with two different textures. What I do is grab a wall and go to polygon subobject , Select the interior wall faces and choose UVW mapping from modifierlist and tile the interior walls with a desired texture and do the same for the outer walls with a different texture. I Finally import my model into unity and I have two materials for a single mesh which I'm not sure is the right way. I can't use Unwrap UVW coz I wanna tile my texture. I'm sure this is gonna make a drawcall issue in long term modeling and texturing.
Any help would be appreciated.
A texture atlas is also just a texture. That's all. There is nothing special on a texture atlas. It's just one big texture with several textures usually arranged in a grid. The important point is that your actual models / meshes are unwrapped correctly. If you created your texture yourself, just unwrap your models onto the atlas texture and everything works as usual.
But!!! If you created your models and unwrapped them onto a single texture and you want to pack all those single textures afterwards in an atlas, you need to adjust the unwrap (the models uv coordinates)
Texture2D.PackTextures is just a helper function. You provide a texture array with all your textures you want to pack and the function pack all those textures into one texture and retuns a Rect for each texture. This rect have to be used to adjust the uvs of each vertex in your mesh.
Basically your uv coordinates are usually between 0 and 1 in each axis. After the packing they have to be remapped to the rectangle. For example if PackTextures returned a rect like this:
You just need to multiply each uv with the rects size (of course seperately for each axis [x,y] or [u,v]) and add the rects position after the scaling. This have to be done with every vertex in a mesh.
btw, tiling within an atlas is usually not possible. There are some shader tricks, but they aren't very efficient.
It can be done with not too much work but it depends on your requirements ...
I'm in the process of building a voxel engine which uses one I made myself. The problem I have is that my terrain is all procedurally generated so I created a simple mechanism for "indexing" the textures. If you force every texture in the atlas to be the same size you can get texture information purely by convention, without that you will need some form of lookup.
I went for the first option ...
So lets say I want to know the uv coords for a texture in the atlas:
I need to know some key things: 1. the number of textures wide my atlas is 2. the number of textures tall my atlas is 3. where your texture is within the atlas
from there i wrote a simple helper method that i put in a helper class that I can call from anywhere which goes something like this ...
Its hardly a complete example but it'll get you started. This means that all you need to do is attach the atlas to your game object then use something like this to calculate the actual uv coords within it on a per tri basis.
I carefully modelled my game code so that I could easily map the 4 corners to 2 tris each time, it's just a matter of figuring out what you're mapping to I guess.