Add procedural 16x16 water waves with sine coast shore peeks.
@@ -53,38 +53,24 @@ 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)
56
function writeWaterSheet (file, base)
57
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++)
58
const image = makeRgba(16, 16, base);
59
for (let y = 0; y < 16; y++)
63
60
{
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
}
61
const t = y / 15;
62
fillRect(image, 0, y, 16, 1, [
63
Math.round(base[0] * (1 - t * 0.15)),
64
Math.round(base[1] * (1 - t * 0.08)),
65
Math.round(base[2] * (1 + t * 0.05)),
66
255
67
]);
82
68
}
83
writeRgbaPng(file, width, height, image.pixels);
69
writeRgbaPng(file, 16, 16, image.pixels);
84
70
}
85
71
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]);
72
writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255]);
73
writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255]);
88
74
89
75
{
90
76
const image = makeRgba(24, 8, [0, 0, 0, 0]);
@@ -53,38 +53,24 @@ overlay(join(root, "items", "lantern", "lantern-equip.png"), [200, 130, 48, 230]53
torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));53
torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));54
torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));54
torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));55
55
56
function writeWaterSheet (file, base, wave, foam)56
function writeWaterSheet (file, base)57
{57
{58
const frames = 4;58
const image = makeRgba(16, 16, base);59
const width = 16 * frames;59
for (let y = 0; y < 16; y++)60
const height = 16;61
const image = makeRgba(width, height, base);62
for (let f = 0; f < frames; f++)63
{60
{64
const ox = f * 16;61
const t = y / 15;65
for (let y = 0; y < 16; y++)62
fillRect(image, 0, y, 16, 1, [66
{63
Math.round(base[0] * (1 - t * 0.15)),67
const t = y / 15;64
Math.round(base[1] * (1 - t * 0.08)),68
fillRect(image, ox, y, 16, 1, [65
Math.round(base[2] * (1 + t * 0.05)),69
Math.round(base[0] * (1 - t * 0.15)),66
25570
Math.round(base[1] * (1 - t * 0.08)),67
]);71
Math.round(base[2] * (1 + t * 0.05)),72
25573
]);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
}68
}83
writeRgbaPng(file, width, height, image.pixels);69
writeRgbaPng(file, 16, 16, image.pixels);84
}70
}85
71
86
writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255], [90, 170, 210, 255], [170, 220, 240, 220]);72
writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255]);87
writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255], [55, 120, 170, 255], [110, 170, 210, 200]);73
writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255]);88
74
89
{75
{90
const image = makeRgba(24, 8, [0, 0, 0, 0]);76
const image = makeRgba(24, 8, [0, 0, 0, 0]);@@ -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)
@@ -652,8 +654,10 @@ function groundCatalogMeta (catalog, ground)
652
654
{
653
655
const entry = normalizeGround(ground);
654
656
const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];
655
return catalog.grounds?.[def.key] ?? {
656
frames: def.frames,
657
animationSpeed: def.animationSpeed
657
const catalogMeta = catalog.grounds?.[def.key] ?? {};
658
return {
659
frames: catalogMeta.frames ?? def.frames,
660
animationSpeed: catalogMeta.animationSpeed ?? def.animationSpeed,
661
proceduralWaves: !!def.proceduralWaves
658
662
};
659
663
}
@@ -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)@@ -652,8 +654,10 @@ function groundCatalogMeta (catalog, ground)652
{654
{653
const entry = normalizeGround(ground);655
const entry = normalizeGround(ground);654
const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];656
const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass];655
return catalog.grounds?.[def.key] ?? {657
const catalogMeta = catalog.grounds?.[def.key] ?? {};656
frames: def.frames,658
return {657
animationSpeed: def.animationSpeed659
frames: catalogMeta.frames ?? def.frames,660
animationSpeed: catalogMeta.animationSpeed ?? def.animationSpeed,661
proceduralWaves: !!def.proceduralWaves658
};662
};659
}663
}@@ -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, isLiquidWaterGround, isGroundPassable, 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,7 @@ 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 { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
31
31
import
32
32
{
33
33
OVERWORLD_ID,
@@ -105,6 +105,7 @@ const WATER_GROUND_FRAG = [
105
105
"precision mediump float;",
106
106
"varying vec2 v_texCoord;",
107
107
"uniform sampler2D u_texture;",
108
"uniform sampler2D u_secondary;",
108
109
"uniform float u_alpha;",
109
110
"uniform float u_ambientDark;",
110
111
"uniform float u_litNW;",
@@ -112,35 +113,121 @@ const WATER_GROUND_FRAG = [
112
113
"uniform float u_litSW;",
113
114
"uniform float u_litSE;",
114
115
"uniform float u_time;",
116
"uniform float u_tileX;",
117
"uniform float u_tileY;",
118
"uniform float u_deep;",
115
119
"uniform float u_edgeN;",
116
120
"uniform float u_edgeE;",
117
121
"uniform float u_edgeS;",
118
122
"uniform float u_edgeW;",
123
"uniform float u_hasShore;",
124
"uniform float u_shoreEdgeN;",
125
"uniform float u_shoreEdgeE;",
126
"uniform float u_shoreEdgeS;",
127
"uniform float u_shoreEdgeW;",
128
"uniform vec4 u_shoreUvRect;",
119
129
"void main() {",
120
" vec4 color = texture2D(u_texture, v_texCoord);",
121
" if (color.a <= 0.0) { discard; }",
122
" vec3 rgb = color.rgb;",
130
// Pixel grid (16x16) for body waves — stable across the tile.
131
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",
132
" vec2 puv = px / 16.0;",
133
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
134
" float w1 = sin(u_time * 1.7 + world.x * 5.1 + world.y * 3.3);",
135
" float w2 = sin(u_time * 2.3 + world.x * -3.7 + world.y * 6.2 + 1.7);",
136
" float body = 0.55 + 0.28 * w1 + 0.17 * w2;",
137
" vec3 shallowA = vec3(0.19, 0.46, 0.66);",
138
" vec3 shallowB = vec3(0.35, 0.67, 0.82);",
139
" vec3 deepA = vec3(0.11, 0.28, 0.46);",
140
" vec3 deepB = vec3(0.22, 0.47, 0.67);",
141
" vec3 baseA = mix(shallowA, deepA, u_deep);",
142
" vec3 baseB = mix(shallowB, deepB, u_deep);",
143
" vec3 rgb = mix(baseA, baseB, clamp(body, 0.0, 1.0));",
144
" vec3 foamCol = vec3(0.78, 0.92, 1.0);",
123
145
" 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);",
146
" float shoreMix = 0.0;",
147
" vec3 shoreRgb = rgb;",
148
// Top-down sine coastline: surge = foam, retreat = neighbor shore pixels.
149
" float coastAmp = 0.09;",
150
" float coastBase = 0.14;",
151
" if (u_edgeN > 0.5) {",
152
" float along = puv.x;",
153
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.9 + u_tileY * 0.4);",
154
" float band = coastBase + coastAmp * wave;",
155
" float dist = puv.y;",
156
" if (dist < band) {",
157
" float t = 1.0 - dist / max(band, 0.001);",
158
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeN > 0.5) {",
159
" vec2 shoreNu = vec2(puv.x, 1.0 - dist);",
160
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
161
" vec4 shore = texture2D(u_secondary, shoreUv);",
162
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",
163
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",
164
" } else {",
165
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",
166
" }",
167
" }",
127
168
" }",
128
" if (u_edgeS > 0.5 && v_texCoord.y > 0.78) {",
129
" foam = max(foam, ((v_texCoord.y - 0.78) / 0.22) * pulse);",
169
" if (u_edgeS > 0.5) {",
170
" float along = puv.x;",
171
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.7 + u_tileY * 1.1 + 2.1);",
172
" float band = coastBase + coastAmp * wave;",
173
" float dist = 1.0 - puv.y;",
174
" if (dist < band) {",
175
" float t = 1.0 - dist / max(band, 0.001);",
176
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeS > 0.5) {",
177
" vec2 shoreNu = vec2(puv.x, dist);",
178
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
179
" vec4 shore = texture2D(u_secondary, shoreUv);",
180
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",
181
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",
182
" } else {",
183
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",
184
" }",
185
" }",
130
186
" }",
131
" if (u_edgeW > 0.5 && v_texCoord.x < 0.22) {",
132
" foam = max(foam, (1.0 - v_texCoord.x / 0.22) * pulse);",
187
" if (u_edgeW > 0.5) {",
188
" float along = puv.y;",
189
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 1.2 + u_tileY * 0.5 + 0.8);",
190
" float band = coastBase + coastAmp * wave;",
191
" float dist = puv.x;",
192
" if (dist < band) {",
193
" float t = 1.0 - dist / max(band, 0.001);",
194
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeW > 0.5) {",
195
" vec2 shoreNu = vec2(1.0 - dist, puv.y);",
196
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
197
" vec4 shore = texture2D(u_secondary, shoreUv);",
198
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",
199
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",
200
" } else {",
201
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",
202
" }",
203
" }",
133
204
" }",
134
" if (u_edgeE > 0.5 && v_texCoord.x > 0.78) {",
135
" foam = max(foam, ((v_texCoord.x - 0.78) / 0.22) * pulse);",
205
" if (u_edgeE > 0.5) {",
206
" float along = puv.y;",
207
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.4 + u_tileY * 0.9 + 3.3);",
208
" float band = coastBase + coastAmp * wave;",
209
" float dist = 1.0 - puv.x;",
210
" if (dist < band) {",
211
" float t = 1.0 - dist / max(band, 0.001);",
212
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeE > 0.5) {",
213
" vec2 shoreNu = vec2(dist, puv.y);",
214
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",
215
" vec4 shore = texture2D(u_secondary, shoreUv);",
216
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",
217
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",
218
" } else {",
219
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",
220
" }",
221
" }",
136
222
" }",
137
" rgb = mix(rgb, vec3(0.78, 0.92, 1.0), clamp(foam, 0.0, 0.85));",
223
" rgb = mix(rgb, foamCol, clamp(foam, 0.0, 0.85));",
224
" rgb = mix(rgb, shoreRgb, clamp(shoreMix, 0.0, 1.0));",
138
225
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
139
226
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
140
227
" float lit = mix(litTop, litBottom, v_texCoord.y);",
141
228
" float darkness = u_ambientDark * (1.0 - lit);",
142
229
" rgb = mix(rgb, vec3(0.0), darkness);",
143
" gl_FragColor = vec4(rgb, color.a * u_alpha);",
230
" gl_FragColor = vec4(rgb, u_alpha);",
144
231
"}"
145
232
].join("\n");
146
233
@@ -3184,7 +3271,87 @@ export class WorldView
3184
3271
};
3185
3272
}
3186
3273
3187
#syncWaterGroundSprite (object, corners, ambientDark, edges, timeSec, fallbackLit = 1)
3274
/**
3275
* Prefer a wet-shore (sand-wet) neighbor sprite for coast retreat peeks.
3276
* @returns {{ sprite: object|null, edgeN: number, edgeE: number, edgeS: number, edgeW: number }}
3277
*/
3278
#waterCoastShore (tileX, tileY, edges)
3279
{
3280
const season = this.worldSeason;
3281
const candidates = [];
3282
if (edges?.n)
3283
{ candidates.push({ edge: "n", tileX, tileY: tileY - 1 }); }
3284
if (edges?.e)
3285
{ candidates.push({ edge: "e", tileX: tileX + 1, tileY }); }
3286
if (edges?.s)
3287
{ candidates.push({ edge: "s", tileX, tileY: tileY + 1 }); }
3288
if (edges?.w)
3289
{ candidates.push({ edge: "w", tileX: tileX - 1, tileY }); }
3290
let pick = null;
3291
for (const candidate of candidates)
3292
{
3293
const ground = this.#groundAtTile(candidate.tileX, candidate.tileY);
3294
if (ground == null)
3295
{ continue; }
3296
const entry = normalizeGround(ground);
3297
const def = GROUND_DEFINITIONS[entry.typeId];
3298
if (!def)
3299
{ continue; }
3300
let spriteName = null;
3301
if (def.wetShore)
3302
{
3303
const wetState = `${def.key}-wet`;
3304
const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3305
if (states.includes(wetState))
3306
{ spriteName = spriteImageName("ground", def.key, wetState); }
3307
}
3308
if (!spriteName)
3309
{
3310
const states = this.catalog?.grounds?.[def.key]?.states ?? [];
3311
const state = resolveSeasonalVisualState(states, entry.state, season) ?? def.key;
3312
spriteName = spriteImageName("ground", def.key, state);
3313
}
3314
const sprite = spriteName ? this.game.images[spriteName] : null;
3315
if (!sprite)
3316
{ continue; }
3317
const ranked = { ...candidate, sprite, wet: !!def.wetShore };
3318
if (ranked.wet)
3319
{
3320
pick = ranked;
3321
break;
3322
}
3323
if (!pick)
3324
{ pick = ranked; }
3325
}
3326
const shore = {
3327
sprite: pick?.sprite ?? null,
3328
edgeN: 0,
3329
edgeE: 0,
3330
edgeS: 0,
3331
edgeW: 0
3332
};
3333
if (pick?.edge === "n")
3334
{ shore.edgeN = 1; }
3335
else if (pick?.edge === "e")
3336
{ shore.edgeE = 1; }
3337
else if (pick?.edge === "s")
3338
{ shore.edgeS = 1; }
3339
else if (pick?.edge === "w")
3340
{ shore.edgeW = 1; }
3341
return shore;
3342
}
3343
3344
#syncWaterGroundSprite (object, {
3345
corners = null,
3346
ambientDark = 0,
3347
edges = null,
3348
shore = null,
3349
timeSec = 0,
3350
fallbackLit = 1,
3351
tileX = 0,
3352
tileY = 0,
3353
deep = false
3354
} = {})
3188
3355
{
3189
3356
if (!object?.renderer)
3190
3357
{ return; }
@@ -3195,9 +3362,12 @@ export class WorldView
3195
3362
se: fallbackLit
3196
3363
};
3197
3364
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
3365
const shoreSprite = shore?.sprite ?? null;
3366
const shoreUv = shoreSprite?.getUvRect?.(0)
3367
?? { u0: 0, v0: 0, u1: 1, v1: 1 };
3198
3368
object._lit = true;
3199
3369
object.renderer.shader = getWaterGroundShader();
3200
object.renderer.secondaryMap = null;
3370
object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
3201
3371
object.renderer.shaderUniforms = {
3202
3372
u_ambientDark: dark,
3203
3373
u_litNW: lit.nw,
@@ -3205,10 +3375,19 @@ export class WorldView
3205
3375
u_litSW: lit.sw,
3206
3376
u_litSE: lit.se,
3207
3377
u_time: timeSec,
3378
u_tileX: tileX | 0,
3379
u_tileY: tileY | 0,
3380
u_deep: deep ? 1 : 0,
3208
3381
u_edgeN: edges?.n ?? 0,
3209
3382
u_edgeE: edges?.e ?? 0,
3210
3383
u_edgeS: edges?.s ?? 0,
3211
u_edgeW: edges?.w ?? 0
3384
u_edgeW: edges?.w ?? 0,
3385
u_hasShore: shoreSprite ? 1 : 0,
3386
u_shoreEdgeN: shore?.edgeN ?? 0,
3387
u_shoreEdgeE: shore?.edgeE ?? 0,
3388
u_shoreEdgeS: shore?.edgeS ?? 0,
3389
u_shoreEdgeW: shore?.edgeW ?? 0,
3390
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1]
3212
3391
};
3213
3392
}
3214
3393
@@ -3242,14 +3421,18 @@ export class WorldView
3242
3421
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
3243
3422
}
3244
3423
objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);
3245
this.#syncWaterGroundSprite(
3246
objects.ground,
3247
litCorners,
3424
const shore = this.#waterCoastShore(objects.tileX, objects.tileY, objects.waterEdges);
3425
this.#syncWaterGroundSprite(objects.ground, {
3426
corners: litCorners,
3248
3427
ambientDark,
3249
objects.waterEdges,
3428
edges: objects.waterEdges,
3429
shore,
3250
3430
timeSec,
3251
fallbackLit
3252
);
3431
fallbackLit,
3432
tileX: objects.tileX,
3433
tileY: objects.tileY,
3434
deep: objects.groundTypeId === GroundType.deepWater
3435
});
3253
3436
}
3254
3437
3255
3438
#ambientDarkness ()
@@ -16,7 +16,7 @@ import16
} from "/shared/render/tint.js";16
} from "/shared/render/tint.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";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, isLiquidWaterGround, isGroundPassable, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -27,7 +27,7 @@ import27
invalidateCanvasTexture27
invalidateCanvasTexture28
} from "./canvasSprite.js";28
} from "./canvasSprite.js";29
import { setNearestFilter } from "./sprites.js";29
import { setNearestFilter } from "./sprites.js";30
import { SeasonId, seasonIdAt } from "/shared/world/season.js";30
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";31
import31
import32
{32
{33
OVERWORLD_ID,33
OVERWORLD_ID,@@ -105,6 +105,7 @@ const WATER_GROUND_FRAG = [105
"precision mediump float;",105
"precision mediump float;",106
"varying vec2 v_texCoord;",106
"varying vec2 v_texCoord;",107
"uniform sampler2D u_texture;",107
"uniform sampler2D u_texture;",108
"uniform sampler2D u_secondary;",108
"uniform float u_alpha;",109
"uniform float u_alpha;",109
"uniform float u_ambientDark;",110
"uniform float u_ambientDark;",110
"uniform float u_litNW;",111
"uniform float u_litNW;",@@ -112,35 +113,121 @@ const WATER_GROUND_FRAG = [112
"uniform float u_litSW;",113
"uniform float u_litSW;",113
"uniform float u_litSE;",114
"uniform float u_litSE;",114
"uniform float u_time;",115
"uniform float u_time;",116
"uniform float u_tileX;",117
"uniform float u_tileY;",118
"uniform float u_deep;",115
"uniform float u_edgeN;",119
"uniform float u_edgeN;",116
"uniform float u_edgeE;",120
"uniform float u_edgeE;",117
"uniform float u_edgeS;",121
"uniform float u_edgeS;",118
"uniform float u_edgeW;",122
"uniform float u_edgeW;",123
"uniform float u_hasShore;",124
"uniform float u_shoreEdgeN;",125
"uniform float u_shoreEdgeE;",126
"uniform float u_shoreEdgeS;",127
"uniform float u_shoreEdgeW;",128
"uniform vec4 u_shoreUvRect;",119
"void main() {",129
"void main() {",120
" vec4 color = texture2D(u_texture, v_texCoord);",130
// Pixel grid (16x16) for body waves — stable across the tile.121
" if (color.a <= 0.0) { discard; }",131
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",122
" vec3 rgb = color.rgb;",132
" vec2 puv = px / 16.0;",133
" vec2 world = vec2(u_tileX, u_tileY) + puv;",134
" float w1 = sin(u_time * 1.7 + world.x * 5.1 + world.y * 3.3);",135
" float w2 = sin(u_time * 2.3 + world.x * -3.7 + world.y * 6.2 + 1.7);",136
" float body = 0.55 + 0.28 * w1 + 0.17 * w2;",137
" vec3 shallowA = vec3(0.19, 0.46, 0.66);",138
" vec3 shallowB = vec3(0.35, 0.67, 0.82);",139
" vec3 deepA = vec3(0.11, 0.28, 0.46);",140
" vec3 deepB = vec3(0.22, 0.47, 0.67);",141
" vec3 baseA = mix(shallowA, deepA, u_deep);",142
" vec3 baseB = mix(shallowB, deepB, u_deep);",143
" vec3 rgb = mix(baseA, baseB, clamp(body, 0.0, 1.0));",144
" vec3 foamCol = vec3(0.78, 0.92, 1.0);",123
" float foam = 0.0;",145
" 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);",146
" float shoreMix = 0.0;",125
" if (u_edgeN > 0.5 && v_texCoord.y < 0.22) {",147
" vec3 shoreRgb = rgb;",126
" foam = max(foam, (1.0 - v_texCoord.y / 0.22) * pulse);",148
// Top-down sine coastline: surge = foam, retreat = neighbor shore pixels.149
" float coastAmp = 0.09;",150
" float coastBase = 0.14;",151
" if (u_edgeN > 0.5) {",152
" float along = puv.x;",153
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.9 + u_tileY * 0.4);",154
" float band = coastBase + coastAmp * wave;",155
" float dist = puv.y;",156
" if (dist < band) {",157
" float t = 1.0 - dist / max(band, 0.001);",158
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeN > 0.5) {",159
" vec2 shoreNu = vec2(puv.x, 1.0 - dist);",160
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",161
" vec4 shore = texture2D(u_secondary, shoreUv);",162
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",163
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",164
" } else {",165
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",166
" }",167
" }",127
" }",168
" }",128
" if (u_edgeS > 0.5 && v_texCoord.y > 0.78) {",169
" if (u_edgeS > 0.5) {",129
" foam = max(foam, ((v_texCoord.y - 0.78) / 0.22) * pulse);",170
" float along = puv.x;",171
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.7 + u_tileY * 1.1 + 2.1);",172
" float band = coastBase + coastAmp * wave;",173
" float dist = 1.0 - puv.y;",174
" if (dist < band) {",175
" float t = 1.0 - dist / max(band, 0.001);",176
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeS > 0.5) {",177
" vec2 shoreNu = vec2(puv.x, dist);",178
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",179
" vec4 shore = texture2D(u_secondary, shoreUv);",180
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",181
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",182
" } else {",183
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",184
" }",185
" }",130
" }",186
" }",131
" if (u_edgeW > 0.5 && v_texCoord.x < 0.22) {",187
" if (u_edgeW > 0.5) {",132
" foam = max(foam, (1.0 - v_texCoord.x / 0.22) * pulse);",188
" float along = puv.y;",189
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 1.2 + u_tileY * 0.5 + 0.8);",190
" float band = coastBase + coastAmp * wave;",191
" float dist = puv.x;",192
" if (dist < band) {",193
" float t = 1.0 - dist / max(band, 0.001);",194
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeW > 0.5) {",195
" vec2 shoreNu = vec2(1.0 - dist, puv.y);",196
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",197
" vec4 shore = texture2D(u_secondary, shoreUv);",198
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",199
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",200
" } else {",201
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",202
" }",203
" }",133
" }",204
" }",134
" if (u_edgeE > 0.5 && v_texCoord.x > 0.78) {",205
" if (u_edgeE > 0.5) {",135
" foam = max(foam, ((v_texCoord.x - 0.78) / 0.22) * pulse);",206
" float along = puv.y;",207
" float wave = sin(u_time * 2.6 + along * 14.0 + u_tileX * 0.4 + u_tileY * 0.9 + 3.3);",208
" float band = coastBase + coastAmp * wave;",209
" float dist = 1.0 - puv.x;",210
" if (dist < band) {",211
" float t = 1.0 - dist / max(band, 0.001);",212
" if (wave < -0.2 && u_hasShore > 0.5 && u_shoreEdgeE > 0.5) {",213
" vec2 shoreNu = vec2(dist, puv.y);",214
" vec2 shoreUv = u_shoreUvRect.xy + shoreNu * (u_shoreUvRect.zw - u_shoreUvRect.xy);",215
" vec4 shore = texture2D(u_secondary, shoreUv);",216
" if (shore.a > 0.1) { shoreRgb = shore.rgb; shoreMix = max(shoreMix, t); }",217
" else { foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave))); }",218
" } else {",219
" foam = max(foam, t * (0.35 + 0.45 * max(0.0, wave)));",220
" }",221
" }",136
" }",222
" }",137
" rgb = mix(rgb, vec3(0.78, 0.92, 1.0), clamp(foam, 0.0, 0.85));",223
" rgb = mix(rgb, foamCol, clamp(foam, 0.0, 0.85));",224
" rgb = mix(rgb, shoreRgb, clamp(shoreMix, 0.0, 1.0));",138
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",225
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",139
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",226
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",140
" float lit = mix(litTop, litBottom, v_texCoord.y);",227
" float lit = mix(litTop, litBottom, v_texCoord.y);",141
" float darkness = u_ambientDark * (1.0 - lit);",228
" float darkness = u_ambientDark * (1.0 - lit);",142
" rgb = mix(rgb, vec3(0.0), darkness);",229
" rgb = mix(rgb, vec3(0.0), darkness);",143
" gl_FragColor = vec4(rgb, color.a * u_alpha);",230
" gl_FragColor = vec4(rgb, u_alpha);",144
"}"231
"}"145
].join("\n");232
].join("\n");146
233
@@ -3184,7 +3271,87 @@ export class WorldView3184
};3271
};3185
}3272
}3186
3273
3187
#syncWaterGroundSprite (object, corners, ambientDark, edges, timeSec, fallbackLit = 1)3274
/**3275
* Prefer a wet-shore (sand-wet) neighbor sprite for coast retreat peeks.3276
* @returns {{ sprite: object|null, edgeN: number, edgeE: number, edgeS: number, edgeW: number }}3277
*/3278
#waterCoastShore (tileX, tileY, edges)3279
{3280
const season = this.worldSeason;3281
const candidates = [];3282
if (edges?.n)3283
{ candidates.push({ edge: "n", tileX, tileY: tileY - 1 }); }3284
if (edges?.e)3285
{ candidates.push({ edge: "e", tileX: tileX + 1, tileY }); }3286
if (edges?.s)3287
{ candidates.push({ edge: "s", tileX, tileY: tileY + 1 }); }3288
if (edges?.w)3289
{ candidates.push({ edge: "w", tileX: tileX - 1, tileY }); }3290
let pick = null;3291
for (const candidate of candidates)3292
{3293
const ground = this.#groundAtTile(candidate.tileX, candidate.tileY);3294
if (ground == null)3295
{ continue; }3296
const entry = normalizeGround(ground);3297
const def = GROUND_DEFINITIONS[entry.typeId];3298
if (!def)3299
{ continue; }3300
let spriteName = null;3301
if (def.wetShore)3302
{3303
const wetState = `${def.key}-wet`;3304
const states = this.catalog?.grounds?.[def.key]?.states ?? [];3305
if (states.includes(wetState))3306
{ spriteName = spriteImageName("ground", def.key, wetState); }3307
}3308
if (!spriteName)3309
{3310
const states = this.catalog?.grounds?.[def.key]?.states ?? [];3311
const state = resolveSeasonalVisualState(states, entry.state, season) ?? def.key;3312
spriteName = spriteImageName("ground", def.key, state);3313
}3314
const sprite = spriteName ? this.game.images[spriteName] : null;3315
if (!sprite)3316
{ continue; }3317
const ranked = { ...candidate, sprite, wet: !!def.wetShore };3318
if (ranked.wet)3319
{3320
pick = ranked;3321
break;3322
}3323
if (!pick)3324
{ pick = ranked; }3325
}3326
const shore = {3327
sprite: pick?.sprite ?? null,3328
edgeN: 0,3329
edgeE: 0,3330
edgeS: 0,3331
edgeW: 03332
};3333
if (pick?.edge === "n")3334
{ shore.edgeN = 1; }3335
else if (pick?.edge === "e")3336
{ shore.edgeE = 1; }3337
else if (pick?.edge === "s")3338
{ shore.edgeS = 1; }3339
else if (pick?.edge === "w")3340
{ shore.edgeW = 1; }3341
return shore;3342
}3343
3344
#syncWaterGroundSprite (object, {3345
corners = null,3346
ambientDark = 0,3347
edges = null,3348
shore = null,3349
timeSec = 0,3350
fallbackLit = 1,3351
tileX = 0,3352
tileY = 0,3353
deep = false3354
} = {})3188
{3355
{3189
if (!object?.renderer)3356
if (!object?.renderer)3190
{ return; }3357
{ return; }@@ -3195,9 +3362,12 @@ export class WorldView3195
se: fallbackLit3362
se: fallbackLit3196
};3363
};3197
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));3364
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));3365
const shoreSprite = shore?.sprite ?? null;3366
const shoreUv = shoreSprite?.getUvRect?.(0)3367
?? { u0: 0, v0: 0, u1: 1, v1: 1 };3198
object._lit = true;3368
object._lit = true;3199
object.renderer.shader = getWaterGroundShader();3369
object.renderer.shader = getWaterGroundShader();3200
object.renderer.secondaryMap = null;3370
object.renderer.secondaryMap = shoreSprite?.g_image ?? null;3201
object.renderer.shaderUniforms = {3371
object.renderer.shaderUniforms = {3202
u_ambientDark: dark,3372
u_ambientDark: dark,3203
u_litNW: lit.nw,3373
u_litNW: lit.nw,@@ -3205,10 +3375,19 @@ export class WorldView3205
u_litSW: lit.sw,3375
u_litSW: lit.sw,3206
u_litSE: lit.se,3376
u_litSE: lit.se,3207
u_time: timeSec,3377
u_time: timeSec,3378
u_tileX: tileX | 0,3379
u_tileY: tileY | 0,3380
u_deep: deep ? 1 : 0,3208
u_edgeN: edges?.n ?? 0,3381
u_edgeN: edges?.n ?? 0,3209
u_edgeE: edges?.e ?? 0,3382
u_edgeE: edges?.e ?? 0,3210
u_edgeS: edges?.s ?? 0,3383
u_edgeS: edges?.s ?? 0,3211
u_edgeW: edges?.w ?? 03384
u_edgeW: edges?.w ?? 0,3385
u_hasShore: shoreSprite ? 1 : 0,3386
u_shoreEdgeN: shore?.edgeN ?? 0,3387
u_shoreEdgeE: shore?.edgeE ?? 0,3388
u_shoreEdgeS: shore?.edgeS ?? 0,3389
u_shoreEdgeW: shore?.edgeW ?? 0,3390
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1]3212
};3391
};3213
}3392
}3214
3393
@@ -3242,14 +3421,18 @@ export class WorldView3242
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }3421
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }3243
}3422
}3244
objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);3423
objects.waterEdges = this.#waterCoastEdges(objects.tileX, objects.tileY);3245
this.#syncWaterGroundSprite(3424
const shore = this.#waterCoastShore(objects.tileX, objects.tileY, objects.waterEdges);3246
objects.ground,3425
this.#syncWaterGroundSprite(objects.ground, {3247
litCorners,3426
corners: litCorners,3248
ambientDark,3427
ambientDark,3249
objects.waterEdges,3428
edges: objects.waterEdges,3429
shore,3250
timeSec,3430
timeSec,3251
fallbackLit3431
fallbackLit,3252
);3432
tileX: objects.tileX,3433
tileY: objects.tileY,3434
deep: objects.groundTypeId === GroundType.deepWater3435
});3253
}3436
}3254
3437
3255
#ambientDarkness ()3438
#ambientDarkness ()