Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Tetrad · May 24, 2010 at 04:46 PM · spriterenderingiphonebatchingdrawcalls

Is it possible to utilize iphone dynamic batching with "traditional" animated sprite techniques?

By traditional animated sprite techniques, I mean having an sprite sheet that I simply animate the UVs on over time.

I have an animated sprite class that accomplishes animations on a sprite sheet by doing something like this

renderer.material.SetTextureOffset( "_MainTex", offset );

The problem, it seems, is that calling renderer.material does a lazy copy, which means that the material on that particular game object is now an instance of the base material. Since my game objects all have "unique" materials now, the engine can't batch my sprites.

I was hoping to avoid having to batch my spites manually (through something I roll myself or something like Sprite Manager).

Basically, I guess, is it possible to set the texture offset without having the material be instantiated?

Answered: As suggested, modifying the UVs of the model instead of the texture instance offset worked. Without pasting my entire AnimatedSprite class, this is the bit that matters:

void OnFrameChanged() { // split into horizontal and vertical index int uIndex = frameIndex % uvAnimationTileX; int vIndex = frameIndex / uvAnimationTileX;

 // v coordinate is the bottom of the image in opengl so we need to invert.
 vIndex = uvAnimationTileY - vIndex - 1;

 // build offset
 Vector2 offset = new Vector2( uIndex * tileUVSize.x, vIndex * tileUVSize.y );

 Vector2[] newUVs = new Vector2[ uvs.Length ];
 for( int i = 0; i < uvs.Length; ++i )
 {
     Vector2 previousUV = uvs[ i ];
     previousUV.x *= tileUVSize.x;
     previousUV.y *= tileUVSize.y;
     newUVs[ i ] = previousUV + offset;
 }

 mesh.uv = newUVs;

}

I haven't done enough benchmarking to know if this is significantly slower/faster than using something like SpriteManager, but at the very least it's plug and play into my existing feature set.

Comment
Add comment · Show 2
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 Tetrad · Jun 02, 2010 at 04:22 PM 0
Share

Just a followup for anybody who may be reading this again. In my particular use case, doing this to get my draw count down was actually SLOWER than doing the material offsets and having each sprite have its own instance of the material. I'm assu$$anonymous$$g it's because modifying the UVs requires resubmitting the VBO to the card and would turn out to be more expensive than eating the draw call saved by doing dynamic batching.

avatar image Tetrad · Jun 04, 2010 at 07:19 PM 0
Share

Followup #2: using Sprite$$anonymous$$anager (or equivalent) is a lot faster than using individual game objects in either case.

1 Reply

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

Answer by Mike 3 · May 24, 2010 at 05:16 PM

The problem is that if you modify the texture offset (and you were using the same material for all of your objects), it would change all of the objects' texture offsets (Since it'd be the same instance of the material class).

The only way to get around that really would be to modify the uvs of the models instead, which may or may not be easy

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 equalsequals · May 24, 2010 at 09:52 PM 0
Share

With 2D sprites the UV map data wouldn't be too difficult to modify since it's likely just done on Quads.

Also, kudos on that idea.

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

No one has followed this question yet.

Related Questions

Drawcalls or Batched, which is more important to performace? 1 Answer

Why isn't dynamic batching working? 3 Answers

Batching to IOS not working ??? 0 Answers

Batching problem when using multiple materials in one model 1 Answer

Force elements in same batch 1 Answer


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