Tag Archives: AnKi

Multithreading: Parallel uniform jobs

Multithreading is a concept that exist for many decades in computer science, nevertheless, only in recent years it become a trend in game development with the arrival of multi-core CPUs in our home PCs. In this small article we will discuss how AnKi utilizes the power of multiple processors. Also the source code of an example can be found at the end of the article.

The concept of multiple threads offers many advantages in applications that execute many uniform jobs at the same time, for example a webserver needs to serve multiple hosts at the same time and without a host waiting for a previous request to finish. A game application though used to have a very standard and linear flow. For example, we first update the AI, then the physics, then we update the world, we do visibility determination and lastly we render, then we repeat the same again. Sometimes its difficult to execute some of these distinctive steps in parallel because the data of the previous step will be used by the next. I bet high class development studios have found ways to blend these steps but in AnKi we use a more simple approach. We use multiple threads to run uniform jobs in parallel.

One good example to illustrate how AnKi uses the power of multiple threads is the visibility determination algorithm. One step of visibility determination is the test for every renderable scene node against the camera’s view frustum. If we have N nodes to test and M threads we can roughly assign for testing the first N/M nodes to the first thread, the next N/M nodes to the next thread etc.

Continue reading “Multithreading: Parallel uniform jobs” »

Screen Space Ambient Occlusion

“Ambient occlusion is a shading method used in 3D computer graphics which helps add realism to local reflection models by taking into account attenuation of light due to occlusion” [Wikipedia.org]

The proper way to do ambient occlusion is very expensive for today’s hardware and especially without the use of a ray-tracing renderer. For that reason a few new techniques developed that tried to produce the same result using simpler and faster algorithms. One of these approaches is the Screen Space Ambient Occlusion (aka SSAO) that makes the calculations of ambient occlusion in 2D space just like a normal 2D filter. This article will not go deep into what SSAO is, there are many great readings around the web that cover the theory behind SSAO, in this article we will jump into the implementation that AnKi uses.

There are quite a few techniques to produce SSAO, a top level way to group them is from the resources they need to produce the SSAO:

  • Some use just the depth buffer (Amnesia, Aliens VS Predator)
  • others use the depth buffer and the normal buffer (Crysis, gamerendering article)
  • and others use the pixel position and the normal buffer (gamedev article)

AnKi used to implement the second technique for quite some time. The results were good but apparently not that good, so for the past couple of weeks I’ve tried to implement the third technique by reading this great article from gamedev. The present article extends the gamedev one by adding a few optimization tips and by presenting the code in GLSL.

Bellow you can see the old and the new SSAO, rendered at the half of the original rendering size with two blurring passes.

Old implementation of SSAO

New implementation of SSAO

The whole scene with the new SSAO

Continue reading “Screen Space Ambient Occlusion” »

Why boost python for AnKi?

Every game engine, at some level, needs to be able to compile and run code at runtime. You need, for example, to trigger a custom event when the hero pushed a button. The button should contain a bunch of code that may call an elevator or/and open a door or/and even kill the hero. All these custom events are possible by embedding a scripting language on top of the native language the game uses. Most of the game developers use native languages like C/C++ (very popular), Objective C (iPhone) and Java (other mobile platforms and rarely on PC). As for the scripting languages, the developers face many more choices with custom scripting languages (Unreal Script), lua, javascript (through various implementations), Python, Squirrel and more.

AnKi, just like every other game engine, needed a scripting language and the searching/prototyping started almost a year back. We have made prototypes for lua, javascript (V8 and SpiderMonkey), squirrel, Qt script, Python and others. Lets see why we chose boost python over others…
Continue reading “Why boost python for AnKi?” »