Tune caustic speed, fix shallow-deep edge midpoint blend, darken coasts.
Shallow/deep tiles now meet at the average depth at shared edges instead of swapping colors; near-land pixels damp caustics and pull darker for softer shorelines.
@@ -161,9 +161,9 @@ const WATER_GROUND_FRAG = [
161
161
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
162
162
" float t = u_time;",
163
163
// Three baked Perlin channels, scrolled at different angles / speeds, additive caustics.
164
" vec2 uvR = wrapUv(rot2(world * 0.42, 0.35) + vec2(t * 0.085, t * 0.058));",
165
" vec2 uvG = wrapUv(rot2(world * 0.51, -1.05) + vec2(-t * 0.068, t * 0.095));",
166
" vec2 uvB = wrapUv(rot2(world * 0.63, 1.55) + vec2(t * 0.105, -t * 0.052));",
164
" vec2 uvR = wrapUv(rot2(world * 0.42, 0.35) + vec2(t * 0.13, t * 0.09));",
165
" vec2 uvG = wrapUv(rot2(world * 0.51, -1.05) + vec2(-t * 0.105, t * 0.145));",
166
" vec2 uvB = wrapUv(rot2(world * 0.63, 1.55) + vec2(t * 0.16, -t * 0.08));",
167
167
" float nR = texture2D(u_texture, uvR).r;",
168
168
" float nG = texture2D(u_texture, uvG).g;",
169
169
" float nB = texture2D(u_texture, uvB).b;",
@@ -171,61 +171,58 @@ const WATER_GROUND_FRAG = [
171
171
" caustic += nR * nG * 0.55 + nG * nB * 0.35;",
172
172
" caustic = clamp(caustic * 0.72, 0.0, 1.0);",
173
173
" caustic = pow(caustic, 1.35);",
174
// Soft shallow↔deep blend toward water neighbors (half-tile ramp).
174
// Coast proximity first — damp caustics so water softens before the land sprite edge.
175
" float edgeProx = 0.0;",
176
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
177
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
178
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
179
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
180
" float causticBody = caustic * (1.0 - edgeProx * 0.72);",
181
// Shallow↔deep: approach the midpoint at the shared edge (not full swap).
175
182
" float deepMix = u_deep;",
176
" float blendW = 0.0;",
177
" float blendAcc = 0.0;",
178
183
" if (u_blendDeepN > 0.5) {",
179
" float w = smoothstep(0.5, 0.0, puv.y);",
180
" blendAcc += w * u_nbrDeepN; blendW += w;",
184
" float w = smoothstep(0.55, 0.0, puv.y);",
185
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepN, 0.5), w);",
181
186
" }",
182
187
" if (u_blendDeepS > 0.5) {",
183
" float w = smoothstep(0.5, 0.0, 1.0 - puv.y);",
184
" blendAcc += w * u_nbrDeepS; blendW += w;",
188
" float w = smoothstep(0.55, 0.0, 1.0 - puv.y);",
189
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepS, 0.5), w);",
185
190
" }",
186
191
" if (u_blendDeepW > 0.5) {",
187
" float w = smoothstep(0.5, 0.0, puv.x);",
188
" blendAcc += w * u_nbrDeepW; blendW += w;",
192
" float w = smoothstep(0.55, 0.0, puv.x);",
193
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepW, 0.5), w);",
189
194
" }",
190
195
" if (u_blendDeepE > 0.5) {",
191
" float w = smoothstep(0.5, 0.0, 1.0 - puv.x);",
192
" blendAcc += w * u_nbrDeepE; blendW += w;",
193
" }",
194
" if (blendW > 0.001) {",
195
" float nbrDeep = clamp(blendAcc / blendW, 0.0, 1.0);",
196
" deepMix = mix(u_deep, nbrDeep, clamp(blendW, 0.0, 1.0));",
196
" float w = smoothstep(0.55, 0.0, 1.0 - puv.x);",
197
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepE, 0.5), w);",
197
198
" }",
198
199
" vec3 deepCol = mix(vec3(0.12, 0.36, 0.56), vec3(0.06, 0.18, 0.34), deepMix);",
199
200
" vec3 midCol = mix(vec3(0.22, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",
200
201
" vec3 litCol = mix(vec3(0.55, 0.82, 0.94), vec3(0.34, 0.60, 0.82), deepMix);",
201
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.15, 0.55, caustic));",
202
" rgb = mix(rgb, litCol, smoothstep(0.45, 0.92, caustic));",
203
// Coast: bright caustic → push light-blue; dark → retreat into shore neighbor.
204
" float edgeProx = 0.0;",
202
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.15, 0.55, causticBody));",
203
" rgb = mix(rgb, litCol, smoothstep(0.45, 0.92, causticBody));",
204
// Force darker near land so the coastline eases into the hard ground sprite.
205
" rgb = mix(rgb, deepCol, edgeProx * 0.62);",
205
206
" float shoreW = 0.0;",
206
207
" vec3 shoreRgb = rgb;",
207
208
" if (u_edgeN > 0.5) {",
208
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, puv.y));",
209
209
" sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
210
210
" }",
211
211
" if (u_edgeS > 0.5) {",
212
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, 1.0 - puv.y));",
213
212
" sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",
214
213
" }",
215
214
" if (u_edgeW > 0.5) {",
216
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, puv.x));",
217
215
" sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
218
216
" }",
219
217
" if (u_edgeE > 0.5) {",
220
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, 1.0 - puv.x));",
221
218
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
222
219
" }",
223
" float lightAmt = smoothstep(0.42, 0.78, caustic);",
224
" float darkAmt = 1.0 - smoothstep(0.28, 0.58, caustic);",
225
" vec3 edgeBlue = mix(vec3(0.62, 0.88, 0.98), vec3(0.42, 0.70, 0.90), deepMix);",
226
" rgb = mix(rgb, edgeBlue, edgeProx * lightAmt * 0.85);",
220
" float lightAmt = smoothstep(0.48, 0.82, causticBody);",
221
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, causticBody);",
222
" vec3 edgeBlue = mix(vec3(0.50, 0.78, 0.92), vec3(0.32, 0.58, 0.80), deepMix);",
223
" rgb = mix(rgb, edgeBlue, edgeProx * lightAmt * 0.35);",
227
224
" if (shoreW > 0.5) {",
228
" rgb = mix(rgb, shoreRgb, edgeProx * darkAmt * 0.92);",
225
" rgb = mix(rgb, shoreRgb, edgeProx * darkAmt * 0.88);",
229
226
" }",
230
227
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
231
228
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
@@ -161,9 +161,9 @@ const WATER_GROUND_FRAG = [161
" vec2 world = vec2(u_tileX, u_tileY) + puv;",161
" vec2 world = vec2(u_tileX, u_tileY) + puv;",162
" float t = u_time;",162
" float t = u_time;",163
// Three baked Perlin channels, scrolled at different angles / speeds, additive caustics.163
// Three baked Perlin channels, scrolled at different angles / speeds, additive caustics.164
" vec2 uvR = wrapUv(rot2(world * 0.42, 0.35) + vec2(t * 0.085, t * 0.058));",164
" vec2 uvR = wrapUv(rot2(world * 0.42, 0.35) + vec2(t * 0.13, t * 0.09));",165
" vec2 uvG = wrapUv(rot2(world * 0.51, -1.05) + vec2(-t * 0.068, t * 0.095));",165
" vec2 uvG = wrapUv(rot2(world * 0.51, -1.05) + vec2(-t * 0.105, t * 0.145));",166
" vec2 uvB = wrapUv(rot2(world * 0.63, 1.55) + vec2(t * 0.105, -t * 0.052));",166
" vec2 uvB = wrapUv(rot2(world * 0.63, 1.55) + vec2(t * 0.16, -t * 0.08));",167
" float nR = texture2D(u_texture, uvR).r;",167
" float nR = texture2D(u_texture, uvR).r;",168
" float nG = texture2D(u_texture, uvG).g;",168
" float nG = texture2D(u_texture, uvG).g;",169
" float nB = texture2D(u_texture, uvB).b;",169
" float nB = texture2D(u_texture, uvB).b;",@@ -171,61 +171,58 @@ const WATER_GROUND_FRAG = [171
" caustic += nR * nG * 0.55 + nG * nB * 0.35;",171
" caustic += nR * nG * 0.55 + nG * nB * 0.35;",172
" caustic = clamp(caustic * 0.72, 0.0, 1.0);",172
" caustic = clamp(caustic * 0.72, 0.0, 1.0);",173
" caustic = pow(caustic, 1.35);",173
" caustic = pow(caustic, 1.35);",174
// Soft shallow↔deep blend toward water neighbors (half-tile ramp).174
// Coast proximity first — damp caustics so water softens before the land sprite edge.175
" float edgeProx = 0.0;",176
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",177
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",178
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",179
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",180
" float causticBody = caustic * (1.0 - edgeProx * 0.72);",181
// Shallow↔deep: approach the midpoint at the shared edge (not full swap).175
" float deepMix = u_deep;",182
" float deepMix = u_deep;",176
" float blendW = 0.0;",177
" float blendAcc = 0.0;",178
" if (u_blendDeepN > 0.5) {",183
" if (u_blendDeepN > 0.5) {",179
" float w = smoothstep(0.5, 0.0, puv.y);",184
" float w = smoothstep(0.55, 0.0, puv.y);",180
" blendAcc += w * u_nbrDeepN; blendW += w;",185
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepN, 0.5), w);",181
" }",186
" }",182
" if (u_blendDeepS > 0.5) {",187
" if (u_blendDeepS > 0.5) {",183
" float w = smoothstep(0.5, 0.0, 1.0 - puv.y);",188
" float w = smoothstep(0.55, 0.0, 1.0 - puv.y);",184
" blendAcc += w * u_nbrDeepS; blendW += w;",189
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepS, 0.5), w);",185
" }",190
" }",186
" if (u_blendDeepW > 0.5) {",191
" if (u_blendDeepW > 0.5) {",187
" float w = smoothstep(0.5, 0.0, puv.x);",192
" float w = smoothstep(0.55, 0.0, puv.x);",188
" blendAcc += w * u_nbrDeepW; blendW += w;",193
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepW, 0.5), w);",189
" }",194
" }",190
" if (u_blendDeepE > 0.5) {",195
" if (u_blendDeepE > 0.5) {",191
" float w = smoothstep(0.5, 0.0, 1.0 - puv.x);",196
" float w = smoothstep(0.55, 0.0, 1.0 - puv.x);",192
" blendAcc += w * u_nbrDeepE; blendW += w;",197
" deepMix = mix(deepMix, mix(u_deep, u_nbrDeepE, 0.5), w);",193
" }",194
" if (blendW > 0.001) {",195
" float nbrDeep = clamp(blendAcc / blendW, 0.0, 1.0);",196
" deepMix = mix(u_deep, nbrDeep, clamp(blendW, 0.0, 1.0));",197
" }",198
" }",198
" vec3 deepCol = mix(vec3(0.12, 0.36, 0.56), vec3(0.06, 0.18, 0.34), deepMix);",199
" vec3 deepCol = mix(vec3(0.12, 0.36, 0.56), vec3(0.06, 0.18, 0.34), deepMix);",199
" vec3 midCol = mix(vec3(0.22, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",200
" vec3 midCol = mix(vec3(0.22, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",200
" vec3 litCol = mix(vec3(0.55, 0.82, 0.94), vec3(0.34, 0.60, 0.82), deepMix);",201
" vec3 litCol = mix(vec3(0.55, 0.82, 0.94), vec3(0.34, 0.60, 0.82), deepMix);",201
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.15, 0.55, caustic));",202
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.15, 0.55, causticBody));",202
" rgb = mix(rgb, litCol, smoothstep(0.45, 0.92, caustic));",203
" rgb = mix(rgb, litCol, smoothstep(0.45, 0.92, causticBody));",203
// Coast: bright caustic → push light-blue; dark → retreat into shore neighbor.204
// Force darker near land so the coastline eases into the hard ground sprite.204
" float edgeProx = 0.0;",205
" rgb = mix(rgb, deepCol, edgeProx * 0.62);",205
" float shoreW = 0.0;",206
" float shoreW = 0.0;",206
" vec3 shoreRgb = rgb;",207
" vec3 shoreRgb = rgb;",207
" if (u_edgeN > 0.5) {",208
" if (u_edgeN > 0.5) {",208
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, puv.y));",209
" sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",209
" sampleShore(1.0, u_shoreEdgeN, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",210
" }",210
" }",211
" if (u_edgeS > 0.5) {",211
" if (u_edgeS > 0.5) {",212
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, 1.0 - puv.y));",213
" sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",212
" sampleShore(1.0, u_shoreEdgeS, vec2(puv.x, 1.0 - puv.y), shoreRgb, shoreW);",214
" }",213
" }",215
" if (u_edgeW > 0.5) {",214
" if (u_edgeW > 0.5) {",216
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, puv.x));",217
" sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",215
" sampleShore(1.0, u_shoreEdgeW, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",218
" }",216
" }",219
" if (u_edgeE > 0.5) {",217
" if (u_edgeE > 0.5) {",220
" edgeProx = max(edgeProx, smoothstep(0.42, 0.0, 1.0 - puv.x));",221
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",218
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",222
" }",219
" }",223
" float lightAmt = smoothstep(0.42, 0.78, caustic);",220
" float lightAmt = smoothstep(0.48, 0.82, causticBody);",224
" float darkAmt = 1.0 - smoothstep(0.28, 0.58, caustic);",221
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, causticBody);",225
" vec3 edgeBlue = mix(vec3(0.62, 0.88, 0.98), vec3(0.42, 0.70, 0.90), deepMix);",222
" vec3 edgeBlue = mix(vec3(0.50, 0.78, 0.92), vec3(0.32, 0.58, 0.80), deepMix);",226
" rgb = mix(rgb, edgeBlue, edgeProx * lightAmt * 0.85);",223
" rgb = mix(rgb, edgeBlue, edgeProx * lightAmt * 0.35);",227
" if (shoreW > 0.5) {",224
" if (shoreW > 0.5) {",228
" rgb = mix(rgb, shoreRgb, edgeProx * darkAmt * 0.92);",225
" rgb = mix(rgb, shoreRgb, edgeProx * darkAmt * 0.88);",229
" }",226
" }",230
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",227
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",231
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",228
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",