Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(society): M3a look - shadows, toon ramp, bevels, shore water, clouds

rubenluetke10-beepe90ef2586125
diff --git a/docs/agent-society/world-masterplan-v2.md b/docs/agent-society/world-masterplan-v2.md
index 8debc6bc8d..01e66e2d07 100644
--- a/docs/agent-society/world-masterplan-v2.md
+++ b/docs/agent-society/world-masterplan-v2.md
@@ -1,8 +1,8 @@
# World Master Plan v2 — from the first island to a professional game world
-Status: **analysis and proposal, written 2026-09-02 after the maintainer saw island V1.** Nothing
-here is decided yet except where §9 says so; the maintainer's answers to §9 turn this into the
-binding successor of [`world-art-direction.md`](world-art-direction.md). Subordinate to
+Status: **binding since 2026-09-02** — the maintainer took the four recommended decisions of §9
+(grain off by default, one house per agent, the 15 hubs, the scripted Blender World Kit); this
+document succeeds [`world-art-direction.md`](world-art-direction.md) for everything it covers. Subordinate to
[`MASTERPLAN.md`](MASTERPLAN.md) (§2 decisions stay untouched: the world is a projection of the
society event stream, idle is LLM-free, dispatch is the scheduler's privilege).
@@ -263,7 +263,7 @@ Figures (character-pipeline F1–F7) run in parallel in the sibling session; `Wa
for `<Figure>` the day F3 lands. The Ledger, reduced motion and no-WebGL fallbacks stay as they
are.
-## 9. Decisions the maintainer owns
+## 9. Decisions (1–4 taken by the maintainer on 2026-09-02, the recommended option each time; 5–6 default until revisited)
1. **Pixel grain — Recommended: off by default, kept as a setting.** The named references (Roblox,
Clash of Clans) are smooth; the grain then serves as a look option and as the low-GPU fallback.
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Clouds.tsx b/jarvis/ui/web/frontend/src/components/society/world/Clouds.tsx
new file mode 100644
index 0000000000..f47d326ca8
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/Clouds.tsx
@@ -0,0 +1,105 @@
+/**
+ * A few soft clouds drifting high over the island. They are never seen from
+ * this camera — the point is their SHADOWS, which the sun's shadow map casts
+ * onto the ground as they pass: the slow-moving patches of shade that make a
+ * Clash-of-Clans village feel outdoors (world-masterplan-v2.md §3.7).
+ */
+import { useEffect, useMemo, useRef } from "react";
+import { useFrame } from "@react-three/fiber";
+import { CanvasTexture, DoubleSide, Group, MeshBasicMaterial, PlaneGeometry } from "three";
+
+import { hash2 } from "./islandLayout";
+
+const CLOUD_Y = 70;
+const CLOUD_COUNT = 4;
+/** Metres per second; the whole sky crosses the island in ~5 minutes. */
+const DRIFT_MPS = 1.1;
+const FIELD = 420;
+
+function makeCloudTexture(): CanvasTexture | null {
+ if (typeof document === "undefined") return null;
+ const c = document.createElement("canvas");
+ c.width = 128;
+ c.height = 128;
+ const ctx = c.getContext("2d");
+ if (!ctx) return null;
+ ctx.clearRect(0, 0, 128, 128);
+ // Three overlapping soft blobs: a cloud, not a disc.
+ for (const [x, y, r] of [
+ [50, 64, 34],
+ [78, 58, 30],
+ [64, 74, 26],
+ ]) {
+ const g = ctx.createRadialGradient(x, y, r * 0.3, x, y, r);
+ g.addColorStop(0, "rgba(255,255,255,1)");
+ g.addColorStop(1, "rgba(255,255,255,0)");
+ ctx.fillStyle = g;
+ ctx.fillRect(0, 0, 128, 128);
+ }
+ return new CanvasTexture(c);
+}
+
+export function Clouds({ paused }: { paused: boolean }) {
+ const group = useRef<Group>(null);
+ const texture = useMemo(makeCloudTexture, []);
+ const geometry = useMemo(() => new PlaneGeometry(1, 1), []);
+ const material = useMemo(
+ () =>
+ new MeshBasicMaterial({
+ map: texture ?? undefined,
+ transparent: true,
+ opacity: 0.0, // invisible from below/above — only its shadow matters
+ alphaTest: 0.45, // the depth material honours this: soft-edged shadow, hard cutoff
+ side: DoubleSide,
+ depthWrite: false,
+ }),
+ [texture],
+ );
+ const seeds = useMemo(
+ () =>
+ Array.from({ length: CLOUD_COUNT }, (_, i) => ({
+ x: (hash2(i, 1, 99) - 0.5) * FIELD,
+ z: (hash2(i, 2, 99) - 0.5) * FIELD,
+ s: 26 + hash2(i, 3, 99) * 22,
+ speed: 0.7 + hash2(i, 4, 99) * 0.6,
+ })),
+ [],
+ );
+
+ useEffect(
+ () => () => {
+ geometry.dispose();
+ material.dispose();
+ texture?.dispose();
+ },
+ [geometry, material, texture],
+ );
+
+ useFrame((_, dt) => {
+ const g = group.current;
+ if (!g || paused) return;
+ const step = Math.min(dt, 0.1) * DRIFT_MPS;
+ g.children.forEach((cloud, i) => {
+ cloud.position.x += step * seeds[i].speed;
+ cloud.position.z += step * seeds[i].speed * 0.35;
+ if (cloud.position.x > FIELD / 2) cloud.position.x -= FIELD;
+ if (cloud.position.z > FIELD / 2) cloud.position.z -= FIELD;
+ });
+ });
+
+ return (
+ <group ref={group}>
+ {seeds.map((s, i) => (
+ <mesh
+ key={i}
+ geometry={geometry}
+ material={material}
+ position={[s.x, CLOUD_Y, s.z]}
+ rotation={[-Math.PI / 2, 0, 0]}
+ scale={[s.s, s.s * 0.7, 1]}
+ castShadow
+ />
+ ))}
+ </group>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/PixelPass.tsx b/jarvis/ui/web/frontend/src/components/society/world/PixelPass.tsx
deleted file mode 100644
index 5e24e103f5..0000000000
--- a/jarvis/ui/web/frontend/src/components/society/world/PixelPass.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * The retro look, and the performance medicine in one: the scene renders into
- * a render target `pixelSize` times smaller than the canvas, nearest-filtered,
- * with thin depth/normal edge lines — three's own `RenderPixelatedPass`
- * (MASTERPLAN §4.1). Fragment cost drops by pixelSize², which is what lets the
- * island run on WebView2's integrated GPU.
- *
- * Mounted INSIDE the R3F Canvas. `useFrame` with priority 1 takes over
- * rendering from R3F, so the composer is the only thing that draws.
- */
-import { useEffect, useMemo } from "react";
-import { useFrame, useThree } from "@react-three/fiber";
-import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
-import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
-import { RenderPixelatedPass } from "three/examples/jsm/postprocessing/RenderPixelatedPass.js";
-
-interface Props {
- pixelSize: number;
-}
-
-export function PixelPass({ pixelSize }: Props) {
- const gl = useThree((s) => s.gl);
- const scene = useThree((s) => s.scene);
- const camera = useThree((s) => s.camera);
- const size = useThree((s) => s.size);
-
- const composer = useMemo(() => {
- const c = new EffectComposer(gl);
- const pass = new RenderPixelatedPass(pixelSize, scene, camera, {
- // Soft outlines: enough to separate a figure from the ground, not a comic ink line.
- normalEdgeStrength: 0.18,
- depthEdgeStrength: 0.28,
- });
- c.addPass(pass);
- c.addPass(new OutputPass());
- return { c, pass };
- }, [gl, scene, camera, pixelSize]);
-
- useEffect(() => {
- composer.c.setSize(size.width, size.height);
- composer.pass.setPixelSize(pixelSize);
- }, [composer, size.width, size.height, pixelSize]);
-
- useEffect(() => () => composer.c.dispose(), [composer]);
-
- useFrame(() => {
- composer.c.render();
- }, 1);
-
- return null;
-}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/README.md b/jarvis/ui/web/frontend/src/components/society/world/README.md
index b9ca2c9930..25daa0e0d6 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/README.md
+++ b/jarvis/ui/web/frontend/src/components/society/world/README.md
@@ -3,8 +3,8 @@
The 3D world of the Jarvis Agents section. Built in the maintainer's own
session; sibling sessions own `../card/`, `../data.ts` and `scripts/figures/`.
-Binding design: `docs/agent-society/world-art-direction.md` (layout, camera,
-palette, building language) under `docs/agent-society/MASTERPLAN.md` §4.
+Binding design: `docs/agent-society/world-masterplan-v2.md` (look, kit, market, behaviour) over
+`world-art-direction.md` (layout, camera, palette) under `docs/agent-society/MASTERPLAN.md` §4.
| File | Role |
|---|---|
@@ -15,7 +15,8 @@ palette, building language) under `docs/agent-society/MASTERPLAN.md` §4.
| `terrainGeometry.ts` | Tile map → one vertex-coloured mesh. Pure three, tested. |
| `worldPalette.ts` | The world's own colours (§4.3). Nothing inside the canvas reads a theme token. |
| `cameraStore.ts` · `useWorldControls.ts` · `WorldCameraRig.tsx` | Target/zoom store, DOM navigation, the R3F camera driver. |
-| `PixelPass.tsx` | `RenderPixelatedPass` + `OutputPass` composer — the retro look and the GPU budget. |
+| `WorldComposer.tsx` · `worldSettings.ts` | Scaled render + bloom (smooth default) or `RenderPixelatedPass` (grain option / cheap-GPU mode). |
+| `SunRig.tsx` · `Clouds.tsx` · `Shadowed.tsx` | The sun with a view-following shadow camera, shadow-casting clouds, the cast/receive marker. |
| `Terrain.tsx` · `Village.tsx` · `Landmarks.tsx` · `Trees.tsx` | The scene, all primitives, shared through `WorldKit.tsx`. |
| `Walkers.tsx` · `WalkerFigure.tsx` · `walkerRegistry.ts` | Agents on foot: state machine, stand-in figure, minimap pins. |
| `PlaceLabels.tsx` · `WorldHud.tsx` · `Minimap.tsx` · `world.css` | DOM over the canvas in the world's type. |
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Shadowed.tsx b/jarvis/ui/web/frontend/src/components/society/world/Shadowed.tsx
new file mode 100644
index 0000000000..c754d231ff
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/Shadowed.tsx
@@ -0,0 +1,22 @@
+/**
+ * Marks every mesh under it as a shadow caster and receiver, once, after mount.
+ * Cheaper to read than `castShadow receiveShadow` on two hundred JSX meshes,
+ * and it covers instanced meshes the same way.
+ */
+import { useLayoutEffect, useRef, type ReactNode } from "react";
+import { Group, Mesh } from "three";
+
+export function Shadowed({ children, receive = true }: { children: ReactNode; receive?: boolean }) {
+ const ref = useRef<Group>(null);
+ useLayoutEffect(() => {
+ const g = ref.current;
+ if (!g) return;
+ g.traverse((o) => {
+ if (o instanceof Mesh) {
+ o.castShadow = true;
+ o.receiveShadow = receive;
+ }
+ });
+ });
+ return <group ref={ref}>{children}</group>;
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/SunRig.tsx b/jarvis/ui/web/frontend/src/components/society/world/SunRig.tsx
new file mode 100644
index 0000000000..9c1fcc02cf
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/SunRig.tsx
@@ -0,0 +1,71 @@
+/**
+ * The sun: one warm directional light with a soft shadow map whose orthographic
+ * shadow camera FOLLOWS the view — fitted to the ground rectangle the player
+ * sees, so shadows are crisp where they are looked at and nothing is rendered
+ * for the rest of the island (world-masterplan-v2.md §3.2).
+ */
+import { useEffect, useRef } from "react";
+import { useFrame, useThree } from "@react-three/fiber";
+import { DirectionalLight, Vector3 } from "three";
+
+import { useCameraStore } from "./cameraStore";
+import { ZOOM_WIDTHS_M, orthoHalfExtents } from "./worldCamera";
+import { SKY } from "./worldPalette";
+import { useWorldSettings } from "./worldSettings";
+
+/** Sun direction (from the target toward the sun), normalised at build. */
+const SUN_DIR = new Vector3(SKY.sunFrom[0], SKY.sunFrom[1], SKY.sunFrom[2]).normalize();
+/** Distance of the light from its target — outside every object, inside the far plane. */
+const SUN_DISTANCE = 220;
+/** The shadow frustum covers this many times the visible ground width (shadows come from off-screen). */
+const COVER = 1.35;
+
+export function SunRig() {
+ const light = useRef<DirectionalLight>(null);
+ const size = useThree((s) => s.size);
+ const shadows = useWorldSettings((s) => s.shadows);
+
+ useEffect(() => {
+ const l = light.current;
+ if (!l) return;
+ l.shadow.mapSize.set(2048, 2048);
+ l.shadow.bias = -0.0006;
+ l.shadow.normalBias = 0.04;
+ l.shadow.camera.near = 1;
+ l.shadow.camera.far = SUN_DISTANCE * 2.5;
+ }, []);
+
+ useFrame(() => {
+ const l = light.current;
+ if (!l) return;
+ const { target, zoom } = useCameraStore.getState();
+ const aspect = size.width / Math.max(1, size.height);
+ const width = ZOOM_WIDTHS_M[zoom] * COVER;
+ const { halfW, halfH } = orthoHalfExtents(width, aspect);
+ const reach = Math.max(halfW, halfH / Math.sin((50 * Math.PI) / 180));
+ l.target.position.set(target[0], 0, target[1]);
+ l.target.updateMatrixWorld();
+ l.position.set(
+ target[0] + SUN_DIR.x * SUN_DISTANCE,
+ SUN_DIR.y * SUN_DISTANCE,
+ target[1] + SUN_DIR.z * SUN_DISTANCE,
+ );
+ const cam = l.shadow.camera;
+ if (cam.left !== -reach) {
+ cam.left = -reach;
+ cam.right = reach;
+ cam.top = reach;
+ cam.bottom = -reach;
+ cam.updateProjectionMatrix();
+ }
+ });
+
+ return (
+ <directionalLight
+ ref={light}
+ color={SKY.sun}
+ intensity={SKY.sunIntensity}
+ castShadow={shadows}
+ />
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx b/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
index 124b93af89..31da662856 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
@@ -1,15 +1,25 @@
/**
* The ground and the sea. The terrain is one merged, vertex-coloured mesh
- * (`terrainGeometry.ts`); the sea is a single plane under everything with a
- * scrolling pixel texture. Both are static apart from the water's drift.
+ * (`terrainGeometry.ts`) that receives the sun's shadows. The sea is a single
+ * plane with a small shader: depth tint toward the coast, an animated foam
+ * line along the shore, sparkle — world-masterplan-v2.md §3.6.
*/
import { useEffect, useMemo } from "react";
import { useFrame } from "@react-three/fiber";
-import { DoubleSide, MeshBasicMaterial, MeshLambertMaterial, PlaneGeometry } from "three";
+import {
+ ClampToEdgeWrapping,
+ Color,
+ DataTexture,
+ DoubleSide,
+ LinearFilter,
+ MeshLambertMaterial,
+ PlaneGeometry,
+ RedFormat,
+ ShaderMaterial,
+} from "three";
-import { buildIsland } from "./islandLayout";
+import { ISLAND_HALF_M, TileKind, buildIsland, type IslandMap } from "./islandLayout";
import { buildTerrainGeometry } from "./terrainGeometry";
-import { WATER_TILE_M, makeWaterTexture } from "./waterTexture";
import { WATER } from "./worldPalette";
export function Terrain() {
@@ -25,37 +35,139 @@ export function Terrain() {
},
[geometry, material],
);
- return <mesh geometry={geometry} material={material} receiveShadow={false} />;
+ return <mesh geometry={geometry} material={material} receiveShadow />;
}
/** The sea plane — far larger than the island so its edge is never in view. */
const SEA_SIZE_M = 1600;
+/** How many tiles out from the coast the foam and the shallow tint reach. */
+const SHORE_REACH_TILES = 4;
+
+/**
+ * Shore proximity per tile, 1 at the coast fading to 0 four tiles out: a
+ * multi-source breadth-first walk from every land tile over the water.
+ */
+export function buildShoreTexture(map: IslandMap): DataTexture {
+ const n = map.size * map.size;
+ const dist = new Int16Array(n).fill(-1);
+ const queue: number[] = [];
+ for (let i = 0; i < n; i++) {
+ if (map.kind[i] !== TileKind.water) {
+ dist[i] = 0;
+ queue.push(i);
+ }
+ }
+ let head = 0;
+ while (head < queue.length) {
+ const cur = queue[head++];
+ const d = dist[cur];
+ if (d >= SHORE_REACH_TILES) continue;
+ const cx = cur % map.size;
+ const cz = Math.floor(cur / map.size);
+ for (const [dx, dz] of [
+ [1, 0],
+ [-1, 0],
+ [0, 1],
+ [0, -1],
+ ] as const) {
+ const nx = cx + dx;
+ const nz = cz + dz;
+ if (nx < 0 || nz < 0 || nx >= map.size || nz >= map.size) continue;
+ const ni = nz * map.size + nx;
+ if (dist[ni] !== -1) continue;
+ dist[ni] = d + 1;
+ queue.push(ni);
+ }
+ }
+ const data = new Uint8Array(n);
+ for (let i = 0; i < n; i++) {
+ if (map.kind[i] !== TileKind.water) {
+ data[i] = 255;
+ continue;
+ }
+ const d = dist[i];
+ data[i] = d < 0 ? 0 : Math.round(255 * (1 - (d - 0.5) / SHORE_REACH_TILES));
+ }
+ const tex = new DataTexture(data, map.size, map.size, RedFormat);
+ tex.minFilter = LinearFilter;
+ tex.magFilter = LinearFilter;
+ tex.wrapS = ClampToEdgeWrapping;
+ tex.wrapT = ClampToEdgeWrapping;
+ tex.needsUpdate = true;
+ return tex;
+}
+
+const WATER_VERTEX = /* glsl */ `
+ varying vec3 vWorld;
+ void main() {
+ vec4 world = modelMatrix * vec4(position, 1.0);
+ vWorld = world.xyz;
+ gl_Position = projectionMatrix * viewMatrix * world;
+ }
+`;
+
+const WATER_FRAGMENT = /* glsl */ `
+ uniform sampler2D shoreTex;
+ uniform float time;
+ uniform float halfSize;
+ uniform vec3 deep;
+ uniform vec3 surface;
+ uniform vec3 ripple;
+ uniform vec3 foam;
+ varying vec3 vWorld;
+
+ void main() {
+ vec2 uv = vWorld.xz / (2.0 * halfSize) + 0.5;
+ float shore = texture2D(shoreTex, uv).r;
+ // Two slow wave fields; their product gives moving glints.
+ float w1 = sin(vWorld.x * 0.42 + vWorld.z * 0.18 + time * 0.9);
+ float w2 = sin(vWorld.z * 0.37 - vWorld.x * 0.21 - time * 0.7);
+ float glint = smoothstep(0.86, 1.0, w1 * w2);
+ vec3 col = mix(deep, surface, clamp(shore * 1.3, 0.0, 1.0));
+ col = mix(col, ripple, glint * 0.5);
+ // Foam: a band hugging the coast that breathes with the waves.
+ float breathe = 0.06 * sin(time * 1.6 + vWorld.x * 0.8 + vWorld.z * 0.6);
+ float band = smoothstep(0.62 + breathe, 0.9 + breathe, shore);
+ float lace = smoothstep(0.2, 0.8, sin(vWorld.x * 0.9 + time * 0.9) * sin(vWorld.z * 0.8 - time * 0.7) * 0.5 + 0.5);
+ col = mix(col, foam, band * (0.7 + 0.3 * lace));
+ gl_FragColor = vec4(col, 1.0);
+ #include <colorspace_fragment>
+ }
+`;
export function Water({ paused }: { paused: boolean }) {
- const texture = useMemo(() => makeWaterTexture(), []);
const geometry = useMemo(() => new PlaneGeometry(SEA_SIZE_M, SEA_SIZE_M), []);
- const material = useMemo(() => {
- if (!texture) return new MeshBasicMaterial({ color: WATER.surface });
- texture.repeat.set(SEA_SIZE_M / WATER_TILE_M, SEA_SIZE_M / WATER_TILE_M);
- return new MeshBasicMaterial({ map: texture });
- }, [texture]);
+ const shore = useMemo(() => buildShoreTexture(buildIsland().map), []);
+ const material = useMemo(
+ () =>
+ new ShaderMaterial({
+ uniforms: {
+ shoreTex: { value: shore },
+ time: { value: 0 },
+ halfSize: { value: ISLAND_HALF_M },
+ deep: { value: new Color(WATER.deep) },
+ surface: { value: new Color(WATER.surface) },
+ ripple: { value: new Color(WATER.ripple) },
+ foam: { value: new Color(WATER.foam) },
+ },
+ vertexShader: WATER_VERTEX,
+ fragmentShader: WATER_FRAGMENT,
+ }),
+ [shore],
+ );
useEffect(
() => () => {
geometry.dispose();
material.dispose();
- texture?.dispose();
+ shore.dispose();
},
- [geometry, material, texture],
+ [geometry, material, shore],
);
useFrame(({ clock }) => {
- if (paused || !texture) return;
- const t = clock.getElapsedTime();
- // A slow drift plus a gentle back-and-forth: water, not a conveyor belt.
- texture.offset.set(t * 0.012 + Math.sin(t * 0.35) * 0.01, t * 0.006);
+ if (paused) return;
+ material.uniforms.time.value = clock.getElapsedTime();
});
- return (
- <mesh geometry={geometry} material={material} rotation={[-Math.PI / 2, 0, 0]} position={[0, 0, 0]} />
- );
+ return <mesh geometry={geometry} material={material} rotation={[-Math.PI / 2, 0, 0]} />;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/WorldComposer.tsx b/jarvis/ui/web/frontend/src/components/society/world/WorldComposer.tsx
new file mode 100644
index 0000000000..f6f66f78d0
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/WorldComposer.tsx
@@ -0,0 +1,78 @@
+/**
+ * The frame, assembled — successor of the V1 `PixelPass`.
+ *
+ * Smooth mode (grain 0, the default): the scene renders into targets `scale`
+ * times smaller than the canvas, gets a soft bloom on its emissives, and is
+ * upscaled with linear filtering by the output pass. Same GPU saving as the
+ * pixel pass, no stair-steps — the Clash-of-Clans softness the maintainer
+ * asked for (world-masterplan-v2.md §3.1).
+ *
+ * Grain mode (2 or 3): three's `RenderPixelatedPass` as in V1, kept as a look
+ * option and as the cheap-GPU fallback.
+ *
+ * Mounted INSIDE the Canvas; `useFrame` priority 1 takes rendering over from R3F.
+ */
+import { useEffect, useMemo } from "react";
+import { useFrame, useThree } from "@react-three/fiber";
+import { Vector2 } from "three";
+import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
+import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
+import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
+import { RenderPixelatedPass } from "three/examples/jsm/postprocessing/RenderPixelatedPass.js";
+import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPass.js";
+
+import { useWorldSettings } from "./worldSettings";
+
+/**
+ * Bloom tuned for lamps and beacons only. Without tone mapping a sunlit white
+ * wall already sits near 1.0, so the threshold must stay above it — and the
+ * effect is off by default (worldSettings): the references have no bloom.
+ */
+const BLOOM = { strength: 0.22, radius: 0.3, threshold: 0.97 };
+
+export function WorldComposer() {
+ const gl = useThree((s) => s.gl);
+ const scene = useThree((s) => s.scene);
+ const camera = useThree((s) => s.camera);
+ const size = useThree((s) => s.size);
+ const grain = useWorldSettings((s) => s.grain);
+ const scale = useWorldSettings((s) => s.scale);
+ const bloom = useWorldSettings((s) => s.bloom);
+
+ const composer = useMemo(() => {
+ const c = new EffectComposer(gl);
+ let pixel: RenderPixelatedPass | null = null;
+ if (grain > 0) {
+ pixel = new RenderPixelatedPass(grain, scene, camera, {
+ normalEdgeStrength: 0.18,
+ depthEdgeStrength: 0.28,
+ });
+ c.addPass(pixel);
+ } else {
+ c.addPass(new RenderPass(scene, camera));
+ if (bloom) {
+ c.addPass(new UnrealBloomPass(new Vector2(256, 256), BLOOM.strength, BLOOM.radius, BLOOM.threshold));
+ }
+ }
+ c.addPass(new OutputPass());
+ return { c, pixel };
+ }, [gl, scene, camera, grain, bloom]);
+
+ useEffect(() => {
+ if (composer.pixel) {
+ composer.c.setSize(size.width, size.height);
+ composer.pixel.setPixelSize(grain);
+ } else {
+ // Smaller internal targets; the output pass stretches them over the canvas.
+ composer.c.setSize(Math.max(2, Math.round(size.width * scale)), Math.max(2, Math.round(size.height * scale)));
+ }
+ }, [composer, size.width, size.height, grain, scale]);
+
+ useEffect(() => () => composer.c.dispose(), [composer]);
+
+ useFrame(() => {
+ composer.c.render();
+ }, 1);
+
+ return null;
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx b/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
index 57b364ea58..cabeda7596 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
@@ -1,6 +1,6 @@
/**
* The island, mounted — the world view of the Jarvis Agents section
- * (MASTERPLAN §4.1) and the first piece of M3.
+ * (MASTERPLAN §4.1); look and behaviour per world-masterplan-v2.md.
*
* Discipline every world canvas owes (society README):
* - the R3F Canvas mounts through `useWebglSurface` (AP-32: context released
@@ -8,7 +8,7 @@
* - the render loop runs only while the host is on screen, gated by an
* IntersectionObserver (`useCanvasAwake`) — never `document.hidden`;
* - `prefers-reduced-motion` freezes the island (demand-driven frames, no
- * wander, no water drift) instead of animating it;
+ * wander, no water drift, no clouds) instead of animating it;
* - no WebGL at all → an honest fallback that points to the ledger.
*
* Everything inside the canvas wears the world's own branding (§4.3); the
@@ -29,19 +29,23 @@ import { useWebglSupported } from "@/lib/graphDimension";
import { useSocietyRoster } from "../data";
import { SAMPLE_ROSTER } from "../mockRoster";
import { useCameraStore } from "./cameraStore";
+import { Clouds } from "./Clouds";
import { Landmarks } from "./Landmarks";
-import { PixelPass } from "./PixelPass";
import { PlaceLabels } from "./PlaceLabels";
+import { Shadowed } from "./Shadowed";
+import { SunRig } from "./SunRig";
import { Terrain, Water } from "./Terrain";
import { Trees } from "./Trees";
import { Village } from "./Village";
import { Walkers } from "./Walkers";
import { useWorldControls } from "./useWorldControls";
import { WorldCameraRig } from "./WorldCameraRig";
+import { WorldComposer } from "./WorldComposer";
import { WorldHud } from "./WorldHud";
import { WorldKitProvider } from "./WorldKit";
-import { PIXEL_SIZE, cameraOffset } from "./worldCamera";
+import { cameraOffset } from "./worldCamera";
import { SKY } from "./worldPalette";
+import { useWorldSettings } from "./worldSettings";
export interface WorldStageProps {
/** App-chrome content for the HUD's top-right corner (the World / Ledger switch). */
@@ -62,6 +66,8 @@ export function WorldStage({ topRight, onOpenLedger, onSelectAgent }: WorldStage
const awake = useCanvasAwake(hostRef);
const reduced = useReducedMotion() ?? false;
const webgl = useWebglSupported();
+ const grain = useWorldSettings((s) => s.grain);
+ const shadows = useWorldSettings((s) => s.shadows);
const roster = useSocietyRoster();
const agents = roster.data ?? [];
const sample = roster.data === SAMPLE_ROSTER;
@@ -104,6 +110,7 @@ export function WorldStage({ topRight, onOpenLedger, onSelectAgent }: WorldStage
<div
ref={hostRef}
className="sw-stage"
+ data-grain={grain > 0 ? grain : undefined}
tabIndex={0}
role="application"
aria-label={ready ? t("society.world.mode_world") : undefined}
@@ -114,30 +121,30 @@ export function WorldStage({ topRight, onOpenLedger, onSelectAgent }: WorldStage
camera={{ position: CAMERA_START, near: 1, far: 1200, zoom: 1 }}
dpr={1}
flat
- gl={{ antialias: false, alpha: false, powerPreference: "high-performance", stencil: false }}
+ shadows={shadows ? "soft" : false}
+ gl={{ antialias: grain === 0, alpha: false, powerPreference: "high-performance", stencil: false }}
frameloop={frameloop}
onPointerMissed={() => {
if (!useCameraStore.getState().dragging) select(null);
}}
>
<color attach="background" args={[SKY.clear]} />
- <hemisphereLight args={[SKY.hemiSky, SKY.hemiGround, SKY.hemiIntensity * Math.PI]} />
- <directionalLight
- position={[SKY.sunFrom[0], SKY.sunFrom[1], SKY.sunFrom[2]]}
- intensity={SKY.sunIntensity * Math.PI * 0.75}
- color={SKY.sun}
- />
+ <hemisphereLight args={[SKY.hemiSky, SKY.hemiGround, SKY.hemiIntensity]} />
+ <SunRig />
<WorldKitProvider>
<Terrain />
<Water paused={reduced} />
- <Village paused={reduced} />
- <Landmarks paused={reduced} />
- <Trees />
- <Walkers agents={agents} paused={reduced} selectedId={selected} onSelect={select} />
+ <Shadowed>
+ <Village paused={reduced} />
+ <Landmarks paused={reduced} />
+ <Trees />
+ <Walkers agents={agents} paused={reduced} selectedId={selected} onSelect={select} />
+ </Shadowed>
+ <Clouds paused={reduced} />
{ready && <PlaceLabels />}
</WorldKitProvider>
<WorldCameraRig />
- <PixelPass pixelSize={PIXEL_SIZE} />
+ <WorldComposer />
</Canvas>
</div>
{ready && (
diff --git a/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts b/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
index 7127e48d7a..8455e9790c 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
@@ -82,6 +82,24 @@ function topY(map: IslandMap, tx: number, tz: number): number {
return LEVEL_Y[map.level[i]];
}
+/** 1 = fully lit; each higher neighbour and each built-on neighbour darkens the tile a step. */
+function tileAo(map: IslandMap, tx: number, tz: number, y: number): number {
+ let ao = 1;
+ for (const [dx, dz] of [
+ [1, 0],
+ [-1, 0],
+ [0, 1],
+ [0, -1],
+ ] as const) {
+ const nx = tx + dx;
+ const nz = tz + dz;
+ if (!inBounds(map, nx, nz)) continue;
+ if (topY(map, nx, nz) > y + 0.01) ao -= 0.09;
+ else if (map.blocked[tileIndex(map, nx, nz)] && map.kind[tileIndex(map, nx, nz)] !== TileKind.water) ao -= 0.05;
+ }
+ return Math.max(0.68, ao);
+}
+
/** Build the terrain mesh for the whole map. */
export function buildTerrainGeometry(map: IslandMap): BufferGeometry {
const b = new MeshBuilder();
@@ -100,7 +118,11 @@ export function buildTerrainGeometry(map: IslandMap): BufferGeometry {
const shade = hash2(tx, tz, 91) < 0.5 ? 0 : 1;
// Garden beds: the second shade is the flower colour, sprinkled sparsely.
const topIdx = kind === TileKind.garden ? (hash2(tx, tz, 92) < 0.3 ? 1 : 0) : shade;
- const top = color(shades.top[topIdx]);
+ // Analytic ambient occlusion (world-masterplan-v2.md §3.3): ground next
+ // to a higher step or a building darkens a little, the way every corner
+ // of a stylised village is shaded.
+ const ao = tileAo(map, tx, tz, y);
+ const top = ao < 1 ? color(shades.top[topIdx]).clone().multiplyScalar(ao) : color(shades.top[topIdx]);
b.quad([x0, y, z0], [x0, y, z1], [x1, y, z1], [x1, y, z0], UP, top);
const side = color(shades.side);
diff --git a/jarvis/ui/web/frontend/src/components/society/world/world.css b/jarvis/ui/web/frontend/src/components/society/world/world.css
index b28750d6e4..149e69bf44 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/world.css
+++ b/jarvis/ui/web/frontend/src/components/society/world/world.css
@@ -25,6 +25,9 @@
}
.sw-stage canvas {
display: block;
+}
+/* Only the optional grain modes want hard pixels; the smooth default upscales linearly. */
+.sw-stage[data-grain] canvas {
image-rendering: pixelated;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts b/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
index 68cc0bca92..d1f8bf9fa5 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
@@ -9,30 +9,56 @@ import {
BoxGeometry,
Color,
CylinderGeometry,
+ DataTexture,
IcosahedronGeometry,
MeshBasicMaterial,
- MeshLambertMaterial,
+ MeshToonMaterial,
+ NearestFilter,
+ RGBAFormat,
SphereGeometry,
TorusGeometry,
} from "three";
+import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
import { BUILDING, NATURE } from "./worldPalette";
+/**
+ * The four-step light ramp every lit object shares (world-masterplan-v2.md §3.4):
+ * a deep shade, a mid tone, a lit face and a bright top. Toon shading with a
+ * ramp is the Clash-of-Clans look — one saturated hue per material, light
+ * carried by steps instead of by a smooth gradient.
+ */
+export function createToonRamp(): DataTexture {
+ const steps = [0.58, 0.8, 0.94, 1.0];
+ const data = new Uint8Array(steps.length * 4);
+ steps.forEach((v, i) => {
+ const b = Math.round(v * 255);
+ data.set([b, b, b, 255], i * 4);
+ });
+ const tex = new DataTexture(data, steps.length, 1, RGBAFormat);
+ tex.minFilter = NearestFilter;
+ tex.magFilter = NearestFilter;
+ tex.generateMipmaps = false;
+ tex.needsUpdate = true;
+ return tex;
+}
+
export interface WorldMaterials {
- lit: (hex: string) => MeshLambertMaterial;
+ lit: (hex: string) => MeshToonMaterial;
glow: (hex: string) => MeshBasicMaterial;
dispose: () => void;
}
/** Build the material cache. Every colour is created at most once. */
export function createWorldMaterials(): WorldMaterials {
- const lit = new Map<string, MeshLambertMaterial>();
+ const lit = new Map<string, MeshToonMaterial>();
const glow = new Map<string, MeshBasicMaterial>();
+ const ramp = createToonRamp();
return {
lit: (hex) => {
let m = lit.get(hex);
if (!m) {
- m = new MeshLambertMaterial({ color: new Color(hex) });
+ m = new MeshToonMaterial({ color: new Color(hex), gradientMap: ramp });
lit.set(hex, m);
}
return m;
@@ -48,6 +74,7 @@ export function createWorldMaterials(): WorldMaterials {
dispose: () => {
for (const m of lit.values()) m.dispose();
for (const m of glow.values()) m.dispose();
+ ramp.dispose();
lit.clear();
glow.clear();
},
@@ -62,7 +89,10 @@ export function useWorldMaterials(): WorldMaterials {
/** Unit geometries, scaled per use. Shared by every house, tree and lamp. */
export interface WorldGeometries {
- box: BoxGeometry;
+ /** A unit box with a small bevel — every edge catches the light (§2 shape language). */
+ box: RoundedBoxGeometry;
+ /** The sharp unit box, for thin slabs where a bevel would smear. */
+ slab: BoxGeometry;
cylinder: CylinderGeometry;
halfCylinder: CylinderGeometry;
cone: CylinderGeometry;
@@ -74,7 +104,8 @@ export interface WorldGeometries {
}
export function createWorldGeometries(): WorldGeometries {
- const box = new BoxGeometry(1, 1, 1);
+ const box = new RoundedBoxGeometry(1, 1, 1, 2, 0.05);
+ const slab = new BoxGeometry(1, 1, 1);
const cylinder = new CylinderGeometry(0.5, 0.5, 1, 10);
const halfCylinder = new CylinderGeometry(0.5, 0.5, 1, 10, 1, false, 0, Math.PI);
const cone = new CylinderGeometry(0, 0.5, 1, 8);
@@ -82,9 +113,10 @@ export function createWorldGeometries(): WorldGeometries {
const sphere = new SphereGeometry(0.5, 10, 8);
const dome = new SphereGeometry(0.5, 12, 6, 0, Math.PI * 2, 0, Math.PI / 2);
const ring = new TorusGeometry(0.5, 0.06, 6, 24);
- const all = [box, cylinder, halfCylinder, cone, blob, sphere, dome, ring];
+ const all = [box, slab, cylinder, halfCylinder, cone, blob, sphere, dome, ring];
return {
box,
+ slab,
cylinder,
halfCylinder,
cone,
diff --git a/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts b/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
index b397e01c55..23385053fc 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
@@ -44,8 +44,9 @@ export const SKY = {
hemiSky: "#d6ecff",
hemiGround: "#7f9c5a",
sun: "#fff1d6",
- sunIntensity: 1.35,
- hemiIntensity: 0.95,
+ /** Directional and hemisphere intensities are plain multipliers in three r155+ — no π. */
+ sunIntensity: 0.8,
+ hemiIntensity: 0.78,
/** Direction the sun shines FROM (unit-ish vector; warm afternoon, south-west). */
sunFrom: [-60, 90, 45] as const,
};
diff --git a/jarvis/ui/web/frontend/src/components/society/world/worldSettings.ts b/jarvis/ui/web/frontend/src/components/society/world/worldSettings.ts
new file mode 100644
index 0000000000..1f03a380ec
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/worldSettings.ts
@@ -0,0 +1,90 @@
+/**
+ * Per-viewer look settings for the island. Cosmetic, local, never synced.
+ *
+ * `grain` — screen pixels per rendered pixel. 0 = smooth (the default since the
+ * world-masterplan-v2 decision: the references are Roblox / Clash of Clans,
+ * both smooth); 2 = the V1 pixel look; 3 = coarse. Any grain > 0 also serves
+ * as the cheap-GPU mode, because the pixel pass renders grain² fewer fragments.
+ * `scale` — internal render scale when grain is 0 (0.5–1). Below 1 the frame
+ * is rendered smaller and upscaled with linear filtering: the same GPU saving
+ * without stair-steps.
+ */
+import { create } from "zustand";
+
+export type Grain = 0 | 2 | 3;
+
+export interface WorldSettings {
+ grain: Grain;
+ scale: number;
+ bloom: boolean;
+ shadows: boolean;
+ setGrain: (grain: Grain) => void;
+ setScale: (scale: number) => void;
+ setBloom: (on: boolean) => void;
+ setShadows: (on: boolean) => void;
+}
+
+const KEY = "jarvis.world.look.v1";
+
+interface Stored {
+ grain?: number;
+ scale?: number;
+ bloom?: boolean;
+ shadows?: boolean;
+}
+
+function read(): Stored {
+ try {
+ const raw = localStorage.getItem(KEY);
+ if (!raw) return {};
+ const parsed = JSON.parse(raw) as Stored;
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
+ } catch {
+ return {};
+ }
+}
+
+function write(s: Stored): void {
+ try {
+ localStorage.setItem(KEY, JSON.stringify(s));
+ } catch {
+ /* not persisted, still applied */
+ }
+}
+
+export function normalizeGrain(v: unknown): Grain {
+ return v === 2 || v === 3 ? v : 0;
+}
+
+export function normalizeScale(v: unknown): number {
+ return typeof v === "number" && Number.isFinite(v) ? Math.min(1, Math.max(0.5, v)) : 0.75;
+}
+
+const initial = typeof localStorage === "undefined" ? {} : read();
+
+export const useWorldSettings = create<WorldSettings>((set, get) => ({
+ grain: normalizeGrain(initial.grain),
+ scale: normalizeScale(initial.scale),
+ bloom: initial.bloom ?? false,
+ shadows: initial.shadows ?? true,
+ setGrain: (grain) => {
+ set({ grain });
+ persist(get());
+ },
+ setScale: (scale) => {
+ set({ scale: normalizeScale(scale) });
+ persist(get());
+ },
+ setBloom: (bloom) => {
+ set({ bloom });
+ persist(get());
+ },
+ setShadows: (shadows) => {
+ set({ shadows });
+ persist(get());
+ },
+}));
+
+function persist(s: WorldSettings): void {
+ write({ grain: s.grain, scale: s.scale, bloom: s.bloom, shadows: s.shadows });
+}