Localised Crepuscular Rays

Crepuscular rays, volumetric rays, or god rays have become a common effect in games. They are used especially in first and third person games – where the player can easily look at the sky – to give the sun, moon, or other bright light sources additional impact and create atmosphere.

Depending on how the effect is used it can emphasize the hot humidity of a rain forest, the creepiness of a foggy swamp, or the desolation of a post-apocalyptic scene.

While there are multiple ways to achieve this and similar effects, the method we will look at in particular is the approximation of volumetric light scattering as a post-process using screen-space ray marching.

In this article we will quickly step through the idea behind this algorithm, and how it is commonly used. We will then show how we can easily expand from there to create a solution that works well with multiple light sources, including some source code and images.

Continue reading →

Detailed frame-time performance measurement

Performance has always been an important aspect of game development. From the early days, where the processing power of hardware was extremely limited, to this day, where we may want to simulate hundreds of thousands of particles at once.

There are many ways to achieve good performance – and thus providing a better experience to the player. From following best practices and applying the right design patterns to using the best technologies.

Ultimately, we can – and should – only do so much before measuring our performance.

In general, the most powerful tool we can apply for this purpose is probably a good performance profiler. This way we can measure the performance of our entire program, down to specific lines of code that may be bottlenecks. Especially when it comes to micro-optimisation such a tool can be very valuable in identifying or confirming problematic code.

Profilers are not necessarily good at giving a higher level overview about our game’s performance, especially if we care less about pieces of code and more about semantic groupings like ‘physics’, ‘AI’ or ‘particles’.

Today we will develop a small class that will allow us to easily measure how much time our game spends on activities like that, and a frame-by-frame basis.

Continue reading →

Using generics for type-safe and type-specific identifiers

After the slightly philosophical diversion of last week’s post, today I would like to present a few more technical ideas building on my post about accessing game objects by unique identifiers.

Last week I made an argument for simplicity, for keeping it simple. However, complexity does have its place and there are several good reasons to increase the complexity of a system. One such reason is, if we can make that complexity do work for us.

That is what we will do today.

Continue reading →