Making a 2D game for iPhone/iPad and need better performance?

I'm using Unity and SpriteManager 2 to make a 2D game for the iPhone/iPad. Using the shader included with SM2 and/or the mobile vertex colored shaders included with Unity left me extremely GPU/fillrate bound on the iPad in particular. I was seeing anywhere from 50-90ms per frame for "cpu-waits-gpu" from the internal profiler running on the iPad. I wrote my own shaders and dropped this to an average of 10ms per frame. I've still got a few optimizations to go on my game but I figured I'd share the shaders I wrote in case anyone else out there might find them useful.

The best use for these shaders is if you are making a sprite-based game where you layer the sprites and use alpha to create a more traditional 2D looking game. These shaders do not support scene lighting at all but they do support vertex coloring. Basically if you just want your textures to look pixel perfect and unaltered when rendered in game then these might help.

Also, be sure to edit your AppController.mm to disable OpenGL ES 2.0 or your framerate is going to suffer tremendously. Line 70 of your AppController.mm should read:

#define USE_OPENGLES20_IF_AVAILABLE 0

Here is the shader that supports alpha transparency and vertex coloring:

Shader "Unlit Transparent Vertex Colored" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

Category {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
Alphatest Greater 0
Blend SrcAlpha OneMinusSrcAlpha 
SubShader {
Pass {
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord 
Bind "Color", color 
}

Fog { Mode Off }
Lighting Off
SetTexture [_MainTex] {
Combine texture * primary, texture * primary
}
}

}
}

Here is a shader that just renders your texture without any lighting or alpha transparency:
Shader "Unlit" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader {
Pass {
SetTexture [_MainTex] {
Combine texture 
}
}
}

}


//


http://forum.unity3d.com/threads/68402-Making-a-2D-game-for-iPhone-iPad-and-need-better-performance

你可能感兴趣的:(Unity3D,iOS,Game,shader,properties,textures,profiler,blend,mobile)