Hello Guest

Author Topic: Some performance questions  (Read 7618 times)

cesarpo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Some performance questions
« on: July 07, 2013, 09:49:22 pm »
I'm finishing the r+d phase of my 2d game for mobile platforms, and I'm about to start real development, but have some technical questions :

1- For doing an on-screen virtual joystick, what would have better performance? A GUITexture with its hitTest methods, or using a tk2dUIItem? (I'm worried about all the screenpoint /raycasting /collider overhead that the tk2dUI does)

2- For a static background, what would be better? The unity mobile skybox, or a big tk2d Sprite?

3- What shader should I choose for my sprites? Should I use the default ones? Is there any documentation about the diferences between them? I see a lot of shaders in the Shaders folder, but I'm totally ignorant about this low level stuff.


Thanks in advance!


Companella

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Some performance questions
« Reply #1 on: July 08, 2013, 05:32:09 am »

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Some performance questions
« Reply #2 on: July 08, 2013, 07:55:58 am »
Can't answer 1 but here are some thoughts on 2 & 3...

Quote
2- For a static background, what would be better? The unity mobile skybox, or a big tk2d Sprite?

If it's static then using a skybox seems like wasted texture memory, since skybox cubemap has 6 sides a lot of it will never be seen. Use a "Sprite from texture".

Quote
3- What shader should I choose for my sprites? Should I use the default ones? Is there any documentation about the diferences between them? I see a lot of shaders in the Shaders folder, but I'm totally ignorant about this low level stuff.

Use the ones in the tk2d folder of the dropdown, and pick the one that has the features you need. Most of the built-in Unity ones do not support vertex colours which tk2d makes heavy use of.

Generally ... if the name has 'Lit' in front, the shader supports lighting. If not then it doesn't. Then you have either 'Solid' or 'Transparent' varieties. Solid is fast, good for ground tiles and such that fill the whole sprite polygon.

Transparent is then split into 'additive', 'blend', 'cut-out' or 'pre-multiply', which are all different methods of blending the pixels with the background. Which one you choose again depends on your requirements:

Additive - 'adds' its pixels to the background ones, you see this a lot in glowy effect stuff.
Blend - uses the alpha channel of the bitmap, where shades of grey determine how transparent a pixel is. The most common general-use solution.
Cutout - like blend but uses a cutoff on the alpha channel to basically use only black or white, so a pixel is either transparent or it isn't. This is used to get sorting within a mesh as it can interact with the depth buffer.
Pre-multiply - is a tricky combination of additive and blend, where the alpha channel controls the mix between the two methods. If the alpha channel pixel is black then the RGB pixel is 100% additive, and if it's white then the RGB pixel is 100% blended.

Some knowledge will be required to make more informed choices, the Unity docs has more info on shader families and the differences between them.
« Last Edit: July 08, 2013, 08:08:47 am by profanicus »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Some performance questions
« Reply #3 on: July 08, 2013, 09:49:04 am »
I'm finishing the r+d phase of my 2d game for mobile platforms, and I'm about to start real development, but have some technical questions :

1- For doing an on-screen virtual joystick, what would have better performance? A GUITexture with its hitTest methods, or using a tk2dUIItem? (I'm worried about all the screenpoint /raycasting /collider overhead that the tk2dUI does)

2- For a static background, what would be better? The unity mobile skybox, or a big tk2d Sprite?

3- What shader should I choose for my sprites? Should I use the default ones? Is there any documentation about the diferences between them? I see a lot of shaders in the Shaders folder, but I'm totally ignorant about this low level stuff.


Thanks in advance!

tk2dUI does exactly one raycast per touch down / mouse click, regardless of how many UI elements you have on screen or off screen. Its as efficient as it gets in that regard :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Some performance questions
« Reply #4 on: July 08, 2013, 09:52:17 am »
Can't answer 1 but here are some thoughts on 2 & 3...

Quote
2- For a static background, what would be better? The unity mobile skybox, or a big tk2d Sprite?

If it's static then using a skybox seems like wasted texture memory, since skybox cubemap has 6 sides a lot of it will never be seen. Use a "Sprite from texture".

Quote
3- What shader should I choose for my sprites? Should I use the default ones? Is there any documentation about the diferences between them? I see a lot of shaders in the Shaders folder, but I'm totally ignorant about this low level stuff.

Use the ones in the tk2d folder of the dropdown, and pick the one that has the features you need. Most of the built-in Unity ones do not support vertex colours which tk2d makes heavy use of.

Generally ... if the name has 'Lit' in front, the shader supports lighting. If not then it doesn't. Then you have either 'Solid' or 'Transparent' varieties. Solid is fast, good for ground tiles and such that fill the whole sprite polygon.

Transparent is then split into 'additive', 'blend', 'cut-out' or 'pre-multiply', which are all different methods of blending the pixels with the background. Which one you choose again depends on your requirements:

Additive - 'adds' its pixels to the background ones, you see this a lot in glowy effect stuff.
Blend - uses the alpha channel of the bitmap, where shades of grey determine how transparent a pixel is. The most common general-use solution.
Cutout - like blend but uses a cutoff on the alpha channel to basically use only black or white, so a pixel is either transparent or it isn't. This is used to get sorting within a mesh as it can interact with the depth buffer.
Pre-multiply - is a tricky combination of additive and blend, where the alpha channel controls the mix between the two methods. If the alpha channel pixel is black then the RGB pixel is 100% additive, and if it's white then the RGB pixel is 100% blended.

Some knowledge will be required to make more informed choices, the Unity docs has more info on shader families and the differences between them.

Thanks profanicus for that comprehensive description :)
I've got one more thing to add -
Premultiplied alpha has one advantage to normal blended, even if you don't consider the crazy possibilities using additive and blended - it gets rid of a LOT of the sprite edge artefacts when using bilinear filtering, when the texture doesn't have correctly dilated color channels. So basically, if you get white/black outlines around your sprites when scaled up, use premultiplied alpha :)

cesarpo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Some performance questions
« Reply #5 on: July 09, 2013, 02:47:04 am »
Thanks for the answers!