Hello Guest

Author Topic: Performance issue with tk2D shaders caused by overly high precision on colors  (Read 5514 times)

striche_FB

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Our team recently encountered a problem when attempting to prototype a new mobile game concept using 2D Toolkit. We found that once we played a full-screen background sprite on the screen we went from 60 FPS to 40 FPS on an iPod 4 device. However, we remained at 60 FPS on an iPhone 3GS. When a game is running faster on a 3GS than newer hardware, this usually indicates one of two problems. There is either a problem stemming from fill-rate issues that don't present on 3GS due to the lower resolution, or there is a problem with the shaders that doesn't present on 3GS since it uses an older version of OpenGLES.

The problem persisted if we diced up the background, so that ruled out fill-rate, so I began to take a look at the shaders when I encountered the following  "float4 color".  I knew this was likely the problem.  You can run into performance problems with shaders if you use high-precision types on color value. Here is some documentation on the topic:

http://docs.unity3d.com/Documentation/Components/SL-ShaderPerformance.html
"Use lowest precision that is possible; this is especially important on mobile platforms like iOS and Android. Good rules of thumb are...For colors and unit length vectors, use fixed."

http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/BestPracticesforShaders/BestPracticesforShaders.html
"Colors in the 0.0 to 1.0 range can usually be represented using low precision variables."

http://stackoverflow.com/questions/4520614/opengl-es-performance-2-0-vs-1-1-ipad

I'm not a shader expert, so as a quick fix, I went through all of the tk2D shaders and changed all instances of "float4 color" to "fixed4 color" and that seemed to do the trick. Our FPS was now back up to 60FPS on our iPod 4 devices and features like color/alpha adjustment were still functioning.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Hey,

As mentioned in the email this has been fixed - ill post the fix on the beta site as soon as I get back from Unite.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
No idea why my fps actually dropped after doing this. Using Unity 4, and OpenGLES 1.x.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
I'm still not back yet, but drop me an email with your changed shader and I'll take a look.