Frostward Colony Wishlist on Steam
← Devlog

How the water reflections work

Someone asked this the other day:

Did you have to write a custom shader for the reflections? It blends perfectly with the low-res aesthetic.

Yeah, had to write one. Here's how it works.

Houses along a lake shore, mirrored in the water
The houses, the flagpole and the reeds are all mirrored. None of it is drawn twice.

It runs on the small picture

The game draws its 3D world at a low resolution and then scales it up with hard edges. That's where the pixel-art look comes from.

The reflection pass runs on that small picture, before it's scaled up. So a reflection is made of the same chunky pixels as everything else. If it ran on the full-size picture it would be smooth, and it would look pasted on.

Look straight up

For each pixel of water, the shader looks straight up the screen until it finds something standing above the waterline. Then it copies that colour down, a bit darker and a bit bluer.

That works because the camera has no perspective. A reflection is always directly below the thing it mirrors, in the same column of pixels. So there's nothing to render a second time, and it costs almost nothing.

The depth buffer tells the shader how tall each thing is, which is how it knows which pixel's mirror image lands where.

Keeping it crisp

Two small rules stop it going soft:

  • The fade is dithered. The top of a tall tree's reflection thins out in a checker pattern until it's gone. There's no smooth blend anywhere.
  • The ripple moves whole rows sideways, one pixel at a time, on a stepped clock. Nothing ever lands between two pixels.

What it can't do

It only knows about what's on screen. If a tower pokes out of the top of the picture, the shader can't see its tip, so the reflection thins out near the top edge. I'd take a missing sliver over a made-up one.

Foam, sun glints, rain rings and the little waves are drawn afterwards, so they sit on top of the reflection like they sit on the water.

Wishlist on Steam