Author Topic: draw call optimization - textures  (Read 8522 times)

VamppiV

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 15
    • View Profile
draw call optimization - textures
« on: October 10, 2014, 04:48:42 AM »
I have at my game a lot of textures that are making "from script" (I'm reading photos from disk and make them into texture). Now every texture generate new drawcall - it's very bad option. How can I change it? Any ideas?

mxml.bernard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 1
    • View Profile
Re: draw call optimization - textures
« Reply #1 on: October 10, 2014, 07:26:50 AM »
Hey,

The idea might be to handle the texture atlas creation at runtime.
You should take a look at Texture2D.PackTextures method : http://docs.unity3d.com/ScriptReference/Texture2D.PackTextures.html.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: draw call optimization - textures
« Reply #2 on: October 10, 2014, 07:31:52 AM »
Don't pack large textures in Atlases.

VamppiV

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: draw call optimization - textures
« Reply #3 on: October 10, 2014, 08:10:07 AM »
Hey,

The idea might be to handle the texture atlas creation at runtime.
You should take a look at Texture2D.PackTextures method : http://docs.unity3d.com/ScriptReference/Texture2D.PackTextures.html.

Sounds good, but if I have about, for example 40 textures and all of them are quite big? Is it all time good idea?

And I see it works at "Start()". Can I use it in other function, eg. OnEnable()?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: draw call optimization - textures
« Reply #4 on: October 10, 2014, 07:06:14 PM »
Depending on your platform/device, an atlas has a max size of 2048x2048 or 4096x4096. Trying to pack anything bigger than that will just flat out fail.

The effort involved in packing at run time doesn't really pay off enough in performance if you only save <50 draw calls, aif you go from 51 to 1. If you go from 150 to 100 it might be a different story, but generally, it's not really worth it.

40 draw calls will generally not do anything, but if you get into the order of hundreds, you might have to start looking at it.

VamppiV

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: draw call optimization - textures
« Reply #5 on: October 13, 2014, 04:22:26 AM »
Sounds wise, but I'm just learning NGUI and I get "task" that I have to minimalize draw calls in my project. At this scene I have 6 drawcalls. So maybe any other simple ideas what should I change?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: draw call optimization - textures
« Reply #6 on: October 13, 2014, 05:25:22 AM »
Well, the minimal amount of drawcalls is 1 per material. Each UITexture is its own material, each atlas is its own material, each dynamic font is its own material. If you have more than the amount of materials you're using, it's because it's been split up with UIPanels or because of "pancaking" different materials.

You can take a look at this tool I made http://www.tasharen.com/forum/index.php?topic=6166.0 to see how things are pancacked and move them around on depth to get to your minimum.

Now I want pancakes.. dammit.

VamppiV

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: draw call optimization - textures
« Reply #7 on: October 13, 2014, 07:39:16 AM »
Well, the minimal amount of drawcalls is 1 per material. Each UITexture is its own material, each atlas is its own material, each dynamic font is its own material. If you have more than the amount of materials you're using, it's because it's been split up with UIPanels or because of "pancaking" different materials.

You can take a look at this tool I made http://www.tasharen.com/forum/index.php?topic=6166.0 to see how things are pancacked and move them around on depth to get to your minimum.

Now I want pancakes.. dammit.

Ok, thanks. If it will work - I'll made you pancakes :D

VamppiV

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: draw call optimization - textures
« Reply #8 on: October 16, 2014, 09:02:47 AM »
Well, the minimal amount of drawcalls is 1 per material. Each UITexture is its own material, each atlas is its own material, each dynamic font is its own material. If you have more than the amount of materials you're using, it's because it's been split up with UIPanels or because of "pancaking" different materials.

You can take a look at this tool I made http://www.tasharen.com/forum/index.php?topic=6166.0 to see how things are pancacked and move them around on depth to get to your minimum.

Now I want pancakes.. dammit.

I don't know why but I doesn't work in my Unity (and it breaks all NGUI). So... I'm all time looking for ideas!