Author Topic: How to dynamically update a atlas?  (Read 4369 times)

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
How to dynamically update a atlas?
« on: August 17, 2013, 11:07:17 AM »
Hi

UISprite is very useful for decrease draw call and atlas maker is very handy.
If I remember it right, only sprites from a same atlas can reduce draw calls to 1.
So we may need more image(say, icon portrait etc.) from online update and add them into atlas instead of UITexture,
especially if they might be duplicate dozens of times.

The problem is I can't search such a tutorial about how to update atlas dynamically in script.
Please help, thank you :)

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: How to dynamically update a atlas?
« Reply #1 on: August 18, 2013, 02:39:52 AM »
I found there's a mistake somewhat.
Strictly, UITexture out of clipping area doesn't count as draw calls.

Then I find this
http://www.tasharen.com/forum/index.php?topic=2700.msg13544#msg13544
Tried to make AtlasMaker a static class but it looks very hard.
Because UIAtlasMaker is in "Assembly-CSharp-Editor" project while my script is in "Assembly-CSharp", worse thing is CSharp actually ref CSharp-Editor, that means my own static class is unable to use calls from NGUIEditorTools & NGUISettings, which seems necessary to AtlasMaker.UpdateAtlas().
Any idea?   :'(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to dynamically update a atlas?
« Reply #2 on: August 18, 2013, 06:59:38 AM »
Not quite right. Yes, using the same atlas will reduce draw calls, but it's using the same material that controls it, not the atlas.

So if you have 10 UITextures all using the same material, then you will only have 1 draw call.

I don't recommend creating atlases at run-time, but if you do, use the atlas maker as a guide. Don't try to convert it to be a run-time class, it's not meant for that.

All you need is to use Texture2D.PackTextures function to pack many textures into one. Doing so also gives you rects, in order of the textures you passed. Meaning the [2] index texture in your array will be using the rect[2] index.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: How to dynamically update a atlas?
« Reply #3 on: August 18, 2013, 11:32:54 PM »
I don't recommend creating atlases at run-time...

Interested, why?

lime-green.at

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: How to dynamically update a atlas?
« Reply #4 on: August 19, 2013, 01:30:50 AM »
I don't think there's any good reason to create / update atlases at runtime. If you want to update your standalone game, you could just create patches with a tool like xdelta, which will binary compare the old with the new version, so you won't have to care about things like that anymore.

Regards

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: How to dynamically update a atlas?
« Reply #5 on: August 19, 2013, 04:31:26 AM »
I don't think there's any good reason to create / update atlases at runtime. If you want to update your standalone game, you could just create patches with a tool like xdelta, which will binary compare the old with the new version, so you won't have to care about things like that anymore.

Regards

I'm not interested in the application patches. I need it to display a loadable textures (UITextures) per drawcall.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to dynamically update a atlas?
« Reply #6 on: August 19, 2013, 09:02:34 AM »
Atlas creation is a slow operation that stalls the application for up to several seconds, which is completely unacceptable in a game. If you want to display loadable textures, use UITexture. Yes it's 1 draw call per, but how many of them do you expect to have visible at once?

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: How to dynamically update a atlas?
« Reply #7 on: August 19, 2013, 11:33:48 PM »
Basically, the elements for the lists (eg a shop or inventory), but I think that at the same time it is not necessary to display many items. I was just wondering why is not desirable to create a dynamic atlas. Thanks!

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: How to dynamically update a atlas?
« Reply #8 on: August 21, 2013, 07:04:41 AM »
Why do you not create an atlas for the items extra? (or multiple atlas if you have a lot items).
Its depending of how big the textures for the items are.