How to implement biomes?

My current project is a 2D platformer in an infinite world, where players can build and mine. This is basically a follow-up of one of my last projects. The game only renders cells that are visible on the player’s screen.

The issue here is that I only have dirt at the moment. I want to implement biomes in a performant way, but I am not sure how. The game finds the material of each cell by its position, so I need to build a system that is able to take in the coordinates of a cell and output its material. The following code (written in TypeScript with roblox-ts) is what I have right now, but it does not support biomes and only returns dirt and air.

import CellTypeName from "./CellTypeName";

const a = 50;

export default abstract class WorldGeneration {
	public static GetCellTypeName(x: number, y: number, z: number): CellTypeName {
		return y < math.noise(x / 30, y / 30, 123) * a - a ? "Dirt" : "Air";
	}
}

I was thinking about generating noise maps for variables such as moisture and temperature, although I am not sure how to get a biome and material from that.

Please let me know if you find TypeScript confusing, cause I can translate it to Luau!

2 Likes

If you search “moisture humidity biome” for images you’ll get various tables showing what we call the biomes that fall into specific ranges of moisture and temperature.

1 Like

I should admit that I feel too lazy to program a diagram with biomes (also I do not want to get a time complexity of O(n^2) or worse). Instead, I think that regarding each biome as a point in space might work as well. The point would be a multidimensional vector of the temperature, moisture, et cetera.

-- point = {temperature, moisture, ...}

This is a vector that I can solve for every cell.

-- point(x, y, z) = {temperature(x, y, z), moisture(x, y, z), ...}

Then I can find the closest biome point to the cell point with this Stanford article. This approach should be extensible for more variables and has a time complexity of roughly O(n).

Perhaps I can use the same approach to find the most fitting cell material within the found biome. Also, this is theoretically still a biome table.