- Home /
How can I use atlas sprite as texture for a material?
http://i.imgur.com/qfypRkL.png (See this image first)
My texture sheet (WIP1) has been spliced into 20x20 squares. I need to use WIP1_01 as a texture in material grass. WIP1_01 is highlighted on the plane in my scene. It is the grass square. I want to tile that onto a background. I can manually slice it and import that I know, but it would be convenient if this way worked too. When I try to add a texture in the material editor it only shows the WIP1 image, not the spliced images.
I will also add that I am using unity 2D. Is this the correct approach to creating a 2d background? I was going to just instantiate a heap of textures onto the screen on load but I figured that would use too much memory.
Thanks
I too would like to be able to accomplish this task... I can definitely cut up my atlas pre import, but it would be awesome to be able to select the sprite post splice within Unity and use that as a material.
Any info would be awesome.
Answer by Adamcbrz · Mar 18, 2014 at 02:02 AM
Well this is somewhat defeating the purpose of the atlas. There are two ways to solve the issue.
1) (The one you already know) Make a material with just that one texture and set the uv tile settings to repeat. This is probably the cheapest and easiest for most applications.
2) Create a mesh that is however many quad meshes that you need to make your tiling. You can do this method using unity quad primitive but that would be more expensive then creating your own meshes.
Hey Adamcbrz! Thanks for the great reply. :)
Perhaps erroneously, I was using the sprite atlas as a sort of catch all for all my assets -- not just what would be used in the particle system. I$$anonymous$$ Players, enemies, random sprites, etc. Granted I am just playing around and testing right now, but it would be fantastic not to have to import several separate .png's for each.
Just have my one big atlas and pick and choose which sprites are used for what purpose.
Seeing as how there is no obvious solution (apart from your great workarounds) I am thinking that I am probably out of luck in this area.
Thank you anyways. :D
To expand a bit on what Adamcbrz was saying at the beginning; pretty much the whole point of texture atlases is combining many logical parts into a single texture, so that a material using that texture can color all the different parts of the object with fewer draw calls. If you are going to render an object with a separate material that is only using one image from that atlas, putting that image in the atlas is just causing you more work for literally no benefit. I don't know your workflow, so maybe you have good reasons, but I'm not sure why it would be "great" to not have separate files for separate assets. I've always viewed atlases as a necessary evil, not a thing I actually want to do...
Having the grass as it's own separate texture is the right solution here--I think you will probably like doing it that way when you try it.
Answer by Yofurioso · Mar 18, 2014 at 12:52 PM
I think in order to make the atlas work properly you have to make your own mesh and UV unwrap it so that the mesh uses only certain coordinates of the atlas for texturing (I'm not sure if that came up right). Try this, use blender or 3dsMax or any other 3d modeling software and make a simple plane (4 verts, one quad), then unwrap it and then scale the uv layout so that the plane uvs cover only the grass texture. After that all you need to do is duplicate that plane as many times as you require.