Tune deep blue, sharper glitter, softer wave ramps, foam before shore clip.
Deep water stays blue instead of near-black; crest sparkles are brighter; highlight-to-trough is gentler; foam sits in the band just inside the binary shore retreat.
@@ -210,7 +210,6 @@ const WATER_GROUND_FRAG = [
210
210
" vec2 puv = px / 16.0;",
211
211
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
212
212
" float t = u_time;",
213
// Scroll XY (flow) + mild Z ripple so the field actually travels.
214
213
" vec2 flow = vec2(t * 0.22, t * 0.14);",
215
214
" float eps = 0.10;",
216
215
" vec3 base = vec3(world * 0.85 + flow, t * 0.35);",
@@ -222,64 +221,46 @@ const WATER_GROUND_FRAG = [
222
221
" vec2 distort = vec2(nL - nR, nD - nU) * 0.14;",
223
222
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
224
223
" float h = nC * 0.9 + (texN - 0.5) * 0.22;",
225
// Flatter normals + light from top-left (screen: -X, -Y).
226
224
" vec3 normal = normalize(vec3(nL - nR, nD - nU, 0.85));",
227
225
" float ndotl = clamp(dot(normal, normalize(vec3(-0.55, -0.5, 0.75))), 0.0, 1.0);",
228
226
" float wave = h * 0.5 + 0.5;",
229
// Soft diffuse water — crest highlights only, no varnish/fresnel shell.
230
" float crest = smoothstep(0.58, 0.82, wave);",
231
" float glitter = pow(max(0.0, ndotl), 3.5) * crest * 0.45;",
227
// Brighter, tighter sparkles on crests (still matte body).
228
" float crest = smoothstep(0.62, 0.88, wave);",
229
" float glitter = max(pow(max(0.0, ndotl), 6.0) * crest, pow(crest, 3.2) * 0.65);",
232
230
" float edgeProx = 0.0;",
233
" float foamBand = 0.0;",
234
" float pxBand = 3.0 / 16.0;",
235
" if (u_edgeN > 0.5) {",
236
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y));",
237
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, puv.y));",
238
" }",
239
" if (u_edgeS > 0.5) {",
240
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y));",
241
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, 1.0 - puv.y));",
242
" }",
243
" if (u_edgeW > 0.5) {",
244
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x));",
245
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, puv.x));",
246
" }",
247
" if (u_edgeE > 0.5) {",
248
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x));",
249
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, 1.0 - puv.x));",
250
" }",
231
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
232
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
233
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
234
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
251
235
" if (u_edgeNE > 0.5) {",
252
236
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, puv.y))));",
253
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(1.0 - puv.x, puv.y))));",
254
237
" }",
255
238
" if (u_edgeNW > 0.5) {",
256
239
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, puv.y))));",
257
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(puv.x, puv.y))));",
258
240
" }",
259
241
" if (u_edgeSE > 0.5) {",
260
242
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
261
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
262
243
" }",
263
244
" if (u_edgeSW > 0.5) {",
264
245
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, 1.0 - puv.y))));",
265
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(puv.x, 1.0 - puv.y))));",
266
246
" }",
267
247
" float waveBody = wave * (1.0 - edgeProx * 0.72);",
268
248
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",
269
249
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",
270
250
" float deepMix = mix(deepTop, deepBot, puv.y);",
271
" vec3 deepCol = mix(vec3(0.12, 0.36, 0.56), vec3(0.03, 0.09, 0.20), deepMix);",
272
" vec3 midCol = mix(vec3(0.22, 0.52, 0.70), vec3(0.07, 0.22, 0.40), deepMix);",
273
" vec3 litCol = mix(vec3(0.48, 0.74, 0.88), vec3(0.22, 0.45, 0.66), deepMix);",
274
" vec3 sparkCol = mix(vec3(0.82, 0.92, 0.98), vec3(0.55, 0.74, 0.88), deepMix);",
275
" vec3 foamCol = vec3(0.90, 0.97, 1.0);",
276
// Height-driven body + gentle top-left diffuse (matte, not plastic).
277
" float shade = mix(0.78, 1.08, ndotl);",
278
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.28, 0.58, waveBody));",
279
" rgb = mix(rgb, litCol, smoothstep(0.48, 0.85, waveBody) * 0.55);",
251
// Deep stays blue (not near-black).
252
" vec3 deepCol = mix(vec3(0.14, 0.38, 0.58), vec3(0.08, 0.24, 0.44), deepMix);",
253
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",
254
" vec3 litCol = mix(vec3(0.50, 0.76, 0.90), vec3(0.28, 0.50, 0.70), deepMix);",
255
" vec3 sparkCol = mix(vec3(0.95, 0.99, 1.0), vec3(0.70, 0.88, 0.98), deepMix);",
256
" vec3 foamCol = vec3(0.92, 0.98, 1.0);",
257
// Gentler crest↔trough ramp.
258
" float shade = mix(0.88, 1.06, ndotl);",
259
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.20, 0.68, waveBody));",
260
" rgb = mix(rgb, litCol, smoothstep(0.42, 0.95, waveBody) * 0.42);",
280
261
" rgb *= shade;",
281
" rgb = mix(rgb, sparkCol, glitter * (1.0 - edgeProx * 0.85));",
282
" rgb = mix(rgb, deepCol, edgeProx * 0.55);",
262
" rgb = mix(rgb, sparkCol, clamp(glitter * 1.15, 0.0, 1.0) * (1.0 - edgeProx * 0.75));",
263
" rgb = mix(rgb, deepCol, edgeProx * 0.45);",
283
264
" float shoreW = 0.0;",
284
265
" vec3 shoreRgb = rgb;",
285
266
" if (u_edgeN > 0.5) {",
@@ -295,10 +276,14 @@ const WATER_GROUND_FRAG = [
295
276
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
296
277
" }",
297
278
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",
298
" float shoreMask = step(0.42, edgeProx * (0.35 + 0.65 * darkAmt)) * shoreW;",
279
" float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",
280
" float shoreClip = 0.42;",
281
" float shoreMask = step(shoreClip, retreat) * shoreW;",
282
// Foam on the last ~2–3 water pixels *before* the shore clip, not on the quad rim.
283
" float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",
284
" * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",
285
" rgb = mix(rgb, foamCol, foamAmt * 0.95);",
299
286
" rgb = mix(rgb, shoreRgb, shoreMask);",
300
// Last 2–3 water pixels along the coast → white foam.
301
" rgb = mix(rgb, foamCol, foamBand * (1.0 - shoreMask) * 0.92);",
302
287
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
303
288
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
304
289
" float lit = mix(litTop, litBottom, v_texCoord.y);",
@@ -210,7 +210,6 @@ const WATER_GROUND_FRAG = [210
" vec2 puv = px / 16.0;",210
" vec2 puv = px / 16.0;",211
" vec2 world = vec2(u_tileX, u_tileY) + puv;",211
" vec2 world = vec2(u_tileX, u_tileY) + puv;",212
" float t = u_time;",212
" float t = u_time;",213
// Scroll XY (flow) + mild Z ripple so the field actually travels.214
" vec2 flow = vec2(t * 0.22, t * 0.14);",213
" vec2 flow = vec2(t * 0.22, t * 0.14);",215
" float eps = 0.10;",214
" float eps = 0.10;",216
" vec3 base = vec3(world * 0.85 + flow, t * 0.35);",215
" vec3 base = vec3(world * 0.85 + flow, t * 0.35);",@@ -222,64 +221,46 @@ const WATER_GROUND_FRAG = [222
" vec2 distort = vec2(nL - nR, nD - nU) * 0.14;",221
" vec2 distort = vec2(nL - nR, nD - nU) * 0.14;",223
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",222
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",224
" float h = nC * 0.9 + (texN - 0.5) * 0.22;",223
" float h = nC * 0.9 + (texN - 0.5) * 0.22;",225
// Flatter normals + light from top-left (screen: -X, -Y).226
" vec3 normal = normalize(vec3(nL - nR, nD - nU, 0.85));",224
" vec3 normal = normalize(vec3(nL - nR, nD - nU, 0.85));",227
" float ndotl = clamp(dot(normal, normalize(vec3(-0.55, -0.5, 0.75))), 0.0, 1.0);",225
" float ndotl = clamp(dot(normal, normalize(vec3(-0.55, -0.5, 0.75))), 0.0, 1.0);",228
" float wave = h * 0.5 + 0.5;",226
" float wave = h * 0.5 + 0.5;",229
// Soft diffuse water — crest highlights only, no varnish/fresnel shell.227
// Brighter, tighter sparkles on crests (still matte body).230
" float crest = smoothstep(0.58, 0.82, wave);",228
" float crest = smoothstep(0.62, 0.88, wave);",231
" float glitter = pow(max(0.0, ndotl), 3.5) * crest * 0.45;",229
" float glitter = max(pow(max(0.0, ndotl), 6.0) * crest, pow(crest, 3.2) * 0.65);",232
" float edgeProx = 0.0;",230
" float edgeProx = 0.0;",233
" float foamBand = 0.0;",231
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",234
" float pxBand = 3.0 / 16.0;",232
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",235
" if (u_edgeN > 0.5) {",233
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",236
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y));",234
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",237
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, puv.y));",238
" }",239
" if (u_edgeS > 0.5) {",240
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y));",241
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, 1.0 - puv.y));",242
" }",243
" if (u_edgeW > 0.5) {",244
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x));",245
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, puv.x));",246
" }",247
" if (u_edgeE > 0.5) {",248
" edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x));",249
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, 1.0 - puv.x));",250
" }",251
" if (u_edgeNE > 0.5) {",235
" if (u_edgeNE > 0.5) {",252
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, puv.y))));",236
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, puv.y))));",253
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(1.0 - puv.x, puv.y))));",254
" }",237
" }",255
" if (u_edgeNW > 0.5) {",238
" if (u_edgeNW > 0.5) {",256
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, puv.y))));",239
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, puv.y))));",257
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(puv.x, puv.y))));",258
" }",240
" }",259
" if (u_edgeSE > 0.5) {",241
" if (u_edgeSE > 0.5) {",260
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",242
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",261
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",262
" }",243
" }",263
" if (u_edgeSW > 0.5) {",244
" if (u_edgeSW > 0.5) {",264
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, 1.0 - puv.y))));",245
" edgeProx = max(edgeProx, smoothstep(0.72, 0.0, length(vec2(puv.x, 1.0 - puv.y))));",265
" foamBand = max(foamBand, 1.0 - smoothstep(0.0, pxBand, length(vec2(puv.x, 1.0 - puv.y))));",266
" }",246
" }",267
" float waveBody = wave * (1.0 - edgeProx * 0.72);",247
" float waveBody = wave * (1.0 - edgeProx * 0.72);",268
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",248
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",269
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",249
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",270
" float deepMix = mix(deepTop, deepBot, puv.y);",250
" float deepMix = mix(deepTop, deepBot, puv.y);",271
" vec3 deepCol = mix(vec3(0.12, 0.36, 0.56), vec3(0.03, 0.09, 0.20), deepMix);",251
// Deep stays blue (not near-black).272
" vec3 midCol = mix(vec3(0.22, 0.52, 0.70), vec3(0.07, 0.22, 0.40), deepMix);",252
" vec3 deepCol = mix(vec3(0.14, 0.38, 0.58), vec3(0.08, 0.24, 0.44), deepMix);",273
" vec3 litCol = mix(vec3(0.48, 0.74, 0.88), vec3(0.22, 0.45, 0.66), deepMix);",253
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",274
" vec3 sparkCol = mix(vec3(0.82, 0.92, 0.98), vec3(0.55, 0.74, 0.88), deepMix);",254
" vec3 litCol = mix(vec3(0.50, 0.76, 0.90), vec3(0.28, 0.50, 0.70), deepMix);",275
" vec3 foamCol = vec3(0.90, 0.97, 1.0);",255
" vec3 sparkCol = mix(vec3(0.95, 0.99, 1.0), vec3(0.70, 0.88, 0.98), deepMix);",276
// Height-driven body + gentle top-left diffuse (matte, not plastic).256
" vec3 foamCol = vec3(0.92, 0.98, 1.0);",277
" float shade = mix(0.78, 1.08, ndotl);",257
// Gentler crest↔trough ramp.278
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.28, 0.58, waveBody));",258
" float shade = mix(0.88, 1.06, ndotl);",279
" rgb = mix(rgb, litCol, smoothstep(0.48, 0.85, waveBody) * 0.55);",259
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.20, 0.68, waveBody));",260
" rgb = mix(rgb, litCol, smoothstep(0.42, 0.95, waveBody) * 0.42);",280
" rgb *= shade;",261
" rgb *= shade;",281
" rgb = mix(rgb, sparkCol, glitter * (1.0 - edgeProx * 0.85));",262
" rgb = mix(rgb, sparkCol, clamp(glitter * 1.15, 0.0, 1.0) * (1.0 - edgeProx * 0.75));",282
" rgb = mix(rgb, deepCol, edgeProx * 0.55);",263
" rgb = mix(rgb, deepCol, edgeProx * 0.45);",283
" float shoreW = 0.0;",264
" float shoreW = 0.0;",284
" vec3 shoreRgb = rgb;",265
" vec3 shoreRgb = rgb;",285
" if (u_edgeN > 0.5) {",266
" if (u_edgeN > 0.5) {",@@ -295,10 +276,14 @@ const WATER_GROUND_FRAG = [295
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",276
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",296
" }",277
" }",297
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",278
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",298
" float shoreMask = step(0.42, edgeProx * (0.35 + 0.65 * darkAmt)) * shoreW;",279
" float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",280
" float shoreClip = 0.42;",281
" float shoreMask = step(shoreClip, retreat) * shoreW;",282
// Foam on the last ~2–3 water pixels *before* the shore clip, not on the quad rim.283
" float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",284
" * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",285
" rgb = mix(rgb, foamCol, foamAmt * 0.95);",299
" rgb = mix(rgb, shoreRgb, shoreMask);",286
" rgb = mix(rgb, shoreRgb, shoreMask);",300
// Last 2–3 water pixels along the coast → white foam.301
" rgb = mix(rgb, foamCol, foamBand * (1.0 - shoreMask) * 0.92);",302
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",287
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",303
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",288
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",304
" float lit = mix(litTop, litBottom, v_texCoord.y);",289
" float lit = mix(litTop, litBottom, v_texCoord.y);",