Water tint
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { block_value, chunk_key, default_block_value } from "$/common/utils.ts";
|
||||
import { AIR_ID } from "$/common/protocol.ts";
|
||||
import { decode_level_chunk } from "$/common/chunk_streaming.ts";
|
||||
import { foliage_color, grass_color } from "$/common/worldgen/biome_colors.ts";
|
||||
import { foliage_color, grass_color, water_color } from "$/common/worldgen/biome_colors.ts";
|
||||
import {
|
||||
block_light_emission,
|
||||
block_light_opacity,
|
||||
@@ -45,7 +45,7 @@ export interface Chunk {
|
||||
max_y: number;
|
||||
// only for translucent meshes that have to be sorted again as the camera moves
|
||||
translucent_sort?: TranslucentSort;
|
||||
// each column's biome grass color, x then z, then each column's foliage color
|
||||
// each column's biome grass color, x then z, then each column's foliage color, then water color
|
||||
biome_colors: Uint32Array;
|
||||
// from its last mesh, see get_light. undefined until it's been meshed
|
||||
light?: Uint8Array;
|
||||
@@ -171,10 +171,11 @@ export class ClientLevel {
|
||||
if (!this.#in_storage_range(x, z)) {
|
||||
return;
|
||||
}
|
||||
const biome_colors = new Uint32Array(CHUNK_AREA * 2);
|
||||
const biome_colors = new Uint32Array(CHUNK_AREA * 3);
|
||||
biomes.forEach((biome, column) => {
|
||||
biome_colors[column] = grass_color(biome);
|
||||
biome_colors[CHUNK_AREA + column] = foliage_color(biome);
|
||||
biome_colors[CHUNK_AREA * 2 + column] = water_color(biome);
|
||||
});
|
||||
|
||||
const chunk = this.get_chunk(x, z);
|
||||
|
||||
@@ -113,7 +113,7 @@ interface MeshQuad {
|
||||
sprite: SpriteRegion;
|
||||
// 4 weights per corner
|
||||
light_weights: number[];
|
||||
// 0xRRGGBB it's drawn in, GRASS or FOLIAGE for the biome's (see "tint"), or white
|
||||
// 0xRRGGBB it's drawn in, GRASS, FOLIAGE or WATER for the biome's (see "tint"), or white
|
||||
tint: number;
|
||||
}
|
||||
|
||||
@@ -207,17 +207,18 @@ function post(message: FromChunkWorker, transfer: Transferable[]) {
|
||||
self.postMessage(message, transfer);
|
||||
}
|
||||
|
||||
// like minecraft's biome blend at its default radius: each column's grass and foliage color is the average of the 5x5
|
||||
// like minecraft's biome blend at its default radius: each column's grass, foliage and water color is the average of the 5x5
|
||||
// columns around it, so biome edges fade instead of being a line. neighbors that aren't there are left out
|
||||
const BLEND_RADIUS = 2;
|
||||
// the middle chunk's blended colors, x then z, grass then foliage
|
||||
const blended = new Uint32Array(CHUNK_AREA * 2);
|
||||
// the middle chunk's blended colors, x then z, grass then foliage then water
|
||||
const blended = new Uint32Array(CHUNK_AREA * 3);
|
||||
// what MeshQuad.tint is for the biome's colors, they aren't colors since those only go up to 0xffffff
|
||||
const GRASS = -1;
|
||||
const FOLIAGE = -2;
|
||||
const WATER = -3;
|
||||
|
||||
function blend_biome_colors(colors: (Uint32Array | null)[]) {
|
||||
for (const offset of [0, CHUNK_AREA]) {
|
||||
for (const offset of [0, CHUNK_AREA, CHUNK_AREA * 2]) {
|
||||
for (let z = 0; z < CHUNK_SIZE; z++) {
|
||||
for (let x = 0; x < CHUNK_SIZE; x++) {
|
||||
let r = 0;
|
||||
@@ -253,6 +254,7 @@ function quad_tint(block: BlockRegistry, variables: string[]) {
|
||||
const color = block.tint!.color;
|
||||
if (color === "grass") return GRASS;
|
||||
if (color === "foliage") return FOLIAGE;
|
||||
if (color === "water") return WATER;
|
||||
return parseInt(color.slice(1), 16);
|
||||
}
|
||||
|
||||
@@ -610,6 +612,8 @@ function make_chunk_mesh(chunk_x: number, chunk_z: number, chunks: (Uint32Array
|
||||
? blended[z * CHUNK_SIZE + x]
|
||||
: quad.tint === FOLIAGE
|
||||
? blended[CHUNK_AREA + z * CHUNK_SIZE + x]
|
||||
: quad.tint === WATER
|
||||
? blended[CHUNK_AREA * 2 + z * CHUNK_SIZE + x]
|
||||
: quad.tint;
|
||||
|
||||
if (layer_id !== TRANSLUCENT) {
|
||||
|
||||
Reference in New Issue
Block a user