Unreal Engine on iPhone: the full story
Epic presents the tech to mobile devs.
Epic Games' senior console programmer Josh Adams officially introduced game developers to the new iPhone edition of Unreal Engine 3 at the Game Developers Conference this week.
While much of the presentation concerned how Epic's Windows-based tools interfaced with the Mac-based "XCode" workflow of the iPhone development kit, Adams also showed a working model of an Unreal Tournament level running on the Apple device, with the developer confirming that the demo refreshed at a rate of 25 to 30 frames per second.
Adams described the process of bringing UE3 to iPhone as a fun "can we do it?" project, based on Open GL ES 2.0, meaning it will only work on the newer Apple devices such as the iPhone 3GS, the iPad, and the third-generation iPod Touch. UE3 won't work on older iPod Touches and iPhones as they do not support the programmable pixel shaders that the engine requires, but, as newer, faster devices in the mobile Apple family appear, Epic's engine will obviously scale with them.
Interestingly, during the presentation Adams also revealed a range of unsupported platforms that Epic currently has Unreal Engine 3 working on: Linux, Mac,and NVIDIA Tegra 2 (potentially very interesting if the Nintendo DS 2 rumours turn out to be true).
Converting Epic's middleware to the iPhone was no mean feat. The engine itself consists of two million lines of code in a 16MB executable, with 90 per cent of that code being platform-independent, with the other 10 per cent tuned to the hardware it is running on.
Almost all of the core functionality of the engine remains in the iPhone iteration of the tech. The same gameplay, collision, math routines and even file formats are used. Game-makers used to the Unreal Engine editor use the exact same Windows-based toolset when developing for iPhone. Where Epic had to make changes was primarily in the Render Hardware Interface (RHI) - the "thin layer" between the engine's render thread and the host platform's API.
Josh Adams also described how Unreal Engine lights environments. The code gathers up static and dynamic lights decided upon by the artists and turns them into just one or two lights instead, with directional, ambient or spherical harmonic lights all supported. This is great for iPhone in that many lights set up by the artists or generated dynamically during gameplay have a very low rendering cost.
New code was created to cope with the iPhone's unique controls. Buffers are set up that store up the touch-screen inputs, which are then all processed as each new frame is rendered. Tilt functions are polled in a similar time period but without the buffering. Adams also talked about how the iPhone 3GS's magnetometer was considered as a means for enhancing turning information, but was dismissed owing to the fact that the input it generated turned out to be unusable while the CPU cost for accessing the function was prohibitively high.
Changes made to the core Unreal Engine renderer were twofold. First of all, the shift to Open GL ES 2.0 had to be accommodated (by expanding upon the existing Open GL driver) and secondly, the fact that the mobile chipsets are considerably less powerful than UE3's usual target platforms had to be taken into account.
Unreal's shader support was completely overhauled. The engine works with thousands of shaders, with between five and 20 of them being used for just one material. Epic's solution was to "auto-flatten" these shaders into a single texture while adding preview support to the PC editor so artists could see how the final art would look on-screen.
While precision is lost (as is support for specular and normal maps), the effect looks similar and as the final work is displayed on a very small screen, the diminished quality is not so apparent. Epic's normal art pipeline can still be used, there are fewer textures to load and it obviously runs faster on the mobile platform.
Another weakness Josh Adams identified was within Open GL ES 2.0 itself. Games optimise their rendering through occlusion culling - killing polygons that are invisible to the user. Occlusion queries aren't supported in ES at the moment, meaning that levels created with Unreal Engine have to be smaller as a result.
Going forward, Epic expects the iPhone, iPad and iPod Touch devices to get progressively more powerful as new hardware revisions hit the market. Newer hardware obviously means more power and the engine-maker expects support for specular and normal mapping to be included at some point, and for prominent "hero" artwork (for example, your main character) to get full material support.
Epic also expects the occlusion query issue to be solved in a later rendition of the Open GL ES 2.0 driver, which should allow for larger, more complex environments. UE3's integration with other middleware - for example, GameSpy and PhysX - will also be added to the iPhone engine as when they are ported across to the mobile format.
When the iPhone version of UE3 was first announced, Epic revealed that it would also support "another platform", which is obviously the recently announced iPad. Josh Adams told GDC delegates that Epic doesn't have access to iPad technology right now and that the firm was no real idea of just how much power the new hardware will bring to the table.
The iPad itself is widely believed to be running a 1GHz ARM A8 Cortex CPU, combined with a more highly clocked version of the same PowerVR SGX535 chip found within the iPhone 3GS. According to Epic, bottlenecks in performance with UE3 on the mobile platform are mostly down to the CPU and as a consequence, the graphics chip isn't really being stressed at all.
So while the short Unreal Tournament demo we had on the iPhone 3GS looked impressive, potentially the iPad architecture could see some fairly radical performance increases - even after factoring in the enormous resolution boost of the iPad's screen.
It took Epic four man-months of work with a two-man team to bring Unreal Engine 3 to the iPhone, and based on the surprise reveal of Tegra 2 work, it's clear that the company is very interested in bringing its middleware to a wide range of mobile platforms. Asked whether UE3 would be heading to Android, Josh Adams pointedly declined to comment...