Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
Add fishing-rod bank pickups and a shader-driven pond water surface for /play
nirholase9cbe95dd22c
diff --git a/multiplayer/src/activities.js b/multiplayer/src/activities.jsindex 1e459c1f1..cb425376e 100644--- a/multiplayer/src/activities.js+++ b/multiplayer/src/activities.js@@ -17,12 +17,12 @@ import { addItem, hasRoomFor, countItem, removeItem } from './economy.js';import {itemLabel, gatherChance, gatherDoubleChance, coalBonusChance, cookBurnChance,} from './items.js';-import { treeInRange, rockInRange, firepitInRange } from './world-features.js';+import { treeInRange, rockInRange, firepitInRange, rodPickupInRange } from './world-features.js';// Per-swing cadence on the real clock (ms). The handlers tolerate a profile whose// `cd` map predates these keys — `now < undefined` is false, so a missing key just// means "ready now", and the first action arms it.-export const ACTIVITY_COOLDOWN_MS = { chop: 1300, mine: 1500, cook: 900 };+export const ACTIVITY_COOLDOWN_MS = { chop: 1300, mine: 1500, cook: 900, pickupRod: 8000 };// The two gather activities differ only in tool, node, resource and the mining-only// coal bonus — so one config table drives both through the shared core below.@@ -153,10 +153,41 @@ export function handleCook(room, client) {room._persistEcon(client.sessionId);}-// Wire the three intents onto a room. Called once from WalkRoom.onCreate — the room's+// Grab a spare rod from a world pickup. No tool or skill gates this (it's a free+// prop, not a resource node) — just proximity, cooldown and pack space. Mirrors+// _handleFish's shape for a non-stackable tool instead of a resource stack.+export function handlePickupRod(room, client) {+ const player = room.state.players.get(client.sessionId);+ const profile = room.econ.get(client.sessionId);+ if (!player || !profile) return;+ if (!room._actionOk(client.sessionId, 'pickupRod')) return;++ const now = Date.now();+ if (profile.cd && now < profile.cd.pickupRod) return;++ const node = rodPickupInRange(player.x, player.z);+ if (!node) {+ client.send('notice', { kind: 'pickupRod', text: 'Move up to a rod stand to pick it up.' });+ return;+ }+ if (!hasRoomFor(profile, 'rod')) {+ client.send('notice', { kind: 'full', text: 'Your inventory is full.' });+ return;+ }++ if (profile.cd) profile.cd.pickupRod = now + ACTIVITY_COOLDOWN_MS.pickupRod;+ addItem(profile, 'rod', 1);+ room._questEvent?.(client, profile, { type: 'collect', item: 'rod', qty: 1 });+ room._sendInv(client, profile);+ client.send('notice', { kind: 'pickupRod', got: 1, node: node.id, text: `Picked up a ${itemLabel('rod').toLowerCase()}.` });+ room._persistEcon(client.sessionId);+}++// Wire the four intents onto a room. Called once from WalkRoom.onCreate — the room's// only obligation, keeping the gather/craft logic out of the room file entirely.export function registerActivityHandlers(room) {room.onMessage('chop', (client) => handleGather(room, client, 'chop'));room.onMessage('mine', (client) => handleGather(room, client, 'mine'));room.onMessage('cook', (client) => handleCook(room, client));+ room.onMessage('pickupRod', (client) => handlePickupRod(room, client));}diff --git a/multiplayer/src/rooms/WalkRoom.js b/multiplayer/src/rooms/WalkRoom.jsindex 376279af0..7e9984606 100644--- a/multiplayer/src/rooms/WalkRoom.js+++ b/multiplayer/src/rooms/WalkRoom.js@@ -268,7 +268,7 @@ const COOK_COOLDOWN_MS = 900; // pace between fish on the fire// vsync rides at the same 15Hz the move netcode uses; allow 2× for jitter, like// MOVES_PER_SEC_LIMIT. enter/exit are deliberate, rare actions.const ACTION_RATES = {- fish: 6, consume: 6, equip: 30, chop: 6, mine: 6, cook: 8, vsync: PATCH_RATE_HZ * 2,+ fish: 6, consume: 6, equip: 30, chop: 6, mine: 6, cook: 8, pickupRod: 4, vsync: PATCH_RATE_HZ * 2,venter: 4, vexit: 4, quest: 8, questInteract: 6, clear: 2,// General store, bank/ATM, and the $THREE boutique (W04) — low-frequency,// currency-mutating actions, throttled tighter than the gather loop.@@ -721,7 +721,7 @@ export class WalkRoom extends Room {if (!this.state.players.has(client.sessionId)) return;const saved = loadPlayer(playerId);const profile = restoreProfile(saved?.profile, playerId);- profile.cd = { fish: 0, consume: 0, chop: 0, mine: 0, cook: 0, attack: 0 }; // per-action cooldown clocks (runtime only)+ profile.cd = { fish: 0, consume: 0, chop: 0, mine: 0, cook: 0, attack: 0, pickupRod: 0 }; // per-action cooldown clocks (runtime only)// Quest log (W05): the player's accepted/completed missions + daily state,// persisted alongside the pack/purse. Stale dailies roll over to today on load.profile.quests = restoreQuestState(saved?.profile?.quests, utcDayKey());diff --git a/multiplayer/src/world-features.js b/multiplayer/src/world-features.jsindex 31ece648c..a6dedb1ee 100644--- a/multiplayer/src/world-features.js+++ b/multiplayer/src/world-features.js@@ -113,6 +113,22 @@ export const COOK_REACH = 2.6;export function nearestFirepit(x, z) { return nearestNode(x, z, FIREPITS, COOK_REACH); }export function firepitInRange(x, z) { return nodeInRange(x, z, FIREPITS, COOK_REACH); }+// Fishing-rod pickups — a spare rod waiting on the bank for anyone without one+// (or anyone who wants a backup to store). Every player already starts with a+// rod in the hotbar and it's never lost on death, so these exist for+// discoverability and flavour, not survival: sited just past each pond's cast+// ring (clear of FISH_REACH, so the Cast and Pick-up prompts never overlap)+// plus one in the plaza for a brand-new player who wanders before their first+// cast. `r` matches the small prop footprint the client renders.+export const ROD_PICKUPS = [+ { id: 'rod-dock-east', x: 40, z: 11, r: 0.6 },+ { id: 'rod-dock-west', x: -37, z: 21, r: 0.6 },+ { id: 'rod-plaza', x: 12, z: 12, r: 0.6 },+];+export const PICKUP_REACH = 2.4;+export function nearestRodPickup(x, z) { return nearestNode(x, z, ROD_PICKUPS, PICKUP_REACH); }+export function rodPickupInRange(x, z) { return nodeInRange(x, z, ROD_PICKUPS, PICKUP_REACH); }+// Mob spawn points — used by W07 combat and the ACTIVITIES dispatch in play-systems.export const MOB_SPAWNS = [{ id: 'mob-danger-n', x: 0, z: -60, r: 1.5 },diff --git a/server/index.mjs b/server/index.mjsindex be6480250..49efde5b7 100644--- a/server/index.mjs+++ b/server/index.mjs@@ -66,6 +66,44 @@ function substitute(template, match) {const isExternalDest = (dest) => /^https?:\/\//.test(dest || '');+// Vercel `has` conditions (query/header/cookie/host presence + optional regex+// value) gate a route to only the requests it's meant for — e.g. the /app and+// /agents/:id OG rules only fire for social-preview bots. Every entry must+// match against the ORIGINAL request (url/headers), independent of any dest+// rewrite already applied earlier in the same phase-1 pass.+function hasMatches(route, req, url) {+ if (!route.has) return true;+ for (const cond of route.has) {+ let val;+ if (cond.type === 'query') val = url.searchParams.get(cond.key);+ else if (cond.type === 'header') val = req.headers[cond.key.toLowerCase()];+ else if (cond.type === 'cookie') {+ const raw = req.headers.cookie || '';+ const m = raw.match(new RegExp(`(?:^|;\\s*)${cond.key}=([^;]*)`));+ val = m ? decodeURIComponent(m[1]) : undefined;+ } else if (cond.type === 'host') val = req.headers.host;+ else continue;+ if (val == null) return false;+ if (cond.value !== undefined && !compileHasValue(cond.value).test(val)) return false;+ }+ return true;+}++// Vercel `has[].value` patterns may carry a leading Perl-style `(?i)` inline+// case-insensitive flag, which native RegExp rejects as an invalid group —+// strip it and apply the `i` flag instead. Compiled patterns are cached since+// the same route's has[] is re-evaluated on every matching request.+const hasValueCache = new Map();+function compileHasValue(value) {+ let re = hasValueCache.get(value);+ if (!re) {+ const caseInsensitive = value.startsWith('(?i)');+ re = new RegExp(caseInsensitive ? value.slice(4) : value, caseInsensitive ? 'i' : undefined);+ hasValueCache.set(value, re);+ }+ return re;+}+// ---------------------------------------------------------------------------// External-URL dests (reverse proxy), e.g. /ingest/* → PostHog.// ---------------------------------------------------------------------------@@ -309,10 +347,12 @@ app.use(compression());// External-dest proxy — before the body parsers (see proxyExternal above).app.use((req, res, next) => {- const pathname = new URL(req.url, 'http://internal').pathname;+ const url = new URL(req.url, 'http://internal');+ const pathname = url.pathname;for (const route of phase1Routes) {const m = route.re.exec(pathname);if (!m) continue;+ if (!hasMatches(route, req, url)) continue;if (route.continue) continue;if (!route.dest || !isExternalDest(route.dest)) break; // a local rule wins — fall throughconst search = req.url.includes('?') ? req.url.slice(req.url.indexOf('?')) : '';@@ -351,6 +391,7 @@ app.use(async (req, res) => {for (const route of phase1Routes) {const m = route.re.exec(currentPath);if (!m) continue;+ if (!hasMatches(route, req, url)) continue;if (route.headers) {for (const [k, v] of Object.entries(route.headers)) collected[k] = substitute(v, m);}@@ -395,6 +436,7 @@ app.use(async (req, res) => {for (const route of postFsRoutes) {const m = route.re.exec(currentPath);if (!m) continue;+ if (!hasMatches(route, req, url)) continue;if (route.headers) {for (const [k, v] of Object.entries(route.headers)) collected[k] = substitute(v, m);}diff --git a/src/game/coincommunities.js b/src/game/coincommunities.jsindex 9328945aa..121db31ab 100644--- a/src/game/coincommunities.js+++ b/src/game/coincommunities.js@@ -62,6 +62,7 @@ import { requestHolderPass, signInWithX, ensureSolanaWallet, relinkSolanaWallet,import { ensurePlayAccess } from './play-gate.js';import { clearStoredPass, refreshPlayPass, loadStoredPass, storePass } from './play-auth.js';import { PlaySystems } from './play-systems.js';+import { PlayActivities } from './play-activities.js';import { PlayOnboard } from './play-onboard.js';import { log } from '../shared/log.js';import { openAvatarInspector, isAvatarInspectorOpen, closeAvatarInspector } from '../shared/avatar-inspector.js';@@ -1129,6 +1130,16 @@ export class CoinCommunities {getPlayer: () => ({ x: this.localPos.x, y: this.localPos.y, z: this.localPos.z, yaw: this.localYaw, height: this.localHeight || 1.6 }),net: this.net,ui: this.ui,+ env: this.env,+ });+ // W06: gather/craft stations (trees, rocks, roast pits) and the fishing-rod+ // pickups scattered around the world. Sibling of PlaySystems — see+ // play-activities.js's header for why they stay decoupled.+ this.playActivities = new PlayActivities({+ scene: this.scene,+ getPlayer: () => ({ x: this.localPos.x, y: this.localPos.y, z: this.localPos.z, yaw: this.localYaw, height: this.localHeight || 1.6 }),+ net: this.net,+ ui: this.ui,});this.net.on('profile', (snap) => { this.playSystems?.setProfile(snap); this._onCosmeticsProfile(snap); });this.net.on('inv', (delta) => this.playSystems?.applyInv(delta));@@ -1485,6 +1496,7 @@ export class CoinCommunities {if (this.vehicles) { this.vehicles.dispose(); this.vehicles = null; }if (this.combat) { this.combat.dispose(); this.combat = null; }if (this.playSystems) { this.playSystems.dispose(); this.playSystems = null; }+ if (this.playActivities) { this.playActivities.dispose(); this.playActivities = null; }if (this.agentCommerce) { this.agentCommerce.dispose(); this.agentCommerce = null; }if (this.intelKiosk) { this.intelKiosk.dispose(); this.intelKiosk = null; }if (this.worldLife) { this.worldLife.dispose(); this.worldLife = null; }@@ -2298,12 +2310,13 @@ export class CoinCommunities {return;}// F is contextual: enter/exit a nearby vehicle takes priority (the- // on-screen prompt already says "F — Drive" / "F — Exit"); otherwise it- // casts a line when standing by a pond (no-op elsewhere). Not while+ // on-screen prompt already says "F — Drive" / "F — Exit"); then a+ // gather/craft/pickup station (chop, mine, cook, grab a rod); otherwise+ // it casts a line when standing by a pond (no-op elsewhere). Not while// building, where keys drive the block palette.if (k === 'f' && !this.buildHud.active) {e.preventDefault();- if (!this.vehicles?.interact()) this.playSystems?.castFish();+ if (!this.vehicles?.interact() && !this.playActivities?.doAction()) this.playSystems?.castFish();return;}// I inspects the nearest avatar — player, townsperson, or yourself:@@ -3124,6 +3137,7 @@ export class CoinCommunities {this._tickKingZone(dt);this._updateVoice();this.playSystems?.tick(dt);+ this.playActivities?.tick(dt);this.agentCommerce?.tick(dt);this.intelKiosk?.tick(dt);if (this.worldLife) { this.worldLife.setRealPeers(this.remotes.size); this.worldLife.tick(dt); }diff --git a/src/game/community-net.js b/src/game/community-net.jsindex 1c39aef47..2542b3361 100644--- a/src/game/community-net.js+++ b/src/game/community-net.js@@ -550,6 +550,7 @@ export class CommunityNet {chop() { this._send('chop'); }mine() { this._send('mine'); }cook() { this._send('cook'); }+ pickupRod() { this._send('pickupRod'); }attack() { this._send('attack'); }// Claim a tombstone's cash + items (W07). Server-gated by proximity; the// result rides back over the usual profile/inv/notice channels.diff --git a/src/game/play-activities.js b/src/game/play-activities.jsindex 1aa81ddff..3383ae497 100644--- a/src/game/play-activities.js+++ b/src/game/play-activities.js@@ -1,9 +1,11 @@// Play activities — the gather→craft layer for the /play coin worlds (W06).//// The chop/mine/cook counterpart to PlaySystems' fishing: it renders the world's-// gather/craft stations (a grove of trees, a quarry of rocks, two roast pits), gates-// a single contextual action prompt as the player walks up to one, plays the local-// 3D feedback (chips, shards, embers, a flaring fire), and sends the intent. Every+// gather/craft/pickup stations (a grove of trees, a quarry of rocks, two roast pits,+// and a few spare fishing rods leaning on the bank for anyone to grab), gates a+// single contextual action prompt as the player walks up to one, plays the local+// 3D feedback (chips, shards, embers, a flaring fire, a rod wobble), and sends the+// intent. Every// yield, XP gain and level-up is rolled SERVER-side (WalkRoom → activities.js) and// streamed back over the same profile/inv/xpgain/levelup/notice events PlaySystems// already renders into the HUD — so this module never simulates a result locally.@@ -18,22 +20,25 @@import {Group, Mesh, Vector3,- RingGeometry, CylinderGeometry, ConeGeometry, BoxGeometry, IcosahedronGeometry,+ RingGeometry, CylinderGeometry, ConeGeometry, BoxGeometry, IcosahedronGeometry, SphereGeometry,MeshStandardMaterial, MeshBasicMaterial, DoubleSide,} from 'three';import {TREES, nearestTree, ROCKS, nearestRock, FIREPITS, nearestFirepit,+ ROD_PICKUPS, nearestRodPickup,} from '../../multiplayer/src/world-features.js';import { itemDisplay } from './items.js';-// The three gather/craft activities. Each knows the tool the player must hold (null-// for cooking — the fire is the station), the nearest-node finder (shared with the-// server so the range rule never drifts), and how the prompt + 3D feedback read.+// The four gather/craft/pickup activities. Each knows the tool the player must hold+// (null for cooking and the rod pickup — no tool gates either), the nearest-node+// finder (shared with the server so the range rule never drifts), and how the+// prompt + 3D feedback read.const ACTIVITIES = [{ type: 'chop', tool: 'axe', skill: 'woodcutting', near: nearestTree, label: 'Chop', glyph: '🪓', noTool: 'Equip an axe', fx: 0x8a5a32 },{ type: 'mine', tool: 'pickaxe', skill: 'mining', near: nearestRock, label: 'Mine', glyph: '⛏️', noTool: 'Equip a pickaxe', fx: 0xb8c0cc },{ type: 'cook', tool: null, skill: 'cooking', near: nearestFirepit, label: 'Cook fish', glyph: '🍳', noTool: '', fx: 0xffa53a },+ { type: 'pickupRod', tool: null, skill: null, near: nearestRodPickup, label: 'Pick up rod', glyph: '🎣', noTool: '', fx: 0xbfeaff },];function el(tag, props = {}, kids = []) {@@ -126,6 +131,7 @@ export class PlayActivities {for (const t of TREES) group.add(this._buildTree(t));for (const r of ROCKS) group.add(this._buildRock(r));for (const f of FIREPITS) group.add(this._buildFirepit(f));+ for (const p of ROD_PICKUPS) group.add(this._buildRodPickup(p));this.scene.add(group);this._group = group;}@@ -188,9 +194,53 @@ export class PlayActivities {return g;}+ // A spare rod leaning against a bank post — a stubby post, the rod resting at+ // an angle with a small reel at its base, and a line running down to a bobber+ // so the silhouette reads as "fishing rod" even from across the bank.+ _buildRodPickup(node) {+ const g = new Group();+ g.position.set(node.x, 0, node.z);++ const woodMat = new MeshStandardMaterial({ color: 0x6b4a2e, roughness: 0.9 });+ const post = new Mesh(new CylinderGeometry(0.07, 0.09, 0.85, 8), woodMat);+ post.position.y = 0.42; post.castShadow = true; g.add(post);++ // The rod sits in its own pivot at rotation.z = 0 so the shared hit-shake+ // path (which resets hitNode.rotation.z to 0 on decay) wobbles it without+ // ever losing its resting lean — that lean lives on the child mesh instead.+ const rodPivot = new Group();+ rodPivot.position.set(0.08, 0.75, 0);+ g.add(rodPivot);+ const rodMat = new MeshStandardMaterial({ color: 0x8a5a32, roughness: 0.7 });+ const rod = new Mesh(new CylinderGeometry(0.014, 0.032, 1.5, 6), rodMat);+ rod.rotation.z = Math.PI * 0.16;+ rod.castShadow = true;+ rodPivot.add(rod);++ const reel = new Mesh(new SphereGeometry(0.07, 10, 8), new MeshStandardMaterial({ color: 0x2b2f38, roughness: 0.5, metalness: 0.4 }));+ reel.position.set(-0.08, 0.36, 0);+ g.add(reel);++ const line = new Mesh(new CylinderGeometry(0.006, 0.006, 0.62, 4), new MeshStandardMaterial({ color: 0xdfe6ea, roughness: 0.4 }));+ line.position.set(0.5, 0.68, 0);+ line.rotation.z = Math.PI * 0.02;+ g.add(line);++ const bobber = new Mesh(new SphereGeometry(0.06, 10, 8), new MeshStandardMaterial({ color: 0xff4d4d, roughness: 0.5 }));+ bobber.position.set(0.52, 0.37, 0);+ g.add(bobber);++ const marker = this._marker(node.r + 0.5, 0xbfeaff); g.add(marker);+ // hitNode gives the pickup the same little wobble chop/mine play on a hit+ // (tick()'s shared shake path — any non-'mine' station rotates on its Z).+ this._stations.push({ type: 'pickupRod', id: node.id, marker, anchor: { x: node.x, z: node.z }, hitNode: rodPivot, baseY: rodPivot.position.y });+ return g;+ }+_stationById(id) { return this._stations.find((s) => s.id === id) || null; }_nodeById(id) {- return TREES.find((n) => n.id === id) || ROCKS.find((n) => n.id === id) || FIREPITS.find((n) => n.id === id) || null;+ return TREES.find((n) => n.id === id) || ROCKS.find((n) => n.id === id) || FIREPITS.find((n) => n.id === id)+ || ROD_PICKUPS.find((n) => n.id === id) || null;}// ---------------------------------------------------------------- prompt DOM@@ -247,10 +297,14 @@ export class PlayActivities {const hasTool = this._hotbar.some((s) => s.item === def.tool);label = holding === def.tool ? `${def.glyph} ${def.label}` : hasTool ? `${def.glyph} Equip ${itemDisplay(def.tool).name.toLowerCase()}` : `${def.glyph} ${def.noTool}`;disabled = !hasTool;- } else {+ } else if (def.type === 'cook') {const hasFish = this._inv.some((s) => s.item === 'fish');label = `${def.glyph} ${def.label}`;disabled = !hasFish;+ } else {+ // pickupRod: a free prop with no precondition beyond being in range.+ label = `${def.glyph} ${def.label}`;+ disabled = false;}this.btn.textContent = label;this.btn.classList.toggle('is-disabled', disabled);diff --git a/src/game/play-systems.js b/src/game/play-systems.jsindex 8581a3544..3fb7d8348 100644--- a/src/game/play-systems.js+++ b/src/game/play-systems.js@@ -18,9 +18,10 @@import {Group, Mesh, Color, Vector3,CircleGeometry, RingGeometry, CylinderGeometry, SphereGeometry, ConeGeometry, BoxGeometry, IcosahedronGeometry,- MeshStandardMaterial, MeshBasicMaterial,+ MeshStandardMaterial, MeshBasicMaterial, ShaderMaterial,BufferGeometry, Line, LineBasicMaterial, Float32BufferAttribute, DoubleSide,} from 'three';+import { WATER_VERTEX_SHADER, WATER_FRAGMENT_SHADER } from './water-shader.js';import {FISHING_SPOTS, nearestFishingSpot,@@ -88,12 +89,17 @@ export class PlaySystems {* @param {() => ({x,y,z,yaw,height})} opts.getPlayer local avatar pose + height* @param {object} opts.net CommunityNet instance (fish/equip/consume intents)* @param {object} opts.ui CommunityUI instance (toast)+ * @param {object} [opts.env] world-env instance (createWorldEnvironment) — its+ * live sun direction/colour keep the pond's sparkle in sync with the day/night+ * cycle. Optional: ponds render fine with a fixed sun when a world has none.*/- constructor({ scene, getPlayer, net, ui }) {+ constructor({ scene, getPlayer, net, ui, env }) {this.scene = scene;this.getPlayer = getPlayer;this.net = net;this.ui = ui;+ this.env = env || null;+ this._waterMats = [];this.profile = null; // last full snapshot from the serverthis.skills = {}; // skill -> { level, xp, levelXp, nextXp }@@ -113,23 +119,39 @@ export class PlaySystems {_buildScene() {const group = new Group();group.name = 'play-ponds';- for (const spot of FISHING_SPOTS) {- group.add(this._buildPond(spot));- }+ FISHING_SPOTS.forEach((spot, i) => group.add(this._buildPond(spot, i)));this.scene.add(group);this._pondGroup = group;}- // A pond: a dark reflective water disc, a bright rim, a soft pulsing marker ring- // (so it reads as an interactable from across the plaza), and a few bank reeds.- _buildPond(spot) {+ // A pond: an animated shader water disc (real ripples + sun sparkle, no flat+ // fake tint), a bright rim, a soft pulsing marker ring (so it reads as an+ // interactable from across the plaza), and a few bank reeds.+ _buildPond(spot, index = 0) {const g = new Group();g.position.set(spot.x, 0, spot.z);- const water = new Mesh(- new CircleGeometry(spot.r, 48),- new MeshStandardMaterial({ color: 0x16323f, roughness: 0.18, metalness: 0.65, transparent: true, opacity: 0.94 }),- );+ const sunDir = this.env?.lights?.sun || new Vector3(0.6, 0.7, 0.3);+ const sunColor = this.env?.lights?.sunLight?.color || new Color(0xfff3d6);+ const skyColor = this.env?.biome?.sky?.[1] ? new Color(this.env.biome.sky[1]) : new Color(0xbfeaff);+ const waterMat = new ShaderMaterial({+ vertexShader: WATER_VERTEX_SHADER,+ fragmentShader: WATER_FRAGMENT_SHADER,+ transparent: true,+ uniforms: {+ uTime: { value: 0 },+ uPhase: { value: index * 11.3 }, // desyncs multiple ponds' ripples+ uDeep: { value: new Color(0x0c232c) },+ uShallow: { value: new Color(0x2f6a78) },+ uSunDir: { value: sunDir.clone().normalize() },+ uSunColor: { value: sunColor.clone() },+ uSkyColor: { value: skyColor },+ uOpacity: { value: 0.92 },+ },+ });+ this._waterMats.push(waterMat);++ const water = new Mesh(new CircleGeometry(spot.r, 48), waterMat);water.rotation.x = -Math.PI / 2;water.position.y = 0.04;water.receiveShadow = true;@@ -735,6 +757,18 @@ export class PlaySystems {this._nearSpot = near && near.gap <= 0 ? near : null;this._updateAction();+ // Advance the water ripple clock and keep the sparkle's light source in+ // sync with the world's live sun (it moves across the day/night cycle).+ if (this._waterMats.length) {+ const sunDir = this.env?.lights?.sun;+ const sunColor = this.env?.lights?.sunLight?.color;+ for (const mat of this._waterMats) {+ mat.uniforms.uTime.value = this._t;+ if (sunDir) mat.uniforms.uSunDir.value.copy(sunDir).normalize();+ if (sunColor) mat.uniforms.uSunColor.value.copy(sunColor);+ }+ }+// Pulse the marker ring of whichever pond is nearest so it reads as live.if (this._pondGroup) {const glow = 0.18 + Math.sin(this._t * 2) * 0.12;@@ -805,6 +839,7 @@ export class PlaySystems {});this._pondGroup = null;}+ this._waterMats = [];this.root?.remove();document.querySelectorAll('.ps-xp-float, .ps-levelup').forEach((n) => n.remove());}diff --git a/src/game/water-shader.js b/src/game/water-shader.jsnew file mode 100644index 000000000..640de4c6d--- /dev/null+++ b/src/game/water-shader.js@@ -0,0 +1,85 @@+// Procedural water shader — shared by every water body /play renders (the+// fishing ponds today; any lake/canal a later brief adds can reuse it).+//+// No texture, no extra render pass: the surface geometry stays a flat disc+// (cheap, no tessellation needed) and all of the "water" reads — rippling+// highlights, a fresnel sky-tint at grazing angles, a deep→shallow gradient —+// come from a fake bump normal derived analytically from a layered sine field+// evaluated in world space each fragment. That's the same trick stylised+// water in shipped games uses instead of a real-time planar reflection, which+// would cost a second scene render per pond and a normal-map asset neither of+// which this world has budget for.+//+// uSunDir/uSunColor are meant to be kept live from the world's own+// DirectionalLight (see play-systems.js `_buildPond`/`tick`) so the sparkle+// tracks the day/night cycle instead of a baked-in highlight.++export const WATER_VERTEX_SHADER = /* glsl */ `+varying vec2 vUv;+varying vec3 vWorldPos;++void main() {+ vUv = uv;+ vec4 wp = modelMatrix * vec4(position, 1.0);+ vWorldPos = wp.xyz;+ gl_Position = projectionMatrix * viewMatrix * wp;+}+`;++export const WATER_FRAGMENT_SHADER = /* glsl */ `+precision highp float;++uniform float uTime;+uniform float uPhase;+uniform vec3 uDeep;+uniform vec3 uShallow;+uniform vec3 uSunDir;+uniform vec3 uSunColor;+uniform vec3 uSkyColor;+uniform float uOpacity;++varying vec2 vUv;+varying vec3 vWorldPos;++// Layered sine field standing in for a real wave simulation — four waves at+// different frequency/speed/direction so the surface never reads as tiled.+float waveHeight(vec2 p, float t) {+ float w = 0.0;+ w += sin(p.x * 1.35 + t * 1.7) * 0.6;+ w += sin(p.y * 1.9 - t * 1.15) * 0.45;+ w += sin((p.x + p.y) * 0.85 + t * 0.65) * 0.5;+ w += sin((p.x - p.y) * 2.6 + t * 2.4) * 0.2;+ return w;+}++void main() {+ vec2 wp = vWorldPos.xz;+ float t = uTime + uPhase;++ // Finite-difference the height field for a shading normal — never touches+ // the actual vertex position, so the low-poly disc stays perfectly flat.+ float e = 0.35;+ float h0 = waveHeight(wp, t);+ float hx = waveHeight(wp + vec2(e, 0.0), t);+ float hy = waveHeight(wp + vec2(0.0, e), t);+ vec3 bump = normalize(vec3(-(hx - h0), e * 3.2, -(hy - h0)));+ vec3 N = normalize(mix(vec3(0.0, 1.0, 0.0), bump, 0.85));++ vec3 V = normalize(cameraPosition - vWorldPos);+ vec3 L = normalize(uSunDir);+ vec3 H = normalize(L + V);++ float fresnel = pow(1.0 - clamp(dot(N, V), 0.0, 1.0), 3.0);+ float edge = clamp(length(vUv - 0.5) * 2.0, 0.0, 1.0);+ vec3 base = mix(uDeep, uShallow, edge * edge * 0.6);++ float spec = pow(max(dot(N, H), 0.0), 70.0);+ float sparkle = pow(max(dot(N, H), 0.0), 340.0) * 2.2;++ vec3 color = mix(base, uSkyColor, fresnel * 0.5);+ color += uSunColor * (spec * 0.35 + sparkle);++ float alpha = clamp(uOpacity + fresnel * 0.08, 0.0, 1.0);+ gl_FragColor = vec4(color, alpha);+}+`;