Slow Rush Studios logo,
    depicting an apprehensive-looking snail rushing forward

Slow Rush Studios

◂  Accidental Aimbot
News index

Texturing Terrain Tops

Contents

All the terrain in this game is made of individually simulated "atoms" (pixels) - just like the water, acid, flammable gas, etc.

But terrain doesn't move, so how can we make it look a little more visually interesting?

Well, we can apply a texture - but it isn't quite as easy as that...

Starting Point

A long time ago, in a game prototype far away, each individual atom was given a slightly-randomized colour:

Screenshot of game with atoms being assigned flat colours
Assigning colours based on the element of each atom, with some randomization for certain elements.

That looks pretty bad, right? Let's see how we can spruce it up.

Tilesets

In pixel art games, it's common to use "tiles" (square images) together with an approach called "autotiling" to add some visual interest to your levels:

Depiction of autotiling for Celeste (adapted from the fantastic Celeste Tilesets, Step-by-Step - well worth a read)

But even though I implemented autotiling at one point, I plan to move away from using square tiles for level design,1 so let's move on.

Texturing Terrain

A more flexible approach is to sample a tiling texture, which is nerd-speak for drawing a repeating image over the top of terrain atoms.

Repeating an image sounds bad, but if you also randomly darken2 some areas, the repetition is far less obvious:

Screenshot of texture applied to atoms
Texture
Screenshot of texture applied to atoms, with noise
Texture with random darkening
Applying a texture to atoms (left), then again with some randomized darkening (right).

This is already a massive improvement,3 but the edges of terrain still look unfinished.

And that is where it gets tricky.

Texturing Edges

In an autotiling approach, it's quick and easy to tell where the edges of your terrain are and what tile image you should apply to each square of atoms: for example, oh this is a tile with empty space above, so pick a tile with an edge on top.

But when you are looking at each pixel individually to determine its colour, it gets quite expensive to work out how far away a pixel is from each edge!

After some research,4 I figured out a reasonable approach: first, group atoms into islands:

Screenshot of game with atoms being assigned flat colours
Starting point
Screenshot of atoms grouped by connectivity groups
Grouped into islands
Identifying the connected islands: all the same-element atoms touching each other.

Then for each island of connected atoms:

  1. Run a marching squares algorithm to convert it into a polygon (possibly with holes).
  2. Trace the edges of the polygon, stopping every so often.
    • Whenever you stop, move inwards a little, and draw a small "edge graphic" image onto the underlying atoms.
Screenshot of atom islands being polygonized
Tracing polygons
Screenshot of edge texture being applied
Edge graphics drawn
Tracing polygon edges (red lines) and stopping every so often (green lines) to draw edge graphic images onto the terrain.

The little images do technically get drawn over each other sometimes, but I don't think you can really tell - and the same idea can also be used to add some outlines around the edges of the stone,5 which makes it look a bit more finished.

Now we just have to put it all together and see what it looks like.

All the tricks applied to get the end product.

Of course, it still looks a little silly with all the square edges, and that little metal bridge still looks terrible - but those are problems for another day.

Discerning Eyes Wanted

Then please, get in touch! I'm trying to polish up the graphics and I'd love to add more things to my hit-list.

Playable web build‎

As (almost) always, here's a new playable web build for you, now with approximately 20% better graphics!

(And yes, there's a neato parallax background now, but we don't have words left to talk about that. There are rules about these things, you know.)

Press F1 for help, including to see keyboard/mouse controls. Mobile devices probably won't work! By playing you agree to our Privacy Policy and Terms of Service.

1

I'm using 8x8 pixel tiles to design my levels right now, but that has a few downsides: the levels look eerily square, and I have very limited flexibility in placing "props" - for example, it's damn near impossible to carefully position a rocket lying on a slope!

2

In this case I am sampling a 2D Perlin noise field: if a point on the field is above some threshold, then I darken that atom.

3

Full credit for this texture (and a lot of other visual improvements you might spot!) is due to this wonderful Australian pixel artist I've been working with lately.

4

And by research, I mean brainstorming and reverse-engineering Noita's approach with the other falling-sand boffins in the Discord Slow Rush Discord .

5

I did try also adding an outline for the wood, but that looked silly, so I still need to figure out a nice approach for that.

◂  Accidental Aimbot
News index