Founder, CTO and president of Terathon Eric Lengyel talks distinguishing features of the C4 Engine.
Next gen consoles are a special breed these days, despite being so familiar in so many ways. Their x86-based architecture ensures that PC developers have an easier time ensuring parity while developing for either the PS4 and Xbox One, but their unique architectures mean they have their own hooks. And while Terathon Software’s C4 Engine might not be the first middleware company to take advantage of next gen hardware, it’s certainly one of the few to work its way up.
The C4 Engine was first created in May 2005 and was only ever made available on the PS3. With its migration to the PS4, GamingBolt spoke to Ph.D. founder, president and chief technology officer of Terathon Software Eric Lengyel about how the engine takes advantage of the next gen console (and vice versa), its overall functionality and distinguishing features from other engines, and why it’s not available for Xbox.
Rashid Sayed: Could you tell us about how C4 differs from most other engines in terms of performance and functionality?
Eric Lengyel: It would be possible to compare feature sets and benchmarks all day long, but I think all of the major engines can demonstrate the same general capabilities with some strengths and weaknesses here and there. I’ll instead comment about some less visible characteristics of our engine that may only become apparent when a developer digs in and starts doing real work on their game. The most important thing to understand when comparing C4 to other engines is that the time and care has always been taken to build C4 the right way from thestart.
The C4 Engine has been in development for a very long time, and it has never suffered from the pressures of corporate deadlines and poor management that has a notoriously negative impact on code quality. Everything from large engine subsystems to each minor feature has been designed with careful consideration for correctness, implemented with meticulous attention to detail, and refined over many years of real-world usage.
The result is that the C4 Engine simply works better than many other engines (meaning that features are complete and function properly when used in combination), it exhibits far fewer technical problems than other engines (like crashes or features not working as expected), and the cleanliness of its source code is undisputedly unrivaled. This means that developers will be able to spend more time making their games instead of trying to figure out how some convoluted hack inside the engine is supposed to work.
"The C4 Engine uses a combination of direct dynamic lighting (with real-time shadows), static precalculated radiosity volumes, and our own flavor of screen-space ambient occlusion. There is no limit to the number of dynamic light sources that can exist in a single level, and the engine can handle several hundred light sources within the current camera view as long as most of them have limited bounds."
Rashid Sayed: One of the bigger talking points for next generation games is realistic lightning. How does C4 accurately render light, and how many light sources could it effectively create in real time on a next generation consoles like the PS4?
Eric Lengyel: The C4 Engine uses a combination of direct dynamic lighting (with real-time shadows), static precalculated radiosity volumes, and our own flavor of screen-space ambient occlusion. There is no limit to the number of dynamic light sources that can exist in a single level, and the engine can handle several hundred light sources within the current camera view as long as most of them have limited bounds.
The radiosity volumes capture directional ambient lighting at many grid points inside a three-dimensional volume and apply this data to both static and dynamic objects in real-time. The data stored in these volumes includescontributions from indirect light bounces, emissive material lighting, and hemispherical sky lighting.
Rashid Sayed: What are your thoughts on the PlayStation 4 especially in comparison to the Xbox One? Is there any specific reason why C4 is exclusive to one next generation console and not the other?
Eric Lengyel: Sony made a lot of good decisions when it comes to the technical design of the PS4. It’s awesome to have a fast, featured-packed GPU that can access a huge amount of fast memory. The Xbox One isn’t a whole lot different, but the slower memory and the irritation of still having something like eSRAM are disappointing.
C4 is currently exclusive to the PS4 for the sole reason that Sony was much more cooperative than Microsoft when we were first exploring conversion to next-gen consoles. Sony treated us with respect and made sure that we had everything we needed to get C4 running on the PS4. Microsoft did not respond to us in any way that included the slightest bit of professionalism, and that’s just one more thing to throw onto the pile of PR missteps surrounding the Xbox One.
"The engine contains a compiler of sorts that takes a user-supplied shader graph (built in the shader editor) and performs tasks such as scheduling, register allocation, dead code removal, and common subexpression elimination (merging duplicate code) at the flow-graph level. Then, it generates the actual text-based shader code that gets sent to the driver (or an offline tool) to be compiled into GPU microcode."
Rashid Sayed: C4 was originally on the PS3 but it was reported that the process of porting it over to the PS4 was much smoother than anticipated. What can you tell us about the process and how does it bode for development in general on the platform? Also, is it easier to optimize the engine for the PC or the PS4, and why?
Eric Lengyel: There are three main reasons why porting to the PS4 went smoothly for us. First, we were able to use all of our SIMD-optimized PC code without modification because the PS4 is based on x86 processors. Second, many of the APIs used by non-graphics components of the engine (like low-level threading, audio, and networking) are very similar between the PS3 and PS4, so we didn’t have to do much work to get them running. Finally, and possibly most importantly, Sony has provided an excellent integration with Visual Studio that makes debugging on the PS4 a pleasant experience.
It’s always going to be easier to optimize for a console because the exact hardware is known. On the PC, we have to consider a huge range of CPU and GPU capabilities, and that often makes straightforward optimizations impractical.
Rashid Sayed: How does the shader technology of C4 work and how does it work towards making the game more realistic? What about next-gen consoles helps to enhance the shaders, especially in comparison to other commercial game engines?
Eric Lengyel: There are two aspects of the C4 shader system that I should talk about here. First, the engine uses a graphical editor to build shaders. A lot of people don’t like these and would prefer to write shader code directly, but the editor has proven to be an extremely practical solution for a cross-platform engine.
At one time or another, the C4 shader system has internally supported four different languages (GLSL, PSSL, Cg, and ARB assembly), and it has been able to do so without any changes being made to the original graphical representation of the shader code. When we ported to the PS4, we never had to touch a single shader (out of many thousands) to get them working properly. A developer can design shaders on a PC, and they “just work” on every other platform supported by the engine.
The engine contains a compiler of sorts that takes a user-supplied shader graph (built in the shader editor) and performs tasks such as scheduling, register allocation, dead code removal, and common subexpression elimination (merging duplicate code) at the flow-graph level. Then, it generates the actual text-based shader code that gets sent to the driver (or an offline tool) to be compiled into GPU microcode.
The second noteworthy aspect of the C4 shader system is that shaders are separated into three orthogonal components, and these are created by the developer in different contexts. The first component, for which most shaders are written, pertains to the surface material and describes only how incoming light from one direction is reflected toward the direction of the camera. The second component describes what happens to light as it travels from the light source to the point being shaded and accounts for things like attenuation and projected textures.
The third component describes what happens to the light after it has left the surface but before it reaches the camera and generally has to account for atmospheric effects like fog. We call these material, light, and fog shaders, respectively. Whenever the engine needs to render something that requires some new combination of these three types of shaders it hasn’t seen yet, it connects their graphs together and generates a complete text shader to be used for all future occurrences of that exact lighting and fog environment for that exact surface material. The developer is able to introduce new types of lights or new types of atmospheric effects without having to modify any existing material shaders.
"From time to time, our existing customers are surprised by a significant speed boost when a new version comes out, and it’s something they just get for free because we included some kind of internal change that made the engine better at what it already does."
Rashid Sayed: What are your thoughts on C4 being an alternative to engines like Unity, which is present on both the PS4 and Xbox One?
Eric Lengyel: The C4 Engine appeals to developers who want full access to the source code and who intend to write their games completely in C++. (Note, however, that C4 also includes a graphical script editor.)
Rashid Sayed: Sony has opted for a pretty fast 8GB GDDR5 RAM of memory. What kind of advantages will it bring to games when used in conjunction with C4 engine?
Eric Lengyel: The fast memory will allow larger textures to be used, and this will enable higher detail on objects when they are close to the camera. Compute shaders are also able to stream data into the GPU faster, and this allows more computation to be done for a large variety of tasks.
Rashid Sayed: Are there plans to develop the engine for the Xbox One? If yes, how do you plan to overcome the bottlenecks [specifically eSRAM] so that C4 engine can take maximum advantage of the hardware?
Eric Lengyel: That depends on Microsoft. If we do port to the Xbox One, it will be unfortunate that we still have to deal with things like the eSRAM in this generation of consoles. Many of the methods established with the 360 still apply, and they’ll provide us with some solutions.
Rashid Sayed: What kind of updates can we expect to see in the C4 Engine?
Eric Lengyel: The C4 Engine is updated regularly, and each update always includes new features in the engine and productivity improvements in the tools. Additionally, we frequently make improvements to existing features whenever we realize that something could be done a better way, and this comes from our first priority being to make the highest-quality product possible and not to make as much money as possible.
From time to time, our existing customers are surprised by a significant speed boost when a new version comes out, and it’s something they just get for free because we included some kind of internal change that made the engine better at what it already does. Some specific features that we currently have in the works are new foliage painting tools, new river sculpting tools, and a new particle system editor.
Rashid Sayed: Is there anything else you want to tell us about the C4 Engine?
Eric Lengyel: If you’re going to be at GDC 2014, please stop by the Terathon Software booth (#741) and check out the C4 Engine for yourself! We’ll be demonstrating the engine with a few levels from our upcoming game The 31st.