BlueGit

timfa questward

Merge branch 'feature/procedural-water-simplex'

Procedural water/lava shaders (simplex FBM), lava ground with light and coasts, palette preview icons.

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
ad9610241446bc14138191cebb2f204899c997f4
26 files changed +1697 −123
client/assets/grounds/deep-water/deep-water-preview.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/grounds/deep-water/deep-water.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/grounds/lava/lava-preview.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/grounds/lava/lava.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/grounds/water/water-preview.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/grounds/water/water.png Binary file +0 −0

The contents of this binary file are not shown.

client/scripts/write-fluid-preview-icons.mjs added +225 −0
@@ -0,0 +1,225 @@
1 /**
2 * Bake 16×16 editor palette icons for procedural fluids.
3 * Renders a 3×3 tile neighborhood and crops the center tile so noise is continuous.
4 *
5 * node client/scripts/write-fluid-preview-icons.mjs
6 */
7 import { join } from "node:path";
8 import { makeRgba, writeRgbaPng } from "../../server/src/assets/placeholderPng.js";
9 import { DEFAULT_WATER_DEBUG, DEFAULT_LAVA_DEBUG } from "../src/play/waterDebug.js";
10
11 const TILE = 16;
12 const GRID = 3;
13 const BAKE = TILE * GRID;
14 const TIME = 2.4;
15 const root = join(import.meta.dirname, "..", "assets", "grounds");
16
17 function clamp (v, lo, hi)
18 {
19 return Math.min(hi, Math.max(lo, v));
20 }
21
22 function mix (a, b, t)
23 {
24 return a + (b - a) * t;
25 }
26
27 function smoothstep (edge0, edge1, x)
28 {
29 const t = clamp((x - edge0) / Math.max(1e-6, edge1 - edge0), 0, 1);
30 return t * t * (3 - 2 * t);
31 }
32
33 /** Compact value-noise FBM (preview-only stand-in for simplex). */
34 function hash3 (x, y, z)
35 {
36 const n = Math.sin(x * 127.1 + y * 311.7 + z * 74.7) * 43758.5453123;
37 return n - Math.floor(n);
38 }
39
40 function valueNoise3 (x, y, z)
41 {
42 const x0 = Math.floor(x);
43 const y0 = Math.floor(y);
44 const z0 = Math.floor(z);
45 const fx = x - x0;
46 const fy = y - y0;
47 const fz = z - z0;
48 const ux = fx * fx * (3 - 2 * fx);
49 const uy = fy * fy * (3 - 2 * fy);
50 const uz = fz * fz * (3 - 2 * fz);
51 const n000 = hash3(x0, y0, z0);
52 const n100 = hash3(x0 + 1, y0, z0);
53 const n010 = hash3(x0, y0 + 1, z0);
54 const n110 = hash3(x0 + 1, y0 + 1, z0);
55 const n001 = hash3(x0, y0, z0 + 1);
56 const n101 = hash3(x0 + 1, y0, z0 + 1);
57 const n011 = hash3(x0, y0 + 1, z0 + 1);
58 const n111 = hash3(x0 + 1, y0 + 1, z0 + 1);
59 const nx00 = mix(n000, n100, ux);
60 const nx10 = mix(n010, n110, ux);
61 const nx01 = mix(n001, n101, ux);
62 const nx11 = mix(n011, n111, ux);
63 const nxy0 = mix(nx00, nx10, uy);
64 const nxy1 = mix(nx01, nx11, uy);
65 return mix(nxy0, nxy1, uz) * 2 - 1;
66 }
67
68 function fbm3 (x, y, z)
69 {
70 let sum = 0;
71 let amp = 0.5;
72 let px = x;
73 let py = y;
74 let pz = z;
75 for (let i = 0; i < 4; i++)
76 {
77 sum += amp * valueNoise3(px, py, pz);
78 px *= 2;
79 py *= 2;
80 pz *= 2;
81 amp *= 0.5;
82 }
83 return sum;
84 }
85
86 function sampleHeight (worldX, worldY, p, timeSec)
87 {
88 const flowX = timeSec * p.flowX;
89 const flowY = timeSec * p.flowY;
90 const baseX = worldX * p.waveScale + flowX;
91 const baseY = worldY * p.waveScale + flowY;
92 const baseZ = timeSec * p.flowZ;
93 const eps = Math.max(p.normalEps, 0.001);
94 const nC = fbm3(baseX, baseY, baseZ);
95 const nL = fbm3(baseX - eps, baseY, baseZ);
96 const nR = fbm3(baseX + eps, baseY, baseZ);
97 const nD = fbm3(baseX, baseY - eps, baseZ);
98 const nU = fbm3(baseX, baseY + eps, baseZ);
99 const h = nC * p.fbmAmp;
100 const ndotl = clamp(
101 (-(nL - nR) * p.lightDirX + -(nD - nU) * p.lightDirY + p.normalZ * p.lightDirZ)
102 / Math.hypot(nL - nR, nD - nU, p.normalZ),
103 0,
104 1
105 );
106 const wave = clamp(h * p.waveGain + 0.5, 0, 1);
107 const crest = smoothstep(p.crestLo, Math.max(p.crestHi, p.crestLo + 0.01), wave) ** Math.max(p.crestPow, 0.01);
108 let glitter = (ndotl ** Math.max(p.glitterPow, 0.01)) * crest;
109 glitter = Math.max(glitter, (crest ** 2.5) * p.crestGlitter);
110 return { wave, glitter, ndotl };
111 }
112
113 function rgbBytes (r, g, b)
114 {
115 return [
116 Math.round(clamp(r, 0, 1) * 255),
117 Math.round(clamp(g, 0, 1) * 255),
118 Math.round(clamp(b, 0, 1) * 255),
119 255
120 ];
121 }
122
123 function paintWaterPixel (worldX, worldY, deepAmt, p)
124 {
125 const { wave, glitter, ndotl } = sampleHeight(worldX, worldY, p, TIME);
126 const darkW = clamp(p.deepDark, 0, 1);
127 const deepCol = [
128 mix(0.12, mix(0.05, 0.015, darkW), deepAmt),
129 mix(0.34, mix(0.16, 0.055, darkW), deepAmt),
130 mix(0.54, mix(0.34, 0.14, darkW), deepAmt)
131 ];
132 const midCol = [
133 mix(0.24, mix(0.10, 0.04, darkW), deepAmt),
134 mix(0.52, mix(0.30, 0.14, darkW), deepAmt),
135 mix(0.70, mix(0.50, 0.28, darkW), deepAmt)
136 ];
137 const litCol = [
138 mix(0.52, mix(0.26, 0.12, darkW), deepAmt),
139 mix(0.78, mix(0.46, 0.28, darkW), deepAmt),
140 mix(0.90, mix(0.66, 0.46, darkW), deepAmt)
141 ];
142 const sparkCol = [
143 mix(0.98, mix(0.72, 0.48, darkW), deepAmt),
144 mix(1.0, mix(0.88, 0.68, darkW), deepAmt),
145 mix(1.0, mix(0.98, 0.86, darkW), deepAmt)
146 ];
147 const body = smoothstep(p.bodyLo, Math.max(p.bodyHi, p.bodyLo + 0.01), wave);
148 const litAmt = smoothstep(p.litLo, Math.max(p.litHi, p.litLo + 0.01), wave) * p.litMix;
149 let r = mix(deepCol[0], midCol[0], body);
150 let g = mix(deepCol[1], midCol[1], body);
151 let b = mix(deepCol[2], midCol[2], body);
152 r = mix(r, litCol[0], litAmt);
153 g = mix(g, litCol[1], litAmt);
154 b = mix(b, litCol[2], litAmt);
155 const shade = mix(p.shadeLo, p.shadeHi, ndotl);
156 r *= shade;
157 g *= shade;
158 b *= shade;
159 const spark = Math.min(glitter, p.glitterCap) * p.glitterMix;
160 r = mix(r, sparkCol[0], spark);
161 g = mix(g, sparkCol[1], spark);
162 b = mix(b, sparkCol[2], spark);
163 return rgbBytes(r, g, b);
164 }
165
166 function paintLavaPixel (worldX, worldY, p)
167 {
168 const { wave, glitter, ndotl } = sampleHeight(worldX, worldY, p, TIME);
169 let heat = smoothstep(p.bodyLo, Math.max(p.bodyHi, p.bodyLo + 0.01), wave);
170 heat = mix(heat, 1, smoothstep(p.litLo, Math.max(p.litHi, p.litLo + 0.01), wave) * p.litMix * 0.35);
171 heat = clamp(heat + Math.min(glitter, p.glitterCap) * p.glitterMix * 0.45, 0, 1);
172 let r = mix(0.16, 0.78, smoothstep(0, 0.38, heat));
173 let g = mix(0.015, 0.08, smoothstep(0, 0.38, heat));
174 let b = mix(0.01, 0.02, smoothstep(0, 0.38, heat));
175 r = mix(r, 0.98, smoothstep(0.28, 0.68, heat));
176 g = mix(g, 0.38, smoothstep(0.28, 0.68, heat));
177 b = mix(b, 0.04, smoothstep(0.28, 0.68, heat));
178 const yellowAmt = smoothstep(0.55, 0.98, heat);
179 r = mix(r, 1.0, yellowAmt);
180 g = mix(g, 0.9, yellowAmt);
181 b = mix(b, 0.28, yellowAmt);
182 const shade = mix(p.shadeLo, p.shadeHi, ndotl);
183 return rgbBytes(r * shade, g * shade, b * shade);
184 }
185
186 function bakeCenterTile (paintPixel)
187 {
188 const full = makeRgba(BAKE, BAKE, [0, 0, 0, 255]);
189 const origin = 1;
190 for (let py = 0; py < BAKE; py++)
191 {
192 for (let px = 0; px < BAKE; px++)
193 {
194 const worldX = origin + px / TILE;
195 const worldY = origin + py / TILE;
196 full.pixels.set(paintPixel(worldX, worldY), (py * BAKE + px) * 4);
197 }
198 }
199 const out = makeRgba(TILE, TILE, [0, 0, 0, 255]);
200 for (let y = 0; y < TILE; y++)
201 {
202 for (let x = 0; x < TILE; x++)
203 {
204 const sx = TILE + x;
205 const sy = TILE + y;
206 const src = (sy * BAKE + sx) * 4;
207 out.pixels.set(full.pixels.subarray(src, src + 4), (y * TILE + x) * 4);
208 }
209 }
210 return out;
211 }
212
213 const waterP = { ...DEFAULT_WATER_DEBUG };
214 const lavaP = { ...DEFAULT_LAVA_DEBUG };
215
216 const waterIcon = bakeCenterTile((x, y) => paintWaterPixel(x, y, 0, waterP));
217 writeRgbaPng(join(root, "water", "water-preview.png"), TILE, TILE, waterIcon.pixels);
218
219 const deepIcon = bakeCenterTile((x, y) => paintWaterPixel(x, y, Math.pow(1, waterP.deepAbrupt), waterP));
220 writeRgbaPng(join(root, "deep-water", "deep-water-preview.png"), TILE, TILE, deepIcon.pixels);
221
222 const lavaIcon = bakeCenterTile((x, y) => paintLavaPixel(x, y, lavaP));
223 writeRgbaPng(join(root, "lava", "lava-preview.png"), TILE, TILE, lavaIcon.pixels);
224
225 console.log("Wrote water / deep-water / lava preview icons (3×3 center crop).");
@@ -0,0 +1,225 @@
1/**
2 * Bake 16×16 editor palette icons for procedural fluids.
3 * Renders a 3×3 tile neighborhood and crops the center tile so noise is continuous.
4 *
5 * node client/scripts/write-fluid-preview-icons.mjs
6 */
7import { join } from "node:path";
8import { makeRgba, writeRgbaPng } from "../../server/src/assets/placeholderPng.js";
9import { DEFAULT_WATER_DEBUG, DEFAULT_LAVA_DEBUG } from "../src/play/waterDebug.js";
10
11const TILE = 16;
12const GRID = 3;
13const BAKE = TILE * GRID;
14const TIME = 2.4;
15const root = join(import.meta.dirname, "..", "assets", "grounds");
16
17function clamp (v, lo, hi)
18{
19 return Math.min(hi, Math.max(lo, v));
20}
21
22function mix (a, b, t)
23{
24 return a + (b - a) * t;
25}
26
27function smoothstep (edge0, edge1, x)
28{
29 const t = clamp((x - edge0) / Math.max(1e-6, edge1 - edge0), 0, 1);
30 return t * t * (3 - 2 * t);
31}
32
33/** Compact value-noise FBM (preview-only stand-in for simplex). */
34function hash3 (x, y, z)
35{
36 const n = Math.sin(x * 127.1 + y * 311.7 + z * 74.7) * 43758.5453123;
37 return n - Math.floor(n);
38}
39
40function valueNoise3 (x, y, z)
41{
42 const x0 = Math.floor(x);
43 const y0 = Math.floor(y);
44 const z0 = Math.floor(z);
45 const fx = x - x0;
46 const fy = y - y0;
47 const fz = z - z0;
48 const ux = fx * fx * (3 - 2 * fx);
49 const uy = fy * fy * (3 - 2 * fy);
50 const uz = fz * fz * (3 - 2 * fz);
51 const n000 = hash3(x0, y0, z0);
52 const n100 = hash3(x0 + 1, y0, z0);
53 const n010 = hash3(x0, y0 + 1, z0);
54 const n110 = hash3(x0 + 1, y0 + 1, z0);
55 const n001 = hash3(x0, y0, z0 + 1);
56 const n101 = hash3(x0 + 1, y0, z0 + 1);
57 const n011 = hash3(x0, y0 + 1, z0 + 1);
58 const n111 = hash3(x0 + 1, y0 + 1, z0 + 1);
59 const nx00 = mix(n000, n100, ux);
60 const nx10 = mix(n010, n110, ux);
61 const nx01 = mix(n001, n101, ux);
62 const nx11 = mix(n011, n111, ux);
63 const nxy0 = mix(nx00, nx10, uy);
64 const nxy1 = mix(nx01, nx11, uy);
65 return mix(nxy0, nxy1, uz) * 2 - 1;
66}
67
68function fbm3 (x, y, z)
69{
70 let sum = 0;
71 let amp = 0.5;
72 let px = x;
73 let py = y;
74 let pz = z;
75 for (let i = 0; i < 4; i++)
76 {
77 sum += amp * valueNoise3(px, py, pz);
78 px *= 2;
79 py *= 2;
80 pz *= 2;
81 amp *= 0.5;
82 }
83 return sum;
84}
85
86function sampleHeight (worldX, worldY, p, timeSec)
87{
88 const flowX = timeSec * p.flowX;
89 const flowY = timeSec * p.flowY;
90 const baseX = worldX * p.waveScale + flowX;
91 const baseY = worldY * p.waveScale + flowY;
92 const baseZ = timeSec * p.flowZ;
93 const eps = Math.max(p.normalEps, 0.001);
94 const nC = fbm3(baseX, baseY, baseZ);
95 const nL = fbm3(baseX - eps, baseY, baseZ);
96 const nR = fbm3(baseX + eps, baseY, baseZ);
97 const nD = fbm3(baseX, baseY - eps, baseZ);
98 const nU = fbm3(baseX, baseY + eps, baseZ);
99 const h = nC * p.fbmAmp;
100 const ndotl = clamp(
101 (-(nL - nR) * p.lightDirX + -(nD - nU) * p.lightDirY + p.normalZ * p.lightDirZ)
102 / Math.hypot(nL - nR, nD - nU, p.normalZ),
103 0,
104 1
105 );
106 const wave = clamp(h * p.waveGain + 0.5, 0, 1);
107 const crest = smoothstep(p.crestLo, Math.max(p.crestHi, p.crestLo + 0.01), wave) ** Math.max(p.crestPow, 0.01);
108 let glitter = (ndotl ** Math.max(p.glitterPow, 0.01)) * crest;
109 glitter = Math.max(glitter, (crest ** 2.5) * p.crestGlitter);
110 return { wave, glitter, ndotl };
111}
112
113function rgbBytes (r, g, b)
114{
115 return [
116 Math.round(clamp(r, 0, 1) * 255),
117 Math.round(clamp(g, 0, 1) * 255),
118 Math.round(clamp(b, 0, 1) * 255),
119 255
120 ];
121}
122
123function paintWaterPixel (worldX, worldY, deepAmt, p)
124{
125 const { wave, glitter, ndotl } = sampleHeight(worldX, worldY, p, TIME);
126 const darkW = clamp(p.deepDark, 0, 1);
127 const deepCol = [
128 mix(0.12, mix(0.05, 0.015, darkW), deepAmt),
129 mix(0.34, mix(0.16, 0.055, darkW), deepAmt),
130 mix(0.54, mix(0.34, 0.14, darkW), deepAmt)
131 ];
132 const midCol = [
133 mix(0.24, mix(0.10, 0.04, darkW), deepAmt),
134 mix(0.52, mix(0.30, 0.14, darkW), deepAmt),
135 mix(0.70, mix(0.50, 0.28, darkW), deepAmt)
136 ];
137 const litCol = [
138 mix(0.52, mix(0.26, 0.12, darkW), deepAmt),
139 mix(0.78, mix(0.46, 0.28, darkW), deepAmt),
140 mix(0.90, mix(0.66, 0.46, darkW), deepAmt)
141 ];
142 const sparkCol = [
143 mix(0.98, mix(0.72, 0.48, darkW), deepAmt),
144 mix(1.0, mix(0.88, 0.68, darkW), deepAmt),
145 mix(1.0, mix(0.98, 0.86, darkW), deepAmt)
146 ];
147 const body = smoothstep(p.bodyLo, Math.max(p.bodyHi, p.bodyLo + 0.01), wave);
148 const litAmt = smoothstep(p.litLo, Math.max(p.litHi, p.litLo + 0.01), wave) * p.litMix;
149 let r = mix(deepCol[0], midCol[0], body);
150 let g = mix(deepCol[1], midCol[1], body);
151 let b = mix(deepCol[2], midCol[2], body);
152 r = mix(r, litCol[0], litAmt);
153 g = mix(g, litCol[1], litAmt);
154 b = mix(b, litCol[2], litAmt);
155 const shade = mix(p.shadeLo, p.shadeHi, ndotl);
156 r *= shade;
157 g *= shade;
158 b *= shade;
159 const spark = Math.min(glitter, p.glitterCap) * p.glitterMix;
160 r = mix(r, sparkCol[0], spark);
161 g = mix(g, sparkCol[1], spark);
162 b = mix(b, sparkCol[2], spark);
163 return rgbBytes(r, g, b);
164}
165
166function paintLavaPixel (worldX, worldY, p)
167{
168 const { wave, glitter, ndotl } = sampleHeight(worldX, worldY, p, TIME);
169 let heat = smoothstep(p.bodyLo, Math.max(p.bodyHi, p.bodyLo + 0.01), wave);
170 heat = mix(heat, 1, smoothstep(p.litLo, Math.max(p.litHi, p.litLo + 0.01), wave) * p.litMix * 0.35);
171 heat = clamp(heat + Math.min(glitter, p.glitterCap) * p.glitterMix * 0.45, 0, 1);
172 let r = mix(0.16, 0.78, smoothstep(0, 0.38, heat));
173 let g = mix(0.015, 0.08, smoothstep(0, 0.38, heat));
174 let b = mix(0.01, 0.02, smoothstep(0, 0.38, heat));
175 r = mix(r, 0.98, smoothstep(0.28, 0.68, heat));
176 g = mix(g, 0.38, smoothstep(0.28, 0.68, heat));
177 b = mix(b, 0.04, smoothstep(0.28, 0.68, heat));
178 const yellowAmt = smoothstep(0.55, 0.98, heat);
179 r = mix(r, 1.0, yellowAmt);
180 g = mix(g, 0.9, yellowAmt);
181 b = mix(b, 0.28, yellowAmt);
182 const shade = mix(p.shadeLo, p.shadeHi, ndotl);
183 return rgbBytes(r * shade, g * shade, b * shade);
184}
185
186function bakeCenterTile (paintPixel)
187{
188 const full = makeRgba(BAKE, BAKE, [0, 0, 0, 255]);
189 const origin = 1;
190 for (let py = 0; py < BAKE; py++)
191 {
192 for (let px = 0; px < BAKE; px++)
193 {
194 const worldX = origin + px / TILE;
195 const worldY = origin + py / TILE;
196 full.pixels.set(paintPixel(worldX, worldY), (py * BAKE + px) * 4);
197 }
198 }
199 const out = makeRgba(TILE, TILE, [0, 0, 0, 255]);
200 for (let y = 0; y < TILE; y++)
201 {
202 for (let x = 0; x < TILE; x++)
203 {
204 const sx = TILE + x;
205 const sy = TILE + y;
206 const src = (sy * BAKE + sx) * 4;
207 out.pixels.set(full.pixels.subarray(src, src + 4), (y * TILE + x) * 4);
208 }
209 }
210 return out;
211}
212
213const waterP = { ...DEFAULT_WATER_DEBUG };
214const lavaP = { ...DEFAULT_LAVA_DEBUG };
215
216const waterIcon = bakeCenterTile((x, y) => paintWaterPixel(x, y, 0, waterP));
217writeRgbaPng(join(root, "water", "water-preview.png"), TILE, TILE, waterIcon.pixels);
218
219const deepIcon = bakeCenterTile((x, y) => paintWaterPixel(x, y, Math.pow(1, waterP.deepAbrupt), waterP));
220writeRgbaPng(join(root, "deep-water", "deep-water-preview.png"), TILE, TILE, deepIcon.pixels);
221
222const lavaIcon = bakeCenterTile((x, y) => paintLavaPixel(x, y, lavaP));
223writeRgbaPng(join(root, "lava", "lava-preview.png"), TILE, TILE, lavaIcon.pixels);
224
225console.log("Wrote water / deep-water / lava preview icons (3×3 center crop).");
client/scripts/write-placeholder-assets.mjs +2 −31
@@ -53,38 +53,9 @@ overlay(join(root, "items", "lantern", "lantern-equip.png"), [200, 130, 48, 230]
53 53 torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));
54 54 torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));
55 55
56 function writeWaterSheet (file, base, wave, foam)
57 {
58 const frames = 4;
59 const width = 16 * frames;
60 const height = 16;
61 const image = makeRgba(width, height, base);
62 for (let f = 0; f < frames; f++)
63 {
64 const ox = f * 16;
65 for (let y = 0; y < 16; y++)
66 {
67 const t = y / 15;
68 fillRect(image, ox, y, 16, 1, [
69 Math.round(base[0] * (1 - t * 0.15)),
70 Math.round(base[1] * (1 - t * 0.08)),
71 Math.round(base[2] * (1 + t * 0.05)),
72 255
73 ]);
74 }
75 for (let i = 0; i < 3; i++)
76 {
77 const y = 3 + ((i * 4 + f) % 10);
78 const x0 = ox + ((f * 3 + i * 5) % 12);
79 fillRect(image, x0, y, 5, 1, wave);
80 fillRect(image, x0 + 1, y - 1, 3, 1, foam);
81 }
82 }
83 writeRgbaPng(file, width, height, image.pixels);
84 }
56 // Water caustic noise (64×64 RGB tiling Perlin) — regenerate via:
57 // node client/scripts/write-water-caustics-noise.mjs
85 58
86 writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255], [90, 170, 210, 255], [170, 220, 240, 220]);
87 writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255], [55, 120, 170, 255], [110, 170, 210, 200]);
88 59
89 60 {
90 61 const image = makeRgba(24, 8, [0, 0, 0, 0]);
@@ -53,38 +53,9 @@ overlay(join(root, "items", "lantern", "lantern-equip.png"), [200, 130, 48, 230]
53torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));
53torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));
54torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));
54torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));
55
55
56function writeWaterSheet (file, base, wave, foam)
56// Water caustic noise (64×64 RGB tiling Perlin) — regenerate via:
57{
57// node client/scripts/write-water-caustics-noise.mjs
58 const frames = 4;
59 const width = 16 * frames;
60 const height = 16;
61 const image = makeRgba(width, height, base);
62 for (let f = 0; f < frames; f++)
63 {
64 const ox = f * 16;
65 for (let y = 0; y < 16; y++)
66 {
67 const t = y / 15;
68 fillRect(image, ox, y, 16, 1, [
69 Math.round(base[0] * (1 - t * 0.15)),
70 Math.round(base[1] * (1 - t * 0.08)),
71 Math.round(base[2] * (1 + t * 0.05)),
72 255
73 ]);
74 }
75 for (let i = 0; i < 3; i++)
76 {
77 const y = 3 + ((i * 4 + f) % 10);
78 const x0 = ox + ((f * 3 + i * 5) % 12);
79 fillRect(image, x0, y, 5, 1, wave);
80 fillRect(image, x0 + 1, y - 1, 3, 1, foam);
81 }
82 }
83 writeRgbaPng(file, width, height, image.pixels);
84}
85
58
86writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255], [90, 170, 210, 255], [170, 220, 240, 220]);
87writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255], [55, 120, 170, 255], [110, 170, 210, 200]);
88
59
89{
60{
90 const image = makeRgba(24, 8, [0, 0, 0, 0]);
61 const image = makeRgba(24, 8, [0, 0, 0, 0]);
client/scripts/write-water-caustics-noise.mjs added +135 −0
@@ -0,0 +1,135 @@
1 /**
2 * Bake seamless water noise packs:
3 * R/G = soft Perlin body layers
4 * B/A = ridged “caustic vein” sprites for crossed glitter overlays
5 */
6 import { join } from "node:path";
7 import { makeRgba, writeRgbaPng } from "../../server/src/assets/placeholderPng.js";
8
9 const SIZE = 64;
10 const root = join(import.meta.dirname, "..", "assets");
11
12 function wrapInt (v, period)
13 {
14 const m = ((v % period) + period) % period;
15 return m | 0;
16 }
17
18 function hash2 (ix, iy, seed)
19 {
20 const n = Math.sin(ix * 127.1 + iy * 311.7 + seed * 74.7) * 43758.5453123;
21 return n - Math.floor(n);
22 }
23
24 function valueNoise (x, y, period, seed)
25 {
26 const x0 = Math.floor(x);
27 const y0 = Math.floor(y);
28 const fx = x - x0;
29 const fy = y - y0;
30 const ux = fx * fx * (3 - 2 * fx);
31 const uy = fy * fy * (3 - 2 * fy);
32 const a = hash2(wrapInt(x0, period), wrapInt(y0, period), seed);
33 const b = hash2(wrapInt(x0 + 1, period), wrapInt(y0, period), seed);
34 const c = hash2(wrapInt(x0, period), wrapInt(y0 + 1, period), seed);
35 const d = hash2(wrapInt(x0 + 1, period), wrapInt(y0 + 1, period), seed);
36 return a + (b - a) * ux + (c - a) * uy + (a - b - c + d) * ux * uy;
37 }
38
39 function fbm (x, y, period, seed, octaves = 4)
40 {
41 let amp = 0.5;
42 let freq = 1;
43 let sum = 0;
44 let norm = 0;
45 for (let i = 0; i < octaves; i++)
46 {
47 const p = Math.max(2, Math.round(period * freq));
48 sum += valueNoise(x * freq, y * freq, p, seed + i * 19.1) * amp;
49 norm += amp;
50 amp *= 0.5;
51 freq *= 2;
52 }
53 return sum / norm;
54 }
55
56 function normalizeLayer (values)
57 {
58 let min = Infinity;
59 let max = -Infinity;
60 for (let i = 0; i < values.length; i++)
61 {
62 if (values[i] < min)
63 { min = values[i]; }
64 if (values[i] > max)
65 { max = values[i]; }
66 }
67 const span = Math.max(1e-6, max - min);
68 const out = new Uint8Array(values.length);
69 for (let i = 0; i < values.length; i++)
70 { out[i] = Math.round(((values[i] - min) / span) * 255); }
71 return out;
72 }
73
74 function bakeSoft (seed, cells)
75 {
76 const values = new Float32Array(SIZE * SIZE);
77 for (let y = 0; y < SIZE; y++)
78 {
79 for (let x = 0; x < SIZE; x++)
80 { values[y * SIZE + x] = fbm((x / SIZE) * cells, (y / SIZE) * cells, cells, seed); }
81 }
82 return normalizeLayer(values);
83 }
84
85 /** Ridged / vein caustic: bright thin networks on dark. */
86 function bakeCaustic (seed, cells)
87 {
88 const values = new Float32Array(SIZE * SIZE);
89 for (let y = 0; y < SIZE; y++)
90 {
91 for (let x = 0; x < SIZE; x++)
92 {
93 const nx = (x / SIZE) * cells;
94 const ny = (y / SIZE) * cells;
95 const n1 = fbm(nx, ny, cells, seed, 5);
96 const n2 = fbm(nx + 3.1, ny - 1.7, cells, seed + 17.3, 4);
97 const ridge = 1 - Math.abs(n1 * 2 - 1);
98 const ridge2 = 1 - Math.abs(n2 * 2 - 1);
99 const veins = Math.pow(ridge, 3.2) * 0.75 + Math.pow(ridge * ridge2, 2.4) * 0.55;
100 values[y * SIZE + x] = veins;
101 }
102 }
103 return normalizeLayer(values);
104 }
105
106 function writePackedNoise (file, softSeeds, causticSeeds)
107 {
108 const r = bakeSoft(softSeeds[0], 4);
109 const g = bakeSoft(softSeeds[1], 5);
110 const b = bakeCaustic(causticSeeds[0], 7);
111 const a = bakeCaustic(causticSeeds[1], 8);
112 const image = makeRgba(SIZE, SIZE, [0, 0, 0, 255]);
113 for (let i = 0; i < SIZE * SIZE; i++)
114 {
115 const o = i * 4;
116 image.pixels[o] = r[i];
117 image.pixels[o + 1] = g[i];
118 image.pixels[o + 2] = b[i];
119 image.pixels[o + 3] = a[i];
120 }
121 writeRgbaPng(file, SIZE, SIZE, image.pixels);
122 }
123
124 writePackedNoise(
125 join(root, "grounds", "water", "water.png"),
126 [11.3, 27.9],
127 [101.4, 133.8]
128 );
129 writePackedNoise(
130 join(root, "grounds", "deep-water", "deep-water.png"),
131 [53.7, 67.1],
132 [157.2, 191.6]
133 );
134
135 console.log(`Wrote ${SIZE}x${SIZE} RGBA soft+caustic packs for water + deep-water.`);
@@ -0,0 +1,135 @@
1/**
2 * Bake seamless water noise packs:
3 * R/G = soft Perlin body layers
4 * B/A = ridged “caustic vein” sprites for crossed glitter overlays
5 */
6import { join } from "node:path";
7import { makeRgba, writeRgbaPng } from "../../server/src/assets/placeholderPng.js";
8
9const SIZE = 64;
10const root = join(import.meta.dirname, "..", "assets");
11
12function wrapInt (v, period)
13{
14 const m = ((v % period) + period) % period;
15 return m | 0;
16}
17
18function hash2 (ix, iy, seed)
19{
20 const n = Math.sin(ix * 127.1 + iy * 311.7 + seed * 74.7) * 43758.5453123;
21 return n - Math.floor(n);
22}
23
24function valueNoise (x, y, period, seed)
25{
26 const x0 = Math.floor(x);
27 const y0 = Math.floor(y);
28 const fx = x - x0;
29 const fy = y - y0;
30 const ux = fx * fx * (3 - 2 * fx);
31 const uy = fy * fy * (3 - 2 * fy);
32 const a = hash2(wrapInt(x0, period), wrapInt(y0, period), seed);
33 const b = hash2(wrapInt(x0 + 1, period), wrapInt(y0, period), seed);
34 const c = hash2(wrapInt(x0, period), wrapInt(y0 + 1, period), seed);
35 const d = hash2(wrapInt(x0 + 1, period), wrapInt(y0 + 1, period), seed);
36 return a + (b - a) * ux + (c - a) * uy + (a - b - c + d) * ux * uy;
37}
38
39function fbm (x, y, period, seed, octaves = 4)
40{
41 let amp = 0.5;
42 let freq = 1;
43 let sum = 0;
44 let norm = 0;
45 for (let i = 0; i < octaves; i++)
46 {
47 const p = Math.max(2, Math.round(period * freq));
48 sum += valueNoise(x * freq, y * freq, p, seed + i * 19.1) * amp;
49 norm += amp;
50 amp *= 0.5;
51 freq *= 2;
52 }
53 return sum / norm;
54}
55
56function normalizeLayer (values)
57{
58 let min = Infinity;
59 let max = -Infinity;
60 for (let i = 0; i < values.length; i++)
61 {
62 if (values[i] < min)
63 { min = values[i]; }
64 if (values[i] > max)
65 { max = values[i]; }
66 }
67 const span = Math.max(1e-6, max - min);
68 const out = new Uint8Array(values.length);
69 for (let i = 0; i < values.length; i++)
70 { out[i] = Math.round(((values[i] - min) / span) * 255); }
71 return out;
72}
73
74function bakeSoft (seed, cells)
75{
76 const values = new Float32Array(SIZE * SIZE);
77 for (let y = 0; y < SIZE; y++)
78 {
79 for (let x = 0; x < SIZE; x++)
80 { values[y * SIZE + x] = fbm((x / SIZE) * cells, (y / SIZE) * cells, cells, seed); }
81 }
82 return normalizeLayer(values);
83}
84
85/** Ridged / vein caustic: bright thin networks on dark. */
86function bakeCaustic (seed, cells)
87{
88 const values = new Float32Array(SIZE * SIZE);
89 for (let y = 0; y < SIZE; y++)
90 {
91 for (let x = 0; x < SIZE; x++)
92 {
93 const nx = (x / SIZE) * cells;
94 const ny = (y / SIZE) * cells;
95 const n1 = fbm(nx, ny, cells, seed, 5);
96 const n2 = fbm(nx + 3.1, ny - 1.7, cells, seed + 17.3, 4);
97 const ridge = 1 - Math.abs(n1 * 2 - 1);
98 const ridge2 = 1 - Math.abs(n2 * 2 - 1);
99 const veins = Math.pow(ridge, 3.2) * 0.75 + Math.pow(ridge * ridge2, 2.4) * 0.55;
100 values[y * SIZE + x] = veins;
101 }
102 }
103 return normalizeLayer(values);
104}
105
106function writePackedNoise (file, softSeeds, causticSeeds)
107{
108 const r = bakeSoft(softSeeds[0], 4);
109 const g = bakeSoft(softSeeds[1], 5);
110 const b = bakeCaustic(causticSeeds[0], 7);
111 const a = bakeCaustic(causticSeeds[1], 8);
112 const image = makeRgba(SIZE, SIZE, [0, 0, 0, 255]);
113 for (let i = 0; i < SIZE * SIZE; i++)
114 {
115 const o = i * 4;
116 image.pixels[o] = r[i];
117 image.pixels[o + 1] = g[i];
118 image.pixels[o + 2] = b[i];
119 image.pixels[o + 3] = a[i];
120 }
121 writeRgbaPng(file, SIZE, SIZE, image.pixels);
122}
123
124writePackedNoise(
125 join(root, "grounds", "water", "water.png"),
126 [11.3, 27.9],
127 [101.4, 133.8]
128);
129writePackedNoise(
130 join(root, "grounds", "deep-water", "deep-water.png"),
131 [53.7, 67.1],
132 [157.2, 191.6]
133);
134
135console.log(`Wrote ${SIZE}x${SIZE} RGBA soft+caustic packs for water + deep-water.`);
client/src/editor/paletteModal.js +3 −2
@@ -1,6 +1,6 @@
1 1 import { listPlaceableGrounds, listPlaceableBlockPaletteEntries } from "/shared/definitions/tiles.js";
2 2 import { listSpawnableMobTypes, mobSpriteName } from "/shared/definitions/mobs.js";
3 import { defaultStateForType, resolveState, spriteImageName } from "/shared/definitions/tileSprites.js";
3 import { defaultStateForType, resolveState, spriteImageName, palettePreviewImageName } from "/shared/definitions/tileSprites.js";
4 4
5 5 /**
6 6 * Select-tool modal: Ground / Blocks / Spawners, auto-built from definitions.
@@ -58,9 +58,10 @@ export function initPaletteModal ({ onSelect, catalog, imageUrlFor })
58 58 catalog.grounds?.[def.key]?.states ?? [],
59 59 state
60 60 ));
61 const previewName = palettePreviewImageName("ground", def.key);
61 62 grid.append(tileCard({
62 63 label: def.displayName,
63 url: imageUrlFor?.(name),
64 url: imageUrlFor?.(previewName) ?? imageUrlFor?.(name),
64 65 onClick ()
65 66 {
66 67 onSelect({ kind: "ground", typeId: def.id });
@@ -1,6 +1,6 @@
1import { listPlaceableGrounds, listPlaceableBlockPaletteEntries } from "/shared/definitions/tiles.js";
1import { listPlaceableGrounds, listPlaceableBlockPaletteEntries } from "/shared/definitions/tiles.js";
2import { listSpawnableMobTypes, mobSpriteName } from "/shared/definitions/mobs.js";
2import { listSpawnableMobTypes, mobSpriteName } from "/shared/definitions/mobs.js";
3import { defaultStateForType, resolveState, spriteImageName } from "/shared/definitions/tileSprites.js";
3import { defaultStateForType, resolveState, spriteImageName, palettePreviewImageName } from "/shared/definitions/tileSprites.js";
4
4
5/**
5/**
6 * Select-tool modal: Ground / Blocks / Spawners, auto-built from definitions.
6 * Select-tool modal: Ground / Blocks / Spawners, auto-built from definitions.
@@ -58,9 +58,10 @@ export function initPaletteModal ({ onSelect, catalog, imageUrlFor })
58 catalog.grounds?.[def.key]?.states ?? [],
58 catalog.grounds?.[def.key]?.states ?? [],
59 state
59 state
60 ));
60 ));
61 const previewName = palettePreviewImageName("ground", def.key);
61 grid.append(tileCard({
62 grid.append(tileCard({
62 label: def.displayName,
63 label: def.displayName,
63 url: imageUrlFor?.(name),
64 url: imageUrlFor?.(previewName) ?? imageUrlFor?.(name),
64 onClick ()
65 onClick ()
65 {
66 {
66 onSelect({ kind: "ground", typeId: def.id });
67 onSelect({ kind: "ground", typeId: def.id });
client/src/play/waterDebug.js added +129 −0
@@ -0,0 +1,129 @@
1 /**
2 * Procedural water / lava shader defaults and uniform bags.
3 * (Debug panel removed after tune-in.)
4 */
5
6 export const DEFAULT_WATER_DEBUG = Object.freeze({
7 flowX: 0.17,
8 flowY: 0.05,
9 flowZ: 0.91,
10 waveScale: 2.07,
11 fbmAmp: 0.15,
12 texAmp: 0.43,
13 distort: 0.09,
14 normalZ: 0.88,
15 waveGain: 0.62,
16 crestLo: 0.54,
17 crestHi: 0.67,
18 crestPow: 2.05,
19 glitterPow: 13.1,
20 crestGlitter: 1.3,
21 glitterCap: 1,
22 glitterMix: 1.24,
23 shadeLo: 1.06,
24 shadeHi: 1,
25 bodyLo: 0.41,
26 bodyHi: 0.85,
27 litLo: 0.5,
28 litHi: 0.86,
29 litMix: 0.46,
30 edgeDark: 0.37,
31 lightDirX: -0.48,
32 lightDirY: -0.63,
33 lightDirZ: 0.78,
34 normalEps: 0.21,
35 foamStrength: 1,
36 shoreClip: 0.55,
37 deepDark: 0.4,
38 deepAbrupt: 0.72
39 });
40
41 export const DEFAULT_LAVA_DEBUG = Object.freeze({
42 flowX: 0.08,
43 flowY: 0.04,
44 flowZ: 0.13,
45 waveScale: 1.83,
46 fbmAmp: 0.43,
47 texAmp: 0.3,
48 distort: 0.3,
49 normalZ: 1.07,
50 waveGain: 0.52,
51 crestLo: 0.57,
52 crestHi: 0.71,
53 crestPow: 1.15,
54 glitterPow: 7.5,
55 crestGlitter: 1.19,
56 glitterCap: 0.31,
57 glitterMix: 0.51,
58 shadeLo: 0.88,
59 shadeHi: 1.07,
60 bodyLo: 0.05,
61 bodyHi: 1,
62 litLo: 0.59,
63 litHi: 0.74,
64 litMix: 1,
65 edgeDark: 1,
66 lightDirX: -0.48,
67 lightDirY: -0.63,
68 lightDirZ: 0.78,
69 normalEps: 0.09,
70 bloomStrength: 0.9,
71 shoreClip: 0.9
72 });
73
74 function uniformBagFrom (p, extras = {})
75 {
76 return {
77 u_flowX: p.flowX,
78 u_flowY: p.flowY,
79 u_flowZ: p.flowZ,
80 u_waveScale: p.waveScale,
81 u_fbmAmp: p.fbmAmp,
82 u_texAmp: p.texAmp,
83 u_distort: p.distort,
84 u_normalZ: p.normalZ,
85 u_waveGain: p.waveGain,
86 u_crestLo: p.crestLo,
87 u_crestHi: p.crestHi,
88 u_crestPow: p.crestPow,
89 u_glitterPow: p.glitterPow,
90 u_crestGlitter: p.crestGlitter,
91 u_glitterCap: p.glitterCap,
92 u_glitterMix: p.glitterMix,
93 u_shadeLo: p.shadeLo,
94 u_shadeHi: p.shadeHi,
95 u_bodyLo: p.bodyLo,
96 u_bodyHi: p.bodyHi,
97 u_litLo: p.litLo,
98 u_litHi: p.litHi,
99 u_litMix: p.litMix,
100 u_edgeDark: p.edgeDark,
101 u_lightDirX: p.lightDirX,
102 u_lightDirY: p.lightDirY,
103 u_lightDirZ: p.lightDirZ,
104 u_normalEps: p.normalEps,
105 ...extras
106 };
107 }
108
109 /** Uniform bag for the water ground fragment shader. */
110 export function waterDebugUniforms ()
111 {
112 const p = DEFAULT_WATER_DEBUG;
113 return uniformBagFrom(p, {
114 u_foamStrength: p.foamStrength,
115 u_shoreClip: p.shoreClip,
116 u_deepDark: p.deepDark,
117 u_deepAbrupt: p.deepAbrupt
118 });
119 }
120
121 /** Uniform bag for lava ground / bloom shaders. */
122 export function lavaDebugUniforms ()
123 {
124 const p = DEFAULT_LAVA_DEBUG;
125 return uniformBagFrom(p, {
126 u_bloomStrength: p.bloomStrength,
127 u_shoreClip: p.shoreClip
128 });
129 }
@@ -0,0 +1,129 @@
1/**
2 * Procedural water / lava shader defaults and uniform bags.
3 * (Debug panel removed after tune-in.)
4 */
5
6export const DEFAULT_WATER_DEBUG = Object.freeze({
7 flowX: 0.17,
8 flowY: 0.05,
9 flowZ: 0.91,
10 waveScale: 2.07,
11 fbmAmp: 0.15,
12 texAmp: 0.43,
13 distort: 0.09,
14 normalZ: 0.88,
15 waveGain: 0.62,
16 crestLo: 0.54,
17 crestHi: 0.67,
18 crestPow: 2.05,
19 glitterPow: 13.1,
20 crestGlitter: 1.3,
21 glitterCap: 1,
22 glitterMix: 1.24,
23 shadeLo: 1.06,
24 shadeHi: 1,
25 bodyLo: 0.41,
26 bodyHi: 0.85,
27 litLo: 0.5,
28 litHi: 0.86,
29 litMix: 0.46,
30 edgeDark: 0.37,
31 lightDirX: -0.48,
32 lightDirY: -0.63,
33 lightDirZ: 0.78,
34 normalEps: 0.21,
35 foamStrength: 1,
36 shoreClip: 0.55,
37 deepDark: 0.4,
38 deepAbrupt: 0.72
39});
40
41export const DEFAULT_LAVA_DEBUG = Object.freeze({
42 flowX: 0.08,
43 flowY: 0.04,
44 flowZ: 0.13,
45 waveScale: 1.83,
46 fbmAmp: 0.43,
47 texAmp: 0.3,
48 distort: 0.3,
49 normalZ: 1.07,
50 waveGain: 0.52,
51 crestLo: 0.57,
52 crestHi: 0.71,
53 crestPow: 1.15,
54 glitterPow: 7.5,
55 crestGlitter: 1.19,
56 glitterCap: 0.31,
57 glitterMix: 0.51,
58 shadeLo: 0.88,
59 shadeHi: 1.07,
60 bodyLo: 0.05,
61 bodyHi: 1,
62 litLo: 0.59,
63 litHi: 0.74,
64 litMix: 1,
65 edgeDark: 1,
66 lightDirX: -0.48,
67 lightDirY: -0.63,
68 lightDirZ: 0.78,
69 normalEps: 0.09,
70 bloomStrength: 0.9,
71 shoreClip: 0.9
72});
73
74function uniformBagFrom (p, extras = {})
75{
76 return {
77 u_flowX: p.flowX,
78 u_flowY: p.flowY,
79 u_flowZ: p.flowZ,
80 u_waveScale: p.waveScale,
81 u_fbmAmp: p.fbmAmp,
82 u_texAmp: p.texAmp,
83 u_distort: p.distort,
84 u_normalZ: p.normalZ,
85 u_waveGain: p.waveGain,
86 u_crestLo: p.crestLo,
87 u_crestHi: p.crestHi,
88 u_crestPow: p.crestPow,
89 u_glitterPow: p.glitterPow,
90 u_crestGlitter: p.crestGlitter,
91 u_glitterCap: p.glitterCap,
92 u_glitterMix: p.glitterMix,
93 u_shadeLo: p.shadeLo,
94 u_shadeHi: p.shadeHi,
95 u_bodyLo: p.bodyLo,
96 u_bodyHi: p.bodyHi,
97 u_litLo: p.litLo,
98 u_litHi: p.litHi,
99 u_litMix: p.litMix,
100 u_edgeDark: p.edgeDark,
101 u_lightDirX: p.lightDirX,
102 u_lightDirY: p.lightDirY,
103 u_lightDirZ: p.lightDirZ,
104 u_normalEps: p.normalEps,
105 ...extras
106 };
107}
108
109/** Uniform bag for the water ground fragment shader. */
110export function waterDebugUniforms ()
111{
112 const p = DEFAULT_WATER_DEBUG;
113 return uniformBagFrom(p, {
114 u_foamStrength: p.foamStrength,
115 u_shoreClip: p.shoreClip,
116 u_deepDark: p.deepDark,
117 u_deepAbrupt: p.deepAbrupt
118 });
119}
120
121/** Uniform bag for lava ground / bloom shaders. */
122export function lavaDebugUniforms ()
123{
124 const p = DEFAULT_LAVA_DEBUG;
125 return uniformBagFrom(p, {
126 u_bloomStrength: p.bloomStrength,
127 u_shoreClip: p.shoreClip
128 });
129}
client/src/render/chunkBake.js +12 −3
@@ -340,6 +340,8 @@ export function isBakeable (sprite, meta = null)
340 340 { return false; }
341 341 if (sprite.width > SPRITE_SIZE_PX || sprite.height > SPRITE_SIZE_PX)
342 342 { return false; }
343 if (meta?.proceduralWaves)
344 { return false; }
343 345 const frames = Number(sprite.subImages) || Number(sprite.subImgTotal) || (meta?.frames ?? 1);
344 346 const speed = sprite._animationSpeed ?? meta?.animationSpeed ?? 0;
345 347 if (frames > 1)
@@ -491,6 +493,11 @@ function blitBlendedGround (
491 493 { continue; }
492 494 if (groundVisualKey(catalog, neighborGround, season) === selfKey)
493 495 { continue; }
496 // Never soft-blend land into procedural/liquid water — that pulls the noise sheet into the rim.
497 const nbrTypeId = normalizeGround(neighborGround).typeId;
498 const nbrDef = GROUND_DEFINITIONS[nbrTypeId];
499 if (nbrDef?.proceduralWaves || isLiquidWaterGround(nbrTypeId, season))
500 { continue; }
494 501 const neighborName = groundSpriteName(catalog, neighborGround, season);
495 502 const pixels = spritePixels(images[neighborName], pixelCache);
496 503 if (!pixels)
@@ -652,8 +659,10 @@ function groundCatalogMeta (catalog, ground)
652 659 {
653 660 const entry = normalizeGround(ground);
654 661 const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];
655 return catalog.grounds?.[def.key] ?? {
656 frames: def.frames,
657 animationSpeed: def.animationSpeed
662 const catalogMeta = catalog.grounds?.[def.key] ?? {};
663 return {
664 frames: catalogMeta.frames ?? def.frames,
665 animationSpeed: catalogMeta.animationSpeed ?? def.animationSpeed,
666 proceduralWaves: !!def.proceduralWaves
658 667 };
659 668 }
@@ -340,6 +340,8 @@ export function isBakeable (sprite, meta = null)
340 { return false; }
340 { return false; }
341 if (sprite.width > SPRITE_SIZE_PX || sprite.height > SPRITE_SIZE_PX)
341 if (sprite.width > SPRITE_SIZE_PX || sprite.height > SPRITE_SIZE_PX)
342 { return false; }
342 { return false; }
343 if (meta?.proceduralWaves)
344 { return false; }
343 const frames = Number(sprite.subImages) || Number(sprite.subImgTotal) || (meta?.frames ?? 1);
345 const frames = Number(sprite.subImages) || Number(sprite.subImgTotal) || (meta?.frames ?? 1);
344 const speed = sprite._animationSpeed ?? meta?.animationSpeed ?? 0;
346 const speed = sprite._animationSpeed ?? meta?.animationSpeed ?? 0;
345 if (frames > 1)
347 if (frames > 1)
@@ -491,6 +493,11 @@ function blitBlendedGround (
491 { continue; }
493 { continue; }
492 if (groundVisualKey(catalog, neighborGround, season) === selfKey)
494 if (groundVisualKey(catalog, neighborGround, season) === selfKey)
493 { continue; }
495 { continue; }
496 // Never soft-blend land into procedural/liquid water — that pulls the noise sheet into the rim.
497 const nbrTypeId = normalizeGround(neighborGround).typeId;
498 const nbrDef = GROUND_DEFINITIONS[nbrTypeId];
499 if (nbrDef?.proceduralWaves || isLiquidWaterGround(nbrTypeId, season))
500 { continue; }
494 const neighborName = groundSpriteName(catalog, neighborGround, season);
501 const neighborName = groundSpriteName(catalog, neighborGround, season);
495 const pixels = spritePixels(images[neighborName], pixelCache);
502 const pixels = spritePixels(images[neighborName], pixelCache);
496 if (!pixels)
503 if (!pixels)
@@ -652,8 +659,10 @@ function groundCatalogMeta (catalog, ground)
652{
659{
653 const entry = normalizeGround(ground);
660 const entry = normalizeGround(ground);
654 const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];
661 const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];
655 return catalog.grounds?.[def.key] ?? {
662 const catalogMeta = catalog.grounds?.[def.key] ?? {};
656 frames: def.frames,
663 return {
657 animationSpeed: def.animationSpeed
664 frames: catalogMeta.frames ?? def.frames,
665 animationSpeed: catalogMeta.animationSpeed ?? def.animationSpeed,
666 proceduralWaves: !!def.proceduralWaves
658 };
667 };
659}
668}
client/src/render/worldView.js +987 −45
@@ -2,7 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO
2 2 import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3 3 import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4 4 import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
5 import { collectBlockLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
5 import { collectBlockLightSources, collectGroundLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
6 6 import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
7 7 import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
8 8 import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
@@ -16,7 +16,7 @@ import
16 16 } from "/shared/render/tint.js";
17 17 import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
18 18 import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
19 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, LightOcclusion, blockDefinition, blockLightOcclusionForBlock } from "/shared/definitions/tiles.js";
19 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
20 20 import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
21 21 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
22 22 import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -27,7 +27,8 @@ import
27 27 invalidateCanvasTexture
28 28 } from "./canvasSprite.js";
29 29 import { setNearestFilter } from "./sprites.js";
30 import { SeasonId, seasonIdAt } from "/shared/world/season.js";
30 import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";
31 import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
31 32 import
32 33 {
33 34 OVERWORLD_ID,
@@ -105,6 +106,7 @@ const WATER_GROUND_FRAG = [
105 106 "precision mediump float;",
106 107 "varying vec2 v_texCoord;",
107 108 "uniform sampler2D u_texture;",
109 "uniform sampler2D u_secondary;",
108 110 "uniform float u_alpha;",
109 111 "uniform float u_ambientDark;",
110 112 "uniform float u_litNW;",
@@ -112,35 +114,564 @@ const WATER_GROUND_FRAG = [
112 114 "uniform float u_litSW;",
113 115 "uniform float u_litSE;",
114 116 "uniform float u_time;",
117 "uniform float u_tileX;",
118 "uniform float u_tileY;",
119 "uniform float u_deepNW;",
120 "uniform float u_deepNE;",
121 "uniform float u_deepSW;",
122 "uniform float u_deepSE;",
115 123 "uniform float u_edgeN;",
116 124 "uniform float u_edgeE;",
117 125 "uniform float u_edgeS;",
118 126 "uniform float u_edgeW;",
127 "uniform float u_edgeNE;",
128 "uniform float u_edgeNW;",
129 "uniform float u_edgeSE;",
130 "uniform float u_edgeSW;",
131 "uniform float u_hasShore;",
132 "uniform float u_shoreEdgeN;",
133 "uniform float u_shoreEdgeE;",
134 "uniform float u_shoreEdgeS;",
135 "uniform float u_shoreEdgeW;",
136 "uniform float u_shoreEdgeNE;",
137 "uniform float u_shoreEdgeNW;",
138 "uniform float u_shoreEdgeSE;",
139 "uniform float u_shoreEdgeSW;",
140 "uniform vec4 u_shoreUvRect;",
141 "uniform float u_flowX;",
142 "uniform float u_flowY;",
143 "uniform float u_flowZ;",
144 "uniform float u_waveScale;",
145 "uniform float u_fbmAmp;",
146 "uniform float u_texAmp;",
147 "uniform float u_distort;",
148 "uniform float u_normalZ;",
149 "uniform float u_waveGain;",
150 "uniform float u_crestLo;",
151 "uniform float u_crestHi;",
152 "uniform float u_crestPow;",
153 "uniform float u_glitterPow;",
154 "uniform float u_crestGlitter;",
155 "uniform float u_glitterCap;",
156 "uniform float u_glitterMix;",
157 "uniform float u_shadeLo;",
158 "uniform float u_shadeHi;",
159 "uniform float u_bodyLo;",
160 "uniform float u_bodyHi;",
161 "uniform float u_litLo;",
162 "uniform float u_litHi;",
163 "uniform float u_litMix;",
164 "uniform float u_edgeDark;",
165 "uniform float u_lightDirX;",
166 "uniform float u_lightDirY;",
167 "uniform float u_lightDirZ;",
168 "uniform float u_normalEps;",
169 "uniform float u_foamStrength;",
170 "uniform float u_shoreClip;",
171 "uniform float u_deepDark;",
172 "uniform float u_deepAbrupt;",
173 // 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).
174 "vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
175 "vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
176 "vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",
177 "vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",
178 "float snoise(vec3 v) {",
179 " vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",
180 " vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",
181 " vec3 i = floor(v + dot(v, C.yyy));",
182 " vec3 x0 = v - i + dot(i, C.xxx);",
183 " vec3 g = step(x0.yzx, x0.xyz);",
184 " vec3 l = 1.0 - g;",
185 " vec3 i1 = min(g.xyz, l.zxy);",
186 " vec3 i2 = max(g.xyz, l.zxy);",
187 " vec3 x1 = x0 - i1 + C.xxx;",
188 " vec3 x2 = x0 - i2 + C.yyy;",
189 " vec3 x3 = x0 - D.yyy;",
190 " i = mod289(i);",
191 " vec4 p = permute(permute(permute(",
192 " i.z + vec4(0.0, i1.z, i2.z, 1.0))",
193 " + i.y + vec4(0.0, i1.y, i2.y, 1.0))",
194 " + i.x + vec4(0.0, i1.x, i2.x, 1.0));",
195 " float n_ = 0.142857142857;",
196 " vec3 ns = n_ * D.wyz - D.xzx;",
197 " vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",
198 " vec4 x_ = floor(j * ns.z);",
199 " vec4 y_ = floor(j - 7.0 * x_);",
200 " vec4 x = x_ * ns.x + ns.yyyy;",
201 " vec4 y = y_ * ns.x + ns.yyyy;",
202 " vec4 h = 1.0 - abs(x) - abs(y);",
203 " vec4 b0 = vec4(x.xy, y.xy);",
204 " vec4 b1 = vec4(x.zw, y.zw);",
205 " vec4 s0 = floor(b0) * 2.0 + 1.0;",
206 " vec4 s1 = floor(b1) * 2.0 + 1.0;",
207 " vec4 sh = -step(h, vec4(0.0));",
208 " vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",
209 " vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",
210 " vec3 p0 = vec3(a0.xy, h.x);",
211 " vec3 p1 = vec3(a0.zw, h.y);",
212 " vec3 p2 = vec3(a1.xy, h.z);",
213 " vec3 p3 = vec3(a1.zw, h.w);",
214 " vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",
215 " p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",
216 " vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",
217 " m = m * m;",
218 " return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",
219 "}",
220 // 4-octave FBM: freq ×2, amp ×0.5 each layer; time in Z for continuous ripple.
221 "float fbm(vec3 p) {",
222 " float sum = 0.0;",
223 " float amp = 0.5;",
224 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
225 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
226 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
227 " sum += amp * snoise(p);",
228 " return sum;",
229 "}",
230 "vec2 wrapUv(vec2 uv) {",
231 " return fract(uv) * 0.998 + 0.001;",
232 "}",
233 "float sampleShore(",
234 " float enabled, float useShore, vec2 shoreNu,",
235 " inout vec3 shoreRgb, inout float shoreW",
236 ") {",
237 " if (enabled < 0.5 || useShore < 0.5 || u_hasShore < 0.5) { return 0.0; }",
238 " vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
239 " vec4 shore = texture2D(u_secondary, shoreUv);",
240 " if (shore.a <= 0.1) { return 0.0; }",
241 " shoreRgb = shore.rgb;",
242 " shoreW = 1.0;",
243 " return 1.0;",
244 "}",
119 245 "void main() {",
120 " vec4 color = texture2D(u_texture, v_texCoord);",
121 " if (color.a <= 0.0) { discard; }",
122 " vec3 rgb = color.rgb;",
123 " float foam = 0.0;",
124 " float pulse = 0.55 + 0.45 * sin(u_time * 3.2 + v_texCoord.x * 18.0 + v_texCoord.y * 10.0);",
125 " if (u_edgeN > 0.5 && v_texCoord.y < 0.22) {",
126 " foam = max(foam, (1.0 - v_texCoord.y / 0.22) * pulse);",
246 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
247 " vec2 puv = px / 16.0;",
248 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
249 " float t = u_time;",
250 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
251 " float eps = max(u_normalEps, 0.001);",
252 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
253 " float nC = fbm(base);",
254 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
255 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
256 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
257 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
258 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
259 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
260 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
261 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
262 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
263 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
264 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
265 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
266 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
267 " float edgeProx = 0.0;",
268 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
269 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
270 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
271 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
272 " if (u_edgeNE > 0.5) {",
273 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
274 " }",
275 " if (u_edgeNW > 0.5) {",
276 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
277 " }",
278 " if (u_edgeSE > 0.5) {",
279 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
280 " }",
281 " if (u_edgeSW > 0.5) {",
282 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
283 " }",
284 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
285 " float deepTop = mix(u_deepNW, u_deepNE, puv.x);",
286 " float deepBot = mix(u_deepSW, u_deepSE, puv.x);",
287 " float deepMix = mix(deepTop, deepBot, puv.y);",
288 " float deepAmt = pow(clamp(deepMix, 0.0, 1.0), max(u_deepAbrupt, 0.05));",
289 " float darkW = clamp(u_deepDark, 0.0, 1.0);",
290 " vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), mix(vec3(0.05, 0.16, 0.34), vec3(0.015, 0.055, 0.14), darkW), deepAmt);",
291 " vec3 midCol = mix(vec3(0.24, 0.52, 0.70), mix(vec3(0.10, 0.30, 0.50), vec3(0.04, 0.14, 0.28), darkW), deepAmt);",
292 " vec3 litCol = mix(vec3(0.52, 0.78, 0.90), mix(vec3(0.26, 0.46, 0.66), vec3(0.12, 0.28, 0.46), darkW), deepAmt);",
293 " vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), mix(vec3(0.72, 0.88, 0.98), vec3(0.48, 0.68, 0.86), darkW), deepAmt);",
294 " vec3 foamCol = vec3(0.94, 0.99, 1.0);",
295 " float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
296 " vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",
297 " rgb = mix(rgb, litCol, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix);",
298 " rgb *= shade;",
299 " rgb = mix(rgb, sparkCol, min(glitter, u_glitterCap) * u_glitterMix * (1.0 - edgeProx * 0.7));",
300 " rgb = mix(rgb, deepCol, edgeProx * u_edgeDark);",
301 " float shoreW = 0.0;",
302 " vec3 shoreRgb = rgb;",
303 " if (u_edgeN > 0.5) {",
304 " sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
305 " }",
306 " if (u_edgeS > 0.5) {",
307 " sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
308 " }",
309 " if (u_edgeW > 0.5) {",
310 " sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
127 311 " }",
128 " if (u_edgeS > 0.5 && v_texCoord.y > 0.78) {",
129 " foam = max(foam, ((v_texCoord.y - 0.78) / 0.22) * pulse);",
312 " if (u_edgeE > 0.5) {",
313 " sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
130 314 " }",
131 " if (u_edgeW > 0.5 && v_texCoord.x < 0.22) {",
132 " foam = max(foam, (1.0 - v_texCoord.x / 0.22) * pulse);",
315 " if (u_edgeNE > 0.5) {",
316 " sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
133 317 " }",
134 " if (u_edgeE > 0.5 && v_texCoord.x > 0.78) {",
135 " foam = max(foam, ((v_texCoord.x - 0.78) / 0.22) * pulse);",
318 " if (u_edgeNW > 0.5) {",
319 " sampleShore(1.0, max(u_shoreEdgeNW, u_hasShore), vec2(puv.x, puv.y), shoreRgb, shoreW);",
136 320 " }",
137 " rgb = mix(rgb, vec3(0.78, 0.92, 1.0), clamp(foam, 0.0, 0.85));",
321 " if (u_edgeSE > 0.5) {",
322 " sampleShore(1.0, max(u_shoreEdgeSE, u_hasShore), vec2(1.0 - puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
323 " }",
324 " if (u_edgeSW > 0.5) {",
325 " sampleShore(1.0, max(u_shoreEdgeSW, u_hasShore), vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
326 " }",
327 " float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",
328 " float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",
329 " float shoreClip = u_shoreClip;",
330 " float shoreMask = step(shoreClip, retreat) * shoreW;",
331 " float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",
332 " * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",
333 " rgb = mix(rgb, foamCol, foamAmt * u_foamStrength);",
334 " rgb = mix(rgb, shoreRgb, shoreMask);",
138 335 " float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
139 336 " float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
140 337 " float lit = mix(litTop, litBottom, v_texCoord.y);",
141 338 " float darkness = u_ambientDark * (1.0 - lit);",
142 339 " rgb = mix(rgb, vec3(0.0), darkness);",
143 " gl_FragColor = vec4(rgb, color.a * u_alpha);",
340 " gl_FragColor = vec4(rgb, u_alpha);",
341 "}"
342 ].join("\n");
343
344 /** Lava heat: dark red → red → orange → yellow; yellow drives bloom companion. */
345 const LAVA_FBM_COMMON = [
346 "vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
347 "vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
348 "vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",
349 "vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",
350 "float snoise(vec3 v) {",
351 " vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",
352 " vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",
353 " vec3 i = floor(v + dot(v, C.yyy));",
354 " vec3 x0 = v - i + dot(i, C.xxx);",
355 " vec3 g = step(x0.yzx, x0.xyz);",
356 " vec3 l = 1.0 - g;",
357 " vec3 i1 = min(g.xyz, l.zxy);",
358 " vec3 i2 = max(g.xyz, l.zxy);",
359 " vec3 x1 = x0 - i1 + C.xxx;",
360 " vec3 x2 = x0 - i2 + C.yyy;",
361 " vec3 x3 = x0 - D.yyy;",
362 " i = mod289(i);",
363 " vec4 p = permute(permute(permute(",
364 " i.z + vec4(0.0, i1.z, i2.z, 1.0))",
365 " + i.y + vec4(0.0, i1.y, i2.y, 1.0))",
366 " + i.x + vec4(0.0, i1.x, i2.x, 1.0));",
367 " float n_ = 0.142857142857;",
368 " vec3 ns = n_ * D.wyz - D.xzx;",
369 " vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",
370 " vec4 x_ = floor(j * ns.z);",
371 " vec4 y_ = floor(j - 7.0 * x_);",
372 " vec4 x = x_ * ns.x + ns.yyyy;",
373 " vec4 y = y_ * ns.x + ns.yyyy;",
374 " vec4 h = 1.0 - abs(x) - abs(y);",
375 " vec4 b0 = vec4(x.xy, y.xy);",
376 " vec4 b1 = vec4(x.zw, y.zw);",
377 " vec4 s0 = floor(b0) * 2.0 + 1.0;",
378 " vec4 s1 = floor(b1) * 2.0 + 1.0;",
379 " vec4 sh = -step(h, vec4(0.0));",
380 " vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",
381 " vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",
382 " vec3 p0 = vec3(a0.xy, h.x);",
383 " vec3 p1 = vec3(a0.zw, h.y);",
384 " vec3 p2 = vec3(a1.xy, h.z);",
385 " vec3 p3 = vec3(a1.zw, h.w);",
386 " vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",
387 " p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",
388 " vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",
389 " m = m * m;",
390 " return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",
391 "}",
392 "float fbm(vec3 p) {",
393 " float sum = 0.0;",
394 " float amp = 0.5;",
395 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
396 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
397 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
398 " sum += amp * snoise(p);",
399 " return sum;",
400 "}",
401 "vec2 wrapUv(vec2 uv) {",
402 " return fract(uv) * 0.998 + 0.001;",
403 "}"
404 ];
405
406 const LAVA_GROUND_FRAG = [
407 "precision mediump float;",
408 "varying vec2 v_texCoord;",
409 "uniform sampler2D u_texture;",
410 "uniform float u_alpha;",
411 "uniform float u_ambientDark;",
412 "uniform float u_litNW;",
413 "uniform float u_litNE;",
414 "uniform float u_litSW;",
415 "uniform float u_litSE;",
416 "uniform float u_time;",
417 "uniform float u_tileX;",
418 "uniform float u_tileY;",
419 "uniform float u_edgeN;",
420 "uniform float u_edgeE;",
421 "uniform float u_edgeS;",
422 "uniform float u_edgeW;",
423 "uniform float u_edgeNE;",
424 "uniform float u_edgeNW;",
425 "uniform float u_edgeSE;",
426 "uniform float u_edgeSW;",
427 "uniform float u_flowX;",
428 "uniform float u_flowY;",
429 "uniform float u_flowZ;",
430 "uniform float u_waveScale;",
431 "uniform float u_fbmAmp;",
432 "uniform float u_texAmp;",
433 "uniform float u_distort;",
434 "uniform float u_normalZ;",
435 "uniform float u_waveGain;",
436 "uniform float u_crestLo;",
437 "uniform float u_crestHi;",
438 "uniform float u_crestPow;",
439 "uniform float u_glitterPow;",
440 "uniform float u_crestGlitter;",
441 "uniform float u_glitterCap;",
442 "uniform float u_glitterMix;",
443 "uniform float u_shadeLo;",
444 "uniform float u_shadeHi;",
445 "uniform float u_bodyLo;",
446 "uniform float u_bodyHi;",
447 "uniform float u_litLo;",
448 "uniform float u_litHi;",
449 "uniform float u_litMix;",
450 "uniform float u_edgeDark;",
451 "uniform float u_lightDirX;",
452 "uniform float u_lightDirY;",
453 "uniform float u_lightDirZ;",
454 "uniform float u_normalEps;",
455 "uniform float u_shoreClip;",
456 "uniform float u_hasShore;",
457 "uniform float u_shoreEdgeN;",
458 "uniform float u_shoreEdgeE;",
459 "uniform float u_shoreEdgeS;",
460 "uniform float u_shoreEdgeW;",
461 "uniform float u_shoreEdgeNE;",
462 "uniform float u_shoreEdgeNW;",
463 "uniform float u_shoreEdgeSE;",
464 "uniform float u_shoreEdgeSW;",
465 "uniform vec4 u_shoreUvRect;",
466 "uniform sampler2D u_secondary;",
467 ...LAVA_FBM_COMMON,
468 "float sampleShore(",
469 " float enabled, float useShore, vec2 shoreNu,",
470 " inout vec3 shoreRgb, inout float shoreW",
471 ") {",
472 " if (enabled < 0.5 || useShore < 0.5 || u_hasShore < 0.5) { return 0.0; }",
473 " vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
474 " vec4 shore = texture2D(u_secondary, shoreUv);",
475 " if (shore.a <= 0.1) { return 0.0; }",
476 " shoreRgb = shore.rgb;",
477 " shoreW = 1.0;",
478 " return 1.0;",
479 "}",
480 "void main() {",
481 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
482 " vec2 puv = px / 16.0;",
483 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
484 " float t = u_time;",
485 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
486 " float eps = max(u_normalEps, 0.001);",
487 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
488 " float nC = fbm(base);",
489 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
490 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
491 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
492 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
493 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
494 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
495 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
496 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
497 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
498 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
499 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
500 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
501 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
502 " float edgeProx = 0.0;",
503 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
504 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
505 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
506 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
507 " if (u_edgeNE > 0.5) {",
508 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
509 " }",
510 " if (u_edgeNW > 0.5) {",
511 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
512 " }",
513 " if (u_edgeSE > 0.5) {",
514 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
515 " }",
516 " if (u_edgeSW > 0.5) {",
517 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
518 " }",
519 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
520 " float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
521 " heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
522 " heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
523 " vec3 darkRed = vec3(0.16, 0.015, 0.01);",
524 " vec3 brightRed = vec3(0.78, 0.08, 0.02);",
525 " vec3 orange = vec3(0.98, 0.38, 0.04);",
526 " vec3 yellow = vec3(1.0, 0.9, 0.28);",
527 " vec3 rgb = mix(darkRed, brightRed, smoothstep(0.0, 0.38, heat));",
528 " rgb = mix(rgb, orange, smoothstep(0.28, 0.68, heat));",
529 " float yellowAmt = smoothstep(0.55, 0.98, heat);",
530 " rgb = mix(rgb, yellow, yellowAmt);",
531 " float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
532 " rgb *= shade;",
533 " rgb = mix(rgb, darkRed, edgeProx * u_edgeDark * 0.35);",
534 " float shoreW = 0.0;",
535 " vec3 shoreRgb = rgb;",
536 " if (u_edgeN > 0.5) {",
537 " sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
538 " }",
539 " if (u_edgeS > 0.5) {",
540 " sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
541 " }",
542 " if (u_edgeW > 0.5) {",
543 " sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
544 " }",
545 " if (u_edgeE > 0.5) {",
546 " sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
547 " }",
548 " if (u_edgeNE > 0.5) {",
549 " sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
550 " }",
551 " if (u_edgeNW > 0.5) {",
552 " sampleShore(1.0, max(u_shoreEdgeNW, u_hasShore), vec2(puv.x, puv.y), shoreRgb, shoreW);",
553 " }",
554 " if (u_edgeSE > 0.5) {",
555 " sampleShore(1.0, max(u_shoreEdgeSE, u_hasShore), vec2(1.0 - puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
556 " }",
557 " if (u_edgeSW > 0.5) {",
558 " sampleShore(1.0, max(u_shoreEdgeSW, u_hasShore), vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
559 " }",
560 " float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",
561 " float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",
562 " float shoreClip = u_shoreClip;",
563 " float shoreMask = step(shoreClip, retreat) * shoreW;",
564 " float crustAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.2, shoreClip - 0.06, retreat)",
565 " * (1.0 - smoothstep(shoreClip - 0.06, shoreClip, retreat));",
566 " rgb = mix(rgb, vec3(0.05, 0.01, 0.0), crustAmt);",
567 " rgb = mix(rgb, shoreRgb, shoreMask);",
568 " float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
569 " float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
570 " float lit = mix(litTop, litBottom, v_texCoord.y);",
571 " float darkness = u_ambientDark * (1.0 - lit);",
572 " rgb = mix(rgb, vec3(0.0), darkness);",
573 " gl_FragColor = vec4(rgb, u_alpha);",
574 "}"
575 ].join("\n");
576
577 /** Unlit bloom overlay — strength tracks yellow heat (exempt from world darkness). */
578 const LAVA_BLOOM_FRAG = [
579 "precision mediump float;",
580 "varying vec2 v_texCoord;",
581 "uniform sampler2D u_texture;",
582 "uniform float u_alpha;",
583 "uniform float u_time;",
584 "uniform float u_tileX;",
585 "uniform float u_tileY;",
586 "uniform float u_edgeN;",
587 "uniform float u_edgeE;",
588 "uniform float u_edgeS;",
589 "uniform float u_edgeW;",
590 "uniform float u_edgeNE;",
591 "uniform float u_edgeNW;",
592 "uniform float u_edgeSE;",
593 "uniform float u_edgeSW;",
594 "uniform float u_flowX;",
595 "uniform float u_flowY;",
596 "uniform float u_flowZ;",
597 "uniform float u_waveScale;",
598 "uniform float u_fbmAmp;",
599 "uniform float u_texAmp;",
600 "uniform float u_distort;",
601 "uniform float u_normalZ;",
602 "uniform float u_waveGain;",
603 "uniform float u_crestLo;",
604 "uniform float u_crestHi;",
605 "uniform float u_crestPow;",
606 "uniform float u_glitterPow;",
607 "uniform float u_crestGlitter;",
608 "uniform float u_glitterCap;",
609 "uniform float u_glitterMix;",
610 "uniform float u_bodyLo;",
611 "uniform float u_bodyHi;",
612 "uniform float u_litLo;",
613 "uniform float u_litHi;",
614 "uniform float u_litMix;",
615 "uniform float u_lightDirX;",
616 "uniform float u_lightDirY;",
617 "uniform float u_lightDirZ;",
618 "uniform float u_normalEps;",
619 "uniform float u_bloomStrength;",
620 "uniform float u_shoreClip;",
621 ...LAVA_FBM_COMMON,
622 "void main() {",
623 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
624 " vec2 puv = px / 16.0;",
625 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
626 " float t = u_time;",
627 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
628 " float eps = max(u_normalEps, 0.001);",
629 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
630 " float nC = fbm(base);",
631 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
632 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
633 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
634 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
635 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
636 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
637 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
638 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
639 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
640 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
641 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
642 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
643 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
644 " float edgeProx = 0.0;",
645 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
646 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
647 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
648 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
649 " if (u_edgeNE > 0.5) {",
650 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
651 " }",
652 " if (u_edgeNW > 0.5) {",
653 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
654 " }",
655 " if (u_edgeSE > 0.5) {",
656 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
657 " }",
658 " if (u_edgeSW > 0.5) {",
659 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
660 " }",
661 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
662 " float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
663 " heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
664 " heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
665 " float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",
666 " float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",
667 " float hasEdge = max(max(u_edgeN, u_edgeE), max(u_edgeS, u_edgeW));",
668 " hasEdge = max(hasEdge, max(max(u_edgeNE, u_edgeNW), max(u_edgeSE, u_edgeSW)));",
669 " float shoreW = step(0.5, hasEdge);",
670 " float shoreMask = step(u_shoreClip, retreat) * shoreW;",
671 " float yellowAmt = smoothstep(0.55, 0.98, heat) * (1.0 - edgeProx * 0.85) * (1.0 - shoreMask);",
672 " float bloom = yellowAmt * max(u_bloomStrength, 0.0);",
673 " vec3 glow = vec3(1.0, 0.82, 0.28) * bloom;",
674 " gl_FragColor = vec4(glow, bloom * u_alpha);",
144 675 "}"
145 676 ].join("\n");
146 677
@@ -392,6 +923,8 @@ let spriteLightingShader = null;
392 923 let atlasLightingShader = null;
393 924 let cliffGroundTopShader = null;
394 925 let waterGroundShader = null;
926 let lavaGroundShader = null;
927 let lavaBloomShader = null;
395 928 let tintLitSpriteShader = null;
396 929 let dualTintLitSpriteShader = null;
397 930 let tightFitTintLitSpriteShader = null;
@@ -425,6 +958,20 @@ function getWaterGroundShader ()
425 958 return waterGroundShader;
426 959 }
427 960
961 function getLavaGroundShader ()
962 {
963 if (!lavaGroundShader)
964 { lavaGroundShader = Shader.fragment(LAVA_GROUND_FRAG); }
965 return lavaGroundShader;
966 }
967
968 function getLavaBloomShader ()
969 {
970 if (!lavaBloomShader)
971 { lavaBloomShader = Shader.fragment(LAVA_BLOOM_FRAG); }
972 return lavaBloomShader;
973 }
974
428 975 function getTintLitSpriteShader ()
429 976 {
430 977 if (!tintLitSpriteShader)
@@ -726,6 +1273,7 @@ export class WorldView
726 1273 {
727 1274 objects.ground?.destroy();
728 1275 objects.groundBloom?.destroy();
1276 objects.lavaBloom?.destroy();
729 1277 objects.block?.destroy();
730 1278 objects.blockBloom?.destroy();
731 1279 this.tiles.delete(tileKey);
@@ -3176,15 +3724,171 @@ export class WorldView
3176 3724 #waterCoastEdges (tileX, tileY)
3177 3725 {
3178 3726 const season = this.worldSeason;
3727 const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);
3728 const n = liquid(tileX, tileY - 1);
3729 const e = liquid(tileX + 1, tileY);
3730 const s = liquid(tileX, tileY + 1);
3731 const w = liquid(tileX - 1, tileY);
3732 const ne = liquid(tileX + 1, tileY - 1);
3733 const nw = liquid(tileX - 1, tileY - 1);
3734 const se = liquid(tileX + 1, tileY + 1);
3735 const sw = liquid(tileX - 1, tileY + 1);
3736 return {
3737 n: n ? 0 : 1,
3738 e: e ? 0 : 1,
3739 s: s ? 0 : 1,
3740 w: w ? 0 : 1,
3741 // Pure diagonal land pockets (e.g. WWW/WLL) — only when cardinals stay water.
3742 ne: (!ne && n && e) ? 1 : 0,
3743 nw: (!nw && n && w) ? 1 : 0,
3744 se: (!se && s && e) ? 1 : 0,
3745 sw: (!sw && s && w) ? 1 : 0
3746 };
3747 }
3748
3749 /**
3750 * Corner deepness = average of liquid-water tiles meeting that corner.
3751 * Bilinear sampling of these corners is continuous across shared edges/corners.
3752 */
3753 #waterDeepCorners (tileX, tileY, selfDeep)
3754 {
3755 const season = this.worldSeason;
3756 const fallback = selfDeep ? 1 : 0;
3757 const depthAt = (x, y) =>
3758 {
3759 const typeId = this.#groundTypeAt(x, y);
3760 if (!isLiquidWaterGround(typeId, season))
3761 { return null; }
3762 return typeId === GroundType.deepWater ? 1 : 0;
3763 };
3764 const corner = (offsets) =>
3765 {
3766 let sum = 0;
3767 let count = 0;
3768 for (const [dx, dy] of offsets)
3769 {
3770 const d = depthAt(tileX + dx, tileY + dy);
3771 if (d == null)
3772 { continue; }
3773 sum += d;
3774 count += 1;
3775 }
3776 return count ? sum / count : fallback;
3777 };
3179 3778 return {
3180 n: !isLiquidWaterGround(this.#groundTypeAt(tileX, tileY - 1), season) ? 1 : 0,
3181 e: !isLiquidWaterGround(this.#groundTypeAt(tileX + 1, tileY), season) ? 1 : 0,
3182 s: !isLiquidWaterGround(this.#groundTypeAt(tileX, tileY + 1), season) ? 1 : 0,
3183 w: !isLiquidWaterGround(this.#groundTypeAt(tileX - 1, tileY), season) ? 1 : 0
3779 nw: corner([[0, 0], [-1, 0], [0, -1], [-1, -1]]),
3780 ne: corner([[0, 0], [1, 0], [0, -1], [1, -1]]),
3781 sw: corner([[0, 0], [-1, 0], [0, 1], [-1, 1]]),
3782 se: corner([[0, 0], [1, 0], [0, 1], [1, 1]])
3184 3783 };
3185 3784 }
3186 3785
3187 #syncWaterGroundSprite (object, corners, ambientDark, edges, timeSec, fallbackLit = 1)
3786 /**
3787 * Neighbor ground sprite for coast retreat peeks.
3788 * Water prefers wet-shore (sand-wet); lava uses dry land only.
3789 */
3790 #fluidCoastShore (tileX, tileY, edges, { preferWet = true } = {})
3791 {
3792 const season = this.worldSeason;
3793 const candidates = [];
3794 if (edges?.n)
3795 { candidates.push({ edge: "n", tileX, tileY: tileY - 1 }); }
3796 if (edges?.e)
3797 { candidates.push({ edge: "e", tileX: tileX + 1, tileY }); }
3798 if (edges?.s)
3799 { candidates.push({ edge: "s", tileX, tileY: tileY + 1 }); }
3800 if (edges?.w)
3801 { candidates.push({ edge: "w", tileX: tileX - 1, tileY }); }
3802 if (edges?.ne)
3803 { candidates.push({ edge: "ne", tileX: tileX + 1, tileY: tileY - 1 }); }
3804 if (edges?.nw)
3805 { candidates.push({ edge: "nw", tileX: tileX - 1, tileY: tileY - 1 }); }
3806 if (edges?.se)
3807 { candidates.push({ edge: "se", tileX: tileX + 1, tileY: tileY + 1 }); }
3808 if (edges?.sw)
3809 { candidates.push({ edge: "sw", tileX: tileX - 1, tileY: tileY + 1 }); }
3810 let pick = null;
3811 for (const candidate of candidates)
3812 {
3813 const ground = this.#groundAtTile(candidate.tileX, candidate.tileY);
3814 if (ground == null)
3815 { continue; }
3816 const entry = normalizeGround(ground);
3817 const def = GROUND_DEFINITIONS[entry.typeId];
3818 if (!def || def.proceduralWaves)
3819 { continue; }
3820 let spriteName = null;
3821 if (preferWet && def.wetShore)
3822 {
3823 const wetState = `${def.key}-wet`;
3824 const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3825 if (states.includes(wetState))
3826 { spriteName = spriteImageName("ground", def.key, wetState); }
3827 }
3828 if (!spriteName)
3829 {
3830 const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3831 const state = resolveSeasonalVisualState(states, entry.state, season) ?? def.key;
3832 spriteName = spriteImageName("ground", def.key, state);
3833 }
3834 const sprite = spriteName ? this.game.images[spriteName] : null;
3835 if (!sprite)
3836 { continue; }
3837 const ranked = { ...candidate, sprite, wet: !!(preferWet && def.wetShore) };
3838 if (ranked.wet)
3839 {
3840 pick = ranked;
3841 break;
3842 }
3843 if (!pick)
3844 { pick = ranked; }
3845 }
3846 const shore = {
3847 sprite: pick?.sprite ?? null,
3848 edgeN: 0,
3849 edgeE: 0,
3850 edgeS: 0,
3851 edgeW: 0,
3852 edgeNE: 0,
3853 edgeNW: 0,
3854 edgeSE: 0,
3855 edgeSW: 0
3856 };
3857 if (pick?.edge === "n")
3858 { shore.edgeN = 1; }
3859 else if (pick?.edge === "e")
3860 { shore.edgeE = 1; }
3861 else if (pick?.edge === "s")
3862 { shore.edgeS = 1; }
3863 else if (pick?.edge === "w")
3864 { shore.edgeW = 1; }
3865 else if (pick?.edge === "ne")
3866 { shore.edgeNE = 1; }
3867 else if (pick?.edge === "nw")
3868 { shore.edgeNW = 1; }
3869 else if (pick?.edge === "se")
3870 { shore.edgeSE = 1; }
3871 else if (pick?.edge === "sw")
3872 { shore.edgeSW = 1; }
3873 return shore;
3874 }
3875
3876 #waterCoastShore (tileX, tileY, edges)
3877 {
3878 return this.#fluidCoastShore(tileX, tileY, edges, { preferWet: true });
3879 }
3880
3881 #syncWaterGroundSprite (object, {
3882 corners = null,
3883 ambientDark = 0,
3884 edges = null,
3885 shore = null,
3886 timeSec = 0,
3887 fallbackLit = 1,
3888 tileX = 0,
3889 tileY = 0,
3890 deepCorners = null
3891 } = {})
3188 3892 {
3189 3893 if (!object?.renderer)
3190 3894 { return; }
@@ -3195,9 +3899,20 @@ export class WorldView
3195 3899 se: fallbackLit
3196 3900 };
3197 3901 const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
3902 const shoreSprite = shore?.sprite ?? null;
3903 const shoreUv = shoreSprite?.getUvRect?.(0)
3904 ?? { u0: 0, v0: 0, u1: 1, v1: 1 };
3905 const dNW = deepCorners?.nw ?? 0;
3906 const dNE = deepCorners?.ne ?? 0;
3907 const dSW = deepCorners?.sw ?? 0;
3908 const dSE = deepCorners?.se ?? 0;
3198 3909 object._lit = true;
3199 3910 object.renderer.shader = getWaterGroundShader();
3200 object.renderer.secondaryMap = null;
3911 // Shallow + deep share one noise atlas so texAmp seams don't hard-cut at depth edges.
3912 const sharedNoise = this.game.images[spriteImageName("ground", "water", "water")];
3913 if (sharedNoise)
3914 { object.renderer.sprite = sharedNoise; }
3915 object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
3201 3916 object.renderer.shaderUniforms = {
3202 3917 u_ambientDark: dark,
3203 3918 u_litNW: lit.nw,
@@ -3205,18 +3920,46 @@ export class WorldView
3205 3920 u_litSW: lit.sw,
3206 3921 u_litSE: lit.se,
3207 3922 u_time: timeSec,
3923 u_tileX: tileX | 0,
3924 u_tileY: tileY | 0,
3925 u_deepNW: dNW,
3926 u_deepNE: dNE,
3927 u_deepSW: dSW,
3928 u_deepSE: dSE,
3208 3929 u_edgeN: edges?.n ?? 0,
3209 3930 u_edgeE: edges?.e ?? 0,
3210 3931 u_edgeS: edges?.s ?? 0,
3211 u_edgeW: edges?.w ?? 0
3932 u_edgeW: edges?.w ?? 0,
3933 u_edgeNE: edges?.ne ?? 0,
3934 u_edgeNW: edges?.nw ?? 0,
3935 u_edgeSE: edges?.se ?? 0,
3936 u_edgeSW: edges?.sw ?? 0,
3937 u_hasShore: shoreSprite ? 1 : 0,
3938 u_shoreEdgeN: shore?.edgeN ?? 0,
3939 u_shoreEdgeE: shore?.edgeE ?? 0,
3940 u_shoreEdgeS: shore?.edgeS ?? 0,
3941 u_shoreEdgeW: shore?.edgeW ?? 0,
3942 u_shoreEdgeNE: shore?.edgeNE ?? 0,
3943 u_shoreEdgeNW: shore?.edgeNW ?? 0,
3944 u_shoreEdgeSE: shore?.edgeSE ?? 0,
3945 u_shoreEdgeSW: shore?.edgeSW ?? 0,
3946 u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],
3947 ...waterDebugUniforms()
3212 3948 };
3213 3949 }
3214 3950
3215 /** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. */
3951 /** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. Lava is procedural heat. */
3216 3952 #syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)
3217 3953 {
3218 3954 if (!objects?.ground)
3219 3955 { return; }
3956 if (isLavaGround(objects.groundTypeId))
3957 {
3958 objects.waterEdges = null;
3959 this.#syncLavaGroundFx(objects, ambientDark, timeSec, baked);
3960 return;
3961 }
3962 this.#clearLavaBloom(objects);
3220 3963 if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))
3221 3964 {
3222 3965 objects.waterEdges = null;
@@ -3242,14 +3985,200 @@ export class WorldView
3242 3985 { litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
3243 3986 }
3244 3987 objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);
3245 this.#syncWaterGroundSprite(
3246 objects.ground,
3247 litCorners,
3988 const shore = this.#waterCoastShore(objects.tileX, objects.tileY, objects.waterEdges);
3989 const deep = objects.groundTypeId === GroundType.deepWater;
3990 this.#syncWaterGroundSprite(objects.ground, {
3991 corners: litCorners,
3248 3992 ambientDark,
3249 objects.waterEdges,
3993 edges: objects.waterEdges,
3994 shore,
3250 3995 timeSec,
3251 fallbackLit
3252 );
3996 fallbackLit,
3997 tileX: objects.tileX,
3998 tileY: objects.tileY,
3999 deepCorners: this.#waterDeepCorners(objects.tileX, objects.tileY, deep)
4000 });
4001 }
4002
4003 #lavaCoastEdges (tileX, tileY)
4004 {
4005 const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));
4006 const n = lava(tileX, tileY - 1);
4007 const e = lava(tileX + 1, tileY);
4008 const s = lava(tileX, tileY + 1);
4009 const w = lava(tileX - 1, tileY);
4010 const ne = lava(tileX + 1, tileY - 1);
4011 const nw = lava(tileX - 1, tileY - 1);
4012 const se = lava(tileX + 1, tileY + 1);
4013 const sw = lava(tileX - 1, tileY + 1);
4014 return {
4015 n: n ? 0 : 1,
4016 e: e ? 0 : 1,
4017 s: s ? 0 : 1,
4018 w: w ? 0 : 1,
4019 ne: (!ne && n && e) ? 1 : 0,
4020 nw: (!nw && n && w) ? 1 : 0,
4021 se: (!se && s && e) ? 1 : 0,
4022 sw: (!sw && s && w) ? 1 : 0
4023 };
4024 }
4025
4026 #clearLavaBloom (objects)
4027 {
4028 if (!objects)
4029 { return; }
4030 objects.lavaBloom?.destroy();
4031 objects.lavaBloom = null;
4032 }
4033
4034 #ensureLavaBloom (objects)
4035 {
4036 const sprite = objects.ground?.renderer?.sprite;
4037 if (!sprite)
4038 { return null; }
4039 if (!objects.lavaBloom)
4040 {
4041 const bloom = new GameObject(0, 0, sprite, LAYER_GROUND);
4042 bloom.renderer.layer = RENDER_LAYER_BLOOM;
4043 this.#markUnlit(bloom);
4044 this.scene.addObject(bloom);
4045 objects.lavaBloom = bloom;
4046 }
4047 else if (objects.lavaBloom.renderer)
4048 { objects.lavaBloom.renderer.sprite = sprite; }
4049 const size = this.tileSize();
4050 objects.lavaBloom.transform.position.x = objects.tileX * size + size / 2;
4051 objects.lavaBloom.transform.position.y = objects.tileY * size + size / 2;
4052 objects.lavaBloom.transform.size = new vector(size, size);
4053 this.#setLayer(objects.lavaBloom, LAYER_GROUND);
4054 return objects.lavaBloom;
4055 }
4056
4057 #syncLavaGroundFx (objects, ambientDark, timeSec, baked = null)
4058 {
4059 const fallbackLit = 1 - (objects.shadeAlpha ?? 0);
4060 const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);
4061 const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);
4062 const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);
4063 const localX = objects.tileX - chunkX * CHUNK_SIZE;
4064 const localY = objects.tileY - chunkY * CHUNK_SIZE;
4065 let litCorners = null;
4066 if (chunkBaked)
4067 {
4068 if (this.lightingMode === "simple")
4069 {
4070 const gridW = CHUNK_SIZE + 2;
4071 const intensity = chunkBaked.lightIntensityGrid?.[(localY + 1) * gridW + (localX + 1)] ?? fallbackLit;
4072 litCorners = { nw: intensity, ne: intensity, sw: intensity, se: intensity };
4073 }
4074 else
4075 { litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
4076 }
4077 const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);
4078 const shore = this.#fluidCoastShore(objects.tileX, objects.tileY, edges, { preferWet: false });
4079 this.#syncLavaGroundSprite(objects.ground, {
4080 corners: litCorners,
4081 ambientDark,
4082 edges,
4083 shore,
4084 timeSec,
4085 fallbackLit,
4086 tileX: objects.tileX,
4087 tileY: objects.tileY
4088 });
4089 const bloom = this.#ensureLavaBloom(objects);
4090 if (bloom)
4091 {
4092 this.#syncLavaBloomSprite(bloom, {
4093 edges,
4094 timeSec,
4095 tileX: objects.tileX,
4096 tileY: objects.tileY
4097 });
4098 }
4099 }
4100
4101 #syncLavaGroundSprite (object, {
4102 corners = null,
4103 ambientDark = 0,
4104 edges = null,
4105 shore = null,
4106 timeSec = 0,
4107 fallbackLit = 1,
4108 tileX = 0,
4109 tileY = 0
4110 } = {})
4111 {
4112 if (!object?.renderer)
4113 { return; }
4114 const lit = corners ?? {
4115 nw: fallbackLit,
4116 ne: fallbackLit,
4117 sw: fallbackLit,
4118 se: fallbackLit
4119 };
4120 const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
4121 const shoreSprite = shore?.sprite ?? null;
4122 const shoreUv = shoreSprite?.getUvRect?.(0)
4123 ?? { u0: 0, v0: 0, u1: 1, v1: 1 };
4124 object._lit = true;
4125 object.renderer.shader = getLavaGroundShader();
4126 object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
4127 object.renderer.shaderUniforms = {
4128 u_ambientDark: dark,
4129 u_litNW: lit.nw,
4130 u_litNE: lit.ne,
4131 u_litSW: lit.sw,
4132 u_litSE: lit.se,
4133 u_time: timeSec,
4134 u_tileX: tileX | 0,
4135 u_tileY: tileY | 0,
4136 u_edgeN: edges?.n ?? 0,
4137 u_edgeE: edges?.e ?? 0,
4138 u_edgeS: edges?.s ?? 0,
4139 u_edgeW: edges?.w ?? 0,
4140 u_edgeNE: edges?.ne ?? 0,
4141 u_edgeNW: edges?.nw ?? 0,
4142 u_edgeSE: edges?.se ?? 0,
4143 u_edgeSW: edges?.sw ?? 0,
4144 u_hasShore: shoreSprite ? 1 : 0,
4145 u_shoreEdgeN: shore?.edgeN ?? 0,
4146 u_shoreEdgeE: shore?.edgeE ?? 0,
4147 u_shoreEdgeS: shore?.edgeS ?? 0,
4148 u_shoreEdgeW: shore?.edgeW ?? 0,
4149 u_shoreEdgeNE: shore?.edgeNE ?? 0,
4150 u_shoreEdgeNW: shore?.edgeNW ?? 0,
4151 u_shoreEdgeSE: shore?.edgeSE ?? 0,
4152 u_shoreEdgeSW: shore?.edgeSW ?? 0,
4153 u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],
4154 ...lavaDebugUniforms()
4155 };
4156 }
4157
4158 #syncLavaBloomSprite (object, {
4159 edges = null,
4160 timeSec = 0,
4161 tileX = 0,
4162 tileY = 0
4163 } = {})
4164 {
4165 if (!object?.renderer)
4166 { return; }
4167 object.renderer.shader = getLavaBloomShader();
4168 object.renderer.shaderUniforms = {
4169 u_time: timeSec,
4170 u_tileX: tileX | 0,
4171 u_tileY: tileY | 0,
4172 u_edgeN: edges?.n ?? 0,
4173 u_edgeE: edges?.e ?? 0,
4174 u_edgeS: edges?.s ?? 0,
4175 u_edgeW: edges?.w ?? 0,
4176 u_edgeNE: edges?.ne ?? 0,
4177 u_edgeNW: edges?.nw ?? 0,
4178 u_edgeSE: edges?.se ?? 0,
4179 u_edgeSW: edges?.sw ?? 0,
4180 ...lavaDebugUniforms()
4181 };
3253 4182 }
3254 4183
3255 4184 #ambientDarkness ()
@@ -3983,11 +4912,14 @@ export class WorldView
3983 4912 const timeSec = performance.now() / 1000;
3984 4913 for (const objects of this.tiles.values())
3985 4914 {
3986 if (!objects.ground || !isWaterGround(objects.groundTypeId))
4915 if (!objects.ground)
4916 { continue; }
4917 const fluid = isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId);
4918 if (!fluid)
3987 4919 { continue; }
3988 4920 if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)
3989 4921 { continue; }
3990 // Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
4922 // Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
3991 4923 this.#syncGroundWaterFx(objects, 1, timeSec);
3992 4924 }
3993 4925 }
@@ -4032,7 +4964,7 @@ export class WorldView
4032 4964 }
4033 4965 if (animatedGround.bloom)
4034 4966 { objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }
4035 else
4967 else if (!isLavaGround(animatedGround.typeId))
4036 4968 {
4037 4969 objects.groundBloom?.destroy();
4038 4970 objects.groundBloom = null;
@@ -4044,6 +4976,7 @@ export class WorldView
4044 4976 objects.ground = null;
4045 4977 objects.groundBloom?.destroy();
4046 4978 objects.groundBloom = null;
4979 this.#clearLavaBloom(objects);
4047 4980 objects.groundTypeId = null;
4048 4981 objects.waterEdges = null;
4049 4982 }
@@ -4342,27 +5275,33 @@ export class WorldView
4342 5275 );
4343 5276 }
4344 5277
4345 /** Authored torches/furnaces in chunks that can light the active 3×3 (or all chunks in editor). */
5278 /** Authored torches/furnaces/lava in chunks that can light the active 3×3 (or all chunks in editor). */
4346 5279 #collectBlockLightsForShading ()
4347 5280 {
4348 5281 const center = this.#activeLightingCenterChunk();
4349 5282 const maxRange = maxBlockLightRangeTiles();
4350 5283 const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;
4351 5284 const sources = [];
5285 const pushChunk = (snapshot) =>
5286 {
5287 if (!snapshot)
5288 { return; }
5289 if (snapshot.blocks)
5290 { sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5291 if (snapshot.grounds)
5292 { sources.push(...collectGroundLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.grounds)); }
5293 };
4352 5294 if (!center)
4353 5295 {
4354 5296 for (const snapshot of this.chunks.values())
4355 { sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5297 { pushChunk(snapshot); }
4356 5298 return sources;
4357 5299 }
4358 5300 for (let dy = -1 - halo; dy <= 1 + halo; dy++)
4359 5301 {
4360 5302 for (let dx = -1 - halo; dx <= 1 + halo; dx++)
4361 5303 {
4362 const snapshot = this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`);
4363 if (!snapshot?.blocks)
4364 { continue; }
4365 sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks));
5304 pushChunk(this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`));
4366 5305 }
4367 5306 }
4368 5307 return sources;
@@ -4490,14 +5429,17 @@ export class WorldView
4490 5429 else
4491 5430 { this.#syncLitSprite(objects.block, objects.shadeAlpha); }
4492 5431 }
4493 if (objects.ground && isWaterGround(objects.groundTypeId))
5432 if (objects.ground && (isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId)))
4494 5433 {
4495 5434 const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);
4496 // Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
5435 // Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
4497 5436 this.#syncGroundWaterFx(objects, 1, timeSec, baked);
4498 5437 }
4499 5438 else if (objects.ground)
4500 { this.#syncLitSprite(objects.ground, objects.shadeAlpha); }
5439 {
5440 this.#clearLavaBloom(objects);
5441 this.#syncLitSprite(objects.ground, objects.shadeAlpha);
5442 }
4501 5443 }
4502 5444
4503 5445 for (const item of this.groundItems.values())
@@ -4576,7 +5518,7 @@ export class WorldView
4576 5518 { return false; }
4577 5519 const index = localY * CHUNK_SIZE + localX;
4578 5520 const ground = normalizeGround(snapshot.grounds?.[index]);
4579 if (!isGroundPassable(ground.typeId))
5521 if (groundLightOcclusion(ground.typeId) === LightOcclusion.solid)
4580 5522 { return true; }
4581 5523 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4582 5524 }
@@ -2,7 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO
2import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
2import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
4import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
5import { collectBlockLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
5import { collectBlockLightSources, collectGroundLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
6import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
7import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
8import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
8import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
@@ -16,7 +16,7 @@ import
16} from "/shared/render/tint.js";
16} from "/shared/render/tint.js";
17import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
17import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
18import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
18import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
19import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, LightOcclusion, blockDefinition, blockLightOcclusionForBlock } from "/shared/definitions/tiles.js";
19import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
20import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
20import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
21import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
21import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
22import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
22import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -27,7 +27,8 @@ import
27 invalidateCanvasTexture
27 invalidateCanvasTexture
28} from "./canvasSprite.js";
28} from "./canvasSprite.js";
29import { setNearestFilter } from "./sprites.js";
29import { setNearestFilter } from "./sprites.js";
30import { SeasonId, seasonIdAt } from "/shared/world/season.js";
30import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";
31import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
31import
32import
32{
33{
33 OVERWORLD_ID,
34 OVERWORLD_ID,
@@ -105,6 +106,7 @@ const WATER_GROUND_FRAG = [
105 "precision mediump float;",
106 "precision mediump float;",
106 "varying vec2 v_texCoord;",
107 "varying vec2 v_texCoord;",
107 "uniform sampler2D u_texture;",
108 "uniform sampler2D u_texture;",
109 "uniform sampler2D u_secondary;",
108 "uniform float u_alpha;",
110 "uniform float u_alpha;",
109 "uniform float u_ambientDark;",
111 "uniform float u_ambientDark;",
110 "uniform float u_litNW;",
112 "uniform float u_litNW;",
@@ -112,35 +114,564 @@ const WATER_GROUND_FRAG = [
112 "uniform float u_litSW;",
114 "uniform float u_litSW;",
113 "uniform float u_litSE;",
115 "uniform float u_litSE;",
114 "uniform float u_time;",
116 "uniform float u_time;",
117 "uniform float u_tileX;",
118 "uniform float u_tileY;",
119 "uniform float u_deepNW;",
120 "uniform float u_deepNE;",
121 "uniform float u_deepSW;",
122 "uniform float u_deepSE;",
115 "uniform float u_edgeN;",
123 "uniform float u_edgeN;",
116 "uniform float u_edgeE;",
124 "uniform float u_edgeE;",
117 "uniform float u_edgeS;",
125 "uniform float u_edgeS;",
118 "uniform float u_edgeW;",
126 "uniform float u_edgeW;",
127 "uniform float u_edgeNE;",
128 "uniform float u_edgeNW;",
129 "uniform float u_edgeSE;",
130 "uniform float u_edgeSW;",
131 "uniform float u_hasShore;",
132 "uniform float u_shoreEdgeN;",
133 "uniform float u_shoreEdgeE;",
134 "uniform float u_shoreEdgeS;",
135 "uniform float u_shoreEdgeW;",
136 "uniform float u_shoreEdgeNE;",
137 "uniform float u_shoreEdgeNW;",
138 "uniform float u_shoreEdgeSE;",
139 "uniform float u_shoreEdgeSW;",
140 "uniform vec4 u_shoreUvRect;",
141 "uniform float u_flowX;",
142 "uniform float u_flowY;",
143 "uniform float u_flowZ;",
144 "uniform float u_waveScale;",
145 "uniform float u_fbmAmp;",
146 "uniform float u_texAmp;",
147 "uniform float u_distort;",
148 "uniform float u_normalZ;",
149 "uniform float u_waveGain;",
150 "uniform float u_crestLo;",
151 "uniform float u_crestHi;",
152 "uniform float u_crestPow;",
153 "uniform float u_glitterPow;",
154 "uniform float u_crestGlitter;",
155 "uniform float u_glitterCap;",
156 "uniform float u_glitterMix;",
157 "uniform float u_shadeLo;",
158 "uniform float u_shadeHi;",
159 "uniform float u_bodyLo;",
160 "uniform float u_bodyHi;",
161 "uniform float u_litLo;",
162 "uniform float u_litHi;",
163 "uniform float u_litMix;",
164 "uniform float u_edgeDark;",
165 "uniform float u_lightDirX;",
166 "uniform float u_lightDirY;",
167 "uniform float u_lightDirZ;",
168 "uniform float u_normalEps;",
169 "uniform float u_foamStrength;",
170 "uniform float u_shoreClip;",
171 "uniform float u_deepDark;",
172 "uniform float u_deepAbrupt;",
173 // 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).
174 "vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
175 "vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
176 "vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",
177 "vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",
178 "float snoise(vec3 v) {",
179 " vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",
180 " vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",
181 " vec3 i = floor(v + dot(v, C.yyy));",
182 " vec3 x0 = v - i + dot(i, C.xxx);",
183 " vec3 g = step(x0.yzx, x0.xyz);",
184 " vec3 l = 1.0 - g;",
185 " vec3 i1 = min(g.xyz, l.zxy);",
186 " vec3 i2 = max(g.xyz, l.zxy);",
187 " vec3 x1 = x0 - i1 + C.xxx;",
188 " vec3 x2 = x0 - i2 + C.yyy;",
189 " vec3 x3 = x0 - D.yyy;",
190 " i = mod289(i);",
191 " vec4 p = permute(permute(permute(",
192 " i.z + vec4(0.0, i1.z, i2.z, 1.0))",
193 " + i.y + vec4(0.0, i1.y, i2.y, 1.0))",
194 " + i.x + vec4(0.0, i1.x, i2.x, 1.0));",
195 " float n_ = 0.142857142857;",
196 " vec3 ns = n_ * D.wyz - D.xzx;",
197 " vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",
198 " vec4 x_ = floor(j * ns.z);",
199 " vec4 y_ = floor(j - 7.0 * x_);",
200 " vec4 x = x_ * ns.x + ns.yyyy;",
201 " vec4 y = y_ * ns.x + ns.yyyy;",
202 " vec4 h = 1.0 - abs(x) - abs(y);",
203 " vec4 b0 = vec4(x.xy, y.xy);",
204 " vec4 b1 = vec4(x.zw, y.zw);",
205 " vec4 s0 = floor(b0) * 2.0 + 1.0;",
206 " vec4 s1 = floor(b1) * 2.0 + 1.0;",
207 " vec4 sh = -step(h, vec4(0.0));",
208 " vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",
209 " vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",
210 " vec3 p0 = vec3(a0.xy, h.x);",
211 " vec3 p1 = vec3(a0.zw, h.y);",
212 " vec3 p2 = vec3(a1.xy, h.z);",
213 " vec3 p3 = vec3(a1.zw, h.w);",
214 " vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",
215 " p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",
216 " vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",
217 " m = m * m;",
218 " return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",
219 "}",
220 // 4-octave FBM: freq ×2, amp ×0.5 each layer; time in Z for continuous ripple.
221 "float fbm(vec3 p) {",
222 " float sum = 0.0;",
223 " float amp = 0.5;",
224 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
225 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
226 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
227 " sum += amp * snoise(p);",
228 " return sum;",
229 "}",
230 "vec2 wrapUv(vec2 uv) {",
231 " return fract(uv) * 0.998 + 0.001;",
232 "}",
233 "float sampleShore(",
234 " float enabled, float useShore, vec2 shoreNu,",
235 " inout vec3 shoreRgb, inout float shoreW",
236 ") {",
237 " if (enabled < 0.5 || useShore < 0.5 || u_hasShore < 0.5) { return 0.0; }",
238 " vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
239 " vec4 shore = texture2D(u_secondary, shoreUv);",
240 " if (shore.a <= 0.1) { return 0.0; }",
241 " shoreRgb = shore.rgb;",
242 " shoreW = 1.0;",
243 " return 1.0;",
244 "}",
119 "void main() {",
245 "void main() {",
120 " vec4 color = texture2D(u_texture, v_texCoord);",
246 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
121 " if (color.a <= 0.0) { discard; }",
247 " vec2 puv = px / 16.0;",
122 " vec3 rgb = color.rgb;",
248 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
123 " float foam = 0.0;",
249 " float t = u_time;",
124 " float pulse = 0.55 + 0.45 * sin(u_time * 3.2 + v_texCoord.x * 18.0 + v_texCoord.y * 10.0);",
250 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
125 " if (u_edgeN > 0.5 && v_texCoord.y < 0.22) {",
251 " float eps = max(u_normalEps, 0.001);",
126 " foam = max(foam, (1.0 - v_texCoord.y / 0.22) * pulse);",
252 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
253 " float nC = fbm(base);",
254 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
255 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
256 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
257 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
258 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
259 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
260 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
261 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
262 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
263 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
264 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
265 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
266 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
267 " float edgeProx = 0.0;",
268 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
269 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
270 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
271 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
272 " if (u_edgeNE > 0.5) {",
273 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
274 " }",
275 " if (u_edgeNW > 0.5) {",
276 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
277 " }",
278 " if (u_edgeSE > 0.5) {",
279 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
280 " }",
281 " if (u_edgeSW > 0.5) {",
282 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
283 " }",
284 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
285 " float deepTop = mix(u_deepNW, u_deepNE, puv.x);",
286 " float deepBot = mix(u_deepSW, u_deepSE, puv.x);",
287 " float deepMix = mix(deepTop, deepBot, puv.y);",
288 " float deepAmt = pow(clamp(deepMix, 0.0, 1.0), max(u_deepAbrupt, 0.05));",
289 " float darkW = clamp(u_deepDark, 0.0, 1.0);",
290 " vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), mix(vec3(0.05, 0.16, 0.34), vec3(0.015, 0.055, 0.14), darkW), deepAmt);",
291 " vec3 midCol = mix(vec3(0.24, 0.52, 0.70), mix(vec3(0.10, 0.30, 0.50), vec3(0.04, 0.14, 0.28), darkW), deepAmt);",
292 " vec3 litCol = mix(vec3(0.52, 0.78, 0.90), mix(vec3(0.26, 0.46, 0.66), vec3(0.12, 0.28, 0.46), darkW), deepAmt);",
293 " vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), mix(vec3(0.72, 0.88, 0.98), vec3(0.48, 0.68, 0.86), darkW), deepAmt);",
294 " vec3 foamCol = vec3(0.94, 0.99, 1.0);",
295 " float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
296 " vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",
297 " rgb = mix(rgb, litCol, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix);",
298 " rgb *= shade;",
299 " rgb = mix(rgb, sparkCol, min(glitter, u_glitterCap) * u_glitterMix * (1.0 - edgeProx * 0.7));",
300 " rgb = mix(rgb, deepCol, edgeProx * u_edgeDark);",
301 " float shoreW = 0.0;",
302 " vec3 shoreRgb = rgb;",
303 " if (u_edgeN > 0.5) {",
304 " sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
305 " }",
306 " if (u_edgeS > 0.5) {",
307 " sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
308 " }",
309 " if (u_edgeW > 0.5) {",
310 " sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
127 " }",
311 " }",
128 " if (u_edgeS > 0.5 && v_texCoord.y > 0.78) {",
312 " if (u_edgeE > 0.5) {",
129 " foam = max(foam, ((v_texCoord.y - 0.78) / 0.22) * pulse);",
313 " sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
130 " }",
314 " }",
131 " if (u_edgeW > 0.5 && v_texCoord.x < 0.22) {",
315 " if (u_edgeNE > 0.5) {",
132 " foam = max(foam, (1.0 - v_texCoord.x / 0.22) * pulse);",
316 " sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
133 " }",
317 " }",
134 " if (u_edgeE > 0.5 && v_texCoord.x > 0.78) {",
318 " if (u_edgeNW > 0.5) {",
135 " foam = max(foam, ((v_texCoord.x - 0.78) / 0.22) * pulse);",
319 " sampleShore(1.0, max(u_shoreEdgeNW, u_hasShore), vec2(puv.x, puv.y), shoreRgb, shoreW);",
136 " }",
320 " }",
137 " rgb = mix(rgb, vec3(0.78, 0.92, 1.0), clamp(foam, 0.0, 0.85));",
321 " if (u_edgeSE > 0.5) {",
322 " sampleShore(1.0, max(u_shoreEdgeSE, u_hasShore), vec2(1.0 - puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
323 " }",
324 " if (u_edgeSW > 0.5) {",
325 " sampleShore(1.0, max(u_shoreEdgeSW, u_hasShore), vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
326 " }",
327 " float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",
328 " float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",
329 " float shoreClip = u_shoreClip;",
330 " float shoreMask = step(shoreClip, retreat) * shoreW;",
331 " float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",
332 " * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",
333 " rgb = mix(rgb, foamCol, foamAmt * u_foamStrength);",
334 " rgb = mix(rgb, shoreRgb, shoreMask);",
138 " float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
335 " float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
139 " float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
336 " float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
140 " float lit = mix(litTop, litBottom, v_texCoord.y);",
337 " float lit = mix(litTop, litBottom, v_texCoord.y);",
141 " float darkness = u_ambientDark * (1.0 - lit);",
338 " float darkness = u_ambientDark * (1.0 - lit);",
142 " rgb = mix(rgb, vec3(0.0), darkness);",
339 " rgb = mix(rgb, vec3(0.0), darkness);",
143 " gl_FragColor = vec4(rgb, color.a * u_alpha);",
340 " gl_FragColor = vec4(rgb, u_alpha);",
341 "}"
342].join("\n");
343
344/** Lava heat: dark red → red → orange → yellow; yellow drives bloom companion. */
345const LAVA_FBM_COMMON = [
346 "vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
347 "vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
348 "vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",
349 "vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",
350 "float snoise(vec3 v) {",
351 " vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",
352 " vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",
353 " vec3 i = floor(v + dot(v, C.yyy));",
354 " vec3 x0 = v - i + dot(i, C.xxx);",
355 " vec3 g = step(x0.yzx, x0.xyz);",
356 " vec3 l = 1.0 - g;",
357 " vec3 i1 = min(g.xyz, l.zxy);",
358 " vec3 i2 = max(g.xyz, l.zxy);",
359 " vec3 x1 = x0 - i1 + C.xxx;",
360 " vec3 x2 = x0 - i2 + C.yyy;",
361 " vec3 x3 = x0 - D.yyy;",
362 " i = mod289(i);",
363 " vec4 p = permute(permute(permute(",
364 " i.z + vec4(0.0, i1.z, i2.z, 1.0))",
365 " + i.y + vec4(0.0, i1.y, i2.y, 1.0))",
366 " + i.x + vec4(0.0, i1.x, i2.x, 1.0));",
367 " float n_ = 0.142857142857;",
368 " vec3 ns = n_ * D.wyz - D.xzx;",
369 " vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",
370 " vec4 x_ = floor(j * ns.z);",
371 " vec4 y_ = floor(j - 7.0 * x_);",
372 " vec4 x = x_ * ns.x + ns.yyyy;",
373 " vec4 y = y_ * ns.x + ns.yyyy;",
374 " vec4 h = 1.0 - abs(x) - abs(y);",
375 " vec4 b0 = vec4(x.xy, y.xy);",
376 " vec4 b1 = vec4(x.zw, y.zw);",
377 " vec4 s0 = floor(b0) * 2.0 + 1.0;",
378 " vec4 s1 = floor(b1) * 2.0 + 1.0;",
379 " vec4 sh = -step(h, vec4(0.0));",
380 " vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",
381 " vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",
382 " vec3 p0 = vec3(a0.xy, h.x);",
383 " vec3 p1 = vec3(a0.zw, h.y);",
384 " vec3 p2 = vec3(a1.xy, h.z);",
385 " vec3 p3 = vec3(a1.zw, h.w);",
386 " vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",
387 " p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",
388 " vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",
389 " m = m * m;",
390 " return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",
391 "}",
392 "float fbm(vec3 p) {",
393 " float sum = 0.0;",
394 " float amp = 0.5;",
395 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
396 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
397 " sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
398 " sum += amp * snoise(p);",
399 " return sum;",
400 "}",
401 "vec2 wrapUv(vec2 uv) {",
402 " return fract(uv) * 0.998 + 0.001;",
403 "}"
404];
405
406const LAVA_GROUND_FRAG = [
407 "precision mediump float;",
408 "varying vec2 v_texCoord;",
409 "uniform sampler2D u_texture;",
410 "uniform float u_alpha;",
411 "uniform float u_ambientDark;",
412 "uniform float u_litNW;",
413 "uniform float u_litNE;",
414 "uniform float u_litSW;",
415 "uniform float u_litSE;",
416 "uniform float u_time;",
417 "uniform float u_tileX;",
418 "uniform float u_tileY;",
419 "uniform float u_edgeN;",
420 "uniform float u_edgeE;",
421 "uniform float u_edgeS;",
422 "uniform float u_edgeW;",
423 "uniform float u_edgeNE;",
424 "uniform float u_edgeNW;",
425 "uniform float u_edgeSE;",
426 "uniform float u_edgeSW;",
427 "uniform float u_flowX;",
428 "uniform float u_flowY;",
429 "uniform float u_flowZ;",
430 "uniform float u_waveScale;",
431 "uniform float u_fbmAmp;",
432 "uniform float u_texAmp;",
433 "uniform float u_distort;",
434 "uniform float u_normalZ;",
435 "uniform float u_waveGain;",
436 "uniform float u_crestLo;",
437 "uniform float u_crestHi;",
438 "uniform float u_crestPow;",
439 "uniform float u_glitterPow;",
440 "uniform float u_crestGlitter;",
441 "uniform float u_glitterCap;",
442 "uniform float u_glitterMix;",
443 "uniform float u_shadeLo;",
444 "uniform float u_shadeHi;",
445 "uniform float u_bodyLo;",
446 "uniform float u_bodyHi;",
447 "uniform float u_litLo;",
448 "uniform float u_litHi;",
449 "uniform float u_litMix;",
450 "uniform float u_edgeDark;",
451 "uniform float u_lightDirX;",
452 "uniform float u_lightDirY;",
453 "uniform float u_lightDirZ;",
454 "uniform float u_normalEps;",
455 "uniform float u_shoreClip;",
456 "uniform float u_hasShore;",
457 "uniform float u_shoreEdgeN;",
458 "uniform float u_shoreEdgeE;",
459 "uniform float u_shoreEdgeS;",
460 "uniform float u_shoreEdgeW;",
461 "uniform float u_shoreEdgeNE;",
462 "uniform float u_shoreEdgeNW;",
463 "uniform float u_shoreEdgeSE;",
464 "uniform float u_shoreEdgeSW;",
465 "uniform vec4 u_shoreUvRect;",
466 "uniform sampler2D u_secondary;",
467 ...LAVA_FBM_COMMON,
468 "float sampleShore(",
469 " float enabled, float useShore, vec2 shoreNu,",
470 " inout vec3 shoreRgb, inout float shoreW",
471 ") {",
472 " if (enabled < 0.5 || useShore < 0.5 || u_hasShore < 0.5) { return 0.0; }",
473 " vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
474 " vec4 shore = texture2D(u_secondary, shoreUv);",
475 " if (shore.a <= 0.1) { return 0.0; }",
476 " shoreRgb = shore.rgb;",
477 " shoreW = 1.0;",
478 " return 1.0;",
479 "}",
480 "void main() {",
481 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
482 " vec2 puv = px / 16.0;",
483 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
484 " float t = u_time;",
485 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
486 " float eps = max(u_normalEps, 0.001);",
487 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
488 " float nC = fbm(base);",
489 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
490 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
491 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
492 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
493 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
494 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
495 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
496 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
497 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
498 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
499 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
500 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
501 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
502 " float edgeProx = 0.0;",
503 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
504 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
505 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
506 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
507 " if (u_edgeNE > 0.5) {",
508 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
509 " }",
510 " if (u_edgeNW > 0.5) {",
511 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
512 " }",
513 " if (u_edgeSE > 0.5) {",
514 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
515 " }",
516 " if (u_edgeSW > 0.5) {",
517 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
518 " }",
519 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
520 " float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
521 " heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
522 " heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
523 " vec3 darkRed = vec3(0.16, 0.015, 0.01);",
524 " vec3 brightRed = vec3(0.78, 0.08, 0.02);",
525 " vec3 orange = vec3(0.98, 0.38, 0.04);",
526 " vec3 yellow = vec3(1.0, 0.9, 0.28);",
527 " vec3 rgb = mix(darkRed, brightRed, smoothstep(0.0, 0.38, heat));",
528 " rgb = mix(rgb, orange, smoothstep(0.28, 0.68, heat));",
529 " float yellowAmt = smoothstep(0.55, 0.98, heat);",
530 " rgb = mix(rgb, yellow, yellowAmt);",
531 " float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
532 " rgb *= shade;",
533 " rgb = mix(rgb, darkRed, edgeProx * u_edgeDark * 0.35);",
534 " float shoreW = 0.0;",
535 " vec3 shoreRgb = rgb;",
536 " if (u_edgeN > 0.5) {",
537 " sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
538 " }",
539 " if (u_edgeS > 0.5) {",
540 " sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
541 " }",
542 " if (u_edgeW > 0.5) {",
543 " sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
544 " }",
545 " if (u_edgeE > 0.5) {",
546 " sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
547 " }",
548 " if (u_edgeNE > 0.5) {",
549 " sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
550 " }",
551 " if (u_edgeNW > 0.5) {",
552 " sampleShore(1.0, max(u_shoreEdgeNW, u_hasShore), vec2(puv.x, puv.y), shoreRgb, shoreW);",
553 " }",
554 " if (u_edgeSE > 0.5) {",
555 " sampleShore(1.0, max(u_shoreEdgeSE, u_hasShore), vec2(1.0 - puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
556 " }",
557 " if (u_edgeSW > 0.5) {",
558 " sampleShore(1.0, max(u_shoreEdgeSW, u_hasShore), vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
559 " }",
560 " float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",
561 " float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",
562 " float shoreClip = u_shoreClip;",
563 " float shoreMask = step(shoreClip, retreat) * shoreW;",
564 " float crustAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.2, shoreClip - 0.06, retreat)",
565 " * (1.0 - smoothstep(shoreClip - 0.06, shoreClip, retreat));",
566 " rgb = mix(rgb, vec3(0.05, 0.01, 0.0), crustAmt);",
567 " rgb = mix(rgb, shoreRgb, shoreMask);",
568 " float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
569 " float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
570 " float lit = mix(litTop, litBottom, v_texCoord.y);",
571 " float darkness = u_ambientDark * (1.0 - lit);",
572 " rgb = mix(rgb, vec3(0.0), darkness);",
573 " gl_FragColor = vec4(rgb, u_alpha);",
574 "}"
575].join("\n");
576
577/** Unlit bloom overlay — strength tracks yellow heat (exempt from world darkness). */
578const LAVA_BLOOM_FRAG = [
579 "precision mediump float;",
580 "varying vec2 v_texCoord;",
581 "uniform sampler2D u_texture;",
582 "uniform float u_alpha;",
583 "uniform float u_time;",
584 "uniform float u_tileX;",
585 "uniform float u_tileY;",
586 "uniform float u_edgeN;",
587 "uniform float u_edgeE;",
588 "uniform float u_edgeS;",
589 "uniform float u_edgeW;",
590 "uniform float u_edgeNE;",
591 "uniform float u_edgeNW;",
592 "uniform float u_edgeSE;",
593 "uniform float u_edgeSW;",
594 "uniform float u_flowX;",
595 "uniform float u_flowY;",
596 "uniform float u_flowZ;",
597 "uniform float u_waveScale;",
598 "uniform float u_fbmAmp;",
599 "uniform float u_texAmp;",
600 "uniform float u_distort;",
601 "uniform float u_normalZ;",
602 "uniform float u_waveGain;",
603 "uniform float u_crestLo;",
604 "uniform float u_crestHi;",
605 "uniform float u_crestPow;",
606 "uniform float u_glitterPow;",
607 "uniform float u_crestGlitter;",
608 "uniform float u_glitterCap;",
609 "uniform float u_glitterMix;",
610 "uniform float u_bodyLo;",
611 "uniform float u_bodyHi;",
612 "uniform float u_litLo;",
613 "uniform float u_litHi;",
614 "uniform float u_litMix;",
615 "uniform float u_lightDirX;",
616 "uniform float u_lightDirY;",
617 "uniform float u_lightDirZ;",
618 "uniform float u_normalEps;",
619 "uniform float u_bloomStrength;",
620 "uniform float u_shoreClip;",
621 ...LAVA_FBM_COMMON,
622 "void main() {",
623 " vec2 px = floor(v_texCoord * 16.0) + 0.5;",
624 " vec2 puv = px / 16.0;",
625 " vec2 world = vec2(u_tileX, u_tileY) + puv;",
626 " float t = u_time;",
627 " vec2 flow = vec2(t * u_flowX, t * u_flowY);",
628 " float eps = max(u_normalEps, 0.001);",
629 " vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
630 " float nC = fbm(base);",
631 " float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
632 " float nR = fbm(base + vec3(eps, 0.0, 0.0));",
633 " float nD = fbm(base + vec3(0.0, -eps, 0.0));",
634 " float nU = fbm(base + vec3(0.0, eps, 0.0));",
635 " vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
636 " float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
637 " float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
638 " vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
639 " float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
640 " float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
641 " float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
642 " float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
643 " glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
644 " float edgeProx = 0.0;",
645 " if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
646 " if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
647 " if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
648 " if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
649 " if (u_edgeNE > 0.5) {",
650 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
651 " }",
652 " if (u_edgeNW > 0.5) {",
653 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
654 " }",
655 " if (u_edgeSE > 0.5) {",
656 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
657 " }",
658 " if (u_edgeSW > 0.5) {",
659 " edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
660 " }",
661 " float waveBody = wave * (1.0 - edgeProx * 0.72);",
662 " float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
663 " heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
664 " heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
665 " float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",
666 " float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",
667 " float hasEdge = max(max(u_edgeN, u_edgeE), max(u_edgeS, u_edgeW));",
668 " hasEdge = max(hasEdge, max(max(u_edgeNE, u_edgeNW), max(u_edgeSE, u_edgeSW)));",
669 " float shoreW = step(0.5, hasEdge);",
670 " float shoreMask = step(u_shoreClip, retreat) * shoreW;",
671 " float yellowAmt = smoothstep(0.55, 0.98, heat) * (1.0 - edgeProx * 0.85) * (1.0 - shoreMask);",
672 " float bloom = yellowAmt * max(u_bloomStrength, 0.0);",
673 " vec3 glow = vec3(1.0, 0.82, 0.28) * bloom;",
674 " gl_FragColor = vec4(glow, bloom * u_alpha);",
144 "}"
675 "}"
145].join("\n");
676].join("\n");
146
677
@@ -392,6 +923,8 @@ let spriteLightingShader = null;
392let atlasLightingShader = null;
923let atlasLightingShader = null;
393let cliffGroundTopShader = null;
924let cliffGroundTopShader = null;
394let waterGroundShader = null;
925let waterGroundShader = null;
926let lavaGroundShader = null;
927let lavaBloomShader = null;
395let tintLitSpriteShader = null;
928let tintLitSpriteShader = null;
396let dualTintLitSpriteShader = null;
929let dualTintLitSpriteShader = null;
397let tightFitTintLitSpriteShader = null;
930let tightFitTintLitSpriteShader = null;
@@ -425,6 +958,20 @@ function getWaterGroundShader ()
425 return waterGroundShader;
958 return waterGroundShader;
426}
959}
427
960
961function getLavaGroundShader ()
962{
963 if (!lavaGroundShader)
964 { lavaGroundShader = Shader.fragment(LAVA_GROUND_FRAG); }
965 return lavaGroundShader;
966}
967
968function getLavaBloomShader ()
969{
970 if (!lavaBloomShader)
971 { lavaBloomShader = Shader.fragment(LAVA_BLOOM_FRAG); }
972 return lavaBloomShader;
973}
974
428function getTintLitSpriteShader ()
975function getTintLitSpriteShader ()
429{
976{
430 if (!tintLitSpriteShader)
977 if (!tintLitSpriteShader)
@@ -726,6 +1273,7 @@ export class WorldView
726 {
1273 {
727 objects.ground?.destroy();
1274 objects.ground?.destroy();
728 objects.groundBloom?.destroy();
1275 objects.groundBloom?.destroy();
1276 objects.lavaBloom?.destroy();
729 objects.block?.destroy();
1277 objects.block?.destroy();
730 objects.blockBloom?.destroy();
1278 objects.blockBloom?.destroy();
731 this.tiles.delete(tileKey);
1279 this.tiles.delete(tileKey);
@@ -3176,15 +3724,171 @@ export class WorldView
3176 #waterCoastEdges (tileX, tileY)
3724 #waterCoastEdges (tileX, tileY)
3177 {
3725 {
3178 const season = this.worldSeason;
3726 const season = this.worldSeason;
3727 const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);
3728 const n = liquid(tileX, tileY - 1);
3729 const e = liquid(tileX + 1, tileY);
3730 const s = liquid(tileX, tileY + 1);
3731 const w = liquid(tileX - 1, tileY);
3732 const ne = liquid(tileX + 1, tileY - 1);
3733 const nw = liquid(tileX - 1, tileY - 1);
3734 const se = liquid(tileX + 1, tileY + 1);
3735 const sw = liquid(tileX - 1, tileY + 1);
3736 return {
3737 n: n ? 0 : 1,
3738 e: e ? 0 : 1,
3739 s: s ? 0 : 1,
3740 w: w ? 0 : 1,
3741 // Pure diagonal land pockets (e.g. WWW/WLL) — only when cardinals stay water.
3742 ne: (!ne && n && e) ? 1 : 0,
3743 nw: (!nw && n && w) ? 1 : 0,
3744 se: (!se && s && e) ? 1 : 0,
3745 sw: (!sw && s && w) ? 1 : 0
3746 };
3747 }
3748
3749 /**
3750 * Corner deepness = average of liquid-water tiles meeting that corner.
3751 * Bilinear sampling of these corners is continuous across shared edges/corners.
3752 */
3753 #waterDeepCorners (tileX, tileY, selfDeep)
3754 {
3755 const season = this.worldSeason;
3756 const fallback = selfDeep ? 1 : 0;
3757 const depthAt = (x, y) =>
3758 {
3759 const typeId = this.#groundTypeAt(x, y);
3760 if (!isLiquidWaterGround(typeId, season))
3761 { return null; }
3762 return typeId === GroundType.deepWater ? 1 : 0;
3763 };
3764 const corner = (offsets) =>
3765 {
3766 let sum = 0;
3767 let count = 0;
3768 for (const [dx, dy] of offsets)
3769 {
3770 const d = depthAt(tileX + dx, tileY + dy);
3771 if (d == null)
3772 { continue; }
3773 sum += d;
3774 count += 1;
3775 }
3776 return count ? sum / count : fallback;
3777 };
3179 return {
3778 return {
3180 n: !isLiquidWaterGround(this.#groundTypeAt(tileX, tileY - 1), season) ? 1 : 0,
3779 nw: corner([[0, 0], [-1, 0], [0, -1], [-1, -1]]),
3181 e: !isLiquidWaterGround(this.#groundTypeAt(tileX + 1, tileY), season) ? 1 : 0,
3780 ne: corner([[0, 0], [1, 0], [0, -1], [1, -1]]),
3182 s: !isLiquidWaterGround(this.#groundTypeAt(tileX, tileY + 1), season) ? 1 : 0,
3781 sw: corner([[0, 0], [-1, 0], [0, 1], [-1, 1]]),
3183 w: !isLiquidWaterGround(this.#groundTypeAt(tileX - 1, tileY), season) ? 1 : 0
3782 se: corner([[0, 0], [1, 0], [0, 1], [1, 1]])
3184 };
3783 };
3185 }
3784 }
3186
3785
3187 #syncWaterGroundSprite (object, corners, ambientDark, edges, timeSec, fallbackLit = 1)
3786 /**
3787 * Neighbor ground sprite for coast retreat peeks.
3788 * Water prefers wet-shore (sand-wet); lava uses dry land only.
3789 */
3790 #fluidCoastShore (tileX, tileY, edges, { preferWet = true } = {})
3791 {
3792 const season = this.worldSeason;
3793 const candidates = [];
3794 if (edges?.n)
3795 { candidates.push({ edge: "n", tileX, tileY: tileY - 1 }); }
3796 if (edges?.e)
3797 { candidates.push({ edge: "e", tileX: tileX + 1, tileY }); }
3798 if (edges?.s)
3799 { candidates.push({ edge: "s", tileX, tileY: tileY + 1 }); }
3800 if (edges?.w)
3801 { candidates.push({ edge: "w", tileX: tileX - 1, tileY }); }
3802 if (edges?.ne)
3803 { candidates.push({ edge: "ne", tileX: tileX + 1, tileY: tileY - 1 }); }
3804 if (edges?.nw)
3805 { candidates.push({ edge: "nw", tileX: tileX - 1, tileY: tileY - 1 }); }
3806 if (edges?.se)
3807 { candidates.push({ edge: "se", tileX: tileX + 1, tileY: tileY + 1 }); }
3808 if (edges?.sw)
3809 { candidates.push({ edge: "sw", tileX: tileX - 1, tileY: tileY + 1 }); }
3810 let pick = null;
3811 for (const candidate of candidates)
3812 {
3813 const ground = this.#groundAtTile(candidate.tileX, candidate.tileY);
3814 if (ground == null)
3815 { continue; }
3816 const entry = normalizeGround(ground);
3817 const def = GROUND_DEFINITIONS[entry.typeId];
3818 if (!def || def.proceduralWaves)
3819 { continue; }
3820 let spriteName = null;
3821 if (preferWet && def.wetShore)
3822 {
3823 const wetState = `${def.key}-wet`;
3824 const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3825 if (states.includes(wetState))
3826 { spriteName = spriteImageName("ground", def.key, wetState); }
3827 }
3828 if (!spriteName)
3829 {
3830 const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3831 const state = resolveSeasonalVisualState(states, entry.state, season) ?? def.key;
3832 spriteName = spriteImageName("ground", def.key, state);
3833 }
3834 const sprite = spriteName ? this.game.images[spriteName] : null;
3835 if (!sprite)
3836 { continue; }
3837 const ranked = { ...candidate, sprite, wet: !!(preferWet && def.wetShore) };
3838 if (ranked.wet)
3839 {
3840 pick = ranked;
3841 break;
3842 }
3843 if (!pick)
3844 { pick = ranked; }
3845 }
3846 const shore = {
3847 sprite: pick?.sprite ?? null,
3848 edgeN: 0,
3849 edgeE: 0,
3850 edgeS: 0,
3851 edgeW: 0,
3852 edgeNE: 0,
3853 edgeNW: 0,
3854 edgeSE: 0,
3855 edgeSW: 0
3856 };
3857 if (pick?.edge === "n")
3858 { shore.edgeN = 1; }
3859 else if (pick?.edge === "e")
3860 { shore.edgeE = 1; }
3861 else if (pick?.edge === "s")
3862 { shore.edgeS = 1; }
3863 else if (pick?.edge === "w")
3864 { shore.edgeW = 1; }
3865 else if (pick?.edge === "ne")
3866 { shore.edgeNE = 1; }
3867 else if (pick?.edge === "nw")
3868 { shore.edgeNW = 1; }
3869 else if (pick?.edge === "se")
3870 { shore.edgeSE = 1; }
3871 else if (pick?.edge === "sw")
3872 { shore.edgeSW = 1; }
3873 return shore;
3874 }
3875
3876 #waterCoastShore (tileX, tileY, edges)
3877 {
3878 return this.#fluidCoastShore(tileX, tileY, edges, { preferWet: true });
3879 }
3880
3881 #syncWaterGroundSprite (object, {
3882 corners = null,
3883 ambientDark = 0,
3884 edges = null,
3885 shore = null,
3886 timeSec = 0,
3887 fallbackLit = 1,
3888 tileX = 0,
3889 tileY = 0,
3890 deepCorners = null
3891 } = {})
3188 {
3892 {
3189 if (!object?.renderer)
3893 if (!object?.renderer)
3190 { return; }
3894 { return; }
@@ -3195,9 +3899,20 @@ export class WorldView
3195 se: fallbackLit
3899 se: fallbackLit
3196 };
3900 };
3197 const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
3901 const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
3902 const shoreSprite = shore?.sprite ?? null;
3903 const shoreUv = shoreSprite?.getUvRect?.(0)
3904 ?? { u0: 0, v0: 0, u1: 1, v1: 1 };
3905 const dNW = deepCorners?.nw ?? 0;
3906 const dNE = deepCorners?.ne ?? 0;
3907 const dSW = deepCorners?.sw ?? 0;
3908 const dSE = deepCorners?.se ?? 0;
3198 object._lit = true;
3909 object._lit = true;
3199 object.renderer.shader = getWaterGroundShader();
3910 object.renderer.shader = getWaterGroundShader();
3200 object.renderer.secondaryMap = null;
3911 // Shallow + deep share one noise atlas so texAmp seams don't hard-cut at depth edges.
3912 const sharedNoise = this.game.images[spriteImageName("ground", "water", "water")];
3913 if (sharedNoise)
3914 { object.renderer.sprite = sharedNoise; }
3915 object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
3201 object.renderer.shaderUniforms = {
3916 object.renderer.shaderUniforms = {
3202 u_ambientDark: dark,
3917 u_ambientDark: dark,
3203 u_litNW: lit.nw,
3918 u_litNW: lit.nw,
@@ -3205,18 +3920,46 @@ export class WorldView
3205 u_litSW: lit.sw,
3920 u_litSW: lit.sw,
3206 u_litSE: lit.se,
3921 u_litSE: lit.se,
3207 u_time: timeSec,
3922 u_time: timeSec,
3923 u_tileX: tileX | 0,
3924 u_tileY: tileY | 0,
3925 u_deepNW: dNW,
3926 u_deepNE: dNE,
3927 u_deepSW: dSW,
3928 u_deepSE: dSE,
3208 u_edgeN: edges?.n ?? 0,
3929 u_edgeN: edges?.n ?? 0,
3209 u_edgeE: edges?.e ?? 0,
3930 u_edgeE: edges?.e ?? 0,
3210 u_edgeS: edges?.s ?? 0,
3931 u_edgeS: edges?.s ?? 0,
3211 u_edgeW: edges?.w ?? 0
3932 u_edgeW: edges?.w ?? 0,
3933 u_edgeNE: edges?.ne ?? 0,
3934 u_edgeNW: edges?.nw ?? 0,
3935 u_edgeSE: edges?.se ?? 0,
3936 u_edgeSW: edges?.sw ?? 0,
3937 u_hasShore: shoreSprite ? 1 : 0,
3938 u_shoreEdgeN: shore?.edgeN ?? 0,
3939 u_shoreEdgeE: shore?.edgeE ?? 0,
3940 u_shoreEdgeS: shore?.edgeS ?? 0,
3941 u_shoreEdgeW: shore?.edgeW ?? 0,
3942 u_shoreEdgeNE: shore?.edgeNE ?? 0,
3943 u_shoreEdgeNW: shore?.edgeNW ?? 0,
3944 u_shoreEdgeSE: shore?.edgeSE ?? 0,
3945 u_shoreEdgeSW: shore?.edgeSW ?? 0,
3946 u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],
3947 ...waterDebugUniforms()
3212 };
3948 };
3213 }
3949 }
3214
3950
3215 /** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. */
3951 /** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. Lava is procedural heat. */
3216 #syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)
3952 #syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)
3217 {
3953 {
3218 if (!objects?.ground)
3954 if (!objects?.ground)
3219 { return; }
3955 { return; }
3956 if (isLavaGround(objects.groundTypeId))
3957 {
3958 objects.waterEdges = null;
3959 this.#syncLavaGroundFx(objects, ambientDark, timeSec, baked);
3960 return;
3961 }
3962 this.#clearLavaBloom(objects);
3220 if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))
3963 if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))
3221 {
3964 {
3222 objects.waterEdges = null;
3965 objects.waterEdges = null;
@@ -3242,14 +3985,200 @@ export class WorldView
3242 { litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
3985 { litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
3243 }
3986 }
3244 objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);
3987 objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);
3245 this.#syncWaterGroundSprite(
3988 const shore = this.#waterCoastShore(objects.tileX, objects.tileY, objects.waterEdges);
3246 objects.ground,
3989 const deep = objects.groundTypeId === GroundType.deepWater;
3247 litCorners,
3990 this.#syncWaterGroundSprite(objects.ground, {
3991 corners: litCorners,
3248 ambientDark,
3992 ambientDark,
3249 objects.waterEdges,
3993 edges: objects.waterEdges,
3994 shore,
3250 timeSec,
3995 timeSec,
3251 fallbackLit
3996 fallbackLit,
3252 );
3997 tileX: objects.tileX,
3998 tileY: objects.tileY,
3999 deepCorners: this.#waterDeepCorners(objects.tileX, objects.tileY, deep)
4000 });
4001 }
4002
4003 #lavaCoastEdges (tileX, tileY)
4004 {
4005 const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));
4006 const n = lava(tileX, tileY - 1);
4007 const e = lava(tileX + 1, tileY);
4008 const s = lava(tileX, tileY + 1);
4009 const w = lava(tileX - 1, tileY);
4010 const ne = lava(tileX + 1, tileY - 1);
4011 const nw = lava(tileX - 1, tileY - 1);
4012 const se = lava(tileX + 1, tileY + 1);
4013 const sw = lava(tileX - 1, tileY + 1);
4014 return {
4015 n: n ? 0 : 1,
4016 e: e ? 0 : 1,
4017 s: s ? 0 : 1,
4018 w: w ? 0 : 1,
4019 ne: (!ne && n && e) ? 1 : 0,
4020 nw: (!nw && n && w) ? 1 : 0,
4021 se: (!se && s && e) ? 1 : 0,
4022 sw: (!sw && s && w) ? 1 : 0
4023 };
4024 }
4025
4026 #clearLavaBloom (objects)
4027 {
4028 if (!objects)
4029 { return; }
4030 objects.lavaBloom?.destroy();
4031 objects.lavaBloom = null;
4032 }
4033
4034 #ensureLavaBloom (objects)
4035 {
4036 const sprite = objects.ground?.renderer?.sprite;
4037 if (!sprite)
4038 { return null; }
4039 if (!objects.lavaBloom)
4040 {
4041 const bloom = new GameObject(0, 0, sprite, LAYER_GROUND);
4042 bloom.renderer.layer = RENDER_LAYER_BLOOM;
4043 this.#markUnlit(bloom);
4044 this.scene.addObject(bloom);
4045 objects.lavaBloom = bloom;
4046 }
4047 else if (objects.lavaBloom.renderer)
4048 { objects.lavaBloom.renderer.sprite = sprite; }
4049 const size = this.tileSize();
4050 objects.lavaBloom.transform.position.x = objects.tileX * size + size / 2;
4051 objects.lavaBloom.transform.position.y = objects.tileY * size + size / 2;
4052 objects.lavaBloom.transform.size = new vector(size, size);
4053 this.#setLayer(objects.lavaBloom, LAYER_GROUND);
4054 return objects.lavaBloom;
4055 }
4056
4057 #syncLavaGroundFx (objects, ambientDark, timeSec, baked = null)
4058 {
4059 const fallbackLit = 1 - (objects.shadeAlpha ?? 0);
4060 const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);
4061 const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);
4062 const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);
4063 const localX = objects.tileX - chunkX * CHUNK_SIZE;
4064 const localY = objects.tileY - chunkY * CHUNK_SIZE;
4065 let litCorners = null;
4066 if (chunkBaked)
4067 {
4068 if (this.lightingMode === "simple")
4069 {
4070 const gridW = CHUNK_SIZE + 2;
4071 const intensity = chunkBaked.lightIntensityGrid?.[(localY + 1) * gridW + (localX + 1)] ?? fallbackLit;
4072 litCorners = { nw: intensity, ne: intensity, sw: intensity, se: intensity };
4073 }
4074 else
4075 { litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
4076 }
4077 const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);
4078 const shore = this.#fluidCoastShore(objects.tileX, objects.tileY, edges, { preferWet: false });
4079 this.#syncLavaGroundSprite(objects.ground, {
4080 corners: litCorners,
4081 ambientDark,
4082 edges,
4083 shore,
4084 timeSec,
4085 fallbackLit,
4086 tileX: objects.tileX,
4087 tileY: objects.tileY
4088 });
4089 const bloom = this.#ensureLavaBloom(objects);
4090 if (bloom)
4091 {
4092 this.#syncLavaBloomSprite(bloom, {
4093 edges,
4094 timeSec,
4095 tileX: objects.tileX,
4096 tileY: objects.tileY
4097 });
4098 }
4099 }
4100
4101 #syncLavaGroundSprite (object, {
4102 corners = null,
4103 ambientDark = 0,
4104 edges = null,
4105 shore = null,
4106 timeSec = 0,
4107 fallbackLit = 1,
4108 tileX = 0,
4109 tileY = 0
4110 } = {})
4111 {
4112 if (!object?.renderer)
4113 { return; }
4114 const lit = corners ?? {
4115 nw: fallbackLit,
4116 ne: fallbackLit,
4117 sw: fallbackLit,
4118 se: fallbackLit
4119 };
4120 const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
4121 const shoreSprite = shore?.sprite ?? null;
4122 const shoreUv = shoreSprite?.getUvRect?.(0)
4123 ?? { u0: 0, v0: 0, u1: 1, v1: 1 };
4124 object._lit = true;
4125 object.renderer.shader = getLavaGroundShader();
4126 object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
4127 object.renderer.shaderUniforms = {
4128 u_ambientDark: dark,
4129 u_litNW: lit.nw,
4130 u_litNE: lit.ne,
4131 u_litSW: lit.sw,
4132 u_litSE: lit.se,
4133 u_time: timeSec,
4134 u_tileX: tileX | 0,
4135 u_tileY: tileY | 0,
4136 u_edgeN: edges?.n ?? 0,
4137 u_edgeE: edges?.e ?? 0,
4138 u_edgeS: edges?.s ?? 0,
4139 u_edgeW: edges?.w ?? 0,
4140 u_edgeNE: edges?.ne ?? 0,
4141 u_edgeNW: edges?.nw ?? 0,
4142 u_edgeSE: edges?.se ?? 0,
4143 u_edgeSW: edges?.sw ?? 0,
4144 u_hasShore: shoreSprite ? 1 : 0,
4145 u_shoreEdgeN: shore?.edgeN ?? 0,
4146 u_shoreEdgeE: shore?.edgeE ?? 0,
4147 u_shoreEdgeS: shore?.edgeS ?? 0,
4148 u_shoreEdgeW: shore?.edgeW ?? 0,
4149 u_shoreEdgeNE: shore?.edgeNE ?? 0,
4150 u_shoreEdgeNW: shore?.edgeNW ?? 0,
4151 u_shoreEdgeSE: shore?.edgeSE ?? 0,
4152 u_shoreEdgeSW: shore?.edgeSW ?? 0,
4153 u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],
4154 ...lavaDebugUniforms()
4155 };
4156 }
4157
4158 #syncLavaBloomSprite (object, {
4159 edges = null,
4160 timeSec = 0,
4161 tileX = 0,
4162 tileY = 0
4163 } = {})
4164 {
4165 if (!object?.renderer)
4166 { return; }
4167 object.renderer.shader = getLavaBloomShader();
4168 object.renderer.shaderUniforms = {
4169 u_time: timeSec,
4170 u_tileX: tileX | 0,
4171 u_tileY: tileY | 0,
4172 u_edgeN: edges?.n ?? 0,
4173 u_edgeE: edges?.e ?? 0,
4174 u_edgeS: edges?.s ?? 0,
4175 u_edgeW: edges?.w ?? 0,
4176 u_edgeNE: edges?.ne ?? 0,
4177 u_edgeNW: edges?.nw ?? 0,
4178 u_edgeSE: edges?.se ?? 0,
4179 u_edgeSW: edges?.sw ?? 0,
4180 ...lavaDebugUniforms()
4181 };
3253 }
4182 }
3254
4183
3255 #ambientDarkness ()
4184 #ambientDarkness ()
@@ -3983,11 +4912,14 @@ export class WorldView
3983 const timeSec = performance.now() / 1000;
4912 const timeSec = performance.now() / 1000;
3984 for (const objects of this.tiles.values())
4913 for (const objects of this.tiles.values())
3985 {
4914 {
3986 if (!objects.ground || !isWaterGround(objects.groundTypeId))
4915 if (!objects.ground)
4916 { continue; }
4917 const fluid = isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId);
4918 if (!fluid)
3987 { continue; }
4919 { continue; }
3988 if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)
4920 if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)
3989 { continue; }
4921 { continue; }
3990 // Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
4922 // Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
3991 this.#syncGroundWaterFx(objects, 1, timeSec);
4923 this.#syncGroundWaterFx(objects, 1, timeSec);
3992 }
4924 }
3993 }
4925 }
@@ -4032,7 +4964,7 @@ export class WorldView
4032 }
4964 }
4033 if (animatedGround.bloom)
4965 if (animatedGround.bloom)
4034 { objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }
4966 { objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }
4035 else
4967 else if (!isLavaGround(animatedGround.typeId))
4036 {
4968 {
4037 objects.groundBloom?.destroy();
4969 objects.groundBloom?.destroy();
4038 objects.groundBloom = null;
4970 objects.groundBloom = null;
@@ -4044,6 +4976,7 @@ export class WorldView
4044 objects.ground = null;
4976 objects.ground = null;
4045 objects.groundBloom?.destroy();
4977 objects.groundBloom?.destroy();
4046 objects.groundBloom = null;
4978 objects.groundBloom = null;
4979 this.#clearLavaBloom(objects);
4047 objects.groundTypeId = null;
4980 objects.groundTypeId = null;
4048 objects.waterEdges = null;
4981 objects.waterEdges = null;
4049 }
4982 }
@@ -4342,27 +5275,33 @@ export class WorldView
4342 );
5275 );
4343 }
5276 }
4344
5277
4345 /** Authored torches/furnaces in chunks that can light the active 3×3 (or all chunks in editor). */
5278 /** Authored torches/furnaces/lava in chunks that can light the active 3×3 (or all chunks in editor). */
4346 #collectBlockLightsForShading ()
5279 #collectBlockLightsForShading ()
4347 {
5280 {
4348 const center = this.#activeLightingCenterChunk();
5281 const center = this.#activeLightingCenterChunk();
4349 const maxRange = maxBlockLightRangeTiles();
5282 const maxRange = maxBlockLightRangeTiles();
4350 const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;
5283 const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;
4351 const sources = [];
5284 const sources = [];
5285 const pushChunk = (snapshot) =>
5286 {
5287 if (!snapshot)
5288 { return; }
5289 if (snapshot.blocks)
5290 { sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5291 if (snapshot.grounds)
5292 { sources.push(...collectGroundLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.grounds)); }
5293 };
4352 if (!center)
5294 if (!center)
4353 {
5295 {
4354 for (const snapshot of this.chunks.values())
5296 for (const snapshot of this.chunks.values())
4355 { sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5297 { pushChunk(snapshot); }
4356 return sources;
5298 return sources;
4357 }
5299 }
4358 for (let dy = -1 - halo; dy <= 1 + halo; dy++)
5300 for (let dy = -1 - halo; dy <= 1 + halo; dy++)
4359 {
5301 {
4360 for (let dx = -1 - halo; dx <= 1 + halo; dx++)
5302 for (let dx = -1 - halo; dx <= 1 + halo; dx++)
4361 {
5303 {
4362 const snapshot = this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`);
5304 pushChunk(this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`));
4363 if (!snapshot?.blocks)
4364 { continue; }
4365 sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks));
4366 }
5305 }
4367 }
5306 }
4368 return sources;
5307 return sources;
@@ -4490,14 +5429,17 @@ export class WorldView
4490 else
5429 else
4491 { this.#syncLitSprite(objects.block, objects.shadeAlpha); }
5430 { this.#syncLitSprite(objects.block, objects.shadeAlpha); }
4492 }
5431 }
4493 if (objects.ground && isWaterGround(objects.groundTypeId))
5432 if (objects.ground && (isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId)))
4494 {
5433 {
4495 const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);
5434 const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);
4496 // Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
5435 // Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
4497 this.#syncGroundWaterFx(objects, 1, timeSec, baked);
5436 this.#syncGroundWaterFx(objects, 1, timeSec, baked);
4498 }
5437 }
4499 else if (objects.ground)
5438 else if (objects.ground)
4500 { this.#syncLitSprite(objects.ground, objects.shadeAlpha); }
5439 {
5440 this.#clearLavaBloom(objects);
5441 this.#syncLitSprite(objects.ground, objects.shadeAlpha);
5442 }
4501 }
5443 }
4502
5444
4503 for (const item of this.groundItems.values())
5445 for (const item of this.groundItems.values())
@@ -4576,7 +5518,7 @@ export class WorldView
4576 { return false; }
5518 { return false; }
4577 const index = localY * CHUNK_SIZE + localX;
5519 const index = localY * CHUNK_SIZE + localX;
4578 const ground = normalizeGround(snapshot.grounds?.[index]);
5520 const ground = normalizeGround(snapshot.grounds?.[index]);
4579 if (!isGroundPassable(ground.typeId))
5521 if (groundLightOcclusion(ground.typeId) === LightOcclusion.solid)
4580 { return true; }
5522 { return true; }
4581 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
5523 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4582 }
5524 }
server/src/assets/spriteCatalog.js +21 −3
@@ -24,6 +24,7 @@ import
24 24 equipImageName,
25 25 isCompanionSpriteStem,
26 26 parseSpriteStem,
27 palettePreviewImageName,
27 28 spriteImageName
28 29 } from "../../../shared/definitions/tileSprites.js";
29 30 import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";
@@ -246,7 +247,7 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
246 247 for (const def of Object.values(definitions))
247 248 {
248 249 const folder = join(layerDir, def.key);
249 const { states: fileStates, blooms: fileBlooms, equips, equipBlooms } = listVisualStates(folder);
250 const { states: fileStates, blooms: fileBlooms, equips, equipBlooms, previews } = listVisualStates(folder);
250 251 if (fileStates.length === 0)
251 252 { throw new Error(`No PNG states in ${folder}`); }
252 253
@@ -470,6 +471,18 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
470 471 });
471 472 }
472 473 }
474 const previewStem = previews?.[def.key];
475 if (previewStem)
476 {
477 images.push({
478 name: palettePreviewImageName(layer, def.key),
479 url: `/assets/${urlFolder}/${def.key}/${previewStem}.png`,
480 subImgTotal: 1,
481 perRow: 1,
482 loop: false,
483 animationSpeed: 0
484 });
485 }
473 486 images.push(...imagesForType);
474 487 }
475 488 return { types, images };
@@ -481,6 +494,7 @@ function listVisualStates (folder)
481 494 const blooms = {};
482 495 const equips = {};
483 496 const equipBlooms = {};
497 const previews = {};
484 498 const states = [];
485 499 for (const stem of stems)
486 500 {
@@ -489,7 +503,9 @@ function listVisualStates (folder)
489 503 {
490 504 if (!parsed.base)
491 505 { continue; }
492 if (parsed.equip && parsed.bloom)
506 if (parsed.preview)
507 { previews[parsed.base] = stem; }
508 else if (parsed.equip && parsed.bloom)
493 509 { equipBlooms[parsed.base] = true; }
494 510 else if (parsed.equip)
495 511 { equips[parsed.base] = true; }
@@ -515,7 +531,9 @@ function listVisualStates (folder)
515 531 states,
516 532 blooms: filterMap(blooms),
517 533 equips: filterMap(equips),
518 equipBlooms: filterMap(equipBlooms)
534 equipBlooms: filterMap(equipBlooms),
535 /** Editor palette thumbs (`water-preview` → base `water`); not placeable states. */
536 previews
519 537 };
520 538 }
521 539
@@ -24,6 +24,7 @@ import
24 equipImageName,
24 equipImageName,
25 isCompanionSpriteStem,
25 isCompanionSpriteStem,
26 parseSpriteStem,
26 parseSpriteStem,
27 palettePreviewImageName,
27 spriteImageName
28 spriteImageName
28 } from "../../../shared/definitions/tileSprites.js";
29 } from "../../../shared/definitions/tileSprites.js";
29import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";
30import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";
@@ -246,7 +247,7 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
246 for (const def of Object.values(definitions))
247 for (const def of Object.values(definitions))
247 {
248 {
248 const folder = join(layerDir, def.key);
249 const folder = join(layerDir, def.key);
249 const { states: fileStates, blooms: fileBlooms, equips, equipBlooms } = listVisualStates(folder);
250 const { states: fileStates, blooms: fileBlooms, equips, equipBlooms, previews } = listVisualStates(folder);
250 if (fileStates.length === 0)
251 if (fileStates.length === 0)
251 { throw new Error(`No PNG states in ${folder}`); }
252 { throw new Error(`No PNG states in ${folder}`); }
252
253
@@ -470,6 +471,18 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
470 });
471 });
471 }
472 }
472 }
473 }
474 const previewStem = previews?.[def.key];
475 if (previewStem)
476 {
477 images.push({
478 name: palettePreviewImageName(layer, def.key),
479 url: `/assets/${urlFolder}/${def.key}/${previewStem}.png`,
480 subImgTotal: 1,
481 perRow: 1,
482 loop: false,
483 animationSpeed: 0
484 });
485 }
473 images.push(...imagesForType);
486 images.push(...imagesForType);
474 }
487 }
475 return { types, images };
488 return { types, images };
@@ -481,6 +494,7 @@ function listVisualStates (folder)
481 const blooms = {};
494 const blooms = {};
482 const equips = {};
495 const equips = {};
483 const equipBlooms = {};
496 const equipBlooms = {};
497 const previews = {};
484 const states = [];
498 const states = [];
485 for (const stem of stems)
499 for (const stem of stems)
486 {
500 {
@@ -489,7 +503,9 @@ function listVisualStates (folder)
489 {
503 {
490 if (!parsed.base)
504 if (!parsed.base)
491 { continue; }
505 { continue; }
492 if (parsed.equip && parsed.bloom)
506 if (parsed.preview)
507 { previews[parsed.base] = stem; }
508 else if (parsed.equip && parsed.bloom)
493 { equipBlooms[parsed.base] = true; }
509 { equipBlooms[parsed.base] = true; }
494 else if (parsed.equip)
510 else if (parsed.equip)
495 { equips[parsed.base] = true; }
511 { equips[parsed.base] = true; }
@@ -515,7 +531,9 @@ function listVisualStates (folder)
515 states,
531 states,
516 blooms: filterMap(blooms),
532 blooms: filterMap(blooms),
517 equips: filterMap(equips),
533 equips: filterMap(equips),
518 equipBlooms: filterMap(equipBlooms)
534 equipBlooms: filterMap(equipBlooms),
535 /** Editor palette thumbs (`water-preview` → base `water`); not placeable states. */
536 previews
519 };
537 };
520}
538}
521
539
server/src/editor/service.js +2 −3
@@ -1,8 +1,7 @@
1 import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock } from "../../../shared/definitions/tiles.js";
1 import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock, BLOCK_DEFINITIONS, GROUND_DEFINITIONS } from "../../../shared/definitions/tiles.js";
2 2 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
3 3 import { localToTile } from "../world/coordinates.js";
4 4 import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";
5 import { BLOCK_DEFINITIONS } from "../../../shared/definitions/tiles.js";
6 5 import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";
7 6 import { closedNeighborEdges } from "../world/chunkFlags.js";
8 7 import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";
@@ -101,7 +100,7 @@ export class EditorService
101 100 chunkX,
102 101 chunkY,
103 102 (x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),
104 maxDefinitionLightRange(BLOCK_DEFINITIONS)
103 maxDefinitionLightRange(BLOCK_DEFINITIONS, GROUND_DEFINITIONS)
105 104 );
106 105
107 106 for (const result of baked)
@@ -1,8 +1,7 @@
1import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock } from "../../../shared/definitions/tiles.js";
1import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock, BLOCK_DEFINITIONS, GROUND_DEFINITIONS } from "../../../shared/definitions/tiles.js";
2import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
2import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
3import { localToTile } from "../world/coordinates.js";
3import { localToTile } from "../world/coordinates.js";
4import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";
4import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";
5import { BLOCK_DEFINITIONS } from "../../../shared/definitions/tiles.js";
6import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";
5import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";
7import { closedNeighborEdges } from "../world/chunkFlags.js";
6import { closedNeighborEdges } from "../world/chunkFlags.js";
8import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";
7import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";
@@ -101,7 +100,7 @@ export class EditorService
101 chunkX,
100 chunkX,
102 chunkY,
101 chunkY,
103 (x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),
102 (x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),
104 maxDefinitionLightRange(BLOCK_DEFINITIONS)
103 maxDefinitionLightRange(BLOCK_DEFINITIONS, GROUND_DEFINITIONS)
105 );
104 );
106
105
107 for (const result of baked)
106 for (const result of baked)
server/src/lighting/baker.js +7 −2
@@ -6,11 +6,16 @@ import { cloneChunkData, collectLightSources, createEmptyChunkData, chunkTileLig
6 6
7 7 export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";
8 8
9 export function maxDefinitionLightRange (blockDefs)
9 export function maxDefinitionLightRange (blockDefs, groundDefs = null)
10 10 {
11 11 let max = 0;
12 for (const def of Object.values(blockDefs))
12 for (const def of Object.values(blockDefs ?? {}))
13 13 { max = Math.max(max, def.lightRangeTiles ?? 0); }
14 if (groundDefs)
15 {
16 for (const def of Object.values(groundDefs))
17 { max = Math.max(max, def.lightRangeTiles ?? 0); }
18 }
14 19 return max;
15 20 }
16 21
@@ -6,11 +6,16 @@ import { cloneChunkData, collectLightSources, createEmptyChunkData, chunkTileLig
6
6
7export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";
7export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";
8
8
9export function maxDefinitionLightRange (blockDefs)
9export function maxDefinitionLightRange (blockDefs, groundDefs = null)
10{
10{
11 let max = 0;
11 let max = 0;
12 for (const def of Object.values(blockDefs))
12 for (const def of Object.values(blockDefs ?? {}))
13 { max = Math.max(max, def.lightRangeTiles ?? 0); }
13 { max = Math.max(max, def.lightRangeTiles ?? 0); }
14 if (groundDefs)
15 {
16 for (const def of Object.values(groundDefs))
17 { max = Math.max(max, def.lightRangeTiles ?? 0); }
18 }
14 return max;
19 return max;
15}
20}
16
21
server/src/world/chunkData.js +6 −3
@@ -12,7 +12,7 @@ import {
12 12 } from "../../../shared/definitions/tiles.js";
13 13 import { isDoorTraversable } from "../../../shared/world/doors.js";
14 14 import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
15 import { collectBlockLightSources } from "../../../shared/lighting/blockLights.js";
15 import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";
16 16 import {
17 17 flowerBlockState,
18 18 flowerColorIdFromBlockState,
@@ -186,7 +186,7 @@ export function isChunkTilePassable (data, localX, localY, { canOpenDoors = fals
186 186 return isBlockPassable(block.typeId, block.state);
187 187 }
188 188
189 /** Light occlusion level for a chunk tile (ground impassable → solid). */
189 /** Light occlusion level for a chunk tile (water stays clear even when impassable). */
190 190 export function chunkTileLightOcclusion (data, localX, localY)
191 191 {
192 192 return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
@@ -211,7 +211,10 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)
211 211
212 212 export function collectLightSources (chunkX, chunkY, data)
213 213 {
214 return collectBlockLightSources(chunkX, chunkY, data?.blocks);
214 return [
215 ...collectBlockLightSources(chunkX, chunkY, data?.blocks),
216 ...collectGroundLightSources(chunkX, chunkY, data?.grounds)
217 ];
215 218 }
216 219
217 220 function migrateLegacySpawners (blocks, authored, parsedHint)
@@ -12,7 +12,7 @@ import {
12} from "../../../shared/definitions/tiles.js";
12} from "../../../shared/definitions/tiles.js";
13import { isDoorTraversable } from "../../../shared/world/doors.js";
13import { isDoorTraversable } from "../../../shared/world/doors.js";
14import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
14import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
15import { collectBlockLightSources } from "../../../shared/lighting/blockLights.js";
15import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";
16import {
16import {
17 flowerBlockState,
17 flowerBlockState,
18 flowerColorIdFromBlockState,
18 flowerColorIdFromBlockState,
@@ -186,7 +186,7 @@ export function isChunkTilePassable (data, localX, localY, { canOpenDoors = fals
186 return isBlockPassable(block.typeId, block.state);
186 return isBlockPassable(block.typeId, block.state);
187}
187}
188
188
189/** Light occlusion level for a chunk tile (ground impassable → solid). */
189/** Light occlusion level for a chunk tile (water stays clear even when impassable). */
190export function chunkTileLightOcclusion (data, localX, localY)
190export function chunkTileLightOcclusion (data, localX, localY)
191{
191{
192 return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
192 return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
@@ -211,7 +211,10 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)
211
211
212export function collectLightSources (chunkX, chunkY, data)
212export function collectLightSources (chunkX, chunkY, data)
213{
213{
214 return collectBlockLightSources(chunkX, chunkY, data?.blocks);
214 return [
215 ...collectBlockLightSources(chunkX, chunkY, data?.blocks),
216 ...collectGroundLightSources(chunkX, chunkY, data?.grounds)
217 ];
215}
218}
216
219
217function migrateLegacySpawners (blocks, authored, parsedHint)
220function migrateLegacySpawners (blocks, authored, parsedHint)
server/tests/lighting.test.js +13 −2
@@ -4,9 +4,9 @@ import { createEmptyChunkData } from "../src/world/chunkData.js";
4 4 import { bakeLightMaps } from "../src/lighting/baker.js";
5 5 import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";
6 6 import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";
7 import { collectBlockLightSources } from "../../shared/lighting/blockLights.js";
7 import { collectBlockLightSources, collectGroundLightSources } from "../../shared/lighting/blockLights.js";
8 8 import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";
9 import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
9 import { BlockType, GroundType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
10 10 import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
11 11 import { tileLightAt } from "../src/combat/service.js";
12 12 import { maybeOpenDoorOnApproach } from "../src/doors/service.js";
@@ -235,6 +235,17 @@ test("collectBlockLightSources finds torches", () =>
235 235 assert.ok(sources[0].range > 0);
236 236 });
237 237
238 test("collectGroundLightSources finds lava", () =>
239 {
240 const data = createEmptyChunkData();
241 data.grounds[0] = { typeId: GroundType.lava, state: null };
242 const sources = collectGroundLightSources(0, 0, data.grounds);
243 assert.equal(sources.length, 1);
244 assert.equal(sources[0].tileX, 0);
245 assert.equal(sources[0].tileY, 0);
246 assert.equal(sources[0].range, 4);
247 });
248
238 249 test("dynamic block light is blocked by a resting door and passes when passage-open", () =>
239 250 {
240 251 const chunks = new Map();
@@ -4,9 +4,9 @@ import { createEmptyChunkData } from "../src/world/chunkData.js";
4import { bakeLightMaps } from "../src/lighting/baker.js";
4import { bakeLightMaps } from "../src/lighting/baker.js";
5import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";
5import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";
6import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";
6import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";
7import { collectBlockLightSources } from "../../shared/lighting/blockLights.js";
7import { collectBlockLightSources, collectGroundLightSources } from "../../shared/lighting/blockLights.js";
8import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";
8import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";
9import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
9import { BlockType, GroundType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
10import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
10import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
11import { tileLightAt } from "../src/combat/service.js";
11import { tileLightAt } from "../src/combat/service.js";
12import { maybeOpenDoorOnApproach } from "../src/doors/service.js";
12import { maybeOpenDoorOnApproach } from "../src/doors/service.js";
@@ -235,6 +235,17 @@ test("collectBlockLightSources finds torches", () =>
235 assert.ok(sources[0].range > 0);
235 assert.ok(sources[0].range > 0);
236});
236});
237
237
238test("collectGroundLightSources finds lava", () =>
239{
240 const data = createEmptyChunkData();
241 data.grounds[0] = { typeId: GroundType.lava, state: null };
242 const sources = collectGroundLightSources(0, 0, data.grounds);
243 assert.equal(sources.length, 1);
244 assert.equal(sources[0].tileX, 0);
245 assert.equal(sources[0].tileY, 0);
246 assert.equal(sources[0].range, 4);
247});
248
238test("dynamic block light is blocked by a resting door and passes when passage-open", () =>
249test("dynamic block light is blocked by a resting door and passes when passage-open", () =>
239{
250{
240 const chunks = new Map();
251 const chunks = new Map();
server/tests/tile-states.test.js +5 −4
@@ -69,10 +69,11 @@ test("bloom companions are not visual states", () =>
69 69
70 70 test("sprite companion stems peel equip-bloom combinations", () =>
71 71 {
72 assert.deepEqual(parseSpriteStem("torch"), { base: "torch", companion: false, bloom: false, equip: false });
73 assert.deepEqual(parseSpriteStem("torch-bloom"), { base: "torch", companion: true, bloom: true, equip: false });
74 assert.deepEqual(parseSpriteStem("stick-equip"), { base: "stick", companion: true, bloom: false, equip: true });
75 assert.deepEqual(parseSpriteStem("stick-equip-bloom"), { base: "stick", companion: true, bloom: true, equip: true });
72 assert.deepEqual(parseSpriteStem("torch"), { base: "torch", companion: false, bloom: false, equip: false, preview: false });
73 assert.deepEqual(parseSpriteStem("torch-bloom"), { base: "torch", companion: true, bloom: true, equip: false, preview: false });
74 assert.deepEqual(parseSpriteStem("stick-equip"), { base: "stick", companion: true, bloom: false, equip: true, preview: false });
75 assert.deepEqual(parseSpriteStem("stick-equip-bloom"), { base: "stick", companion: true, bloom: true, equip: true, preview: false });
76 assert.deepEqual(parseSpriteStem("water-preview"), { base: "water", companion: true, bloom: false, equip: false, preview: true });
76 77 assert.equal(isCompanionSpriteStem("1-equip-bloom"), true);
77 78 assert.equal(isCompanionSpriteStem("1"), false);
78 79 assert.equal(resolveState(["1", "2"], "1-bloom"), "1");
@@ -69,10 +69,11 @@ test("bloom companions are not visual states", () =>
69
69
70test("sprite companion stems peel equip-bloom combinations", () =>
70test("sprite companion stems peel equip-bloom combinations", () =>
71{
71{
72 assert.deepEqual(parseSpriteStem("torch"), { base: "torch", companion: false, bloom: false, equip: false });
72 assert.deepEqual(parseSpriteStem("torch"), { base: "torch", companion: false, bloom: false, equip: false, preview: false });
73 assert.deepEqual(parseSpriteStem("torch-bloom"), { base: "torch", companion: true, bloom: true, equip: false });
73 assert.deepEqual(parseSpriteStem("torch-bloom"), { base: "torch", companion: true, bloom: true, equip: false, preview: false });
74 assert.deepEqual(parseSpriteStem("stick-equip"), { base: "stick", companion: true, bloom: false, equip: true });
74 assert.deepEqual(parseSpriteStem("stick-equip"), { base: "stick", companion: true, bloom: false, equip: true, preview: false });
75 assert.deepEqual(parseSpriteStem("stick-equip-bloom"), { base: "stick", companion: true, bloom: true, equip: true });
75 assert.deepEqual(parseSpriteStem("stick-equip-bloom"), { base: "stick", companion: true, bloom: true, equip: true, preview: false });
76 assert.deepEqual(parseSpriteStem("water-preview"), { base: "water", companion: true, bloom: false, equip: false, preview: true });
76 assert.equal(isCompanionSpriteStem("1-equip-bloom"), true);
77 assert.equal(isCompanionSpriteStem("1-equip-bloom"), true);
77 assert.equal(isCompanionSpriteStem("1"), false);
78 assert.equal(isCompanionSpriteStem("1"), false);
78 assert.equal(resolveState(["1", "2"], "1-bloom"), "1");
79 assert.equal(resolveState(["1", "2"], "1-bloom"), "1");
server/tests/water-grounds.test.js +26 −2
@@ -1,8 +1,8 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 import { GroundType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason } from "../../shared/definitions/tiles.js";
3 import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";
4 4 import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
5 import { createEmptyChunkData, isChunkTilePassable, setGround } from "../src/world/chunkData.js";
5 import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";
6 6
7 7 test("deep water ground is impassable; shallow water is passable and wadeable", () =>
8 8 {
@@ -20,6 +20,30 @@ test("deep water ground is impassable; shallow water is passable and wadeable",
20 20 assert.equal(isChunkTilePassable(data, 2, 2), false);
21 21 });
22 22
23 test("deep water does not occlude light rays", () =>
24 {
25 assert.equal(groundLightOcclusion(GroundType.water), LightOcclusion.clear);
26 assert.equal(groundLightOcclusion(GroundType.deepWater), LightOcclusion.clear);
27 const data = createEmptyChunkData();
28 setGround(data, 3, 3, GroundType.deepWater);
29 assert.equal(isChunkTileClearForLight(data, 3, 3), true);
30 assert.equal(isChunkTilePassable(data, 3, 3), false);
31 });
32
33 test("lava is impassable, clear for light, and emits half-torch light", () =>
34 {
35 assert.equal(isGroundPassable(GroundType.lava), false);
36 assert.equal(isWaterGround(GroundType.lava), false);
37 assert.equal(groundLightOcclusion(GroundType.lava), LightOcclusion.clear);
38 assert.equal(groundLightRange(GroundType.lava), 4);
39 assert.equal(blockLightRange(BlockType.torch), 8);
40
41 const data = createEmptyChunkData();
42 setGround(data, 4, 4, GroundType.lava);
43 assert.equal(isChunkTilePassable(data, 4, 4), false);
44 assert.equal(isChunkTileClearForLight(data, 4, 4), true);
45 });
46
23 47 test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>
24 48 {
25 49 assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
@@ -1,8 +1,8 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { GroundType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason } from "../../shared/definitions/tiles.js";
3import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";
4import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
4import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
5import { createEmptyChunkData, isChunkTilePassable, setGround } from "../src/world/chunkData.js";
5import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";
6
6
7test("deep water ground is impassable; shallow water is passable and wadeable", () =>
7test("deep water ground is impassable; shallow water is passable and wadeable", () =>
8{
8{
@@ -20,6 +20,30 @@ test("deep water ground is impassable; shallow water is passable and wadeable",
20 assert.equal(isChunkTilePassable(data, 2, 2), false);
20 assert.equal(isChunkTilePassable(data, 2, 2), false);
21});
21});
22
22
23test("deep water does not occlude light rays", () =>
24{
25 assert.equal(groundLightOcclusion(GroundType.water), LightOcclusion.clear);
26 assert.equal(groundLightOcclusion(GroundType.deepWater), LightOcclusion.clear);
27 const data = createEmptyChunkData();
28 setGround(data, 3, 3, GroundType.deepWater);
29 assert.equal(isChunkTileClearForLight(data, 3, 3), true);
30 assert.equal(isChunkTilePassable(data, 3, 3), false);
31});
32
33test("lava is impassable, clear for light, and emits half-torch light", () =>
34{
35 assert.equal(isGroundPassable(GroundType.lava), false);
36 assert.equal(isWaterGround(GroundType.lava), false);
37 assert.equal(groundLightOcclusion(GroundType.lava), LightOcclusion.clear);
38 assert.equal(groundLightRange(GroundType.lava), 4);
39 assert.equal(blockLightRange(BlockType.torch), 8);
40
41 const data = createEmptyChunkData();
42 setGround(data, 4, 4, GroundType.lava);
43 assert.equal(isChunkTilePassable(data, 4, 4), false);
44 assert.equal(isChunkTileClearForLight(data, 4, 4), true);
45});
46
23test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>
47test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>
24{
48{
25 assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
49 assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
shared/definitions/tileSprites.js +15 −2
@@ -24,6 +24,12 @@ export function bloomCompanionName (imageName)
24 24 return `${imageName}:bloom`;
25 25 }
26 26
27 /** Editor palette thumb for procedural grounds (`water` → `ground:water:water-preview`). */
28 export function palettePreviewImageName (layer, key)
29 {
30 return spriteImageName(layer, key, `${key}-preview`);
31 }
32
27 33 /**
28 34 * Companion suffixes peel from the right in fixed order.
29 35 * `torch-equip-bloom` → base torch, equip + bloom.
@@ -35,6 +41,12 @@ export function parseSpriteStem (stem)
35 41 let rest = String(stem ?? "");
36 42 let bloom = false;
37 43 let equip = false;
44 let preview = false;
45 if (rest.endsWith("-preview") && rest.length > "-preview".length)
46 {
47 preview = true;
48 rest = rest.slice(0, -"-preview".length);
49 }
38 50 if (rest.endsWith("-bloom") && rest.length > "-bloom".length)
39 51 {
40 52 bloom = true;
@@ -45,12 +57,13 @@ export function parseSpriteStem (stem)
45 57 equip = true;
46 58 rest = rest.slice(0, -"-equip".length);
47 59 }
48 const companion = bloom || equip;
60 const companion = bloom || equip || preview;
49 61 return {
50 62 base: companion ? rest : String(stem ?? ""),
51 63 companion,
52 64 bloom,
53 equip
65 equip,
66 preview
54 67 };
55 68 }
56 69
@@ -24,6 +24,12 @@ export function bloomCompanionName (imageName)
24 return `${imageName}:bloom`;
24 return `${imageName}:bloom`;
25}
25}
26
26
27/** Editor palette thumb for procedural grounds (`water` → `ground:water:water-preview`). */
28export function palettePreviewImageName (layer, key)
29{
30 return spriteImageName(layer, key, `${key}-preview`);
31}
32
27/**
33/**
28 * Companion suffixes peel from the right in fixed order.
34 * Companion suffixes peel from the right in fixed order.
29 * `torch-equip-bloom` → base torch, equip + bloom.
35 * `torch-equip-bloom` → base torch, equip + bloom.
@@ -35,6 +41,12 @@ export function parseSpriteStem (stem)
35 let rest = String(stem ?? "");
41 let rest = String(stem ?? "");
36 let bloom = false;
42 let bloom = false;
37 let equip = false;
43 let equip = false;
44 let preview = false;
45 if (rest.endsWith("-preview") && rest.length > "-preview".length)
46 {
47 preview = true;
48 rest = rest.slice(0, -"-preview".length);
49 }
38 if (rest.endsWith("-bloom") && rest.length > "-bloom".length)
50 if (rest.endsWith("-bloom") && rest.length > "-bloom".length)
39 {
51 {
40 bloom = true;
52 bloom = true;
@@ -45,12 +57,13 @@ export function parseSpriteStem (stem)
45 equip = true;
57 equip = true;
46 rest = rest.slice(0, -"-equip".length);
58 rest = rest.slice(0, -"-equip".length);
47 }
59 }
48 const companion = bloom || equip;
60 const companion = bloom || equip || preview;
49 return {
61 return {
50 base: companion ? rest : String(stem ?? ""),
62 base: companion ? rest : String(stem ?? ""),
51 companion,
63 companion,
52 bloom,
64 bloom,
53 equip
65 equip,
66 preview
54 };
67 };
55}
68}
56
69
shared/definitions/tiles.js +52 −7
@@ -42,7 +42,8 @@ export const GroundType = Object.freeze({
42 42 deepWater: 4,
43 43 dirt: 5,
44 44 path: 6,
45 sand: 7
45 sand: 7,
46 lava: 8
46 47 });
47 48
48 49 export const BlockType = Object.freeze({
@@ -133,9 +134,11 @@ export const GROUND_DEFINITIONS = Object.freeze({
133 134 passable: true,
134 135 wades: true,
135 136 water: true,
136 frames: 4,
137 framesPerRow: 4,
138 animationSpeed: 0.12,
137 frames: 1,
138 framesPerRow: 1,
139 animationSpeed: 0,
140 /** Per-tile procedural caustic shader; never atlas-baked. */
141 proceduralWaves: true,
139 142 outdoor: true
140 143 }),
141 144 [GroundType.deepWater]: Object.freeze({
@@ -145,9 +148,10 @@ export const GROUND_DEFINITIONS = Object.freeze({
145 148 passable: false,
146 149 wades: false,
147 150 water: true,
148 frames: 4,
149 framesPerRow: 4,
150 animationSpeed: 0.12,
151 frames: 1,
152 framesPerRow: 1,
153 animationSpeed: 0,
154 proceduralWaves: true,
151 155 outdoor: true
152 156 }),
153 157 [GroundType.dirt]: Object.freeze({
@@ -193,6 +197,23 @@ export const GROUND_DEFINITIONS = Object.freeze({
193 197 blendable: true,
194 198 /** Client bakes a wet shoreline toward `sand-wet` (not a placeable state). */
195 199 wetShore: true
200 }),
201 [GroundType.lava]: Object.freeze({
202 id: GroundType.lava,
203 key: "lava",
204 displayName: "Lava",
205 passable: false,
206 wades: false,
207 water: false,
208 lava: true,
209 frames: 1,
210 framesPerRow: 1,
211 animationSpeed: 0,
212 /** Per-tile procedural heat shader; never atlas-baked. */
213 proceduralWaves: true,
214 /** Half a torch (torch is 8). */
215 lightRangeTiles: 4,
216 outdoor: true
196 217 })
197 218 });
198 219
@@ -1054,6 +1075,30 @@ export function isWaterGround (typeId)
1054 1075 return !!groundDefinition(typeId)?.water;
1055 1076 }
1056 1077
1078 export function isLavaGround (typeId)
1079 {
1080 return !!groundDefinition(typeId)?.lava;
1081 }
1082
1083 /**
1084 * Ground contribution to light-ray occlusion.
1085 * Water / lava stay optically clear — only movement is blocked (lava also emits light).
1086 */
1087 export function groundLightOcclusion (typeId)
1088 {
1089 if (isWaterGround(typeId) || isLavaGround(typeId))
1090 { return LightOcclusion.clear; }
1091 if (!isGroundPassable(typeId))
1092 { return LightOcclusion.solid; }
1093 return LightOcclusion.clear;
1094 }
1095
1096 /** Authored ground-emitted light range (lava, …). */
1097 export function groundLightRange (typeId)
1098 {
1099 return groundDefinition(typeId)?.lightRangeTiles ?? 0;
1100 }
1101
1057 1102 export function isWadeGround (typeId)
1058 1103 {
1059 1104 return !!groundDefinition(typeId)?.wades;
@@ -42,7 +42,8 @@ export const GroundType = Object.freeze({
42 deepWater: 4,
42 deepWater: 4,
43 dirt: 5,
43 dirt: 5,
44 path: 6,
44 path: 6,
45 sand: 7
45 sand: 7,
46 lava: 8
46});
47});
47
48
48export const BlockType = Object.freeze({
49export const BlockType = Object.freeze({
@@ -133,9 +134,11 @@ export const GROUND_DEFINITIONS = Object.freeze({
133 passable: true,
134 passable: true,
134 wades: true,
135 wades: true,
135 water: true,
136 water: true,
136 frames: 4,
137 frames: 1,
137 framesPerRow: 4,
138 framesPerRow: 1,
138 animationSpeed: 0.12,
139 animationSpeed: 0,
140 /** Per-tile procedural caustic shader; never atlas-baked. */
141 proceduralWaves: true,
139 outdoor: true
142 outdoor: true
140 }),
143 }),
141 [GroundType.deepWater]: Object.freeze({
144 [GroundType.deepWater]: Object.freeze({
@@ -145,9 +148,10 @@ export const GROUND_DEFINITIONS = Object.freeze({
145 passable: false,
148 passable: false,
146 wades: false,
149 wades: false,
147 water: true,
150 water: true,
148 frames: 4,
151 frames: 1,
149 framesPerRow: 4,
152 framesPerRow: 1,
150 animationSpeed: 0.12,
153 animationSpeed: 0,
154 proceduralWaves: true,
151 outdoor: true
155 outdoor: true
152 }),
156 }),
153 [GroundType.dirt]: Object.freeze({
157 [GroundType.dirt]: Object.freeze({
@@ -193,6 +197,23 @@ export const GROUND_DEFINITIONS = Object.freeze({
193 blendable: true,
197 blendable: true,
194 /** Client bakes a wet shoreline toward `sand-wet` (not a placeable state). */
198 /** Client bakes a wet shoreline toward `sand-wet` (not a placeable state). */
195 wetShore: true
199 wetShore: true
200 }),
201 [GroundType.lava]: Object.freeze({
202 id: GroundType.lava,
203 key: "lava",
204 displayName: "Lava",
205 passable: false,
206 wades: false,
207 water: false,
208 lava: true,
209 frames: 1,
210 framesPerRow: 1,
211 animationSpeed: 0,
212 /** Per-tile procedural heat shader; never atlas-baked. */
213 proceduralWaves: true,
214 /** Half a torch (torch is 8). */
215 lightRangeTiles: 4,
216 outdoor: true
196 })
217 })
197});
218});
198
219
@@ -1054,6 +1075,30 @@ export function isWaterGround (typeId)
1054 return !!groundDefinition(typeId)?.water;
1075 return !!groundDefinition(typeId)?.water;
1055}
1076}
1056
1077
1078export function isLavaGround (typeId)
1079{
1080 return !!groundDefinition(typeId)?.lava;
1081}
1082
1083/**
1084 * Ground contribution to light-ray occlusion.
1085 * Water / lava stay optically clear — only movement is blocked (lava also emits light).
1086 */
1087export function groundLightOcclusion (typeId)
1088{
1089 if (isWaterGround(typeId) || isLavaGround(typeId))
1090 { return LightOcclusion.clear; }
1091 if (!isGroundPassable(typeId))
1092 { return LightOcclusion.solid; }
1093 return LightOcclusion.clear;
1094}
1095
1096/** Authored ground-emitted light range (lava, …). */
1097export function groundLightRange (typeId)
1098{
1099 return groundDefinition(typeId)?.lightRangeTiles ?? 0;
1100}
1101
1057export function isWadeGround (typeId)
1102export function isWadeGround (typeId)
1058{
1103{
1059 return !!groundDefinition(typeId)?.wades;
1104 return !!groundDefinition(typeId)?.wades;
shared/lighting/blockLights.js +45 −8
@@ -1,11 +1,17 @@
1 /** Authored block lights (torches, furnaces, …) for dynamic lighting / combat. */
1 /** Authored block + ground lights (torches, furnaces, lava, …) for dynamic lighting / combat. */
2 2
3 3 import { CHUNK_SIZE } from "../protocol/constants.js";
4 import { BLOCK_DEFINITIONS, blockLightRange } from "../definitions/tiles.js";
4 import {
5 BLOCK_DEFINITIONS,
6 GROUND_DEFINITIONS,
7 blockLightRange,
8 groundLightRange,
9 normalizeGround
10 } from "../definitions/tiles.js";
5 11
6 12 let cachedMaxRange = null;
7 13
8 /** Max `lightRangeTiles` across block defs (cached). */
14 /** Max `lightRangeTiles` across block and ground defs (cached). */
9 15 export function maxBlockLightRangeTiles ()
10 16 {
11 17 if (cachedMaxRange != null)
@@ -13,6 +19,8 @@ export function maxBlockLightRangeTiles ()
13 19 let max = 0;
14 20 for (const def of Object.values(BLOCK_DEFINITIONS))
15 21 { max = Math.max(max, def.lightRangeTiles ?? 0); }
22 for (const def of Object.values(GROUND_DEFINITIONS))
23 { max = Math.max(max, def.lightRangeTiles ?? 0); }
16 24 cachedMaxRange = max;
17 25 return max;
18 26 }
@@ -46,8 +54,36 @@ export function collectBlockLightSources (chunkX, chunkY, blocks)
46 54 }
47 55
48 56 /**
49 * Block lights in chunks that can reach (tileX, tileY).
50 * @param {(chunkX: number, chunkY: number) => { blocks?: any[] }|null|undefined} loadChunk
57 * Collect ground-emitted light sources (e.g. lava) from one chunk's grounds array.
58 * @returns {Array<{ tileX: number, tileY: number, range: number }>}
59 */
60 export function collectGroundLightSources (chunkX, chunkY, grounds)
61 {
62 const sources = [];
63 if (!Array.isArray(grounds) || grounds.length < CHUNK_SIZE * CHUNK_SIZE)
64 { return sources; }
65 for (let localY = 0; localY < CHUNK_SIZE; localY++)
66 {
67 for (let localX = 0; localX < CHUNK_SIZE; localX++)
68 {
69 const ground = normalizeGround(grounds[localY * CHUNK_SIZE + localX]);
70 const range = groundLightRange(ground.typeId);
71 if (range > 0)
72 {
73 sources.push({
74 tileX: chunkX * CHUNK_SIZE + localX,
75 tileY: chunkY * CHUNK_SIZE + localY,
76 range
77 });
78 }
79 }
80 }
81 return sources;
82 }
83
84 /**
85 * Block + ground lights in chunks that can reach (tileX, tileY).
86 * @param {(chunkX: number, chunkY: number) => { blocks?: any[], grounds?: any[] }|null|undefined} loadChunk
51 87 */
52 88 export function blockLightSourcesNearTile (loadChunk, tileX, tileY, maxRange = maxBlockLightRangeTiles())
53 89 {
@@ -63,9 +99,10 @@ export function blockLightSourcesNearTile (loadChunk, tileX, tileY, maxRange = m
63 99 const chunkX = centerX + dx;
64 100 const chunkY = centerY + dy;
65 101 const data = loadChunk(chunkX, chunkY);
66 if (!data?.blocks)
67 { continue; }
68 sources.push(...collectBlockLightSources(chunkX, chunkY, data.blocks));
102 if (data?.blocks)
103 { sources.push(...collectBlockLightSources(chunkX, chunkY, data.blocks)); }
104 if (data?.grounds)
105 { sources.push(...collectGroundLightSources(chunkX, chunkY, data.grounds)); }
69 106 }
70 107 }
71 108 return sources;
@@ -1,11 +1,17 @@
1/** Authored block lights (torches, furnaces, …) for dynamic lighting / combat. */
1/** Authored block + ground lights (torches, furnaces, lava, …) for dynamic lighting / combat. */
2
2
3import { CHUNK_SIZE } from "../protocol/constants.js";
3import { CHUNK_SIZE } from "../protocol/constants.js";
4import { BLOCK_DEFINITIONS, blockLightRange } from "../definitions/tiles.js";
4import {
5 BLOCK_DEFINITIONS,
6 GROUND_DEFINITIONS,
7 blockLightRange,
8 groundLightRange,
9 normalizeGround
10} from "../definitions/tiles.js";
5
11
6let cachedMaxRange = null;
12let cachedMaxRange = null;
7
13
8/** Max `lightRangeTiles` across block defs (cached). */
14/** Max `lightRangeTiles` across block and ground defs (cached). */
9export function maxBlockLightRangeTiles ()
15export function maxBlockLightRangeTiles ()
10{
16{
11 if (cachedMaxRange != null)
17 if (cachedMaxRange != null)
@@ -13,6 +19,8 @@ export function maxBlockLightRangeTiles ()
13 let max = 0;
19 let max = 0;
14 for (const def of Object.values(BLOCK_DEFINITIONS))
20 for (const def of Object.values(BLOCK_DEFINITIONS))
15 { max = Math.max(max, def.lightRangeTiles ?? 0); }
21 { max = Math.max(max, def.lightRangeTiles ?? 0); }
22 for (const def of Object.values(GROUND_DEFINITIONS))
23 { max = Math.max(max, def.lightRangeTiles ?? 0); }
16 cachedMaxRange = max;
24 cachedMaxRange = max;
17 return max;
25 return max;
18}
26}
@@ -46,8 +54,36 @@ export function collectBlockLightSources (chunkX, chunkY, blocks)
46}
54}
47
55
48/**
56/**
49 * Block lights in chunks that can reach (tileX, tileY).
57 * Collect ground-emitted light sources (e.g. lava) from one chunk's grounds array.
50 * @param {(chunkX: number, chunkY: number) => { blocks?: any[] }|null|undefined} loadChunk
58 * @returns {Array<{ tileX: number, tileY: number, range: number }>}
59 */
60export function collectGroundLightSources (chunkX, chunkY, grounds)
61{
62 const sources = [];
63 if (!Array.isArray(grounds) || grounds.length < CHUNK_SIZE * CHUNK_SIZE)
64 { return sources; }
65 for (let localY = 0; localY < CHUNK_SIZE; localY++)
66 {
67 for (let localX = 0; localX < CHUNK_SIZE; localX++)
68 {
69 const ground = normalizeGround(grounds[localY * CHUNK_SIZE + localX]);
70 const range = groundLightRange(ground.typeId);
71 if (range > 0)
72 {
73 sources.push({
74 tileX: chunkX * CHUNK_SIZE + localX,
75 tileY: chunkY * CHUNK_SIZE + localY,
76 range
77 });
78 }
79 }
80 }
81 return sources;
82}
83
84/**
85 * Block + ground lights in chunks that can reach (tileX, tileY).
86 * @param {(chunkX: number, chunkY: number) => { blocks?: any[], grounds?: any[] }|null|undefined} loadChunk
51 */
87 */
52export function blockLightSourcesNearTile (loadChunk, tileX, tileY, maxRange = maxBlockLightRangeTiles())
88export function blockLightSourcesNearTile (loadChunk, tileX, tileY, maxRange = maxBlockLightRangeTiles())
53{
89{
@@ -63,9 +99,10 @@ export function blockLightSourcesNearTile (loadChunk, tileX, tileY, maxRange = m
63 const chunkX = centerX + dx;
99 const chunkX = centerX + dx;
64 const chunkY = centerY + dy;
100 const chunkY = centerY + dy;
65 const data = loadChunk(chunkX, chunkY);
101 const data = loadChunk(chunkX, chunkY);
66 if (!data?.blocks)
102 if (data?.blocks)
67 { continue; }
103 { sources.push(...collectBlockLightSources(chunkX, chunkY, data.blocks)); }
68 sources.push(...collectBlockLightSources(chunkX, chunkY, data.blocks));
104 if (data?.grounds)
105 { sources.push(...collectGroundLightSources(chunkX, chunkY, data.grounds)); }
69 }
106 }
70 }
107 }
71 return sources;
108 return sources;
shared/lighting/chunkOcclusion.js +4 −3
@@ -1,7 +1,7 @@
1 1 import { CHUNK_SIZE } from "../protocol/constants.js";
2 2 import {
3 3 blockLightOcclusionForBlock,
4 isGroundPassable,
4 groundLightOcclusion,
5 5 LightOcclusion,
6 6 normalizeGround
7 7 } from "../definitions/tiles.js";
@@ -11,8 +11,9 @@ export function tileLightOcclusionAt (grounds, blocks, localX, localY)
11 11 {
12 12 const index = localY * CHUNK_SIZE + localX;
13 13 const ground = normalizeGround(grounds?.[index]);
14 if (!isGroundPassable(ground.typeId))
15 { return LightOcclusion.solid; }
14 const groundOcclusion = groundLightOcclusion(ground.typeId);
15 if (groundOcclusion !== LightOcclusion.clear)
16 { return groundOcclusion; }
16 17 return blockLightOcclusionForBlock(blocks?.[index]);
17 18 }
18 19
@@ -1,7 +1,7 @@
1import { CHUNK_SIZE } from "../protocol/constants.js";
1import { CHUNK_SIZE } from "../protocol/constants.js";
2import {
2import {
3 blockLightOcclusionForBlock,
3 blockLightOcclusionForBlock,
4 isGroundPassable,
4 groundLightOcclusion,
5 LightOcclusion,
5 LightOcclusion,
6 normalizeGround
6 normalizeGround
7} from "../definitions/tiles.js";
7} from "../definitions/tiles.js";
@@ -11,8 +11,9 @@ export function tileLightOcclusionAt (grounds, blocks, localX, localY)
11{
11{
12 const index = localY * CHUNK_SIZE + localX;
12 const index = localY * CHUNK_SIZE + localX;
13 const ground = normalizeGround(grounds?.[index]);
13 const ground = normalizeGround(grounds?.[index]);
14 if (!isGroundPassable(ground.typeId))
14 const groundOcclusion = groundLightOcclusion(ground.typeId);
15 { return LightOcclusion.solid; }
15 if (groundOcclusion !== LightOcclusion.clear)
16 { return groundOcclusion; }
16 return blockLightOcclusionForBlock(blocks?.[index]);
17 return blockLightOcclusionForBlock(blocks?.[index]);
17}
18}
18
19
shared/lighting/tilePassable.js +4 −3
@@ -1,7 +1,7 @@
1 1 import { CHUNK_SIZE } from "../protocol/constants.js";
2 2 import {
3 3 blockLightOcclusionForBlock,
4 isGroundPassable,
4 groundLightOcclusion,
5 5 LightOcclusion,
6 6 normalizeGround
7 7 } from "../definitions/tiles.js";
@@ -27,8 +27,9 @@ export function makeSnapshotLightOcclusion (chunks)
27 27 { return LightOcclusion.clear; }
28 28 const index = localY * CHUNK_SIZE + localX;
29 29 const ground = normalizeGround(snapshot.grounds?.[index]);
30 if (!isGroundPassable(ground.typeId))
31 { return LightOcclusion.solid; }
30 const groundOcclusion = groundLightOcclusion(ground.typeId);
31 if (groundOcclusion !== LightOcclusion.clear)
32 { return groundOcclusion; }
32 33 return blockLightOcclusionForBlock(snapshot.blocks?.[index]);
33 34 };
34 35 }
@@ -1,7 +1,7 @@
1import { CHUNK_SIZE } from "../protocol/constants.js";
1import { CHUNK_SIZE } from "../protocol/constants.js";
2import {
2import {
3 blockLightOcclusionForBlock,
3 blockLightOcclusionForBlock,
4 isGroundPassable,
4 groundLightOcclusion,
5 LightOcclusion,
5 LightOcclusion,
6 normalizeGround
6 normalizeGround
7} from "../definitions/tiles.js";
7} from "../definitions/tiles.js";
@@ -27,8 +27,9 @@ export function makeSnapshotLightOcclusion (chunks)
27 { return LightOcclusion.clear; }
27 { return LightOcclusion.clear; }
28 const index = localY * CHUNK_SIZE + localX;
28 const index = localY * CHUNK_SIZE + localX;
29 const ground = normalizeGround(snapshot.grounds?.[index]);
29 const ground = normalizeGround(snapshot.grounds?.[index]);
30 if (!isGroundPassable(ground.typeId))
30 const groundOcclusion = groundLightOcclusion(ground.typeId);
31 { return LightOcclusion.solid; }
31 if (groundOcclusion !== LightOcclusion.clear)
32 { return groundOcclusion; }
32 return blockLightOcclusionForBlock(snapshot.blocks?.[index]);
33 return blockLightOcclusionForBlock(snapshot.blocks?.[index]);
33 };
34 };
34}
35}
shared/render/chunkAtlasKeys.js +4 −0
@@ -223,6 +223,10 @@ function softBorderGroundFingerprint ({
223 223 const neighborKey = groundVisualKey(catalog, neighbor, season);
224 224 if (neighborKey === selfKey)
225 225 { continue; }
226 const nbrTypeId = normalizeGround(neighbor).typeId;
227 const nbrDef = GROUND_DEFINITIONS[nbrTypeId];
228 if (nbrDef?.proceduralWaves || isLiquidWaterGround(nbrTypeId, season))
229 { continue; }
226 230 parts.push(`${tileX},${tileY}:${ndx},${ndy}:${neighborKey}`);
227 231 }
228 232 }
@@ -223,6 +223,10 @@ function softBorderGroundFingerprint ({
223 const neighborKey = groundVisualKey(catalog, neighbor, season);
223 const neighborKey = groundVisualKey(catalog, neighbor, season);
224 if (neighborKey === selfKey)
224 if (neighborKey === selfKey)
225 { continue; }
225 { continue; }
226 const nbrTypeId = normalizeGround(neighbor).typeId;
227 const nbrDef = GROUND_DEFINITIONS[nbrTypeId];
228 if (nbrDef?.proceduralWaves || isLiquidWaterGround(nbrTypeId, season))
229 { continue; }
226 parts.push(`${tileX},${tileY}:${ndx},${ndy}:${neighborKey}`);
230 parts.push(`${tileX},${tileY}:${ndx},${ndy}:${neighborKey}`);
227 }
231 }
228 }
232 }