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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(verse): soft floor reflections and a normal duel field of view (#890)
Ruben Lütkeea94872fac78
diff --git a/docs/verse/combat.md b/docs/verse/combat.mdindex ea97ce8c4a..574876c222 100644--- a/docs/verse/combat.md+++ b/docs/verse/combat.md@@ -269,8 +269,8 @@ and returns a `ControlState`, which becomes an InputCommand through the same`makeInput` as a person's keys.**Fair perception (`observe.ts`).** It sees what the person's screen would-show: the opponent inside the hip camera's view (+-55 deg from the camera-behind the right shoulder: 70 deg vertical at 16:9 shows +-51 deg, so close+show: the opponent inside the hip camera's view (+-44 deg from the camera+behind the right shoulder: 50 deg vertical at 16:9 shows +-40 deg, so closeby it sees far to the sides, as the screen does) or within 3 m, with a clearline to the opponent's head, chest or hips from its eyes or from the camera(the shoulder view looks round a right-hand corner before the body leaves@@ -639,9 +639,10 @@ Presses are latched by the client until the next tick, so a quick tap on a### Camera and aim- `cameraRigFor(player)` gives the over-the-shoulder rig for the player's- state: hip (0.55 m right, 1.68 m up, 2.5 m back, 70 deg), sights (0.42,- 1.62, 1.3, 50 deg; blended by `player.ads`), sprint (2.9 m back, 76 deg),- shield (2.75 m back, 68 deg). Ease between rigs over about 0.15 s; keep the+ state: hip (0.55 m right, 1.68 m up, 2.5 m back, 50 deg), sights (0.42,+ 1.62, 1.3, 34 deg; blended by `player.ads`), sprint (2.9 m back, 55 deg),+ shield (2.75 m back, 48 deg). The angles are vertical, for the default+ third-person field of view. Ease between rigs over about 0.15 s; keep theexisting camera collision.- `cameraPose(player, rig)` places the camera behind the right shoulder andorbits the pivot with the pitch.@@ -758,7 +759,9 @@ is always fought over the shoulder: first person on the deck switches to theduel's camera for the match and back afterwards. It eases the core's rigs(`cameraRigFor`: hip, sights, sprint, shield; about 0.15 s) and adds 0.2 m to the side (less in the sights) so thebody clears the crosshair. The camera's vertical field of view is the rig's-(70 deg hip, the angle the bot's perception assumes). It is pulled in front of+(50 deg hip, about 80 deg across a 16:9 frame, the angle the bot's perception+assumes; 34 deg in the sights), widened or narrowed by the same ratio as the+person's third-person field of view in the view settings (`duelFov`). It is pulled in front ofthe deck's geometry with the eye view's BVH (`runtime.eye.test`) and easesback out. The view follows the blaster's recoil (the screen kicks with everyshot and settles with it) while the aim sent to the simulation is the mouse's;diff --git a/docs/verse/realtime.md b/docs/verse/realtime.mdindex a3d2ecb05c..f20c0ee5f6 100644--- a/docs/verse/realtime.md+++ b/docs/verse/realtime.md@@ -161,7 +161,7 @@ Code: `src/components/society/verse/engine/realtime/`.| File | Role ||---|---|| `realtimeScene.ts` | Loads the glb (GLTFLoader + MeshoptDecoder), the pages (ImageBitmap, flipY off) and the probes (decoded on the GPU into half-float equirects, PMREM); builds one material per chunk key; builds the collision BVH (three-mesh-bvh) over chunks whose material collides. |-| `deckMaterial.ts` | `makeDeckMaterial`: MeshStandardMaterial, or MeshPhysicalMaterial where a coat, a specular level or glass needs it. `patchDeckShader` adds the baked radiance (`totalEmissiveRadiance += decode(lightMap)`), removes lightmap irradiance and environment diffuse, box-projects reflections into the room's box, and for `deck_plates` draws the 2.4 × 1.2 m plate joints and bolts and the smudged, wiped coat close up. Glass blends `ONE, ONE_MINUS_SRC_ALPHA` (its reflection plus what is behind it). |+| `deckMaterial.ts` | `makeDeckMaterial`: MeshStandardMaterial, or MeshPhysicalMaterial where a coat, a specular level or glass needs it. `patchDeckShader` adds the baked radiance (`totalEmissiveRadiance += decode(lightMap)`), removes lightmap irradiance and environment diffuse, box-projects reflections into the room's box (grown to hold a fragment just past it, such as a doorway or a lift alcove, so the projection never jumps), and for `deck_plates` draws the 2.4 × 1.2 m plate joints and bolts and broad, soft smudges on the coat (no fine noise in the coat's roughness: it drew lights as blocky squares). Glass blends `ONE, ONE_MINUS_SRC_ALPHA` (its reflection plus what is behind it). || `shoulderRig.ts` | The camera, third and first person (below). Pure. || `viewMode.ts` | The three views and their keys, the wheel's hand-over between third and first person (`zoomStep`), which way the body faces while walking in a shooter view (`bodyFacing`). Pure. || `mouseLook.ts` | Shooter mouse look shared with the duel: the turn rate per pointer-lock pixel, sensitivity and inverted axis (`lookDelta`), taking the mouse with raw movement where the browser allows it (`requestMouseLook`). |diff --git a/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx b/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsxindex 00115f20ae..4c94244c4a 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx+++ b/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx@@ -267,6 +267,7 @@ export function VerseStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpenGruntime.shoulder.fovFirst = fovFirst;duel.camera.sensitivity = sensitivity;duel.camera.invertY = invertY;+ duel.camera.hfovSetting = fovThird;}, [runtime, duel, sensitivity, invertY, fovThird, fovFirst]);// The doors open once the car has arrived and the new deck is on screen (or after a moment, whatever happens).diff --git a/dodaios/ui/web/frontend/src/components/society/verse/combat/camera.ts b/dodaios/ui/web/frontend/src/components/society/verse/combat/camera.tsindex e4b01b2d26..82f06bc322 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/combat/camera.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/combat/camera.ts@@ -16,15 +16,19 @@ export interface CameraRig {right: number;up: number;back: number;- /** Vertical field of view, degrees. */+ /**+ * Vertical field of view, degrees, at the default third-person setting (the+ * duel camera widens or narrows it with the person's field of view). Hip+ * 50 deg shows about 80 deg across a 16:9 frame, a usual shoulder shooter.+ */fovDeg: number;}export const CAMERA_RIGS: Readonly<Record<"hip" | "ads" | "sprint" | "shield", CameraRig>> = {- hip: { right: 0.55, up: 1.68, back: 2.5, fovDeg: 70 },- ads: { right: 0.42, up: 1.62, back: 1.3, fovDeg: 50 },- sprint: { right: 0.5, up: 1.6, back: 2.9, fovDeg: 76 },- shield: { right: 0.62, up: 1.72, back: 2.75, fovDeg: 68 },+ hip: { right: 0.55, up: 1.68, back: 2.5, fovDeg: 50 },+ ads: { right: 0.42, up: 1.62, back: 1.3, fovDeg: 34 },+ sprint: { right: 0.5, up: 1.6, back: 2.9, fovDeg: 55 },+ shield: { right: 0.62, up: 1.72, back: 2.75, fovDeg: 48 },};function mix(a: CameraRig, b: CameraRig, t: number): CameraRig {diff --git a/dodaios/ui/web/frontend/src/components/society/verse/combat/observe.ts b/dodaios/ui/web/frontend/src/components/society/verse/combat/observe.tsindex e48e0d2309..abfa15e973 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/combat/observe.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/combat/observe.ts@@ -18,12 +18,12 @@ import type { CombatTuning } from "./tuning";import type { BoltKind, BoltState, CombatEvent, MatchPhase, PlayerState } from "./types";/**- * Half the horizontal view of the hip camera (70 deg vertical at 16:9 shows- * +-51 deg), with a little peripheral margin. Measured from the camera, which+ * Half the horizontal view of the hip camera (50 deg vertical at 16:9 shows+ * +-40 deg), with a little peripheral margin. Measured from the camera, which* sits behind the right shoulder, so close by it shows far more to the sides* than this angle from the body would.*/-export const VIEW_HALF_DEG = 55;+export const VIEW_HALF_DEG = 44;/** The hip camera's place (camera.ts CAMERA_RIGS.hip): right of, above and behind the feet. */const CAM_RIGHT = 0.55;const CAM_UP = 1.68;diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/DuelLayer.tsx b/dodaios/ui/web/frontend/src/components/society/verse/duel/DuelLayer.tsxindex 9a8f615437..5e742dc716 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/DuelLayer.tsx+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/DuelLayer.tsx@@ -17,6 +17,7 @@ import type { StageRuntime } from "../runtime";import { disposeInstance, type CharacterLibrary } from "../actors/characters";import { applyLook, type Look } from "../actors/look";import { hash32 } from "../life/crew";+import { CAMERA_RIGS } from "../combat/camera";import type { CombatEvent } from "../combat/types";import { BOLT_COLOURS } from "./blaster";import type { DuelController } from "./duelController";@@ -119,7 +120,7 @@ export function DuelLayer({ runtime, controller, deck, library, commanderId, comuseEffect(() => () => { runtime.cameraOverride = null; }, [runtime]);const scratch = useMemo(() => ({ v: new Vector3(), time: 0, steamAcc: [0, 0] }), []);- const override = useMemo(() => ({ position: { x: 0, y: 0, z: 0 }, target: { x: 0, y: 0, z: 0 }, fovDeg: 70 }), []);+ const override = useMemo(() => ({ position: { x: 0, y: 0, z: 0 }, target: { x: 0, y: 0, z: 0 }, fovDeg: CAMERA_RIGS.hip.fovDeg }), []);useFrame((_, dt) => {if (!controller.active) {diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/duel.test.ts b/dodaios/ui/web/frontend/src/components/society/verse/duel/duel.test.tsindex 6bcd5b099c..d307521c8f 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/duel.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/duel.test.ts@@ -9,7 +9,7 @@ import { describe, expect, it } from "vitest";import { createLocalDuel, type LocalDuelOptions } from "../combat/session";import type { CombatEvent } from "../combat/types";import type { PlayerView, ViewState } from "../combat/view";-import { DuelCamera, DUEL_CAMERA } from "./duelCamera";+import { DuelCamera, DUEL_CAMERA, duelFov } from "./duelCamera";import { DuelController, type DuelExit } from "./duelController";import { buildHudModel, DuelHudFeed, HUD_TIMES } from "./duelHud";import { DuelInput, isDuelKey } from "./duelInput";@@ -140,6 +140,22 @@ describe("duel camera", () => {expect(ads.fovDeg).toBeLessThan(hipFov);});+ it("keeps a normal shooter's field of view that follows the person's setting", () => {+ const cam = new DuelCamera();+ cam.face(0);+ const hip = cam.update(1 / 60, player(), 0).fovDeg;+ // About 80 deg across a 16:9 frame: no fish-eye.+ const across = (2 * Math.atan(Math.tan((hip * Math.PI) / 360) * (16 / 9)) * 180) / Math.PI;+ expect(hip).toBeGreaterThan(45);+ expect(hip).toBeLessThan(56);+ expect(across).toBeLessThan(90);+ expect(duelFov(50)).toBeCloseTo(50);+ expect(duelFov(50, 90)).toBeGreaterThan(50);+ expect(duelFov(50, 55)).toBeLessThan(50);+ cam.hfovSetting = 90;+ expect(cam.update(1 / 60, player(), 0).fovDeg).toBeGreaterThan(hip);+ });+it("is pulled in front of a wall behind the player", () => {const cam = new DuelCamera();cam.face(0);diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelCamera.ts b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelCamera.tsindex 1427356d02..5b22ba4dc6 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelCamera.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelCamera.ts@@ -18,7 +18,7 @@ import { cameraRigFor, type CameraRig } from "../combat/camera";import { DEG } from "../combat/math";import type { PlayerView } from "../combat/view";import { MOUSE_LOOK_RATE, lookDelta } from "../engine/realtime/mouseLook";-import type { SegmentTest, Vec3 } from "../engine/realtime/shoulderRig";+import { SHOULDER, clampHfov, type SegmentTest, type Vec3 } from "../engine/realtime/shoulderRig";export const DUEL_CAMERA = {/** Radians per pointer-lock pixel at sensitivity 1 (the eye-level views' mouse look); sights turn slower. */@@ -53,6 +53,16 @@ export interface DuelCameraPose {fovDeg: number;}+/**+ * A rig's vertical field of view (set for the default third-person field of+ * view) at the person's own third-person setting: the same zoom ratio, so a+ * wider setting widens the duel just as much. Pure.+ */+export function duelFov(rigFovDeg: number, hfovSettingDeg: number = SHOULDER.hfovDeg): number {+ const ratio = Math.tan((clampHfov(hfovSettingDeg, SHOULDER.hfovDeg) * DEG) / 2) / Math.tan((SHOULDER.hfovDeg * DEG) / 2);+ return (2 * Math.atan(Math.tan((rigFovDeg * DEG) / 2) * ratio)) / DEG;+}+function clamp(v: number, lo: number, hi: number): number {return Math.max(lo, Math.min(hi, v));}@@ -75,8 +85,10 @@ export class DuelCamera {pitch = 0;sensitivity = 1;invertY = false;+ /** The person's third-person horizontal field of view (view settings), degrees. */+ hfovSetting: number = SHOULDER.hfovDeg;readonly pose: DuelCameraPose = {- position: { x: 0, y: 0, z: 0 }, target: { x: 0, y: 0, z: 0 }, dir: { x: 0, y: 0, z: 1 }, aimDir: { x: 0, y: 0, z: 1 }, fovDeg: 70,+ position: { x: 0, y: 0, z: 0 }, target: { x: 0, y: 0, z: 0 }, dir: { x: 0, y: 0, z: 1 }, aimDir: { x: 0, y: 0, z: 1 }, fovDeg: duelFov(cameraRigFor({ sprinting: false, shieldUp: false, ads: 0 } as PlayerView).fovDeg),};private rig: CameraRig = { ...cameraRigFor({ sprinting: false, shieldUp: false, ads: 0 } as PlayerView) };private primed = false;@@ -175,7 +187,7 @@ export class DuelCamera {pose.target.x = pivot.x + dir.x * 20;pose.target.y = pivot.y + dir.y * 20;pose.target.z = pivot.z + dir.z * 20;- pose.fovDeg = r.fovDeg;+ pose.fovDeg = duelFov(r.fovDeg, this.hfovSetting);return pose;}}diff --git a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/deckMaterial.ts b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/deckMaterial.tsindex 05925cb929..17f0c678e1 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/deckMaterial.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/deckMaterial.ts@@ -49,16 +49,20 @@ vec3 verseDecode( vec4 t ) {}// Parallax-corrected reflection direction (world space) inside the room's box.+// A fragment past the box (a doorway, a lift alcove, a sill a hair outside) grows+// the box to hold it, so the projection never jumps to the unprojected direction:+// that jump drew lights far from where they hang, cut off at a hard line.vec3 verseBoxProject( vec3 dir, float roughness ) {if ( verseBoxOn < 0.5 ) return dir;vec3 p = vVerseWorld;- if ( any( lessThan( p, verseBoxMin - 0.05 ) ) || any( greaterThan( p, verseBoxMax + 0.05 ) ) ) return dir;+ vec3 boxMin = min( verseBoxMin, p - 0.02 );+ vec3 boxMax = max( verseBoxMax, p + 0.02 );vec3 d = vec3(abs( dir.x ) < 1e-5 ? 1e-5 : dir.x,abs( dir.y ) < 1e-5 ? 1e-5 : dir.y,abs( dir.z ) < 1e-5 ? 1e-5 : dir.z);- vec3 far = max( ( verseBoxMax - p ) / d, ( verseBoxMin - p ) / d );+ vec3 far = max( ( boxMax - p ) / d, ( boxMin - p ) / d );float t = max( 0.0, min( min( far.x, far.y ), far.z ) );vec3 projected = normalize( p + dir * t - verseProbePos );return normalize( mix( projected, dir, roughness * roughness ) );@@ -124,13 +128,14 @@ const DETAIL_PROPERTIES = /* glsl */ `const DETAIL_COAT = /* glsl */ `#if defined( VERSE_DECK_PLATES ) && defined( USE_CLEARCOAT ){- // Smudges, wipe marks and dust blur and dim the mirror (as the plate's coat does).- vec2 q = vVerseWorld.xz;- float smudge = smoothstep( 0.42, 0.78, verseFbm( q * 0.7 ) );- float wipe = smoothstep( 0.52, 0.76, verseFbm( vec2( q.x * 2.2, q.y * 15.4 ) ) );- float dust = smoothstep( 0.55, 0.8, verseFbm( q * 6.0 + 11.0 ) ) * 0.4;- material.clearcoatRoughness = clamp( material.clearcoatRoughness + 0.03 * smudge + 0.04 * wipe + 0.08 * dust - 0.02 + verseCoatBias, 0.02, 1.0 );- material.clearcoat *= ( 1.0 - verseJoint ) * mix( 1.0, 0.8, max( smudge * 0.85, wipe * 0.75 ) );+ // Broad, soft smudges dim the mirror a little and haze it a little. Only+ // large, rounded patches (a rotated domain, no lattice-aligned cells):+ // fine noise in the coat's roughness switched the probe's blur level from+ // one small cell to the next, which drew every light as blocky squares.+ vec2 q = mat2( 0.8, -0.6, 0.6, 0.8 ) * vVerseWorld.xz;+ float smudge = smoothstep( 0.35, 0.8, verseFbm( q * 0.45 ) );+ material.clearcoatRoughness = clamp( material.clearcoatRoughness + 0.025 * smudge + verseCoatBias, 0.02, 1.0 );+ material.clearcoat *= ( 1.0 - verseJoint ) * mix( 1.0, 0.85, smudge );}#endif`;diff --git a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/realtime.test.ts b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/realtime.test.tsindex d504a2fe3f..4f12837be6 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/realtime.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/realtime.test.ts@@ -118,6 +118,9 @@ describe("deck shader patch", () => {expect(fragmentShader).toContain("totalEmissiveRadiance += verseDecode( texture2D( lightMap, vLightMapUv ) ) * verseBakedGain;");expect(fragmentShader).toContain("reflectVec = verseBoxProject( reflectVec, roughness );");expect(fragmentShader).toContain("float verseJoint = verseSeam( vVerseWorld );");+ // A fragment just past its room's box grows the box: no jump to the unprojected direction.+ expect(fragmentShader).toContain("vec3 boxMin = min( verseBoxMin, p - 0.02 );");+ expect(fragmentShader).not.toMatch(/lessThan\( p, verseBoxMin/);// The lightmap never adds irradiance, and the environment adds no diffuse: the bake holds it.expect(fragmentShader).not.toContain("#include <lights_fragment_maps>");expect(fragmentShader).not.toContain("irradiance += lightMapIrradiance");