Water tint

This commit is contained in:
2026-10-07 11:29:58 -03:00
parent b830196829
commit 40d5a4f5af
8 changed files with 84 additions and 29 deletions
+21 -9
View File
@@ -1,13 +1,13 @@
// blocks with a "tint" are drawn in their biome's grass or foliage color, blended across biome edges, or a fixed one
// blocks with a "tint" are drawn in their biome's grass or foliage color, blended across biome edges, or a fixed one. water is its biome's water color
import { assert, assertEquals } from "@std/assert";
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "$/common/constants.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
import { BIOME_FOLIAGE_COLORS, BIOME_GRASS_COLORS } from "$/common/worldgen/biome_colors.ts";
import { BIOME_FOLIAGE_COLORS, BIOME_GRASS_COLORS, BIOME_WATER_COLORS } from "$/common/worldgen/biome_colors.ts";
import { type LayerMesh, TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
import { test_game } from "./helpers.ts";
type Colors = { grass: number; foliage: number };
type Colors = { grass: number; foliage: number; water?: number };
// one block at x, 10, 8 of the middle chunk, meshed with these biome colors for the middle chunk and the one to its
// -x side (the others aren't there). returns the colors of the quads on its top and on its sides
@@ -30,16 +30,17 @@ async function mesh_block(id: string, x: number, middle: Colors, west: Colors |
const empty = () => new Uint32Array(CHUNK_AREA * CHUNK_HEIGHT);
const chunks = [empty(), empty(), empty(), empty(), chunk, empty(), empty(), empty(), empty()];
const colors = chunks.map(() => null as Uint32Array | null);
const biome_colors = ({ grass, foliage }: Colors) => {
const array = new Uint32Array(CHUNK_AREA * 2);
const biome_colors = ({ grass, foliage, water = 0 }: Colors) => {
const array = new Uint32Array(CHUNK_AREA * 3);
array.fill(grass, 0, CHUNK_AREA);
array.fill(foliage, CHUNK_AREA);
array.fill(foliage, CHUNK_AREA, CHUNK_AREA * 2);
array.fill(water, CHUNK_AREA * 2);
return array;
};
colors[4] = biome_colors(middle);
if (west) colors[3] = biome_colors(west);
const meshed = await new Promise<{ solid: LayerMesh; cutout: LayerMesh }>((resolve) => {
const meshed = await new Promise<{ solid: LayerMesh; cutout: LayerMesh; translucent: LayerMesh }>((resolve) => {
worker.onmessage = (e) => resolve(e.data);
worker.postMessage({
type: "mesh",
@@ -55,7 +56,7 @@ async function mesh_block(id: string, x: number, middle: Colors, west: Colors |
const top: number[][] = [];
const sides: number[][] = [];
for (const mesh of [meshed.solid, meshed.cutout]) {
for (const mesh of [meshed.solid, meshed.cutout, meshed.translucent]) {
const f32 = new Float32Array(mesh.vertices.buffer);
for (let quad = 0; quad < mesh.quad_count; quad++) {
const byte = quad * 4 * TERRAIN_VERTEX_BYTES;
@@ -101,7 +102,17 @@ Deno.test("oak leaves are the biome's foliage color on every side, birch a fixed
assertEquals(spruce.top, [[255, 255, 255]]);
});
Deno.test("every column the overworld generates has a biome with grass and foliage colors", async () => {
Deno.test("water is its biome's water color", async () => {
const { sides } = await mesh_block(
"bworld:water",
8,
{ grass: 0xff0000, foliage: 0x00ff00, water: 0x2040ff },
null,
);
assert(sides.some((rgb) => JSON.stringify(rgb) === JSON.stringify(shaded(0x2040ff, 0.8))));
});
Deno.test("every column the overworld generates has a biome with grass, foliage and water colors", async () => {
const { game } = await test_game("mods");
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
const block_ids: Record<string, number> = {};
@@ -112,6 +123,7 @@ Deno.test("every column the overworld generates has a biome with grass and folia
for (const biome of biomes) {
assert(biome in BIOME_GRASS_COLORS, `${biome} has no grass color`);
assert(biome in BIOME_FOLIAGE_COLORS, `${biome} has no foliage color`);
assert(biome in BIOME_WATER_COLORS, `${biome} has no water color`);
}
}
});