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

27 篇文章 0 订阅
10 篇文章 0 订阅
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值