GameLoom Studio in Instagram GameLoom Studio in Facebook GameLoom Studio in Itch.io GameLoom Studio in Steam GameLoom Studio in Discord
Older blogposts ≫

Obstruction of Visibility - Temporal Beer's Law (2/2)


Games must be fast…

It's obvious why it's slow; raycasting from observer to each pixel with a step of one pixel is just too many iterations. At this point you can start thinking about what smart data structures to use and… or you can do like me, check how bad things get if we increase the step size for each ray. How big must each step be until the below-minimum-spec-machine can run at a decent framerate?

15 pixels. A huge amount.

Banding artifact (zoom in to the rock on the right-side view).

With such a large step you can clearly see banding appear. The ray is cast from the ship in each direction, to each pixel, so a circular pattern shouldn't be surprising.

… and look good!

One thing to notice is that the results of the raycasts in one frame are very close to that of the previous frame, simply because the view isn't moving that fast. This means using the previous frame's result and combining it with the new results might be possible, similar to how Temporal anti-aliasing works. But first, let's get rid of the circular artifacts.

If each ray would have a slight randomization in their step lengths, the circular banding should disappear. Easy enough, just use a little GLSL function called noise1, recompile the shaders aaaand… nothing changed. Absolutely nothing. You should never ever ever ever use GLSL noise function, never ever! So here's a funny thing with GLSL noise function, it's commonly not implemented by GPU vendors. With the graphics card I was using, it just returned zero every time.

Thankfully, I had done quite a lot of reading up on randomization and hashing. This shadertoy program by David Hoskins shows many different algorithms you might find useful.

Grainy artifact (scaled up to 300 %).

After adding a real noise for the rays, screenshots shows the sprites as a bit "grainy". But this is not how your eye sees it when it's running at 60 FPS. I had expected flickering, which is a little bit present in 30 FPS, but I saw none at 60 FPS. This is probably because the ray casts have so similar values each frame so the human brain just "makes it work".

So why add any low-pass filter algorithm or similar when the human mind does the trick already? I ended up not bothering, at the cost of slightly grainy screenshots.

Visibility with slightly randomized step length.

Oh and you might wonder - Doesn't the circular artifact still happen in the center of the viewpoint? The steps are still very similar in that area right? Yes, yes it is and it does. However, the center of view is masked out since we don't want to hide your own ship from the controlling player. So fixed by game design! đŸ˜‚

- Jens the Temporal Programmer, June 2024

Older blog posts:

2024

Task-Centric Development

Obstruction of Visibility - Temporal Beer's Law (1/2)

Obstruction of Visibility - Temporal Beer's Law (2/2)

2022

Portability and the Demo Effect

Iterative "KIS(S)" - The Sprite Atlas

About Animations…

Asteroid Arena - How It All Began