Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by christo1745 · Jun 24, 2011 at 04:09 PM · texturematerialbatchingskinned mesh renderer

Texture Atlasing

I want to combine a bunch of textures into one material, then use that material for multiple gameobjects so they will batch. However, if I use material offsets to do this, it creates a copy of the material for each object, thus no batching. I noticed that imported meshes use a skinned mesh renderer, which looks like it uses Bounds to achieve the effect I'm looking for. However, I think you can only use that with imported objects.

In other words, instead of having eyes, a nose, and a mouth all on one texture, I want 5 different 2d buildings.

Edit: I thought that SetTextureOffset changed the UVs. Apparently I need to use the method suggested by The comments below. Thanks guys!

Comment
Add comment · Show 13
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Toxic Blob · Jun 24, 2011 at 04:16 PM 0
Share

I’m not sure I perfectly understand what you’re trying - I got confused when eyes, nodes and a mouth became 5 buildings… If you’re importing your meshes from a 3D package then you can set the UV offsets in that package so you can share textures between meshes.

avatar image christo1745 · Jun 24, 2011 at 04:21 PM 0
Share

What I meant is this: When you import a character from a 3d program, the eyes, nose, and mouth are all on one texture. Then for each gameobject that texture's material is used with offsets. So if the eyes are in the top left, the eye object uses coords 1,1. If the nose is just to the right of the eyes, the nose object uses coords 1,2.

I want to do the same thing with 2d buildings. So building1 is in the top left of the texture, thus building1 gameobject uses coords 1,1 and so on.

The buildings are 2d and made in photoshop, so not imported from a 3d program.

avatar image Marnix · Jun 24, 2011 at 04:23 PM 0
Share

@christo1745 ok I answered your question, but now I'm actually getting confused about buildings as well. You just wanted to change a material for multiple objects, right?

avatar image Toxic Blob · Jun 24, 2011 at 04:27 PM 0
Share

I think what you want is to change the UV coordinates of the polygon sprite that you’re dealing with. That way the material won’t be changed and you can batch the objects. You can do this either through rolling you own sprite class, or use one of the several that exist for Unity (on the Asset Store)

avatar image Toxic Blob · Jun 24, 2011 at 04:47 PM 2
Share

Indeed. You must change the mesh’s UV coordinates directly. So using “mesh.uv”. http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$esh-uv.html

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Marnix · Jun 24, 2011 at 04:22 PM

You should use the `sharedMaterial` property in the renderer. You could even already define it in the material prefab in your project before adding it to an object. In runtime, it will only change one object, but sharedMaterial changes it for everyone.

New answer

Change the uv-coordinates of your vertices instead. It is just a quad, so you can change the vertex data!

Comment
Add comment · Show 14 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image christo1745 · Jun 24, 2011 at 04:24 PM 0
Share

The problem with shared$$anonymous$$aterial is that you can only have one offset. so if I offset the shared$$anonymous$$aterial to 1,2 all of my buildings would show the material at offset 1,2. Thus all of my buildings would be the same image.

avatar image Marnix · Jun 24, 2011 at 04:25 PM 0
Share

So you actually don't want to use shared$$anonymous$$aterial, but just the normal material? You can just call `Renderer.material`

avatar image christo1745 · Jun 24, 2011 at 04:35 PM 0
Share

if I change the offset like this: objSpriteRender.renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", spriteSheetOffset);

Then I get a copy of the material, so no batching. If I change it like this:

bjSpriteRender.renderer.shared$$anonymous$$aterial.SetTextureOffset ("_$$anonymous$$ainTex", spriteSheetOffset);

it will batch, but all objects with that material will have the same offset.

avatar image Marnix · Jun 24, 2011 at 04:37 PM 0
Share

@christo1745 The trick of batching, is that no uniform variables have to be changed in the shader, so it can just continue rendering vertices. If you change a uniform like the offset, there is no speaking of batching anymore.

avatar image Marnix · Jun 24, 2011 at 04:48 PM 1
Share

@christo1745 And read this as well http://unity3d.com/support/documentation/$$anonymous$$anual/iphone-DrawCall-Batching.html

It tells you indeed that you can do atlasing, but I think you need multiple objects with other vertex data. The material stays the same, but your uv-coordinates per vertex are different

Show more comments
avatar image
2

Answer by Steven-Walker · Jun 24, 2011 at 04:56 PM

You need to offset the UV coordinates of your meshes so they correspond to the atlas coordinates. So there's 1 atlas containing multiple textures and 1 material applied to multiple objects. What makes this work are the UV coordinates of the mesh. Your material in Unity should have default offsets (1,0 1,0).

You can build an atlas in Unity and create the UV mesh coordinates using an editor script (or tool like Sprite Manager). Or you can manually build an atlas in Photoshop and assign the mapping/UVs in an external 3D program.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by raminsh · Jun 24, 2011 at 05:05 PM

ok I have actually done this but not in unity, I usually use one of the following:

1- NVIDIA Texture atlas (you can get it from: http://developer.nvidia.com/legacy-texture-tools and it has pretty much all you need)

2- Flatiron from: http://www.texturebaking.com/ this one is a 3dmax plugin and really useful

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image christo1745 · Jun 24, 2011 at 05:09 PM 0
Share

I believe that is mentioned in one of the links $$anonymous$$arnix posted above. I think they are windows only :(. I think I need to use PackTextures(), then mesh.uv. I'll update later today when I get it working.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture Discoloration Issue When Importing Into Unity 1 Answer

Adding a Material to Particle System 1 Answer

Texture not showing on game objects 1 Answer

Regular grid on irregular mesh 0 Answers

Repeating a texture over an object 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges