Lightmap baking on CPU using Embree and OpenImageDenoise

I wanted to have a portable lightmapper that is part of a custom map editor that I was building in C++. Thus I chose to build CPU powered lightmapper.

And to my amazement, it is really fast as OpenImageDenoise works like magic and the noisy CPU path tracer result gets smoothed out. The lightmapper is based on design described by the creator of Bakery-addon for Unity.

First, it creates the lightmap UV space GBuffer with multipass rendering to emulate conservative rasterization. Secondly, it offsets the sample position by raytracing from each sample position. It checks if the sample position resides inside geometry and offsets it to redure shadow leaks. Thirdly, using Embree it path traces from the sample positions and builds the lightmap. Finally, the lightmap is filtered using the OpenImageDenoiser.

The only downside is that the OpenImageDenoise is huge. The .dll takes around 45 megabytes (compared to my exe ~700KB). Anyway, I think it is worth having as it speeds up the path tracing result significantly. Here is a screenshot of preliminary result.

Denoised lightmap result in 20 seconds on Intel i7-5820k

Developing own custom game engine from scratch in 2023

With the freshly released Unreal Engine 5 and its groundbreaking features, Unity’s free dark mode, and Godot 4’s ambitious plans to dominate the indie gamedev community, indie developers have a plethora of options to choose from. In this blog post, I’ll discuss the decision-making process behind selecting a game engine like Unity, Unreal, or Godot, versus building a custom game engine. I’ll also share the reasons why some developers, including myself, have chosen to build custom game engines for their game projects.

Next, I go through some decision reasons of choosing between Unity / Unreal / Godot vs Custom Game Engine. Lastly, I go over the reasons why I did choose to build my own custom game engine for my game project.

When to Choose Unity, Unreal, or Godot?

A cross-platform game

Developing cross-platform games can be challenging due to the many moving parts and potential undefined behaviors. Popular game engines like Unity, Unreal, and Godot have been extensively tested and provide built-in workarounds for many issues, making them ideal for cross-platform development.

Proper asset content pipeline

For games that rely heavily on imported 3D models, animations, collision, and materials, having a reliable content pipeline and asset authoring system is crucial. Off-the-shelf game engines can handle a wide variety of 3D model formats and offer effective texture compression, making them an excellent choice for such projects.

Realistic or next-gen graphics

Achieving cutting-edge graphics as an indie developer can be challenging. Choosing an off-the-shelf game engine ensures that your game stays competitive with current industry standards.

Build in the shortest time possible

Custom game engines require significant development time, making it difficult to beat the time-to-market offered by off-the-shelf game engines.

Find people with existing skills to use the engine

When bringing new team members on board, it’s advantageous to use a game engine with which they already have experience.

Mobile game that ships for Android

Developing games with OpenGL ES for Android can be challenging due to the wide variety of devices and drivers with inconsistent behavior. For mobile games, choosing a proven game engine like Unity or Defold is advisable.

No specific or good reasoning for building a custom engine

If there are no significant business or game design motivations to build a custom game engine, it’s best to opt for an off-the-shelf solution.

When it is viable to build a custom game engine?

Fine-tuning the technical aspects

A custom game engine allows developers to optimize and customize the entire stack, from raw input to rendering. This is particularly advantageous when seeking minimal distribution size and maximum performance.

Needs are well known before building the game

Having a clear understanding of the features required for your game engine ensures accurate estimations of development time and resources.

Content pipeline is simple and limited

If your game design allows for limited 3D model formats and excludes textures with alpha, building a custom engine might be more suitable.

No next-gen graphics

Sometimes, less is more. For games that don’t require cutting-edge visuals, a custom game engine can be a viable choice.

Long-term development or support plans

Upgrading a game built with off-the-shelf engines can result in game-breaking changes, requiring rework of levels and mechanics. For projects with long development cycles or extended post-launch support, a custom game engine offers greater control and stability.

Why I have chosen to build custom game engine for my game projects?

Achieving the lowest possible network and input lag

To ensure a smooth and responsive gaming experience, it’s essential to minimize input and network latency. With a custom game engine, I have full control over the rendering loop, swapchain presentation, and input polling. This allows me to fine-tune these aspects, resulting in a more enjoyable and lag-free experience for the players.

Ultra-light and ultra-fast

One of my top priorities is to create games that are small in distribution size, boast ultra-fast startup times, and have minimal loading times. By building a custom game engine, I can optimize performance for low-end machines, making the game non-intrusive, lightweight, and accessible to a wider range of players.

Simple visuals

While visuals are undeniably important, I believe that overly realistic or flashy graphics can detract from the core gameplay experience. By opting for simple visuals, I can create a streamlined content pipeline and rendering engine for my custom game engine. This design choice also allows me to focus on gameplay mechanics and ensure a fun, immersive experience for players.

Provide a map editor for the community

Yes, you can also build map editor with Unreal / Unity / Godot. Building a custom game engine also allows me to create a map editor tailored to my game’s specific needs. While it does require some additional effort to polish the editor for external users, I believe it’s worth it. Providing the community with a user-friendly map editor will enable players to create their own content and further engage with the game.

Long term project!

By having control over the entire software stack, I can more easily support future Windows versions and address issues related to new hardware. Using an existing engine like Unity or Unreal could result in being locked into a specific version, making it difficult to adapt to changes in core engine components. With my custom engine, I can ensure that my game stays up-to-date and true to its original vision.

PC-only game

By concentrating on a single platform, I can avoid the complexities of cross-platform development and tailor the game engine specifically for PC users. This focused approach allows me to optimize the game for the PC platform and create a more polished and enjoyable experience.

Software engineer first, game designer second.

Lastly, I simply enjoy the process of tinkering, learning, and developing new techniques and possibilities. As a software engineer first and a game designer second, building a custom game engine aligns with my interests and allows me to challenge myself in ways that using an off-the-shelf engine might not.

Note: This post was originally published in 2021 but I updated it for 2023. Not much has changed.

Sound and audio in competitive FPS game

Lately, I have been thinking sound design in my a multiplayer FPS game prototype.

Audio is very important in games. Sounds gives clues and reference about the current game situation and environment the listener is in. Both silence and high volume sounds have their places, but is important that the audio volume levels are correct.

In competitive FPS game, 3D positional audio plays important role when locating opponents. Headphones are must have to be competitive in multiplayer FPS game.

When working on the audio and sound design for my multiplayer FPS game, I take account the importance of audio occlusion, clues, directivity, effects and more.

Audio occlusion

Occlusion happens when there is physical obstacle (medium) between listener and audio source. Often the sound doesn’t completely get blocked because the sound either reflects from nearby walls which bounce the sound waves to the listener. Also lower frequency sound waves are good at traveling through mediums.

In games, audio occlusion test is often implemented using raycasting. Most likely a good estimation of audio occlusion is done by raycasting multiple lines from the listener to points near by the audio source. Path tracing can also be used to compute better reflection and realistic audio directivity.

In multiplayer FPS games, I argue that realistic audio directivity will cause confusion for the player. For example, gun shots or footstep audio should be seemed to be coming directly from the true audio source and not reflected from walls. Although it isn’t realistic, it is important from gameplay perspective to avoid confusing the player.

In my FPS game prototype, the audio occlusion implementation is still work-in-progress. Currently I use multiple raycast testing to define audio occlusion. The audio is simply low-pass filtered and reduced by volume depending on the obstace medium size.

Improving audio directivity with HRTF

For audio, I leverage OpenAL Soft audio library. It comes with an excellent HRTF (Head Related Transfer Function) implementation. In short, HRTF simulates how ears will hear the sound from a certain point in 3D world. Headphones has to be used when HRTF is enabled. With HRTF player gets much better immersion of the sound direction, especially on the up/down axis.