create-threenative 0.2.10 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-docs/references/assertion-reference.md +109 -3
- package/agent-docs/references/auto-exposure.md +28 -45
- package/agent-docs/references/build-profiles.md +1 -1
- package/agent-docs/references/capability-reference.md +527 -44
- package/agent-docs/references/debug-surface.md +64 -0
- package/agent-docs/references/finding-assets.md +11 -12
- package/agent-docs/references/performance-basics.md +19 -0
- package/agent-docs/references/trace-a-slow-frame.md +21 -0
- package/agent-docs/references/visual-baseline.md +23 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +17 -6
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +87 -23
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +12 -11
- package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
- package/agent-files/scripts/reference.mjs +9 -4
- package/capabilities.json +739 -50
- package/dist/index.d.ts +40 -6
- package/dist/index.js +227 -34
- package/dist/quality.d.ts +12 -0
- package/dist/quality.js +166747 -0
- package/dist/threenative.js +60 -44
- package/dist/web-engine-gltf-loader.js +2 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +1 -1
- package/dist/web-engine-mesh-bvh.js +7 -0
- package/dist/web-engine-post-effects.js +645 -19
- package/dist/web-engine-runtime.js +3528 -343
- package/package.json +19 -9
- package/template-assets/assets/bay-PROVENANCE.md +21 -0
- package/template-assets/assets/bay-ground.webp +0 -0
- package/template-assets/assets/bay-metal.webp +0 -0
- package/template-assets/assets/bay-pavement-normal.webp +0 -0
- package/template-assets/assets/bay-pavement.webp +0 -0
- package/template-assets/assets/bay-plaster-normal.webp +0 -0
- package/template-assets/assets/bay-plaster.webp +0 -0
- package/template-assets/assets/bay-wood-normal.webp +0 -0
- package/template-assets/assets/bay-wood.webp +0 -0
- package/template-assets/assets/tex-PROVENANCE.md +25 -0
- package/template-assets/assets/tex-bark-normal.webp +0 -0
- package/template-assets/assets/tex-bark.webp +0 -0
- package/template-assets/assets/tex-birch-bark.webp +0 -0
- package/template-assets/assets/tex-grass.webp +0 -0
- package/template-assets/assets/tex-planks-normal.webp +0 -0
- package/template-assets/assets/tex-planks.webp +0 -0
- package/template-assets/assets/tex-rock-normal.webp +0 -0
- package/template-assets/assets/tex-rock.webp +0 -0
- package/template-assets/assets/tex-roof-tiles-normal.webp +0 -0
- package/template-assets/assets/tex-roof-tiles.webp +0 -0
- package/template-assets/assets/tex-sand-normal.webp +0 -0
- package/template-assets/assets/tex-sand.webp +0 -0
- package/template-assets/assets/tex-stone-wall-normal.webp +0 -0
- package/template-assets/assets/tex-stone-wall.webp +0 -0
- package/template-assets/kitExposure.ts +20 -0
- package/template-assets/patches/three@0.185.1.patch +481 -272
- package/template-assets/quality/biome.json +7 -0
- package/template-assets/quality/eslint.config.js +3 -0
- package/template-assets/realistic-ocean/README.md +113 -0
- package/template-assets/realistic-ocean/install.mjs +56 -0
- package/template-assets/realistic-ocean/src/realisticOcean.ts +151 -0
- package/template-assets/realistic-ocean/src/realisticOceanLifetime.ts +29 -0
- package/template-assets/realistic-ocean/src/render/REALISTIC-OCEAN-LICENSE.txt +25 -0
- package/template-assets/realistic-ocean/src/render/realisticSea.ts +642 -0
- package/template-assets/realistic-ocean/src/render/realisticSeaMaps.ts +311 -0
- package/template-assets/realistic-ocean/src/render/realisticSpectrum.ts +289 -0
- package/templates/AGENTS.md +21 -0
- package/templates/CLAUDE.md +23 -0
- package/templates/action-rpg/.codex/config.toml +6 -2
- package/templates/action-rpg/.cursor/mcp.json +8 -2
- package/templates/action-rpg/.gemini/settings.json +8 -2
- package/templates/action-rpg/.mcp.json +8 -2
- package/templates/action-rpg/.vscode/mcp.json +9 -2
- package/templates/action-rpg/.zed/settings.json +9 -2
- package/templates/action-rpg/AGENTS.md +11 -11
- package/templates/action-rpg/CLAUDE.md +11 -11
- package/templates/action-rpg/opencode.json +10 -2
- package/templates/action-rpg/package.json +15 -10
- package/templates/action-rpg/playtests/combat.playtest.json +6 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +22 -0
- package/templates/action-rpg/playtests/performance.playtest.json +1 -1
- package/templates/action-rpg/playtests/roll.playtest.json +112 -0
- package/templates/action-rpg/playtests/swing.playtest.json +55 -0
- package/templates/action-rpg/playtests/win.playtest.json +4 -4
- package/templates/action-rpg/src/entities/Fighter.ts +44 -4
- package/templates/action-rpg/src/entities/Player.ts +64 -12
- package/templates/action-rpg/src/render/atmosphere.ts +444 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +49 -18
- package/templates/action-rpg/src/render/clouds.ts +605 -0
- package/templates/action-rpg/src/render/dungeon.ts +8 -6
- package/templates/action-rpg/src/render/exposure.ts +11 -109
- package/templates/action-rpg/src/render/gpuSky.ts +752 -0
- package/templates/action-rpg/src/render/lighting.ts +27 -4
- package/templates/action-rpg/src/render/materialLighting.ts +2 -11
- package/templates/action-rpg/src/render/palette.ts +1 -0
- package/templates/action-rpg/src/render/postprocessing.ts +4 -4
- package/templates/action-rpg/src/render/props.ts +10 -8
- package/templates/action-rpg/src/render/quality.ts +56 -108
- package/templates/action-rpg/src/render/sky.ts +74 -1
- package/templates/action-rpg/src/scenes/Play.ts +16 -12
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +7 -2
- package/templates/action-rpg/src/ui/Hud.tsx +5 -7
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +14 -14
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/adventure/.codex/config.toml +23 -0
- package/templates/adventure/.cursor/mcp.json +38 -0
- package/templates/adventure/.gemini/settings.json +38 -0
- package/templates/adventure/.mcp.json +38 -0
- package/templates/adventure/.vscode/mcp.json +43 -0
- package/templates/adventure/.zed/settings.json +43 -0
- package/templates/adventure/AGENTS.md +60 -0
- package/templates/adventure/CLAUDE.md +62 -0
- package/templates/adventure/index.html +14 -0
- package/templates/adventure/kit.json +8 -0
- package/templates/adventure/native-playtests/survives.playtest.json +52 -0
- package/templates/adventure/opencode.json +49 -0
- package/templates/adventure/package.json +65 -0
- package/templates/adventure/playtests/boss.playtest.json +406 -0
- package/templates/adventure/playtests/combat.playtest.json +342 -0
- package/templates/adventure/playtests/controls.playtest.json +142 -0
- package/templates/adventure/playtests/explore.playtest.json +45 -0
- package/templates/adventure/playtests/flicker.playtest.json +206 -0
- package/templates/adventure/playtests/hearts.playtest.json +171 -0
- package/templates/adventure/playtests/lockon.playtest.json +256 -0
- package/templates/adventure/playtests/look.playtest.json +72 -0
- package/templates/adventure/playtests/move-hollow.playtest.json +106 -0
- package/templates/adventure/playtests/move.playtest.json +84 -0
- package/templates/adventure/playtests/performance.playtest.json +55 -0
- package/templates/adventure/playtests/puzzle.playtest.json +250 -0
- package/templates/adventure/playtests/stride.playtest.json +67 -0
- package/templates/adventure/playtests/survives.playtest.json +171 -0
- package/templates/adventure/playtests/thornback.playtest.json +267 -0
- package/templates/adventure/public/favicon.svg +4 -0
- package/templates/adventure/src/entities/Block.ts +114 -0
- package/templates/adventure/src/entities/Chest.ts +69 -0
- package/templates/adventure/src/entities/Door.ts +81 -0
- package/templates/adventure/src/entities/Dummy.ts +69 -0
- package/templates/adventure/src/entities/Flicker.ts +239 -0
- package/templates/adventure/src/entities/Hero.ts +561 -0
- package/templates/adventure/src/entities/LockOn.ts +180 -0
- package/templates/adventure/src/entities/Mossling.ts +249 -0
- package/templates/adventure/src/entities/Switch.ts +49 -0
- package/templates/adventure/src/entities/Thornback.ts +238 -0
- package/templates/adventure/src/entities/Warden.ts +196 -0
- package/templates/adventure/src/game.ts +65 -0
- package/templates/adventure/src/interact.ts +63 -0
- package/templates/adventure/src/level/Hollow.ts +240 -0
- package/templates/adventure/src/level/Vale.ts +383 -0
- package/templates/adventure/src/main.ts +18 -0
- package/templates/adventure/src/render/camera.ts +416 -0
- package/templates/adventure/src/render/creatures.ts +405 -0
- package/templates/adventure/src/render/effects.ts +333 -0
- package/templates/adventure/src/render/foliage.ts +1072 -0
- package/templates/adventure/src/render/hero.ts +1447 -0
- package/templates/adventure/src/render/kitExposure.ts +20 -0
- package/templates/adventure/src/render/lighting.ts +74 -0
- package/templates/adventure/src/render/loading.ts +332 -0
- package/templates/adventure/src/render/materials.ts +179 -0
- package/templates/adventure/src/render/palette.ts +137 -0
- package/templates/adventure/src/render/postprocessing.ts +70 -0
- package/templates/adventure/src/render/props.ts +383 -0
- package/templates/adventure/src/render/quality.ts +46 -0
- package/templates/adventure/src/render/sky.ts +271 -0
- package/templates/adventure/src/render/surface.ts +259 -0
- package/templates/adventure/src/render/touch-controls.ts +137 -0
- package/templates/adventure/src/scenes/Play.ts +959 -0
- package/templates/adventure/src/state.ts +113 -0
- package/templates/adventure/src/style.css +98 -0
- package/templates/adventure/src/ui/App.tsx +22 -0
- package/templates/adventure/src/ui/GameUi.tsx +20 -0
- package/templates/adventure/src/ui/Hud.tsx +70 -0
- package/templates/adventure/src/ui/Menu.tsx +15 -0
- package/templates/adventure/src/ui/main.tsx +14 -0
- package/templates/adventure/tailwind.config.ts +2 -0
- package/templates/adventure/threenative.config.ts +62 -0
- package/templates/adventure/tsconfig.json +17 -0
- package/templates/adventure/vite.config.ts +49 -0
- package/templates/collectathon/.codex/config.toml +23 -0
- package/templates/collectathon/.cursor/mcp.json +38 -0
- package/templates/collectathon/.gemini/settings.json +38 -0
- package/templates/collectathon/.mcp.json +38 -0
- package/templates/collectathon/.vscode/mcp.json +43 -0
- package/templates/collectathon/.zed/settings.json +43 -0
- package/templates/collectathon/AGENTS.md +58 -0
- package/templates/collectathon/CLAUDE.md +60 -0
- package/templates/collectathon/index.html +14 -0
- package/templates/collectathon/kit.json +8 -0
- package/templates/collectathon/native-playtests/survives.playtest.json +52 -0
- package/templates/collectathon/opencode.json +49 -0
- package/templates/collectathon/package.json +65 -0
- package/templates/collectathon/playtests/acrobatics.playtest.json +238 -0
- package/templates/collectathon/playtests/camera.playtest.json +80 -0
- package/templates/collectathon/playtests/clipped-probe.playtest.json +101 -0
- package/templates/collectathon/playtests/collect.playtest.json +196 -0
- package/templates/collectathon/playtests/combat.playtest.json +246 -0
- package/templates/collectathon/playtests/double-tap-air.playtest.json +198 -0
- package/templates/collectathon/playtests/double-tap.playtest.json +136 -0
- package/templates/collectathon/playtests/effects.playtest.json +124 -0
- package/templates/collectathon/playtests/enemies.playtest.json +295 -0
- package/templates/collectathon/playtests/explore.playtest.json +45 -0
- package/templates/collectathon/playtests/hop-reach.playtest.json +117 -0
- package/templates/collectathon/playtests/jump-chain.playtest.json +274 -0
- package/templates/collectathon/playtests/ledge-angle.playtest.json +107 -0
- package/templates/collectathon/playtests/ledge-too-high.playtest.json +115 -0
- package/templates/collectathon/playtests/ledge.playtest.json +100 -0
- package/templates/collectathon/playtests/look.playtest.json +64 -0
- package/templates/collectathon/playtests/performance.playtest.json +55 -0
- package/templates/collectathon/playtests/stride.playtest.json +111 -0
- package/templates/collectathon/playtests/survives.playtest.json +123 -0
- package/templates/collectathon/playtests/telegraphs.playtest.json +132 -0
- package/templates/collectathon/playtests/thornback.playtest.json +157 -0
- package/templates/collectathon/playtests/wall-kick.playtest.json +206 -0
- package/templates/collectathon/playtests/win.playtest.json +166 -0
- package/templates/collectathon/public/favicon.svg +4 -0
- package/templates/collectathon/src/entities/Hero.ts +915 -0
- package/templates/collectathon/src/entities/Pickup.ts +63 -0
- package/templates/collectathon/src/entities/Walker.ts +248 -0
- package/templates/collectathon/src/game.ts +51 -0
- package/templates/collectathon/src/level/Course.ts +590 -0
- package/templates/collectathon/src/level/terrain.ts +144 -0
- package/templates/collectathon/src/main.ts +14 -0
- package/templates/collectathon/src/playtest-events.ts +15 -0
- package/templates/collectathon/src/render/camera.ts +163 -0
- package/templates/collectathon/src/render/castle.ts +408 -0
- package/templates/collectathon/src/render/effects.ts +284 -0
- package/templates/collectathon/src/render/foliage.ts +744 -0
- package/templates/collectathon/src/render/ground.ts +139 -0
- package/templates/collectathon/src/render/hero.ts +452 -0
- package/templates/collectathon/src/render/kitExposure.ts +20 -0
- package/templates/collectathon/src/render/lighting.ts +65 -0
- package/templates/collectathon/src/render/loading.ts +332 -0
- package/templates/collectathon/src/render/materials.ts +196 -0
- package/templates/collectathon/src/render/palette.ts +82 -0
- package/templates/collectathon/src/render/postprocessing.ts +79 -0
- package/templates/collectathon/src/render/props.ts +218 -0
- package/templates/collectathon/src/render/quality.ts +54 -0
- package/templates/collectathon/src/render/sky.ts +262 -0
- package/templates/collectathon/src/render/surface.ts +269 -0
- package/templates/collectathon/src/render/touch-controls.ts +179 -0
- package/templates/collectathon/src/render/touch-layout.ts +48 -0
- package/templates/collectathon/src/render/water.ts +191 -0
- package/templates/collectathon/src/scenes/Play.ts +481 -0
- package/templates/collectathon/src/state.ts +38 -0
- package/templates/collectathon/src/style.css +106 -0
- package/templates/collectathon/src/ui/App.tsx +22 -0
- package/templates/collectathon/src/ui/GameUi.tsx +20 -0
- package/templates/collectathon/src/ui/Hud.tsx +77 -0
- package/templates/collectathon/src/ui/Menu.tsx +13 -0
- package/templates/collectathon/src/ui/main.tsx +14 -0
- package/templates/collectathon/tailwind.config.ts +2 -0
- package/templates/collectathon/threenative.config.ts +62 -0
- package/templates/collectathon/tsconfig.json +17 -0
- package/templates/collectathon/vite.config.ts +49 -0
- package/templates/kart/.codex/config.toml +23 -0
- package/templates/kart/.cursor/mcp.json +38 -0
- package/templates/kart/.gemini/settings.json +38 -0
- package/templates/kart/.mcp.json +38 -0
- package/templates/kart/.vscode/mcp.json +43 -0
- package/templates/kart/.zed/settings.json +43 -0
- package/templates/kart/AGENTS.md +58 -0
- package/templates/kart/CLAUDE.md +60 -0
- package/templates/kart/index.html +14 -0
- package/templates/kart/kit.json +8 -0
- package/templates/kart/native-playtests/survives.playtest.json +65 -0
- package/templates/kart/opencode.json +49 -0
- package/templates/kart/package.json +64 -0
- package/templates/kart/playtests/drift.playtest.json +226 -0
- package/templates/kart/playtests/explore.playtest.json +45 -0
- package/templates/kart/playtests/hit-stays-above-road.playtest.json +92 -0
- package/templates/kart/playtests/item-key.playtest.json +108 -0
- package/templates/kart/playtests/items.playtest.json +143 -0
- package/templates/kart/playtests/lap-times.playtest.json +138 -0
- package/templates/kart/playtests/laps.playtest.json +149 -0
- package/templates/kart/playtests/performance.playtest.json +57 -0
- package/templates/kart/playtests/race.playtest.json +294 -0
- package/templates/kart/playtests/restart.playtest.json +87 -0
- package/templates/kart/playtests/rocket-start.playtest.json +56 -0
- package/templates/kart/playtests/smooth-drive.playtest.json +101 -0
- package/templates/kart/playtests/surfaces.playtest.json +113 -0
- package/templates/kart/playtests/survives.playtest.json +116 -0
- package/templates/kart/playtests/wall.playtest.json +118 -0
- package/templates/kart/public/favicon.svg +4 -0
- package/templates/kart/src/entities/Driver.ts +123 -0
- package/templates/kart/src/entities/Items.ts +194 -0
- package/templates/kart/src/entities/Kart.ts +517 -0
- package/templates/kart/src/game.ts +45 -0
- package/templates/kart/src/main.ts +14 -0
- package/templates/kart/src/playtest-events.ts +15 -0
- package/templates/kart/src/render/camera.ts +83 -0
- package/templates/kart/src/render/course.ts +579 -0
- package/templates/kart/src/render/effects.ts +266 -0
- package/templates/kart/src/render/items.ts +163 -0
- package/templates/kart/src/render/kart.ts +256 -0
- package/templates/kart/src/render/kitExposure.ts +20 -0
- package/templates/kart/src/render/lighting.ts +58 -0
- package/templates/kart/src/render/loading.ts +332 -0
- package/templates/kart/src/render/materials.ts +119 -0
- package/templates/kart/src/render/palette.ts +74 -0
- package/templates/kart/src/render/postprocessing.ts +79 -0
- package/templates/kart/src/render/quality.ts +54 -0
- package/templates/kart/src/render/skids.ts +86 -0
- package/templates/kart/src/render/sky.ts +105 -0
- package/templates/kart/src/render/touch-controls.ts +168 -0
- package/templates/kart/src/render/touch-layout.ts +48 -0
- package/templates/kart/src/scenes/Race.ts +850 -0
- package/templates/kart/src/state.ts +53 -0
- package/templates/kart/src/style.css +106 -0
- package/templates/kart/src/track/Course.ts +276 -0
- package/templates/kart/src/track/Race.ts +133 -0
- package/templates/kart/src/ui/App.tsx +21 -0
- package/templates/kart/src/ui/GameUi.tsx +20 -0
- package/templates/kart/src/ui/Hud.tsx +172 -0
- package/templates/kart/src/ui/Menu.tsx +13 -0
- package/templates/kart/src/ui/main.tsx +14 -0
- package/templates/kart/tailwind.config.ts +2 -0
- package/templates/kart/threenative.config.ts +62 -0
- package/templates/kart/tsconfig.json +17 -0
- package/templates/kart/vite.config.ts +49 -0
- package/templates/minimal/.codex/config.toml +6 -2
- package/templates/minimal/.cursor/mcp.json +8 -2
- package/templates/minimal/.gemini/settings.json +8 -2
- package/templates/minimal/.mcp.json +8 -2
- package/templates/minimal/.vscode/mcp.json +9 -2
- package/templates/minimal/.zed/settings.json +9 -2
- package/templates/minimal/AGENTS.md +11 -13
- package/templates/minimal/CLAUDE.md +11 -13
- package/templates/minimal/opencode.json +10 -2
- package/templates/minimal/package.json +14 -9
- package/templates/minimal/playtests/camera-wall.playtest.json +36 -0
- package/templates/minimal/playtests/jump.playtest.json +45 -0
- package/templates/minimal/playtests/play.playtest.json +1 -1
- package/templates/minimal/src/game.ts +2 -0
- package/templates/minimal/src/render/atmosphere.ts +444 -0
- package/templates/minimal/src/render/backlightMaterial.ts +49 -18
- package/templates/minimal/src/render/camera.ts +35 -4
- package/templates/minimal/src/render/clouds.ts +605 -0
- package/templates/minimal/src/render/exposure.ts +7 -111
- package/templates/minimal/src/render/gpuSky.ts +752 -0
- package/templates/minimal/src/render/lighting.ts +26 -4
- package/templates/minimal/src/render/materialLighting.ts +2 -10
- package/templates/minimal/src/render/postprocessing.ts +4 -4
- package/templates/minimal/src/render/quality.ts +10 -116
- package/templates/minimal/src/render/sky.ts +73 -1
- package/templates/minimal/src/scenes/Play.ts +18 -7
- package/templates/platformer/.codex/config.toml +6 -2
- package/templates/platformer/.cursor/mcp.json +8 -2
- package/templates/platformer/.gemini/settings.json +8 -2
- package/templates/platformer/.mcp.json +8 -2
- package/templates/platformer/.vscode/mcp.json +9 -2
- package/templates/platformer/.zed/settings.json +9 -2
- package/templates/platformer/AGENTS.md +13 -9
- package/templates/platformer/CLAUDE.md +13 -9
- package/templates/platformer/opencode.json +10 -2
- package/templates/platformer/package.json +15 -10
- package/templates/platformer/playtests/dash-jump.playtest.json +34 -0
- package/templates/platformer/playtests/finish.playtest.json +58 -0
- package/templates/platformer/playtests/idle.playtest.json +44 -0
- package/templates/platformer/playtests/performance.playtest.json +1 -1
- package/templates/platformer/src/entities/Fox.ts +19 -6
- package/templates/platformer/src/game.ts +1 -0
- package/templates/platformer/src/level/Stage.ts +4 -1
- package/templates/platformer/src/render/backlightMaterial.ts +49 -18
- package/templates/platformer/src/render/camera.ts +30 -1
- package/templates/platformer/src/render/exposure.ts +6 -111
- package/templates/platformer/src/render/fox.ts +5 -2
- package/templates/platformer/src/render/kitExposure.ts +20 -0
- package/templates/platformer/src/render/materialLighting.ts +2 -11
- package/templates/platformer/src/render/postprocessing.ts +4 -4
- package/templates/platformer/src/render/props.ts +1 -2
- package/templates/platformer/src/render/quality.ts +10 -118
- package/templates/platformer/src/scenes/Play.ts +31 -15
- package/templates/platformer/src/ui/Menu.tsx +1 -1
- package/templates/puzzle/.codex/config.toml +6 -2
- package/templates/puzzle/.cursor/mcp.json +8 -2
- package/templates/puzzle/.gemini/settings.json +8 -2
- package/templates/puzzle/.mcp.json +8 -2
- package/templates/puzzle/.vscode/mcp.json +9 -2
- package/templates/puzzle/.zed/settings.json +9 -2
- package/templates/puzzle/AGENTS.md +14 -17
- package/templates/puzzle/CLAUDE.md +14 -17
- package/templates/puzzle/opencode.json +10 -2
- package/templates/puzzle/package.json +15 -10
- package/templates/puzzle/playtests/performance.playtest.json +1 -1
- package/templates/puzzle/playtests/replay-keeps-progress.playtest.json +78 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +49 -18
- package/templates/puzzle/src/render/exposure.ts +11 -109
- package/templates/puzzle/src/render/lighting.ts +3 -3
- package/templates/puzzle/src/render/materialLighting.ts +2 -11
- package/templates/puzzle/src/render/palette.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +4 -4
- package/templates/puzzle/src/render/quality.ts +44 -153
- package/templates/puzzle/src/render/vault.ts +18 -6
- package/templates/puzzle/src/scenes/Play.ts +6 -1
- package/templates/puzzle/src/ui/Hud.tsx +8 -43
- package/templates/racing/.codex/config.toml +6 -2
- package/templates/racing/.cursor/mcp.json +8 -2
- package/templates/racing/.gemini/settings.json +8 -2
- package/templates/racing/.mcp.json +8 -2
- package/templates/racing/.vscode/mcp.json +9 -2
- package/templates/racing/.zed/settings.json +9 -2
- package/templates/racing/AGENTS.md +10 -12
- package/templates/racing/CLAUDE.md +10 -12
- package/templates/racing/opencode.json +10 -2
- package/templates/racing/package.json +15 -10
- package/templates/racing/playtests/brake.playtest.json +54 -0
- package/templates/racing/playtests/outcome.playtest.json +19 -0
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/stopped-car-is-not-rescued.playtest.json +59 -0
- package/templates/racing/src/entities/RacingCar.ts +12 -3
- package/templates/racing/src/entities/Rival.ts +11 -2
- package/templates/racing/src/render/atmosphere.ts +444 -0
- package/templates/racing/src/render/backlightMaterial.ts +49 -18
- package/templates/racing/src/render/clouds.ts +605 -0
- package/templates/racing/src/render/exposure.ts +6 -111
- package/templates/racing/src/render/gpuSky.ts +752 -0
- package/templates/racing/src/render/kitExposure.ts +20 -0
- package/templates/racing/src/render/lighting.ts +26 -4
- package/templates/racing/src/render/materialLighting.ts +2 -11
- package/templates/racing/src/render/materials.ts +2 -1
- package/templates/racing/src/render/postprocessing.ts +4 -4
- package/templates/racing/src/render/quality.ts +27 -115
- package/templates/racing/src/render/sky.ts +72 -1
- package/templates/racing/src/scenes/Race.ts +9 -7
- package/templates/racing/src/track/TrackSector.ts +5 -2
- package/templates/racing/src/ui/Hud.tsx +12 -7
- package/templates/rain/.codex/config.toml +6 -2
- package/templates/rain/.cursor/mcp.json +8 -2
- package/templates/rain/.gemini/settings.json +8 -2
- package/templates/rain/.mcp.json +8 -2
- package/templates/rain/.vscode/mcp.json +9 -2
- package/templates/rain/.zed/settings.json +9 -2
- package/templates/rain/AGENTS.md +12 -12
- package/templates/rain/CLAUDE.md +12 -12
- package/templates/rain/opencode.json +10 -2
- package/templates/rain/package.json +14 -9
- package/templates/rain/playtests/performance.playtest.json +1 -1
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/render/bloom-shader.ts +1 -1
- package/templates/rain/src/render/clouds-shader.ts +2 -2
- package/templates/rain/src/render/clouds.ts +2 -1
- package/templates/rain/src/render/exposure.ts +11 -109
- package/templates/rain/src/render/post-shader.ts +7 -11
- package/templates/rain/src/render/postprocessing.ts +8 -24
- package/templates/rain/src/render/quality.ts +44 -98
- package/templates/rain/src/render/world-shader.ts +281 -97
- package/templates/rain/src/render/world.ts +82 -2
- package/templates/rain/src/style.css +1 -1
- package/templates/rain/src/ui/GameUi.tsx +6 -2
- package/templates/rain/src/ui/Hud.tsx +1 -1
- package/templates/rain/tools/generate-shaders.mjs +2 -2
- package/templates/rain/tools/tempest-post.frag +4 -6
- package/templates/rain/tools/tempest-world.frag +80 -12
- package/templates/rts/.codex/config.toml +6 -2
- package/templates/rts/.cursor/mcp.json +8 -2
- package/templates/rts/.gemini/settings.json +8 -2
- package/templates/rts/.mcp.json +8 -2
- package/templates/rts/.vscode/mcp.json +9 -2
- package/templates/rts/.zed/settings.json +9 -2
- package/templates/rts/AGENTS.md +15 -16
- package/templates/rts/CLAUDE.md +15 -16
- package/templates/rts/opencode.json +10 -2
- package/templates/rts/package.json +14 -9
- package/templates/rts/playtests/performance.playtest.json +1 -1
- package/templates/rts/playtests/rts-attack.playtest.json +5 -0
- package/templates/rts/playtests/rts-build.playtest.json +20 -1
- package/templates/rts/playtests/rts-orders.playtest.json +1 -1
- package/templates/rts/playtests/rts-pause.playtest.json +112 -0
- package/templates/rts/playtests/rts-train.playtest.json +1 -1
- package/templates/rts/playtests/rts-zoom.playtest.json +81 -0
- package/templates/rts/src/game.ts +29 -7
- package/templates/rts/src/render/army.ts +181 -49
- package/templates/rts/src/render/backlightMaterial.ts +49 -18
- package/templates/rts/src/render/environment.ts +276 -0
- package/templates/rts/src/render/exposure.ts +3 -65
- package/templates/rts/src/render/ground.ts +478 -0
- package/templates/rts/src/render/lighting.ts +62 -11
- package/templates/rts/src/render/materialLighting.ts +2 -11
- package/templates/rts/src/render/materials.ts +47 -118
- package/templates/rts/src/render/palette.ts +30 -13
- package/templates/rts/src/render/picking.ts +18 -0
- package/templates/rts/src/render/postprocessing.ts +4 -4
- package/templates/rts/src/render/quality.ts +64 -85
- package/templates/rts/src/render/resources.ts +21 -22
- package/templates/rts/src/render/sky.ts +9 -12
- package/templates/rts/src/render/terrain.ts +36 -11
- package/templates/rts/src/scenes/Play.ts +373 -38
- package/templates/rts/src/sim/ai.ts +0 -11
- package/templates/rts/src/state.ts +46 -0
- package/templates/rts/src/style.css +1543 -0
- package/templates/rts/src/ui/Commands.tsx +204 -107
- package/templates/rts/src/ui/GameUi.tsx +12 -5
- package/templates/rts/src/ui/Hud.tsx +611 -116
- package/templates/rts/src/ui/Minimap.tsx +103 -37
- package/templates/rts/src/ui/icons.tsx +116 -0
- package/templates/rts/src/ui/labels.ts +73 -0
- package/templates/rts/src/ui/minimapPoint.ts +30 -0
- package/templates/rts/threenative.config.ts +1 -1
- package/templates/runner/.codex/config.toml +6 -2
- package/templates/runner/.cursor/mcp.json +8 -2
- package/templates/runner/.gemini/settings.json +8 -2
- package/templates/runner/.mcp.json +8 -2
- package/templates/runner/.vscode/mcp.json +9 -2
- package/templates/runner/.zed/settings.json +9 -2
- package/templates/runner/AGENTS.md +12 -12
- package/templates/runner/CLAUDE.md +12 -12
- package/templates/runner/opencode.json +10 -2
- package/templates/runner/package.json +15 -10
- package/templates/runner/playtests/near-miss.playtest.json +48 -0
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/playtests/stride.playtest.json +27 -0
- package/templates/runner/playtests/survives.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +3 -1
- package/templates/runner/src/entities/Runner.ts +11 -5
- package/templates/runner/src/render/atmosphere.ts +444 -0
- package/templates/runner/src/render/backlightMaterial.ts +49 -18
- package/templates/runner/src/render/clouds.ts +605 -0
- package/templates/runner/src/render/exposure.ts +6 -111
- package/templates/runner/src/render/gpuSky.ts +752 -0
- package/templates/runner/src/render/kitExposure.ts +20 -0
- package/templates/runner/src/render/lighting.ts +26 -4
- package/templates/runner/src/render/materialLighting.ts +2 -11
- package/templates/runner/src/render/postprocessing.ts +4 -4
- package/templates/runner/src/render/quality.ts +26 -114
- package/templates/runner/src/render/sky.ts +73 -1
- package/templates/runner/src/scenes/Run.ts +19 -15
- package/templates/runner/src/track.ts +12 -3
- package/templates/sailing/.codex/config.toml +6 -2
- package/templates/sailing/.cursor/mcp.json +8 -2
- package/templates/sailing/.gemini/settings.json +8 -2
- package/templates/sailing/.mcp.json +8 -2
- package/templates/sailing/.vscode/mcp.json +9 -2
- package/templates/sailing/.zed/settings.json +9 -2
- package/templates/sailing/AGENTS.md +10 -11
- package/templates/sailing/CLAUDE.md +10 -11
- package/templates/sailing/opencode.json +10 -2
- package/templates/sailing/package.json +15 -10
- package/templates/sailing/playtests/fail.playtest.json +46 -5
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +7 -0
- package/templates/sailing/playtests/performance.playtest.json +1 -1
- package/templates/sailing/src/game.ts +1 -0
- package/templates/sailing/src/render/backlightMaterial.ts +49 -18
- package/templates/sailing/src/render/exposure.ts +6 -111
- package/templates/sailing/src/render/kitExposure.ts +20 -0
- package/templates/sailing/src/render/materialLighting.ts +2 -11
- package/templates/sailing/src/render/ocean.ts +0 -1
- package/templates/sailing/src/render/postprocessing.ts +4 -4
- package/templates/sailing/src/render/quality.ts +31 -138
- package/templates/sailing/src/scenes/Sailing.ts +12 -4
- package/templates/sailing/src/ui/Hud.tsx +6 -2
- package/templates/sailing/src/ui/Menu.tsx +1 -1
- package/templates/shooter/.codex/config.toml +6 -2
- package/templates/shooter/.cursor/mcp.json +8 -2
- package/templates/shooter/.gemini/settings.json +8 -2
- package/templates/shooter/.mcp.json +8 -2
- package/templates/shooter/.vscode/mcp.json +9 -2
- package/templates/shooter/.zed/settings.json +9 -2
- package/templates/shooter/AGENTS.md +13 -12
- package/templates/shooter/CLAUDE.md +13 -12
- package/templates/shooter/index.html +1 -1
- package/templates/shooter/main.html +13 -0
- package/templates/shooter/opencode.json +10 -2
- package/templates/shooter/package.json +15 -10
- package/templates/shooter/playtests/breakable-shatters.playtest.json +6 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +6 -0
- package/templates/shooter/playtests/hands-authored-rate.playtest.json +54 -0
- package/templates/shooter/playtests/movement-eases.playtest.json +53 -0
- package/templates/shooter/playtests/performance.playtest.json +3 -3
- package/templates/shooter/playtests/stairs-smooth-the-eye.playtest.json +56 -0
- package/templates/shooter/playtests/weapon-sharp-while-turning.playtest.json +206 -0
- package/templates/shooter/src/entities/Breakables.ts +34 -10
- package/templates/shooter/src/entities/Enemy.ts +176 -54
- package/templates/shooter/src/entities/FpsPlayer.ts +55 -16
- package/templates/shooter/src/entities/Rifle.ts +83 -9
- package/templates/shooter/src/entities/movement.ts +96 -0
- package/templates/shooter/src/render/atmosphere.ts +444 -0
- package/templates/shooter/src/render/backlightMaterial.ts +49 -18
- package/templates/shooter/src/render/camera.ts +3 -1
- package/templates/shooter/src/render/clouds.ts +605 -0
- package/templates/shooter/src/render/exposure.ts +10 -109
- package/templates/shooter/src/render/facade.ts +26 -68
- package/templates/shooter/src/render/gpuSky.ts +752 -0
- package/templates/shooter/src/render/lighting.ts +27 -4
- package/templates/shooter/src/render/materialAssignments.ts +9 -1
- package/templates/shooter/src/render/materialLighting.ts +2 -11
- package/templates/shooter/src/render/occlusion.ts +13 -4
- package/templates/shooter/src/render/palette.ts +1 -0
- package/templates/shooter/src/render/postprocessing.ts +4 -4
- package/templates/shooter/src/render/quality.ts +50 -108
- package/templates/shooter/src/render/scale.ts +0 -11
- package/templates/shooter/src/render/sky.ts +103 -2
- package/templates/shooter/src/render/surface.ts +140 -0
- package/templates/shooter/src/render/town.ts +3 -6
- package/templates/shooter/src/render/townMaterials.ts +95 -42
- package/templates/shooter/src/render/vehicles.ts +2 -0
- package/templates/shooter/src/scenes/Play.ts +83 -23
- package/templates/shooter/src/ui/Hud.tsx +268 -193
- package/templates/shooter/src/worker-page.ts +29 -0
- package/templates/shooter/src/worker.ts +5 -0
- package/templates/shooter/threenative.config.ts +3 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/.codex/config.toml +6 -2
- package/templates/snow/.cursor/mcp.json +8 -2
- package/templates/snow/.gemini/settings.json +8 -2
- package/templates/snow/.mcp.json +8 -2
- package/templates/snow/.vscode/mcp.json +9 -2
- package/templates/snow/.zed/settings.json +9 -2
- package/templates/snow/AGENTS.md +12 -10
- package/templates/snow/CLAUDE.md +12 -10
- package/templates/snow/opencode.json +10 -2
- package/templates/snow/package.json +15 -10
- package/templates/snow/playtests/performance.playtest.json +1 -1
- package/templates/snow/src/render/backlightMaterial.ts +49 -18
- package/templates/snow/src/render/exposure.ts +17 -106
- package/templates/snow/src/render/materialLighting.ts +2 -11
- package/templates/snow/src/render/postprocessing.ts +11 -5
- package/templates/snow/src/render/quality.ts +46 -126
- package/templates/snow/src/render/snowSurface.ts +32 -15
- package/templates/snow/src/scenes/Snow.ts +2 -1
- package/templates/starter/.codex/config.toml +6 -2
- package/templates/starter/.cursor/mcp.json +8 -2
- package/templates/starter/.gemini/settings.json +8 -2
- package/templates/starter/.mcp.json +8 -2
- package/templates/starter/.vscode/mcp.json +9 -2
- package/templates/starter/.zed/settings.json +9 -2
- package/templates/starter/AGENTS.md +18 -14
- package/templates/starter/CLAUDE.md +18 -14
- package/templates/starter/index.html +1 -1
- package/templates/starter/main.html +12 -0
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -0
- package/templates/starter/native-playtests/render-chain.playtest.json +34 -21
- package/templates/starter/opencode.json +10 -2
- package/templates/starter/package.json +15 -10
- package/templates/starter/playtests/play.playtest.json +22 -2
- package/templates/starter/playtests/production-readiness.playtest.json +14 -0
- package/templates/starter/src/entities/Crate.ts +19 -1
- package/templates/starter/src/render/arena.ts +2 -2
- package/templates/starter/src/render/atmosphere.ts +444 -0
- package/templates/starter/src/render/backlightMaterial.ts +49 -18
- package/templates/starter/src/render/camera.ts +28 -0
- package/templates/starter/src/render/clouds.ts +605 -0
- package/templates/starter/src/render/contactShadow.ts +50 -0
- package/templates/starter/src/render/exposure.ts +9 -111
- package/templates/starter/src/render/gpuSky.ts +752 -0
- package/templates/starter/src/render/grade.ts +1 -1
- package/templates/starter/src/render/lighting.ts +34 -6
- package/templates/starter/src/render/materialLighting.ts +2 -11
- package/templates/starter/src/render/postprocessing.ts +27 -14
- package/templates/starter/src/render/quality.ts +18 -147
- package/templates/starter/src/render/sky.ts +90 -40
- package/templates/starter/src/render/temporalAA.ts +1 -1
- package/templates/starter/src/render/temporalAAStage.ts +1 -1
- package/templates/starter/src/render/temporalCurrentFootprint.ts +0 -1
- package/templates/starter/src/render/temporalDetailStage.ts +106 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +2 -2
- package/templates/starter/src/render/volumetricFogCamera.ts +32 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +7 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +27 -19
- package/templates/starter/src/render/volumetricFogVolume.ts +31 -7
- package/templates/starter/src/scenes/Play.ts +11 -8
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/worker-page.ts +29 -0
- package/templates/starter/src/worker.ts +5 -0
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/.codex/config.toml +6 -2
- package/templates/tower-defense/.cursor/mcp.json +8 -2
- package/templates/tower-defense/.gemini/settings.json +8 -2
- package/templates/tower-defense/.mcp.json +8 -2
- package/templates/tower-defense/.vscode/mcp.json +9 -2
- package/templates/tower-defense/.zed/settings.json +9 -2
- package/templates/tower-defense/AGENTS.md +10 -12
- package/templates/tower-defense/CLAUDE.md +10 -12
- package/templates/tower-defense/opencode.json +10 -2
- package/templates/tower-defense/package.json +15 -10
- package/templates/tower-defense/playtests/chill-tint.playtest.json +387 -0
- package/templates/tower-defense/playtests/performance.playtest.json +1 -1
- package/templates/tower-defense/src/enemies/Enemy.ts +9 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +49 -18
- package/templates/tower-defense/src/render/exposure.ts +11 -109
- package/templates/tower-defense/src/render/lighting.ts +4 -2
- package/templates/tower-defense/src/render/materialLighting.ts +2 -11
- package/templates/tower-defense/src/render/postprocessing.ts +4 -4
- package/templates/tower-defense/src/render/quality.ts +10 -116
- package/templates/tower-defense/src/render/sky.ts +2 -2
- package/templates/tower-defense/src/scenes/Battle.ts +4 -0
- package/template-assets/autoExposure.ts +0 -225
- package/template-assets/exposureGraph.ts +0 -178
- package/template-assets/exposureReadback.ts +0 -79
- package/template-assets/worldEnvironment.ts +0 -1212
- package/templates/action-rpg/src/render/autoExposure.ts +0 -225
- package/templates/action-rpg/src/render/exposureGraph.ts +0 -178
- package/templates/action-rpg/src/render/exposureReadback.ts +0 -79
- package/templates/action-rpg/src/render/worldEnvironment.ts +0 -1212
- package/templates/minimal/src/render/autoExposure.ts +0 -225
- package/templates/minimal/src/render/exposureGraph.ts +0 -178
- package/templates/minimal/src/render/exposureReadback.ts +0 -79
- package/templates/minimal/src/render/worldEnvironment.ts +0 -1212
- package/templates/platformer/src/render/autoExposure.ts +0 -225
- package/templates/platformer/src/render/exposureGraph.ts +0 -178
- package/templates/platformer/src/render/exposureReadback.ts +0 -79
- package/templates/platformer/src/render/worldEnvironment.ts +0 -1212
- package/templates/puzzle/src/render/autoExposure.ts +0 -225
- package/templates/puzzle/src/render/exposureGraph.ts +0 -178
- package/templates/puzzle/src/render/exposureReadback.ts +0 -79
- package/templates/puzzle/src/render/worldEnvironment.ts +0 -1212
- package/templates/racing/src/render/autoExposure.ts +0 -225
- package/templates/racing/src/render/exposureGraph.ts +0 -178
- package/templates/racing/src/render/exposureReadback.ts +0 -79
- package/templates/racing/src/render/worldEnvironment.ts +0 -1212
- package/templates/rain/src/render/autoExposure.ts +0 -225
- package/templates/rain/src/render/exposureGraph.ts +0 -178
- package/templates/rain/src/render/exposureReadback.ts +0 -79
- package/templates/rain/src/render/worldEnvironment.ts +0 -1212
- package/templates/rts/src/render/autoExposure.ts +0 -225
- package/templates/rts/src/render/exposureGraph.ts +0 -178
- package/templates/rts/src/render/exposureReadback.ts +0 -79
- package/templates/rts/src/render/worldEnvironment.ts +0 -1212
- package/templates/runner/src/render/autoExposure.ts +0 -225
- package/templates/runner/src/render/exposureGraph.ts +0 -178
- package/templates/runner/src/render/exposureReadback.ts +0 -79
- package/templates/runner/src/render/worldEnvironment.ts +0 -1212
- package/templates/sailing/src/render/autoExposure.ts +0 -225
- package/templates/sailing/src/render/exposureGraph.ts +0 -178
- package/templates/sailing/src/render/exposureReadback.ts +0 -79
- package/templates/sailing/src/render/worldEnvironment.ts +0 -1212
- package/templates/shooter/src/render/autoExposure.ts +0 -225
- package/templates/shooter/src/render/exposureGraph.ts +0 -178
- package/templates/shooter/src/render/exposureReadback.ts +0 -79
- package/templates/shooter/src/render/worldEnvironment.ts +0 -1212
- package/templates/snow/src/render/autoExposure.ts +0 -225
- package/templates/snow/src/render/exposureGraph.ts +0 -178
- package/templates/snow/src/render/exposureReadback.ts +0 -79
- package/templates/snow/src/render/worldEnvironment.ts +0 -1212
- package/templates/starter/src/render/autoExposure.ts +0 -225
- package/templates/starter/src/render/exposureGraph.ts +0 -178
- package/templates/starter/src/render/exposureReadback.ts +0 -79
- package/templates/starter/src/render/worldEnvironment.ts +0 -1212
- package/templates/tower-defense/src/render/autoExposure.ts +0 -225
- package/templates/tower-defense/src/render/exposureGraph.ts +0 -178
- package/templates/tower-defense/src/render/exposureReadback.ts +0 -79
- package/templates/tower-defense/src/render/worldEnvironment.ts +0 -1212
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Generated for you, and ThreeNative does not read it. The surface the material shades is not the
|
|
2
|
+
// raw displacement buffer: it needs the surface's slope and its horizontal Jacobian, and it needs
|
|
3
|
+
// foam that remembers where waves broke. Both are computed here, on the GPU, from the buffers
|
|
4
|
+
// `SpectralOcean` already writes, as one more compute-driven object the scene adds after the sea.
|
|
5
|
+
//
|
|
6
|
+
// Foam is stored in the waves' own (Lagrangian) coordinates: a texel is a patch of water, not a
|
|
7
|
+
// patch of space. Sampling it at a vertex's rest position therefore carries the foam along with the
|
|
8
|
+
// crest that made it, the grid tiles with the same period as the cascade it lives on, and a camera
|
|
9
|
+
// teleport cannot desynchronise it — there is no camera-relative history to lose.
|
|
10
|
+
//
|
|
11
|
+
// Adapted from web-ocean (MIT, Copyright (c) 2026 Maksymilian Dendura; see
|
|
12
|
+
// REALISTIC-OCEAN-LICENSE.txt): its derivative cascade textures and persistent foam clipmaps.
|
|
13
|
+
import type { SpectralOcean } from "@threenative/core";
|
|
14
|
+
import { Group } from "three";
|
|
15
|
+
import { Fn, float, instanceIndex, instancedArray, mix, uniform, vec4 } from "three/tsl";
|
|
16
|
+
import type { ComputeNode, Node, StorageBufferNode } from "three/webgpu";
|
|
17
|
+
|
|
18
|
+
/** Structural, so this file asks the engine for nothing but a `compute()`. */
|
|
19
|
+
interface IComputeHost {
|
|
20
|
+
compute(nodes: unknown): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ISeaMapsOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Foam half-life in seconds. Foam falls as `exp(-ln2 * t / halfLife)`, so a larger number is a
|
|
26
|
+
* longer-lived whitecap. Game-owned: it decides how the sea ages.
|
|
27
|
+
*/
|
|
28
|
+
readonly foamHalfLife: number;
|
|
29
|
+
/**
|
|
30
|
+
* The Jacobian below which a wave is breaking. 1 is undisturbed water and 0 is a crest folding
|
|
31
|
+
* over itself, so values near 0.6 foam the steepest few per cent of the surface.
|
|
32
|
+
*/
|
|
33
|
+
readonly foamThreshold: number;
|
|
34
|
+
/** How quickly foam saturates as the Jacobian drops below the threshold. */
|
|
35
|
+
readonly foamGain: number;
|
|
36
|
+
/** Cascade indices that carry a foam grid, finest first. Each one tiles with its own patch. */
|
|
37
|
+
readonly foamCascades: readonly number[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `(slopeX, slopeZ, dDx/dx, dDz/dz)` and `(dDx/dz)` per texel, in the cascade's own rest frame. */
|
|
41
|
+
interface ICascadeMaps {
|
|
42
|
+
readonly slope: StorageBufferNode<"vec4">;
|
|
43
|
+
readonly shear: StorageBufferNode<"vec4">;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type Fnode = Node<"float">;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Bilinear read of a periodic storage grid at a world position.
|
|
50
|
+
*
|
|
51
|
+
* Nearest-texel reads make the shaded normal piecewise constant, and the sun's reflection then
|
|
52
|
+
* breaks into axis-aligned rectangles; the two `mod`s are not redundant, because the first is still
|
|
53
|
+
* negative left of the origin and a negative index reads whatever sits behind the buffer.
|
|
54
|
+
*/
|
|
55
|
+
function bilinear(
|
|
56
|
+
read: (index: Fnode) => Node<"vec4">,
|
|
57
|
+
resolution: number,
|
|
58
|
+
patchSize: number,
|
|
59
|
+
x: Fnode,
|
|
60
|
+
z: Fnode,
|
|
61
|
+
): Node<"vec4"> {
|
|
62
|
+
const grid = float(resolution);
|
|
63
|
+
const u = x.div(patchSize).mul(grid);
|
|
64
|
+
const v = z.div(patchSize).mul(grid);
|
|
65
|
+
const u0 = u.floor();
|
|
66
|
+
const v0 = v.floor();
|
|
67
|
+
const wrap = (value: Fnode): Fnode => value.mod(grid).add(grid).mod(grid);
|
|
68
|
+
const at = (cx: Fnode, cz: Fnode) => read(wrap(cz).mul(grid).add(wrap(cx)));
|
|
69
|
+
const near = mix(at(u0, v0), at(u0.add(1), v0), u.sub(u0));
|
|
70
|
+
const far = mix(at(u0, v0.add(1)), at(u0.add(1), v0.add(1)), u.sub(u0));
|
|
71
|
+
return mix(near, far, v.sub(v0)) as Node<"vec4">;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function sampleBilinear(
|
|
75
|
+
buffer: StorageBufferNode<"vec4">,
|
|
76
|
+
resolution: number,
|
|
77
|
+
patchSize: number,
|
|
78
|
+
x: Fnode,
|
|
79
|
+
z: Fnode,
|
|
80
|
+
): Node<"vec4"> {
|
|
81
|
+
return bilinear(
|
|
82
|
+
(index) => buffer.element(index.toUint()) as Node<"vec4">,
|
|
83
|
+
resolution,
|
|
84
|
+
patchSize,
|
|
85
|
+
x,
|
|
86
|
+
z,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The same read for a one-channel grid, in `.x`. */
|
|
91
|
+
export function sampleBilinearFloat(
|
|
92
|
+
buffer: StorageBufferNode<"float">,
|
|
93
|
+
resolution: number,
|
|
94
|
+
patchSize: number,
|
|
95
|
+
x: Fnode,
|
|
96
|
+
z: Fnode,
|
|
97
|
+
): Fnode {
|
|
98
|
+
return bilinear(
|
|
99
|
+
(index) => vec4(buffer.element(index.toUint()), 0, 0, 0),
|
|
100
|
+
resolution,
|
|
101
|
+
patchSize,
|
|
102
|
+
x,
|
|
103
|
+
z,
|
|
104
|
+
).x;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export class SeaMaps extends Group {
|
|
108
|
+
readonly warmupNodes: readonly ComputeNode[];
|
|
109
|
+
readonly processCadence: "fixed" | "render";
|
|
110
|
+
readonly foamCascades: readonly number[];
|
|
111
|
+
|
|
112
|
+
#ocean: SpectralOcean;
|
|
113
|
+
#cascades: ICascadeMaps[] = [];
|
|
114
|
+
#foam: StorageBufferNode<"float">[] = [];
|
|
115
|
+
#derivativePasses: ComputeNode[] = [];
|
|
116
|
+
#foamPasses: ComputeNode[] = [];
|
|
117
|
+
#clearPasses: ComputeNode[] = [];
|
|
118
|
+
#time = 0;
|
|
119
|
+
#lastTime: number | undefined;
|
|
120
|
+
#pendingClear = true;
|
|
121
|
+
#host: IComputeHost | undefined;
|
|
122
|
+
#released = false;
|
|
123
|
+
readonly #retain = uniform(1);
|
|
124
|
+
readonly #halfLife: number;
|
|
125
|
+
|
|
126
|
+
constructor(ocean: SpectralOcean, options: ISeaMapsOptions) {
|
|
127
|
+
super();
|
|
128
|
+
if (!Number.isFinite(options.foamHalfLife) || options.foamHalfLife <= 0)
|
|
129
|
+
throw new Error("SeaMaps.foamHalfLife must be a positive number.");
|
|
130
|
+
if (!Number.isFinite(options.foamThreshold) || !Number.isFinite(options.foamGain))
|
|
131
|
+
throw new Error("SeaMaps.foamThreshold and foamGain must be finite numbers.");
|
|
132
|
+
for (const index of options.foamCascades)
|
|
133
|
+
if (!Number.isInteger(index) || index < 0 || index >= ocean.cascades.length)
|
|
134
|
+
throw new Error(
|
|
135
|
+
`SeaMaps.foamCascades names cascade ${index}, which the sea does not have.`,
|
|
136
|
+
);
|
|
137
|
+
this.#ocean = ocean;
|
|
138
|
+
this.processCadence = ocean.processCadence;
|
|
139
|
+
this.foamCascades = [...options.foamCascades];
|
|
140
|
+
this.#halfLife = options.foamHalfLife;
|
|
141
|
+
|
|
142
|
+
const size = ocean.resolution;
|
|
143
|
+
const count = size * size;
|
|
144
|
+
for (let c = 0; c < ocean.cascades.length; c += 1) {
|
|
145
|
+
const slope = instancedArray(count, "vec4") as StorageBufferNode<"vec4">;
|
|
146
|
+
const shear = instancedArray(count, "vec4") as StorageBufferNode<"vec4">;
|
|
147
|
+
this.#cascades.push({ slope, shear });
|
|
148
|
+
this.#derivativePasses.push(this.#derivativePass(c, slope, shear));
|
|
149
|
+
}
|
|
150
|
+
for (const c of this.foamCascades) {
|
|
151
|
+
const foam = instancedArray(count, "float") as StorageBufferNode<"float">;
|
|
152
|
+
this.#foam.push(foam);
|
|
153
|
+
this.#foamPasses.push(this.#foamPass(c, foam, options));
|
|
154
|
+
this.#clearPasses.push(Fn(() => foam.element(instanceIndex).assign(0))().compute(count));
|
|
155
|
+
}
|
|
156
|
+
this.warmupNodes = [...this.#derivativePasses, ...this.#foamPasses, ...this.#clearPasses];
|
|
157
|
+
this.addEventListener("removed", this.#onRemoved);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get released(): boolean {
|
|
161
|
+
return this.#released;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
slope(cascade: number): StorageBufferNode<"vec4"> {
|
|
165
|
+
return this.#cascadeMaps(cascade).slope;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
shear(cascade: number): StorageBufferNode<"vec4"> {
|
|
169
|
+
return this.#cascadeMaps(cascade).shear;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The foam grid of the `level`-th foam cascade (0 is the finest). */
|
|
173
|
+
foam(level: number): StorageBufferNode<"float"> {
|
|
174
|
+
const grid = this.#foam[level];
|
|
175
|
+
if (grid === undefined) throw new Error(`SeaMaps has no foam level ${level}.`);
|
|
176
|
+
return grid;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Seconds of wave time, the same clock the sea runs on. */
|
|
180
|
+
advance(seconds: number): void {
|
|
181
|
+
if (!Number.isFinite(seconds)) throw new Error("SeaMaps.advance needs a finite time.");
|
|
182
|
+
this.#time = seconds;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Forget every whitecap. The next dispatch clears each foam grid before it injects any. */
|
|
186
|
+
reset(): void {
|
|
187
|
+
this.#pendingClear = true;
|
|
188
|
+
this.#lastTime = undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
attachRenderer(renderer: IComputeHost): void {
|
|
192
|
+
if (this.#released) throw new Error("SeaMaps cannot be attached after release.");
|
|
193
|
+
this.#host = renderer;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
process(renderer: IComputeHost | undefined = this.#host): void {
|
|
197
|
+
if (this.#released) return;
|
|
198
|
+
if (renderer === undefined) throw new Error("SeaMaps is not attached to a renderer.");
|
|
199
|
+
const step = this.#lastTime === undefined ? 0 : this.#time - this.#lastTime;
|
|
200
|
+
this.#lastTime = this.#time;
|
|
201
|
+
// A paused or rewound clock decays nothing, and a long stall decays one step's worth, so a
|
|
202
|
+
// hidden tab cannot wipe the foam and a teleport cannot invent age.
|
|
203
|
+
const delta = Number.isFinite(step) && step > 0 ? Math.min(step, 0.1) : 0;
|
|
204
|
+
this.#retain.value = 0.5 ** (delta / this.#halfLife);
|
|
205
|
+
const passes: ComputeNode[] = [];
|
|
206
|
+
if (this.#pendingClear) {
|
|
207
|
+
passes.push(...this.#clearPasses);
|
|
208
|
+
this.#pendingClear = false;
|
|
209
|
+
}
|
|
210
|
+
passes.push(...this.#derivativePasses, ...this.#foamPasses);
|
|
211
|
+
renderer.compute(passes);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
detach(): void {
|
|
215
|
+
if (this.#released) return;
|
|
216
|
+
this.removeEventListener("removed", this.#onRemoved);
|
|
217
|
+
this.#host = undefined;
|
|
218
|
+
for (const pass of this.warmupNodes) pass.dispose();
|
|
219
|
+
for (const maps of this.#cascades) {
|
|
220
|
+
maps.slope.value.dispose();
|
|
221
|
+
maps.shear.value.dispose();
|
|
222
|
+
}
|
|
223
|
+
for (const grid of this.#foam) grid.value.dispose();
|
|
224
|
+
this.#cascades = [];
|
|
225
|
+
this.#foam = [];
|
|
226
|
+
this.#released = true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
#onRemoved = (): void => this.detach();
|
|
230
|
+
|
|
231
|
+
#cascadeMaps(cascade: number): ICascadeMaps {
|
|
232
|
+
const maps = this.#cascades[cascade];
|
|
233
|
+
if (maps === undefined) throw new Error(`SeaMaps has no cascade ${cascade}.`);
|
|
234
|
+
return maps;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The displacement's derivatives, wrapping at the patch edge. */
|
|
238
|
+
#derivativePass(
|
|
239
|
+
cascade: number,
|
|
240
|
+
slope: StorageBufferNode<"vec4">,
|
|
241
|
+
shear: StorageBufferNode<"vec4">,
|
|
242
|
+
): ComputeNode {
|
|
243
|
+
const size = this.#ocean.resolution;
|
|
244
|
+
const grid = float(size);
|
|
245
|
+
const texel = this.#ocean.cascadePatchSize(cascade) / size;
|
|
246
|
+
const displacement = this.#ocean.cascadeDisplacement(cascade);
|
|
247
|
+
return Fn(() => {
|
|
248
|
+
const index = float(instanceIndex);
|
|
249
|
+
const x = index.mod(grid);
|
|
250
|
+
const y = index.div(grid).floor();
|
|
251
|
+
const at = (cx: Fnode, cy: Fnode) =>
|
|
252
|
+
displacement.element(cy.add(grid).mod(grid).mul(grid).add(cx.add(grid).mod(grid)).toUint());
|
|
253
|
+
// Sixth-order central difference. Each cascade carries waves up to its own Nyquist, where a
|
|
254
|
+
// one-texel difference returns sin(k dx) / (k dx) of the slope: half of it an octave below
|
|
255
|
+
// Nyquist, which is where the crests' compression and the foam are.
|
|
256
|
+
const along = (dx: number, dy: number) => {
|
|
257
|
+
const span = (n: number) =>
|
|
258
|
+
at(x.add(dx * n), y.add(dy * n)).sub(at(x.sub(dx * n), y.sub(dy * n)));
|
|
259
|
+
return span(1)
|
|
260
|
+
.mul(45)
|
|
261
|
+
.sub(span(2).mul(9))
|
|
262
|
+
.add(span(3))
|
|
263
|
+
.mul(1 / (60 * texel));
|
|
264
|
+
};
|
|
265
|
+
const ddx = along(1, 0);
|
|
266
|
+
const ddz = along(0, 1);
|
|
267
|
+
// Slope in the rest frame; the material divides by the Jacobian to get it in the world's.
|
|
268
|
+
slope.element(instanceIndex).assign(vec4(ddx.y, ddz.y, ddx.x, ddz.z));
|
|
269
|
+
shear.element(instanceIndex).assign(vec4(ddz.x, 0, 0, 0));
|
|
270
|
+
})().compute(size * size);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** `foam = max(foam * decay, injection)`, at each texel's rest position. */
|
|
274
|
+
#foamPass(
|
|
275
|
+
cascade: number,
|
|
276
|
+
foam: StorageBufferNode<"float">,
|
|
277
|
+
options: ISeaMapsOptions,
|
|
278
|
+
): ComputeNode {
|
|
279
|
+
const size = this.#ocean.resolution;
|
|
280
|
+
const grid = float(size);
|
|
281
|
+
const patch = this.#ocean.cascadePatchSize(cascade);
|
|
282
|
+
const retain = this.#retain;
|
|
283
|
+
const { foamThreshold, foamGain } = options;
|
|
284
|
+
return Fn(() => {
|
|
285
|
+
const index = float(instanceIndex);
|
|
286
|
+
const x = index
|
|
287
|
+
.mod(grid)
|
|
288
|
+
.add(0.5)
|
|
289
|
+
.mul(patch / size);
|
|
290
|
+
const z = index
|
|
291
|
+
.div(grid)
|
|
292
|
+
.floor()
|
|
293
|
+
.add(0.5)
|
|
294
|
+
.mul(patch / size);
|
|
295
|
+
const jxx = float(0).toVar();
|
|
296
|
+
const jzz = float(0).toVar();
|
|
297
|
+
const jxz = float(0).toVar();
|
|
298
|
+
for (let c = 0; c < this.#cascades.length; c += 1) {
|
|
299
|
+
const maps = this.#cascades[c] as ICascadeMaps;
|
|
300
|
+
const patchSize = this.#ocean.cascadePatchSize(c);
|
|
301
|
+
const slope = sampleBilinear(maps.slope, size, patchSize, x, z);
|
|
302
|
+
jxx.addAssign(slope.z);
|
|
303
|
+
jzz.addAssign(slope.w);
|
|
304
|
+
jxz.addAssign(sampleBilinear(maps.shear, size, patchSize, x, z).x);
|
|
305
|
+
}
|
|
306
|
+
const jacobian = jxx.add(1).mul(jzz.add(1)).sub(jxz.mul(jxz));
|
|
307
|
+
const injection = float(foamThreshold).sub(jacobian).mul(foamGain).clamp(0, 1);
|
|
308
|
+
foam.element(instanceIndex).assign(foam.element(instanceIndex).mul(retain).max(injection));
|
|
309
|
+
})().compute(size * size);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Generated for you, and ThreeNative does not read it. The sea's *spectrum* — which wavelengths
|
|
2
|
+
// carry energy and from where — is this game's decision, so it lives here and is handed to
|
|
3
|
+
// `SpectralOcean` as its `energy` curve. Nothing in this file touches the GPU, which is what lets a
|
|
4
|
+
// test integrate it and say how tall the sea it describes will be.
|
|
5
|
+
//
|
|
6
|
+
// Adapted from web-ocean (MIT, Copyright (c) 2026 Maksymilian Dendura; see
|
|
7
|
+
// REALISTIC-OCEAN-LICENSE.txt): a fetch-limited JONSWAP wind sea with Donelan-Banner directional
|
|
8
|
+
// spreading, an independently directed long-crested swell, and capillary dispersion.
|
|
9
|
+
|
|
10
|
+
const TWO_PI = Math.PI * 2;
|
|
11
|
+
|
|
12
|
+
/** A wind sea that has had `fetch` metres of open water to grow in. */
|
|
13
|
+
export interface IWindSea {
|
|
14
|
+
/** Wind speed at ten metres, in m/s. */
|
|
15
|
+
readonly speed: number;
|
|
16
|
+
/** Direction the waves travel, in radians. */
|
|
17
|
+
readonly direction: number;
|
|
18
|
+
/** Open-water distance the wind has blown over, in metres. A longer fetch is a taller, longer sea. */
|
|
19
|
+
readonly fetch: number;
|
|
20
|
+
/** JONSWAP peak enhancement. 3.3 is the North Sea mean; higher is a narrower, sharper peak. */
|
|
21
|
+
readonly peakEnhancement: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A swell: long, narrow in direction, and independent of the local wind. */
|
|
25
|
+
export interface ISwell {
|
|
26
|
+
/** Significant wave height of the swell alone, in metres. */
|
|
27
|
+
readonly height: number;
|
|
28
|
+
readonly direction: number;
|
|
29
|
+
/** Peak angular frequency in rad/s. 0.5 is a 12.6 s period. */
|
|
30
|
+
readonly peakFrequency: number;
|
|
31
|
+
/** The `cos^2s` spreading exponent. Larger is a straighter-crested swell. */
|
|
32
|
+
readonly spreading: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ISeaState {
|
|
36
|
+
readonly wind: IWindSea;
|
|
37
|
+
/** Omit for a pure wind sea. */
|
|
38
|
+
readonly swell?: ISwell;
|
|
39
|
+
readonly gravity: number;
|
|
40
|
+
/** Surface tension over density, in m^3/s^2. Water at 20 C is 7.4e-5. */
|
|
41
|
+
readonly surfaceTension: number;
|
|
42
|
+
/** Waves shorter than this are damped out, in metres. */
|
|
43
|
+
readonly shortWaveCut: number;
|
|
44
|
+
/**
|
|
45
|
+
* The significant wave height the whole sea is scaled to, in metres (four standard deviations of
|
|
46
|
+
* the surface). Omitted, the physical spectrum is used as it falls.
|
|
47
|
+
*/
|
|
48
|
+
readonly waveHeight?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type SeaEnergy = (kx: number, kz: number) => number;
|
|
52
|
+
|
|
53
|
+
function wrapAngle(angle: number): number {
|
|
54
|
+
return angle - TWO_PI * Math.floor((angle + Math.PI) / TWO_PI);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The wavenumber above which surface tension, not gravity, restores the surface. */
|
|
58
|
+
export function capillaryCrossover(gravity: number, surfaceTension: number): number {
|
|
59
|
+
return Math.sqrt(gravity / surfaceTension);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function angularFrequency(k: number, gravity: number, surfaceTension: number): number {
|
|
63
|
+
return Math.sqrt(gravity * k + surfaceTension * k * k * k);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function groupDerivative(k: number, gravity: number, surfaceTension: number): number {
|
|
67
|
+
return (
|
|
68
|
+
(gravity + 3 * surfaceTension * k * k) / (2 * angularFrequency(k, gravity, surfaceTension))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The JONSWAP frequency spectrum `S(w)`. */
|
|
73
|
+
export function jonswap(
|
|
74
|
+
w: number,
|
|
75
|
+
peak: number,
|
|
76
|
+
alpha: number,
|
|
77
|
+
gamma: number,
|
|
78
|
+
gravity: number,
|
|
79
|
+
): number {
|
|
80
|
+
const sigma = w <= peak ? 0.07 : 0.09;
|
|
81
|
+
const d = (w - peak) / (sigma * peak);
|
|
82
|
+
const enhancement = gamma ** Math.exp(-0.5 * d * d);
|
|
83
|
+
const q = peak / w;
|
|
84
|
+
return ((alpha * gravity * gravity) / w ** 5) * Math.exp(-1.25 * q ** 4) * enhancement;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Donelan-Banner directional spreading, normalised over [-pi, pi]. */
|
|
88
|
+
export function donelanBanner(theta: number, w: number, peak: number): number {
|
|
89
|
+
const ratio = w / peak;
|
|
90
|
+
let beta: number;
|
|
91
|
+
if (ratio < 0.95) beta = 2.61 * ratio ** 1.3;
|
|
92
|
+
else if (ratio < 1.6) beta = 2.28 * ratio ** -1.3;
|
|
93
|
+
else beta = 10 ** (-0.4 + 0.8393 * Math.exp(-0.567 * Math.log(ratio * ratio)));
|
|
94
|
+
const sech = 1 / Math.cosh(Math.max(-20, Math.min(20, beta * theta)));
|
|
95
|
+
return (beta / (2 * Math.tanh(beta * Math.PI))) * sech * sech;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** `cos^2s(theta / 2)` spreading, normalised. */
|
|
99
|
+
export function cosineSpread(theta: number, s: number): number {
|
|
100
|
+
const normaliser = Math.sqrt(s + 0.25) / (2 * Math.sqrt(Math.PI));
|
|
101
|
+
return normaliser * Math.abs(Math.cos(theta * 0.5)) ** (2 * s);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function validate(state: ISeaState): void {
|
|
105
|
+
const positive = (name: string, value: number) => {
|
|
106
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
107
|
+
throw new Error(`Realistic ocean ${name} must be a positive number.`);
|
|
108
|
+
};
|
|
109
|
+
positive("wind.speed", state.wind.speed);
|
|
110
|
+
positive("wind.fetch", state.wind.fetch);
|
|
111
|
+
positive("wind.peakEnhancement", state.wind.peakEnhancement);
|
|
112
|
+
if (!Number.isFinite(state.wind.direction))
|
|
113
|
+
throw new Error("Realistic ocean wind.direction must be a finite number.");
|
|
114
|
+
positive("gravity", state.gravity);
|
|
115
|
+
positive("surfaceTension", state.surfaceTension);
|
|
116
|
+
positive("shortWaveCut", state.shortWaveCut);
|
|
117
|
+
if (state.waveHeight !== undefined) positive("waveHeight", state.waveHeight);
|
|
118
|
+
if (state.swell !== undefined) {
|
|
119
|
+
positive("swell.height", state.swell.height);
|
|
120
|
+
positive("swell.peakFrequency", state.swell.peakFrequency);
|
|
121
|
+
positive("swell.spreading", state.swell.spreading);
|
|
122
|
+
if (!Number.isFinite(state.swell.direction))
|
|
123
|
+
throw new Error("Realistic ocean swell.direction must be a finite number.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The sea's energy per wavenumber cell at `(kx, kz)`, before any height normalisation.
|
|
129
|
+
*
|
|
130
|
+
* The frequency spectrum is changed to a wavenumber one by `dw/dk / k`, so the result has the
|
|
131
|
+
* units `SpectralOcean.energy` expects and the same `Δk` weighting the Phillips default carries.
|
|
132
|
+
*/
|
|
133
|
+
export function rawSeaEnergy(state: ISeaState): SeaEnergy {
|
|
134
|
+
validate(state);
|
|
135
|
+
const { wind, swell, gravity, surfaceTension, shortWaveCut } = state;
|
|
136
|
+
const alpha = 0.076 * (wind.speed ** 2 / (wind.fetch * gravity)) ** 0.22;
|
|
137
|
+
const windPeak = 22 * (gravity ** 2 / (wind.speed * wind.fetch)) ** (1 / 3);
|
|
138
|
+
const swellAlpha =
|
|
139
|
+
swell === undefined
|
|
140
|
+
? 0
|
|
141
|
+
: (swell.height / 4) ** 2 *
|
|
142
|
+
5 *
|
|
143
|
+
(swell.peakFrequency ** 4 / gravity ** 2) *
|
|
144
|
+
(1 - 0.287 * Math.log(6));
|
|
145
|
+
return (kx, kz) => {
|
|
146
|
+
const k = Math.hypot(kx, kz);
|
|
147
|
+
if (k < 1e-9) return 0;
|
|
148
|
+
const w = angularFrequency(k, gravity, surfaceTension);
|
|
149
|
+
const theta = Math.atan2(kz, kx);
|
|
150
|
+
let density = 0;
|
|
151
|
+
if (wind.speed > 0.1) {
|
|
152
|
+
density +=
|
|
153
|
+
jonswap(w, windPeak, alpha, wind.peakEnhancement, gravity) *
|
|
154
|
+
donelanBanner(wrapAngle(theta - wind.direction), w, windPeak);
|
|
155
|
+
}
|
|
156
|
+
if (swell !== undefined) {
|
|
157
|
+
density +=
|
|
158
|
+
jonswap(w, swell.peakFrequency, swellAlpha, 6, gravity) *
|
|
159
|
+
cosineSpread(wrapAngle(theta - swell.direction), swell.spreading);
|
|
160
|
+
}
|
|
161
|
+
density *= Math.exp(-k * k * shortWaveCut * shortWaveCut);
|
|
162
|
+
return (density * groupDerivative(k, gravity, surfaceTension)) / k;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** One cascade as the simulation lays it out: its grid, its patch and the band it owns. */
|
|
167
|
+
export interface ISeaBand {
|
|
168
|
+
readonly patchSize: number;
|
|
169
|
+
readonly kMin: number;
|
|
170
|
+
readonly kMax: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The bands `SpectralOcean` assigns, so this file can count energy the way the simulation does. */
|
|
174
|
+
export function seaBands(resolution: number, patchSizes: readonly number[]): readonly ISeaBand[] {
|
|
175
|
+
return patchSizes.map((patchSize, index) => ({
|
|
176
|
+
patchSize,
|
|
177
|
+
kMin: index === 0 ? 0 : (Math.PI * resolution) / (patchSizes[index - 1] as number),
|
|
178
|
+
kMax:
|
|
179
|
+
index === patchSizes.length - 1
|
|
180
|
+
? Number.POSITIVE_INFINITY
|
|
181
|
+
: (Math.PI * resolution) / patchSize,
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The variance of the surface height the simulation will realise, in m^2.
|
|
187
|
+
*
|
|
188
|
+
* Each texel carries `E·Δk^2` and its mirror carries the same, so the expected variance is twice
|
|
189
|
+
* the sum. The self-mirrored row and column hold nothing, exactly as `initialSpectrumData` leaves
|
|
190
|
+
* them. Checked in the tests against the energy of a real seeded realisation.
|
|
191
|
+
*/
|
|
192
|
+
export function expectedVariance(
|
|
193
|
+
energy: SeaEnergy,
|
|
194
|
+
resolution: number,
|
|
195
|
+
bands: readonly ISeaBand[],
|
|
196
|
+
): number {
|
|
197
|
+
let sum = 0;
|
|
198
|
+
const half = resolution / 2;
|
|
199
|
+
for (const band of bands) {
|
|
200
|
+
const step = TWO_PI / band.patchSize;
|
|
201
|
+
for (let y = 1; y < resolution; y += 1) {
|
|
202
|
+
for (let x = 1; x < resolution; x += 1) {
|
|
203
|
+
const kx = (x - half) * step;
|
|
204
|
+
const kz = (y - half) * step;
|
|
205
|
+
const k = Math.hypot(kx, kz);
|
|
206
|
+
if (k < band.kMin || k >= band.kMax) continue;
|
|
207
|
+
sum += energy(kx, kz) * step * step;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return 2 * sum;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Significant wave height of a Gaussian sea of this variance. */
|
|
215
|
+
export function significantHeight(variance: number): number {
|
|
216
|
+
return 4 * Math.sqrt(variance);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The energy curve to hand to `SpectralOcean`, scaled so the realised sea is `waveHeight` tall.
|
|
221
|
+
*
|
|
222
|
+
* The scale is measured on the grid the simulation will actually use, so changing `resolution` or
|
|
223
|
+
* the cascades moves the *detail* and never the height. Without `waveHeight` the physical spectrum
|
|
224
|
+
* is returned unscaled.
|
|
225
|
+
*/
|
|
226
|
+
export function seaEnergy(
|
|
227
|
+
state: ISeaState,
|
|
228
|
+
resolution: number,
|
|
229
|
+
patchSizes: readonly number[],
|
|
230
|
+
): SeaEnergy {
|
|
231
|
+
const raw = rawSeaEnergy(state);
|
|
232
|
+
if (state.waveHeight === undefined) return raw;
|
|
233
|
+
const variance = expectedVariance(raw, resolution, seaBands(resolution, patchSizes));
|
|
234
|
+
if (!(variance > 0)) throw new Error("Realistic ocean spectrum holds no energy on this grid.");
|
|
235
|
+
const scale = (state.waveHeight / 4) ** 2 / variance;
|
|
236
|
+
return (kx, kz) => raw(kx, kz) * scale;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Mean-square slope carried by waves shorter than each of `count` wavelengths, log-spaced between
|
|
241
|
+
* `nearest` and `farthest` metres of pixel footprint.
|
|
242
|
+
*
|
|
243
|
+
* This is the slope-moment filter's table. A pixel that spans many metres cannot resolve the short
|
|
244
|
+
* waves inside it, but their slope still decides how wide its sun glitter is: the variance they
|
|
245
|
+
* carry is taken out of the resolved surface and spent as roughness instead, so the highlight
|
|
246
|
+
* neither disappears nor shimmers. Entry `i` is for waves with `k > pi / footprint_i`.
|
|
247
|
+
*/
|
|
248
|
+
export function slopeVarianceTable(
|
|
249
|
+
energy: SeaEnergy,
|
|
250
|
+
options: {
|
|
251
|
+
readonly count: number;
|
|
252
|
+
readonly nearest: number;
|
|
253
|
+
readonly farthest: number;
|
|
254
|
+
readonly directions?: number;
|
|
255
|
+
},
|
|
256
|
+
): Float32Array {
|
|
257
|
+
const { count, nearest, farthest } = options;
|
|
258
|
+
const directions = options.directions ?? 48;
|
|
259
|
+
const kLow = Math.PI / farthest;
|
|
260
|
+
const kHigh = (Math.PI / nearest) * 64;
|
|
261
|
+
const rings = 160;
|
|
262
|
+
const growth = Math.log(kHigh / kLow) / rings;
|
|
263
|
+
// Per-ring slope variance: sum over angle of k^2 E(k) times the ring's area `k dk dtheta`.
|
|
264
|
+
const ring = new Float64Array(rings);
|
|
265
|
+
for (let i = 0; i < rings; i += 1) {
|
|
266
|
+
const k = kLow * Math.exp((i + 0.5) * growth);
|
|
267
|
+
const dk = k * growth;
|
|
268
|
+
let sum = 0;
|
|
269
|
+
for (let d = 0; d < directions; d += 1) {
|
|
270
|
+
const angle = ((d + 0.5) / directions) * TWO_PI;
|
|
271
|
+
sum += energy(k * Math.cos(angle), k * Math.sin(angle));
|
|
272
|
+
}
|
|
273
|
+
ring[i] = 2 * k * k * sum * (TWO_PI / directions) * k * dk;
|
|
274
|
+
}
|
|
275
|
+
const table = new Float32Array(count);
|
|
276
|
+
const tail = new Float64Array(rings + 1);
|
|
277
|
+
for (let i = rings - 1; i >= 0; i -= 1) tail[i] = (tail[i + 1] as number) + (ring[i] as number);
|
|
278
|
+
for (let i = 0; i < count; i += 1) {
|
|
279
|
+
const footprint = nearest * (farthest / nearest) ** (i / (count - 1));
|
|
280
|
+
const k = Math.PI / footprint;
|
|
281
|
+
const position = Math.max(0, Math.min(rings, Math.log(k / kLow) / growth));
|
|
282
|
+
const base = Math.floor(position);
|
|
283
|
+
const fraction = position - base;
|
|
284
|
+
table[i] =
|
|
285
|
+
(tail[base] as number) * (1 - fraction) +
|
|
286
|
+
(tail[Math.min(rings, base + 1)] as number) * fraction;
|
|
287
|
+
}
|
|
288
|
+
return table;
|
|
289
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Template rendering
|
|
2
|
+
|
|
3
|
+
The shared Unreal 5.8.3 look comes from `@threenative/core`: `WorldEnvironment`,
|
|
4
|
+
`qualityPreset` and `qualityTiers`. Keep scene lighting, materials and authored stages in
|
|
5
|
+
`src/render/`. Each kit's `quality.ts` spreads the core preset and names any override with
|
|
6
|
+
its reason. `tonemapMode: "aces"` and `autoExposureEnabled: false` with fixed `exposure`
|
|
7
|
+
are explicit overrides, reported by the chain.
|
|
8
|
+
|
|
9
|
+
The starter kits meter at 0 EV (key 0.18), not core's Unreal +1 EV: `template-assets/kitExposure.ts`
|
|
10
|
+
is the one source, `pnpm stamp:template-render` copies it into each kit's `src/render/kitExposure.ts`,
|
|
11
|
+
and `kit-exposure.spec.ts` names the kits that keep their own key (minimal, rain, shooter, snow).
|
|
12
|
+
|
|
13
|
+
The tuning target is `scripts/unreal-look/scaffold/Reference.ts.in` at L9 and the
|
|
14
|
+
`CalibrationScene.ts.in` scenes. Judge the kit's own game against two headed WebGPU runs
|
|
15
|
+
per arm and the target frames. Each migration requires a fresh read-only judge's
|
|
16
|
+
IMPROVEMENT, with gameplay subjects at least as readable. Adjust old look assertions only
|
|
17
|
+
after that verdict. Keep frame budgets and timeouts fixed; a budget breach selects a lower
|
|
18
|
+
`renderChainTier`, keeping the filmic curve and metered exposure.
|
|
19
|
+
|
|
20
|
+
PRD-723 migrates the kits one at a time. Until a kit's visual judge approves migration,
|
|
21
|
+
its `quality.ts` explicitly retains ACES and fixed exposure to preserve its baseline.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!-- Generated mirror of AGENTS.md. Do not edit; edit AGENTS.md. -->
|
|
2
|
+
|
|
3
|
+
# Template rendering
|
|
4
|
+
|
|
5
|
+
The shared Unreal 5.8.3 look comes from `@threenative/core`: `WorldEnvironment`,
|
|
6
|
+
`qualityPreset` and `qualityTiers`. Keep scene lighting, materials and authored stages in
|
|
7
|
+
`src/render/`. Each kit's `quality.ts` spreads the core preset and names any override with
|
|
8
|
+
its reason. `tonemapMode: "aces"` and `autoExposureEnabled: false` with fixed `exposure`
|
|
9
|
+
are explicit overrides, reported by the chain.
|
|
10
|
+
|
|
11
|
+
The starter kits meter at 0 EV (key 0.18), not core's Unreal +1 EV: `template-assets/kitExposure.ts`
|
|
12
|
+
is the one source, `pnpm stamp:template-render` copies it into each kit's `src/render/kitExposure.ts`,
|
|
13
|
+
and `kit-exposure.spec.ts` names the kits that keep their own key (minimal, rain, shooter, snow).
|
|
14
|
+
|
|
15
|
+
The tuning target is `scripts/unreal-look/scaffold/Reference.ts.in` at L9 and the
|
|
16
|
+
`CalibrationScene.ts.in` scenes. Judge the kit's own game against two headed WebGPU runs
|
|
17
|
+
per arm and the target frames. Each migration requires a fresh read-only judge's
|
|
18
|
+
IMPROVEMENT, with gameplay subjects at least as readable. Adjust old look assertions only
|
|
19
|
+
after that verdict. Keep frame budgets and timeouts fixed; a budget breach selects a lower
|
|
20
|
+
`renderChainTier`, keeping the filmic curve and metered exposure.
|
|
21
|
+
|
|
22
|
+
PRD-723 migrates the kits one at a time. Until a kit's visual judge approves migration,
|
|
23
|
+
its `quality.ts` explicitly retains ACES and fixed exposure to preserve its baseline.
|
|
@@ -14,6 +14,10 @@ args = ["./node_modules/@threenative/core/mcp/sculpt.mjs"]
|
|
|
14
14
|
command = "node"
|
|
15
15
|
args = ["./node_modules/@threenative/core/mcp/engine.mjs"]
|
|
16
16
|
|
|
17
|
-
[mcp_servers.threenative-
|
|
17
|
+
[mcp_servers.threenative-animation]
|
|
18
18
|
command = "node"
|
|
19
|
-
args = ["./node_modules/@threenative/core/mcp/
|
|
19
|
+
args = ["./node_modules/@threenative/core/mcp/animation.mjs"]
|
|
20
|
+
|
|
21
|
+
[mcp_servers.threenative-devtools]
|
|
22
|
+
command = "node"
|
|
23
|
+
args = ["./node_modules/@threenative/core/mcp/devtools.mjs"]
|
|
@@ -22,10 +22,16 @@
|
|
|
22
22
|
"./node_modules/@threenative/core/mcp/engine.mjs"
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
|
-
"threenative-
|
|
25
|
+
"threenative-animation": {
|
|
26
26
|
"command": "node",
|
|
27
27
|
"args": [
|
|
28
|
-
"./node_modules/@threenative/core/mcp/
|
|
28
|
+
"./node_modules/@threenative/core/mcp/animation.mjs"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"threenative-devtools": {
|
|
32
|
+
"command": "node",
|
|
33
|
+
"args": [
|
|
34
|
+
"./node_modules/@threenative/core/mcp/devtools.mjs"
|
|
29
35
|
]
|
|
30
36
|
}
|
|
31
37
|
}
|