- Home /
Per Pixel Lighting on iOS
Hi All
I've just purchased an iPad and built and run our concept game on the iPad. While I was hitting 30fps on 3G S the framerate crumbled on the iPad. I understand that this could be insurmountable as I am presuming that the fill limit is being hit because of the drastically increased screen size. Basically I have one directional light and one point light. Everything is set to diffuse fast bar one object which I have set to diffuse and one point light on the player set as important for per-pixel lighting. It feels like a simple setup, but it seems to be crippling performance - 30fps everywhere else, but when the one large object fills the screen I drop to 20fps. Scene is relatively low poly with 4.2K tris in view at the time I get 30 fps. I've reduced the entire scene to one material just to see if it is hammering to swap materials.
I've recently seen the Epic Citadel demo from Unreal, which I think is running native res, and probably massively simplified lighting, but they appear to be getting some nice per pixel effects with normal mapping, so I'm surprised that with just one object affected by per pixel lighting, that the performance drops so dramatically.
Is it worth me writing some simple shaders to improve performance?
Thanks Ian H
Answer by robert · Oct 26, 2010 at 10:27 AM
It looks like indeed you're fill-rate bound if there are too many pixels running with an expensive shader on the screen. I'd make some more experiments to confirm this and as a solution maybe try to simplify the lighting, use lightmaps or try to achieve the effect in a different way.
As far as I know Epic Citadel doesn't have any dynamic lights - it's lightmaps only. Because these are UE3-style lightmaps, you see some specular highlights. Also in the demo they avoid drawing anything that might consume the fill-rate excessively, so for instance there are no particles and almost no foliage and the demo is already running on the edge. Adding anything more to it (a dynamic light, a particle effect, an animated character) would also probably put the framerate under acceptable levels.
Answer by runonthespot · Nov 02, 2010 at 04:56 PM
Pay close attention to the size and compression settings on your textures too. I found by reducing texture sizes and acquiescing to using PVRTC compression as much as acceptable, significantly improved performance on ipad and iphone4 (ipad being the worst of the bunch, performance wise). Test this by setting all textures to the worst quality possible, PVRTC 2bit, 256x256 and see how it performs.
Drawcalls are apparently less of an issue than they were. Also look at baking in light, and occlusion culling.
Finally, can I recommend going into your xcode project application delegate and removing the 30fps limit when testing and always running your code with fps meter on, and then aim for >50fps on 3gs or iphone 4. I find I then get relatively acceptable performance on ipad. You generally don't want to go less than around 25fps (I consider this passable for very complex scenes, given that a Hollywood film does 24fps as standard)
Yes, I have been thinking about removing the limit and ensuring that the game flies on 3G S, so that sounds good. True blu-rays are 24P, but each frame is a snapshot of real action, so will include motion blur, naturally captured at that frame, which I understand helps keep things looking fluid and of course, unless you add motion blur, a game will always be a crisp snapshot of time at that frame.
A good point re motion blur- explains why I never feel comfortable under 30fps :) I remove the limit only for testing purposes, as it's too onerous to test on multiple devices the whole time. That way I can mostly ensure that it'll perform okay on ipad without tying up my wife's ipad ;-)
Also, I recommend using the Simply Lit shaders from the unify community wiki.
http://www.unifycommunity.com/wiki/index.php?title=Simply_Lit
I've been simplifying the per pixel lighting shaders to do things like ignore alpha and assume the diffuse is always white.
Answer by noradninja · Oct 27, 2010 at 11:11 PM
If you want to keep the same visuals as your game on the 3GS and dont mind the lower resolution, you can force your game to run in standard resolution on the iPad/iPhone4/iPod4G by setting Target Resolution to Standard in the Player settings in Unity before you build. This will keep your framerate acceptable at the expense of resolution and is what I do for the games that I require pixel lighting in (mostly for normal mapping).
I don't know if was doing something wrong here, but this didn't seem to make any difference for me at all.