Disclaimer:
Most of the projects that I will be doing are for a game that I am developing on my own code named Project Ninjio. In short, the game is a story action driven role playing game (common referred to as an action RPG). It features 2 uniquely styled areas, one in which the cities are built to flow along with nature, and the other where the cites are hyper futuristic. The game is set in a futuristic China, where after a large war, the country is split into the two settings described above. The game is built in the Unity 3D game engine.
The Art of Optimization
Introduction
It has been my goal to insure that Ninjio is the best experience that I can offer to its players. I had many smaller goals that I have for Ninjio to insure this high quality experience, however one of them (and the most important one to the gamer inside me) is making sure that the game will run at a constant 60 frames per second (FPS) or higher at all times on all sorts of hardware.
60 whats?
Without diving too far into the technology that we all use on a nearly daily basis, a frame in terms of a computer is the image that the computer is outputting to your monitor or display. It is well documented that the human eye can only see around 30 to 60 of these images per second, any lower number and the image would look choppy while any higher number would result in a similar looking image while wasting computing power, which is not ideal. Gamers, like myself, can definitely "feel" the difference between 60 fps and it's lower counterparts. Most games these days strive to run at this 60 fps threshold, however most fail (especially when running on consoles) and run at around 30 fps.
So what are the benefits of this higher frame rate?
Look at the difference, the 30 FPS image looks smeared compared to the 60 FPS one. |
In short, the higher the frame rate (and therefore higher fps) the faster you see the result of your action, say moving your mouse or pressing a button. This is generally what you want in games where there is a lot of action going on at a time, like Ninjio. Another benefit to this higher frame rate is that images do not look blurry and smeared when you pause the game, as there are more images being outputted to you monitor.
The challenges of achieving higher frame rates
In short, there are 2 ways to achieve higher frame rates, by either optimizing your code or optimizing your art. While optimizing your code could yield a better result on a per optimization basis, it is generally harder to do. Art, on the other hand is very easy to do. It is important to optimize your art as best as you can, even while you are creating it.
How to optimize your art
Not a too much changes visually here |
One easy way of optimizing art in video games is to make sure you are using the least amount of vertices (or points in 3D space) as you can. By doing so and asking questions like "Do I really need a ton vertices to make a sphere when I could do it in much less vertices and have it look the same", you can optimize different pieces of art very easily. Another method is to remove any faces (3 or more vertices put together to make a side of an object) that you know that players are not supposed to see. This could be like the back of a building facade that players cannot see in game or the bottom of a building that would normally be buried under the ground. These methods are very simple and easy to do, however sometimes you do need a high polygon count on an object or sometimes you do need all of the faces to be filled in, it is situations like this where different programing tricks come in handy.
Level of detail (LOD) in Team Fortress 2 |
One programming trick is level of detail, or LOD for short. It is the process of making it so that the game engine gradually reduces the amount of detail in the object as object gets farther away from the player. This method has to be programmed, but the results of it can vastly improve the performance of the game.
An example of draw call, look at how the trees are rendered together in a single graphics call, as shown by the grey box. |
Occlusion culling in Horizon: Zero Dawn |