Peek dry neighbor tiles on lava coasts like water.
Lava coasts sample adjacent ground sprites into the clipped band instead of discarding; wet sand is never used for lava peeks.
@@ -453,7 +453,30 @@ const LAVA_GROUND_FRAG = [
453
453
"uniform float u_lightDirZ;",
454
454
"uniform float u_normalEps;",
455
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;",
456
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
"}",
457
480
"void main() {",
458
481
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",
459
482
" vec2 puv = px / 16.0;",
@@ -508,26 +531,46 @@ const LAVA_GROUND_FRAG = [
508
531
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
509
532
" rgb *= shade;",
510
533
" rgb = mix(rgb, darkRed, edgeProx * u_edgeDark * 0.35);",
511
// Coast: outer pixels always stop (black); noise only wiggles how far inland.
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
" }",
512
560
" float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",
513
561
" float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",
514
" float hasEdge = max(max(u_edgeN, u_edgeE), max(u_edgeS, u_edgeW));",
515
" hasEdge = max(hasEdge, max(max(u_edgeNE, u_edgeNW), max(u_edgeSE, u_edgeSW)));",
516
" float shoreW = step(0.5, hasEdge);",
517
562
" float shoreClip = u_shoreClip;",
518
563
" float shoreMask = step(shoreClip, retreat) * shoreW;",
519
564
" float crustAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.2, shoreClip - 0.06, retreat)",
520
565
" * (1.0 - smoothstep(shoreClip - 0.06, shoreClip, retreat));",
521
566
" rgb = mix(rgb, vec3(0.05, 0.01, 0.0), crustAmt);",
522
" rgb = mix(rgb, vec3(0.0), shoreMask);",
567
" rgb = mix(rgb, shoreRgb, shoreMask);",
523
568
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
524
569
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
525
570
" float lit = mix(litTop, litBottom, v_texCoord.y);",
526
571
" float darkness = u_ambientDark * (1.0 - lit);",
527
572
" rgb = mix(rgb, vec3(0.0), darkness);",
528
" float alpha = u_alpha * (1.0 - shoreMask);",
529
" if (alpha <= 0.001) { discard; }",
530
" gl_FragColor = vec4(rgb, alpha);",
573
" gl_FragColor = vec4(rgb, u_alpha);",
531
574
"}"
532
575
].join("\n");
533
576
@@ -3741,10 +3784,10 @@ export class WorldView
3741
3784
}
3742
3785
3743
3786
/**
3744
* Prefer a wet-shore (sand-wet) neighbor sprite for coast retreat peeks.
3745
* @returns {{ sprite: object|null, edgeN: number, edgeE: number, edgeS: number, edgeW: number }}
3787
* Neighbor ground sprite for coast retreat peeks.
3788
* Water prefers wet-shore (sand-wet); lava uses dry land only.
3746
3789
*/
3747
#waterCoastShore (tileX, tileY, edges)
3790
#fluidCoastShore (tileX, tileY, edges, { preferWet = true } = {})
3748
3791
{
3749
3792
const season = this.worldSeason;
3750
3793
const candidates = [];
@@ -3772,10 +3815,10 @@ export class WorldView
3772
3815
{ continue; }
3773
3816
const entry = normalizeGround(ground);
3774
3817
const def = GROUND_DEFINITIONS[entry.typeId];
3775
if (!def)
3818
if (!def || def.proceduralWaves)
3776
3819
{ continue; }
3777
3820
let spriteName = null;
3778
if (def.wetShore)
3821
if (preferWet && def.wetShore)
3779
3822
{
3780
3823
const wetState = `${def.key}-wet`;
3781
3824
const states = this.catalog?.grounds?.[def.key]?.states ?? [];
@@ -3791,7 +3834,7 @@ export class WorldView
3791
3834
const sprite = spriteName ? this.game.images[spriteName] : null;
3792
3835
if (!sprite)
3793
3836
{ continue; }
3794
const ranked = { ...candidate, sprite, wet: !!def.wetShore };
3837
const ranked = { ...candidate, sprite, wet: !!(preferWet && def.wetShore) };
3795
3838
if (ranked.wet)
3796
3839
{
3797
3840
pick = ranked;
@@ -3830,6 +3873,11 @@ export class WorldView
3830
3873
return shore;
3831
3874
}
3832
3875
3876
#waterCoastShore (tileX, tileY, edges)
3877
{
3878
return this.#fluidCoastShore(tileX, tileY, edges, { preferWet: true });
3879
}
3880
3833
3881
#syncWaterGroundSprite (object, {
3834
3882
corners = null,
3835
3883
ambientDark = 0,
@@ -4027,10 +4075,12 @@ export class WorldView
4027
4075
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
4028
4076
}
4029
4077
const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);
4078
const shore = this.#fluidCoastShore(objects.tileX, objects.tileY, edges, { preferWet: false });
4030
4079
this.#syncLavaGroundSprite(objects.ground, {
4031
4080
corners: litCorners,
4032
4081
ambientDark,
4033
4082
edges,
4083
shore,
4034
4084
timeSec,
4035
4085
fallbackLit,
4036
4086
tileX: objects.tileX,
@@ -4052,6 +4102,7 @@ export class WorldView
4052
4102
corners = null,
4053
4103
ambientDark = 0,
4054
4104
edges = null,
4105
shore = null,
4055
4106
timeSec = 0,
4056
4107
fallbackLit = 1,
4057
4108
tileX = 0,
@@ -4067,9 +4118,12 @@ export class WorldView
4067
4118
se: fallbackLit
4068
4119
};
4069
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 };
4070
4124
object._lit = true;
4071
4125
object.renderer.shader = getLavaGroundShader();
4072
object.renderer.secondaryMap = null;
4126
object.renderer.secondaryMap = shoreSprite?.g_image ?? null;
4073
4127
object.renderer.shaderUniforms = {
4074
4128
u_ambientDark: dark,
4075
4129
u_litNW: lit.nw,
@@ -4087,6 +4141,16 @@ export class WorldView
4087
4141
u_edgeNW: edges?.nw ?? 0,
4088
4142
u_edgeSE: edges?.se ?? 0,
4089
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],
4090
4154
...lavaDebugUniforms()
4091
4155
};
4092
4156
}
@@ -453,7 +453,30 @@ const LAVA_GROUND_FRAG = [453
"uniform float u_lightDirZ;",453
"uniform float u_lightDirZ;",454
"uniform float u_normalEps;",454
"uniform float u_normalEps;",455
"uniform float u_shoreClip;",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;",456
...LAVA_FBM_COMMON,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
"}",457
"void main() {",480
"void main() {",458
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",481
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",459
" vec2 puv = px / 16.0;",482
" vec2 puv = px / 16.0;",@@ -508,26 +531,46 @@ const LAVA_GROUND_FRAG = [508
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",531
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",509
" rgb *= shade;",532
" rgb *= shade;",510
" rgb = mix(rgb, darkRed, edgeProx * u_edgeDark * 0.35);",533
" rgb = mix(rgb, darkRed, edgeProx * u_edgeDark * 0.35);",511
// Coast: outer pixels always stop (black); noise only wiggles how far inland.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
" }",512
" float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",560
" float darkAmt = 1.0 - smoothstep(0.12, 0.48, waveBody);",513
" float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",561
" float retreat = edgeProx * mix(0.72, 1.0, darkAmt);",514
" float hasEdge = max(max(u_edgeN, u_edgeE), max(u_edgeS, u_edgeW));",515
" hasEdge = max(hasEdge, max(max(u_edgeNE, u_edgeNW), max(u_edgeSE, u_edgeSW)));",516
" float shoreW = step(0.5, hasEdge);",517
" float shoreClip = u_shoreClip;",562
" float shoreClip = u_shoreClip;",518
" float shoreMask = step(shoreClip, retreat) * shoreW;",563
" float shoreMask = step(shoreClip, retreat) * shoreW;",519
" float crustAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.2, shoreClip - 0.06, retreat)",564
" float crustAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.2, shoreClip - 0.06, retreat)",520
" * (1.0 - smoothstep(shoreClip - 0.06, shoreClip, retreat));",565
" * (1.0 - smoothstep(shoreClip - 0.06, shoreClip, retreat));",521
" rgb = mix(rgb, vec3(0.05, 0.01, 0.0), crustAmt);",566
" rgb = mix(rgb, vec3(0.05, 0.01, 0.0), crustAmt);",522
" rgb = mix(rgb, vec3(0.0), shoreMask);",567
" rgb = mix(rgb, shoreRgb, shoreMask);",523
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",568
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",524
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",569
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",525
" float lit = mix(litTop, litBottom, v_texCoord.y);",570
" float lit = mix(litTop, litBottom, v_texCoord.y);",526
" float darkness = u_ambientDark * (1.0 - lit);",571
" float darkness = u_ambientDark * (1.0 - lit);",527
" rgb = mix(rgb, vec3(0.0), darkness);",572
" rgb = mix(rgb, vec3(0.0), darkness);",528
" float alpha = u_alpha * (1.0 - shoreMask);",573
" gl_FragColor = vec4(rgb, u_alpha);",529
" if (alpha <= 0.001) { discard; }",530
" gl_FragColor = vec4(rgb, alpha);",531
"}"574
"}"532
].join("\n");575
].join("\n");533
576
@@ -3741,10 +3784,10 @@ export class WorldView3741
}3784
}3742
3785
3743
/**3786
/**3744
* Prefer a wet-shore (sand-wet) neighbor sprite for coast retreat peeks.3787
* Neighbor ground sprite for coast retreat peeks.3745
* @returns {{ sprite: object|null, edgeN: number, edgeE: number, edgeS: number, edgeW: number }}3788
* Water prefers wet-shore (sand-wet); lava uses dry land only.3746
*/3789
*/3747
#waterCoastShore (tileX, tileY, edges)3790
#fluidCoastShore (tileX, tileY, edges, { preferWet = true } = {})3748
{3791
{3749
const season = this.worldSeason;3792
const season = this.worldSeason;3750
const candidates = [];3793
const candidates = [];@@ -3772,10 +3815,10 @@ export class WorldView3772
{ continue; }3815
{ continue; }3773
const entry = normalizeGround(ground);3816
const entry = normalizeGround(ground);3774
const def = GROUND_DEFINITIONS[entry.typeId];3817
const def = GROUND_DEFINITIONS[entry.typeId];3775
if (!def)3818
if (!def || def.proceduralWaves)3776
{ continue; }3819
{ continue; }3777
let spriteName = null;3820
let spriteName = null;3778
if (def.wetShore)3821
if (preferWet && def.wetShore)3779
{3822
{3780
const wetState = `${def.key}-wet`;3823
const wetState = `${def.key}-wet`;3781
const states = this.catalog?.grounds?.[def.key]?.states ?? [];3824
const states = this.catalog?.grounds?.[def.key]?.states ?? [];@@ -3791,7 +3834,7 @@ export class WorldView3791
const sprite = spriteName ? this.game.images[spriteName] : null;3834
const sprite = spriteName ? this.game.images[spriteName] : null;3792
if (!sprite)3835
if (!sprite)3793
{ continue; }3836
{ continue; }3794
const ranked = { ...candidate, sprite, wet: !!def.wetShore };3837
const ranked = { ...candidate, sprite, wet: !!(preferWet && def.wetShore) };3795
if (ranked.wet)3838
if (ranked.wet)3796
{3839
{3797
pick = ranked;3840
pick = ranked;@@ -3830,6 +3873,11 @@ export class WorldView3830
return shore;3873
return shore;3831
}3874
}3832
3875
3876
#waterCoastShore (tileX, tileY, edges)3877
{3878
return this.#fluidCoastShore(tileX, tileY, edges, { preferWet: true });3879
}3880
3833
#syncWaterGroundSprite (object, {3881
#syncWaterGroundSprite (object, {3834
corners = null,3882
corners = null,3835
ambientDark = 0,3883
ambientDark = 0,@@ -4027,10 +4075,12 @@ export class WorldView4027
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }4075
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }4028
}4076
}4029
const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);4077
const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);4078
const shore = this.#fluidCoastShore(objects.tileX, objects.tileY, edges, { preferWet: false });4030
this.#syncLavaGroundSprite(objects.ground, {4079
this.#syncLavaGroundSprite(objects.ground, {4031
corners: litCorners,4080
corners: litCorners,4032
ambientDark,4081
ambientDark,4033
edges,4082
edges,4083
shore,4034
timeSec,4084
timeSec,4035
fallbackLit,4085
fallbackLit,4036
tileX: objects.tileX,4086
tileX: objects.tileX,@@ -4052,6 +4102,7 @@ export class WorldView4052
corners = null,4102
corners = null,4053
ambientDark = 0,4103
ambientDark = 0,4054
edges = null,4104
edges = null,4105
shore = null,4055
timeSec = 0,4106
timeSec = 0,4056
fallbackLit = 1,4107
fallbackLit = 1,4057
tileX = 0,4108
tileX = 0,@@ -4067,9 +4118,12 @@ export class WorldView4067
se: fallbackLit4118
se: fallbackLit4068
};4119
};4069
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));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 };4070
object._lit = true;4124
object._lit = true;4071
object.renderer.shader = getLavaGroundShader();4125
object.renderer.shader = getLavaGroundShader();4072
object.renderer.secondaryMap = null;4126
object.renderer.secondaryMap = shoreSprite?.g_image ?? null;4073
object.renderer.shaderUniforms = {4127
object.renderer.shaderUniforms = {4074
u_ambientDark: dark,4128
u_ambientDark: dark,4075
u_litNW: lit.nw,4129
u_litNW: lit.nw,@@ -4087,6 +4141,16 @@ export class WorldView4087
u_edgeNW: edges?.nw ?? 0,4141
u_edgeNW: edges?.nw ?? 0,4088
u_edgeSE: edges?.se ?? 0,4142
u_edgeSE: edges?.se ?? 0,4089
u_edgeSW: edges?.sw ?? 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],4090
...lavaDebugUniforms()4154
...lavaDebugUniforms()4091
};4155
};4092
}4156
}