Water tint
This commit is contained in:
@@ -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