create-threenative 0.2.5 → 0.2.7
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/README.md +25 -3
- package/agent-docs/references/assertion-reference.md +40 -1
- package/agent-docs/references/build-profiles.md +126 -0
- package/agent-docs/references/capability-reference.md +1382 -65
- package/agent-docs/references/finding-assets.md +8 -1
- package/agent-docs/references/performance-basics.md +117 -0
- package/agent-docs/references/rigging-characters.md +51 -0
- package/agent-docs/references/sculpt-from-a-reference.md +1 -1
- package/agent-docs/references/trace-a-slow-frame.md +1 -1
- package/agent-docs/references/visual-baseline.md +8 -4
- package/agent-docs/references/webview-ui.md +3 -2
- package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +68 -0
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +12 -4
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-context/SKILL.md +9 -1
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +26 -10
- package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
- package/agent-files/.claude/hooks/ponytail-context.mjs +51 -0
- package/agent-files/.claude/settings.json +38 -0
- package/agent-files/.codex/hooks.json +40 -0
- package/capabilities.json +1891 -101
- package/dist/index.d.ts +39 -1
- package/dist/index.js +480 -56
- package/dist/threenative.js +1247 -177
- package/package.json +6 -6
- package/template-assets/assets/mannequin-combat.glb +0 -0
- package/template-assets/assets/mannequin.glb +0 -0
- package/template-assets/assets/player-viewmodel.glb +0 -0
- package/template-assets/assets/sky.jpg +0 -0
- package/template-assets/clearwater/README.md +141 -0
- package/template-assets/clearwater/install.mjs +50 -0
- package/template-assets/clearwater/src/clearwater.ts +180 -0
- package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
- package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
- package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
- package/template-assets/clearwater/src/render/clearwater.ts +278 -0
- package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
- package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
- package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
- package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
- package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
- package/template-assets/patches/three@0.185.1.patch +2228 -105
- package/template-assets/worldEnvironment.ts +52 -1
- package/templates/action-rpg/AGENTS.md +43 -43
- package/templates/action-rpg/CLAUDE.md +43 -43
- package/templates/action-rpg/kit.json +1 -1
- package/templates/action-rpg/package.json +14 -8
- package/templates/action-rpg/playtests/combat.playtest.json +162 -23
- package/templates/action-rpg/playtests/performance.playtest.json +4 -3
- package/templates/action-rpg/playtests/survives.playtest.json +25 -8
- package/templates/action-rpg/src/conventions.ts +24 -18
- package/templates/action-rpg/src/entities/Enemy.ts +74 -24
- package/templates/action-rpg/src/entities/Fighter.ts +127 -0
- package/templates/action-rpg/src/entities/Player.ts +102 -32
- package/templates/action-rpg/src/game.ts +3 -3
- package/templates/action-rpg/src/render/camera.ts +18 -16
- package/templates/action-rpg/src/render/dungeon.ts +192 -0
- package/templates/action-rpg/src/render/lighting.ts +45 -28
- package/templates/action-rpg/src/render/loading.ts +4 -4
- package/templates/action-rpg/src/render/materials.ts +191 -47
- package/templates/action-rpg/src/render/palette.ts +14 -13
- package/templates/action-rpg/src/render/postprocessing.ts +12 -2
- package/templates/action-rpg/src/render/props.ts +117 -0
- package/templates/action-rpg/src/render/quality.ts +40 -82
- package/templates/action-rpg/src/render/sky.ts +36 -13
- package/templates/action-rpg/src/render/touch-controls.ts +1 -1
- package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
- package/templates/action-rpg/src/scenes/Play.ts +61 -39
- package/templates/action-rpg/src/style.css +9 -7
- package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
- package/templates/action-rpg/src/ui/Hud.tsx +3 -3
- package/templates/action-rpg/threenative.config.ts +14 -1
- package/templates/action-rpg/vite.config.ts +4 -1
- package/templates/minimal/AGENTS.md +12 -12
- package/templates/minimal/CLAUDE.md +12 -12
- package/templates/minimal/package.json +13 -7
- package/templates/minimal/playtests/play.playtest.json +6 -5
- package/templates/minimal/playtests/sky.playtest.json +27 -0
- package/templates/minimal/src/conventions.ts +6 -3
- package/templates/minimal/src/entities/Player.ts +73 -27
- package/templates/minimal/src/main.ts +2 -3
- package/templates/minimal/src/render/camera.ts +22 -4
- package/templates/minimal/src/render/lighting.ts +24 -48
- package/templates/minimal/src/render/materials.ts +158 -13
- package/templates/minimal/src/render/palette.ts +10 -7
- package/templates/minimal/src/render/postprocessing.ts +12 -25
- package/templates/minimal/src/render/quality.ts +35 -69
- package/templates/minimal/src/render/sky.ts +35 -54
- package/templates/minimal/src/render/touch-controls.ts +1 -1
- package/templates/minimal/src/render/worldEnvironment.ts +52 -1
- package/templates/minimal/src/scenes/Play.ts +121 -111
- package/templates/minimal/src/state.ts +0 -4
- package/templates/minimal/src/style.css +0 -10
- package/templates/minimal/threenative.config.ts +15 -1
- package/templates/minimal/vite.config.ts +4 -1
- package/templates/platformer/AGENTS.md +18 -56
- package/templates/platformer/CLAUDE.md +18 -56
- package/templates/platformer/kit.json +2 -2
- package/templates/platformer/package.json +14 -10
- package/templates/platformer/playtests/buffer.playtest.json +15 -5
- package/templates/platformer/playtests/collect.playtest.json +8 -34
- package/templates/platformer/playtests/coyote.playtest.json +12 -34
- package/templates/platformer/playtests/damage.playtest.json +40 -15
- package/templates/platformer/playtests/hud.playtest.json +34 -0
- package/templates/platformer/playtests/move.playtest.json +24 -0
- package/templates/platformer/playtests/performance.playtest.json +24 -7
- package/templates/platformer/playtests/respawn.playtest.json +46 -11
- package/templates/platformer/playtests/stomp.playtest.json +49 -12
- package/templates/platformer/playtests/survives.playtest.json +3 -19
- package/templates/platformer/playtests/world.playtest.json +26 -0
- package/templates/platformer/src/entities/Fox.ts +273 -0
- package/templates/platformer/src/entities/Pickup.ts +43 -60
- package/templates/platformer/src/entities/Walker.ts +88 -0
- package/templates/platformer/src/game.ts +11 -8
- package/templates/platformer/src/level/Checkpoints.ts +29 -16
- package/templates/platformer/src/level/Stage.ts +469 -0
- package/templates/platformer/src/render/blocks.ts +94 -0
- package/templates/platformer/src/render/camera.ts +28 -3
- package/templates/platformer/src/render/fox.ts +196 -0
- package/templates/platformer/src/render/lighting.ts +42 -33
- package/templates/platformer/src/render/materials.ts +115 -5
- package/templates/platformer/src/render/palette.ts +68 -53
- package/templates/platformer/src/render/pickups.ts +142 -0
- package/templates/platformer/src/render/postprocessing.ts +12 -2
- package/templates/platformer/src/render/props.ts +147 -0
- package/templates/platformer/src/render/quality.ts +47 -99
- package/templates/platformer/src/render/scenery.ts +172 -0
- package/templates/platformer/src/render/sky.ts +120 -31
- package/templates/platformer/src/render/touch-controls.ts +5 -2
- package/templates/platformer/src/render/walkers.ts +96 -0
- package/templates/platformer/src/render/waterfall.ts +85 -0
- package/templates/platformer/src/render/worldEnvironment.ts +52 -1
- package/templates/platformer/src/scenes/Boot.ts +3 -4
- package/templates/platformer/src/scenes/Play.ts +362 -0
- package/templates/platformer/src/state.ts +16 -14
- package/templates/platformer/src/style.css +9 -8
- package/templates/platformer/src/ui/Hud.tsx +62 -29
- package/templates/platformer/src/ui/Menu.tsx +2 -2
- package/templates/platformer/threenative.config.ts +14 -1
- package/templates/platformer/vite.config.ts +4 -1
- package/templates/puzzle/AGENTS.md +21 -22
- package/templates/puzzle/CLAUDE.md +21 -22
- package/templates/puzzle/assets/native-proof.glb +0 -0
- package/templates/puzzle/assets/native-proof.png +0 -0
- package/templates/puzzle/kit.json +1 -1
- package/templates/puzzle/package.json +14 -8
- package/templates/puzzle/playtests/axis.playtest.json +20 -0
- package/templates/puzzle/playtests/blocked.playtest.json +73 -0
- package/templates/puzzle/playtests/caused.playtest.json +65 -0
- package/templates/puzzle/playtests/lit.playtest.json +74 -0
- package/templates/puzzle/playtests/performance.playtest.json +24 -7
- package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
- package/templates/puzzle/playtests/replay.playtest.json +81 -0
- package/templates/puzzle/playtests/restart.playtest.json +108 -0
- package/templates/puzzle/playtests/seal.playtest.json +98 -0
- package/templates/puzzle/playtests/settle.playtest.json +100 -0
- package/templates/puzzle/playtests/survives.playtest.json +6 -29
- package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
- package/templates/puzzle/src/entities/Crate.ts +99 -42
- package/templates/puzzle/src/entities/Seal.ts +69 -0
- package/templates/puzzle/src/entities/Warden.ts +135 -0
- package/templates/puzzle/src/game.ts +15 -11
- package/templates/puzzle/src/render/camera.ts +66 -31
- package/templates/puzzle/src/render/crateShape.ts +70 -0
- package/templates/puzzle/src/render/lighting.ts +41 -41
- package/templates/puzzle/src/render/loading.ts +4 -4
- package/templates/puzzle/src/render/materials.ts +131 -27
- package/templates/puzzle/src/render/palette.ts +19 -29
- package/templates/puzzle/src/render/postprocessing.ts +15 -3
- package/templates/puzzle/src/render/quality.ts +71 -80
- package/templates/puzzle/src/render/shapes.ts +109 -108
- package/templates/puzzle/src/render/sky.ts +18 -10
- package/templates/puzzle/src/render/touch-controls.ts +8 -51
- package/templates/puzzle/src/render/vault.ts +315 -0
- package/templates/puzzle/src/render/warden.ts +46 -0
- package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
- package/templates/puzzle/src/scenes/Play.ts +793 -0
- package/templates/puzzle/src/state.ts +55 -24
- package/templates/puzzle/src/style.css +7 -8
- package/templates/puzzle/src/ui/App.tsx +2 -2
- package/templates/puzzle/src/ui/Hud.tsx +92 -40
- package/templates/puzzle/src/ui/Menu.tsx +40 -2
- package/templates/puzzle/threenative.config.ts +14 -1
- package/templates/puzzle/vite.config.ts +4 -1
- package/templates/racing/AGENTS.md +20 -21
- package/templates/racing/CLAUDE.md +20 -21
- package/templates/racing/package.json +14 -8
- package/templates/racing/playtests/boost.playtest.json +33 -12
- package/templates/racing/playtests/outcome.playtest.json +32 -50
- package/templates/racing/playtests/performance.playtest.json +2 -1
- package/templates/racing/playtests/ranking.playtest.json +5 -14
- package/templates/racing/playtests/rescue.playtest.json +2 -2
- package/templates/racing/playtests/reverse.playtest.json +30 -8
- package/templates/racing/playtests/shortcut.playtest.json +54 -9
- package/templates/racing/playtests/touch-controls.playtest.json +32 -5
- package/templates/racing/src/entities/CarBody.ts +327 -0
- package/templates/racing/src/entities/LineDriver.ts +220 -0
- package/templates/racing/src/entities/RacingCar.ts +150 -89
- package/templates/racing/src/entities/Rival.ts +61 -24
- package/templates/racing/src/game.ts +5 -0
- package/templates/racing/src/render/camera.ts +49 -7
- package/templates/racing/src/render/lighting.ts +36 -37
- package/templates/racing/src/render/materials.ts +239 -19
- package/templates/racing/src/render/palette.ts +19 -21
- package/templates/racing/src/render/postprocessing.ts +12 -2
- package/templates/racing/src/render/quality.ts +43 -82
- package/templates/racing/src/render/shapes.ts +20 -6
- package/templates/racing/src/render/sky.ts +47 -39
- package/templates/racing/src/render/touch-controls.ts +1 -1
- package/templates/racing/src/render/worldEnvironment.ts +52 -1
- package/templates/racing/src/scenes/Race.ts +107 -54
- package/templates/racing/src/state.ts +2 -0
- package/templates/racing/src/track/Checkline.ts +22 -7
- package/templates/racing/src/track/Lap.ts +64 -36
- package/templates/racing/src/track/Ranking.ts +20 -11
- package/templates/racing/src/track/Track.ts +809 -361
- package/templates/racing/src/track/TrackSector.ts +40 -11
- package/templates/racing/src/track/circuit.ts +477 -0
- package/templates/racing/src/track/rescue.ts +16 -4
- package/templates/racing/threenative.config.ts +14 -1
- package/templates/racing/vite.config.ts +4 -1
- package/templates/rts/AGENTS.md +96 -0
- package/templates/rts/CLAUDE.md +98 -0
- package/templates/rts/kit.json +7 -0
- package/templates/{defense → rts}/package.json +14 -8
- package/templates/{defense → rts}/playtests/performance.playtest.json +28 -26
- package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
- package/templates/rts/playtests/rts-attack.playtest.json +75 -0
- package/templates/rts/playtests/rts-build.playtest.json +68 -0
- package/templates/rts/playtests/rts-orders.playtest.json +150 -0
- package/templates/rts/playtests/rts-train.playtest.json +62 -0
- package/templates/rts/playtests/survives.playtest.json +58 -0
- package/templates/rts/public/favicon.svg +4 -0
- package/templates/rts/src/game.ts +64 -0
- package/templates/rts/src/orders.ts +22 -0
- package/templates/rts/src/render/army.ts +346 -0
- package/templates/rts/src/render/camera.ts +123 -0
- package/templates/rts/src/render/lighting.ts +61 -0
- package/templates/rts/src/render/loading.ts +33 -0
- package/templates/rts/src/render/materials.ts +152 -0
- package/templates/rts/src/render/models.ts +705 -0
- package/templates/rts/src/render/palette.ts +17 -0
- package/templates/rts/src/render/picking.ts +93 -0
- package/templates/{defense → rts}/src/render/postprocessing.ts +15 -3
- package/templates/rts/src/render/quality.ts +128 -0
- package/templates/rts/src/render/resources.ts +141 -0
- package/templates/rts/src/render/sky.ts +44 -0
- package/templates/rts/src/render/terrain.ts +116 -0
- package/templates/{defense → rts}/src/render/worldEnvironment.ts +52 -1
- package/templates/rts/src/scenes/Play.ts +650 -0
- package/templates/rts/src/sim/ai.ts +1140 -0
- package/templates/rts/src/sim/combat.ts +416 -0
- package/templates/rts/src/sim/construction.ts +374 -0
- package/templates/rts/src/sim/economy.ts +167 -0
- package/templates/rts/src/sim/game.ts +1082 -0
- package/templates/rts/src/sim/movement.ts +371 -0
- package/templates/rts/src/sim/nav.ts +276 -0
- package/templates/rts/src/sim/production.ts +180 -0
- package/templates/rts/src/sim/terrain.ts +170 -0
- package/templates/rts/src/sim/types.ts +647 -0
- package/templates/rts/src/sim/vision.ts +46 -0
- package/templates/rts/src/state.ts +100 -0
- package/templates/{defense → rts}/src/style.css +21 -8
- package/templates/rts/src/ui/App.tsx +21 -0
- package/templates/rts/src/ui/Commands.tsx +129 -0
- package/templates/rts/src/ui/GameUi.tsx +22 -0
- package/templates/rts/src/ui/Hud.tsx +165 -0
- package/templates/rts/src/ui/Minimap.tsx +84 -0
- package/templates/rts/tailwind.config.ts +2 -0
- package/templates/rts/threenative.config.ts +56 -0
- package/templates/rts/tsconfig.json +17 -0
- package/templates/{defense → rts}/vite.config.ts +4 -1
- package/templates/runner/AGENTS.md +8 -12
- package/templates/runner/CLAUDE.md +8 -12
- package/templates/runner/README.md +3 -3
- package/templates/runner/package.json +14 -8
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +4 -3
- package/templates/runner/src/entities/Runner.ts +54 -7
- package/templates/runner/src/game.ts +2 -0
- package/templates/runner/src/render/camera.ts +4 -2
- package/templates/runner/src/render/dust.ts +5 -2
- package/templates/runner/src/render/lighting.ts +41 -45
- package/templates/runner/src/render/loading.ts +2 -2
- package/templates/runner/src/render/materials.ts +165 -25
- package/templates/runner/src/render/palette.ts +17 -28
- package/templates/runner/src/render/postprocessing.ts +12 -2
- package/templates/runner/src/render/quality.ts +42 -96
- package/templates/runner/src/render/shapes.ts +59 -37
- package/templates/runner/src/render/sky.ts +32 -41
- package/templates/runner/src/render/touch-controls.ts +1 -1
- package/templates/runner/src/render/worldEnvironment.ts +52 -1
- package/templates/runner/src/scenes/Run.ts +26 -6
- package/templates/runner/src/track.ts +6 -1
- package/templates/runner/threenative.config.ts +14 -1
- package/templates/runner/vite.config.ts +4 -1
- package/templates/sailing/AGENTS.md +14 -14
- package/templates/sailing/CLAUDE.md +14 -14
- package/templates/sailing/assets/ship.glb +0 -0
- package/templates/sailing/package.json +14 -8
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
- package/templates/sailing/playtests/sails.playtest.json +33 -0
- package/templates/sailing/playtests/win.playtest.json +156 -8
- package/templates/sailing/src/conventions.ts +29 -2
- package/templates/sailing/src/entities/Ship.ts +381 -57
- package/templates/sailing/src/game.ts +14 -0
- package/templates/sailing/src/render/camera.ts +63 -9
- package/templates/sailing/src/render/lighting.ts +49 -27
- package/templates/sailing/src/render/materials.ts +50 -15
- package/templates/sailing/src/render/ocean.ts +647 -60
- package/templates/sailing/src/render/palette.ts +16 -12
- package/templates/sailing/src/render/postprocessing.ts +12 -2
- package/templates/sailing/src/render/props.ts +316 -442
- package/templates/sailing/src/render/quality.ts +14 -4
- package/templates/sailing/src/render/sky.ts +116 -23
- package/templates/sailing/src/render/worldEnvironment.ts +52 -1
- package/templates/sailing/src/scenes/Boot.ts +21 -0
- package/templates/sailing/src/scenes/Sailing.ts +173 -39
- package/templates/sailing/src/state.ts +6 -0
- package/templates/sailing/src/ui/Hud.tsx +41 -9
- package/templates/sailing/threenative.config.ts +14 -1
- package/templates/sailing/vite.config.ts +4 -1
- package/templates/shooter/AGENTS.md +29 -44
- package/templates/shooter/CLAUDE.md +29 -44
- package/templates/shooter/index.html +1 -0
- package/templates/shooter/package.json +14 -8
- package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
- package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
- package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
- package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
- package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
- package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
- package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
- package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
- package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
- package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
- package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
- package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
- package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
- package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
- package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
- package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
- package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
- package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
- package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
- package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
- package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
- package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
- package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
- package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
- package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
- package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
- package/templates/shooter/playtests/input-control.playtest.json +43 -98
- package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
- package/templates/shooter/playtests/performance.playtest.json +62 -26
- package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
- package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
- package/templates/shooter/playtests/survives.playtest.json +36 -30
- package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
- package/templates/shooter/src/entities/Breakables.ts +412 -0
- package/templates/shooter/src/entities/Enemy.ts +2095 -0
- package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
- package/templates/shooter/src/entities/Rifle.ts +442 -0
- package/templates/shooter/src/entities/Target.ts +199 -83
- package/templates/shooter/src/entities/TouchControls.ts +276 -0
- package/templates/shooter/src/game.ts +75 -41
- package/templates/shooter/src/main.ts +0 -1
- package/templates/shooter/src/postPhysics.ts +36 -0
- package/templates/shooter/src/render/camera.ts +78 -74
- package/templates/shooter/src/render/decals.ts +142 -82
- package/templates/shooter/src/render/facade.ts +1373 -0
- package/templates/shooter/src/render/gunfx.ts +704 -0
- package/templates/shooter/src/render/lighting.ts +52 -38
- package/templates/shooter/src/render/loading.ts +2 -2
- package/templates/shooter/src/render/materials.ts +100 -88
- package/templates/shooter/src/render/occlusion.ts +108 -0
- package/templates/shooter/src/render/palette.ts +10 -10
- package/templates/shooter/src/render/palm.ts +455 -0
- package/templates/shooter/src/render/pooled-billboards.ts +144 -0
- package/templates/shooter/src/render/postprocessing.ts +15 -3
- package/templates/shooter/src/render/quality.ts +40 -82
- package/templates/shooter/src/render/scale.ts +148 -15
- package/templates/shooter/src/render/shapes.ts +138 -613
- package/templates/shooter/src/render/sky.ts +35 -35
- package/templates/shooter/src/render/town-schematic.ts +120 -0
- package/templates/shooter/src/render/town.ts +986 -0
- package/templates/shooter/src/render/townMaterials.ts +160 -0
- package/templates/shooter/src/render/vehicles.ts +741 -0
- package/templates/shooter/src/render/worldEnvironment.ts +52 -1
- package/templates/shooter/src/scenes/Play.ts +727 -650
- package/templates/shooter/src/state.ts +26 -41
- package/templates/shooter/src/style.css +207 -11
- package/templates/shooter/src/surfaces.ts +131 -0
- package/templates/shooter/src/ui/App.tsx +9 -10
- package/templates/shooter/src/ui/Crosshair.tsx +25 -18
- package/templates/shooter/src/ui/GameUi.tsx +6 -9
- package/templates/shooter/src/ui/Hud.tsx +428 -39
- package/templates/shooter/src/ui/Minimap.tsx +164 -0
- package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
- package/templates/shooter/src/ui/main.tsx +2 -3
- package/templates/shooter/threenative.config.ts +14 -1
- package/templates/shooter/vite.config.ts +4 -1
- package/templates/starter/AGENTS.md +20 -20
- package/templates/starter/CLAUDE.md +20 -20
- package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
- package/templates/starter/package.json +15 -9
- package/templates/starter/playtests/play.playtest.json +2 -1
- package/templates/starter/playtests/{restart.playtest.json → production-readiness.playtest.json} +17 -12
- package/templates/starter/playtests/survives.playtest.json +1 -1
- package/templates/starter/src/conventions.ts +6 -3
- package/templates/starter/src/entities/Goal.ts +35 -42
- package/templates/starter/src/entities/Player.ts +99 -16
- package/templates/starter/src/render/arena.ts +131 -0
- package/templates/starter/src/render/lighting.ts +27 -44
- package/templates/starter/src/render/materials.ts +164 -35
- package/templates/starter/src/render/palette.ts +16 -16
- package/templates/starter/src/render/postprocessing.ts +6 -7
- package/templates/starter/src/render/quality.ts +43 -101
- package/templates/starter/src/render/shapes.ts +1 -1
- package/templates/starter/src/render/sky.ts +39 -45
- package/templates/starter/src/render/touch-controls.ts +3 -1
- package/templates/starter/src/render/worldEnvironment.ts +52 -1
- package/templates/starter/src/scenes/Play.ts +82 -81
- package/templates/starter/src/ui/Hud.tsx +2 -2
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/threenative.config.ts +14 -1
- package/templates/starter/vite.config.ts +4 -1
- package/templates/tower-defense/.codex/config.toml +19 -0
- package/templates/tower-defense/.cursor/mcp.json +32 -0
- package/templates/tower-defense/.gemini/settings.json +32 -0
- package/templates/tower-defense/.mcp.json +32 -0
- package/templates/tower-defense/.vscode/mcp.json +36 -0
- package/templates/tower-defense/.zed/settings.json +36 -0
- package/templates/{defense → tower-defense}/AGENTS.md +16 -14
- package/templates/{defense → tower-defense}/CLAUDE.md +16 -14
- package/templates/tower-defense/README.md +16 -0
- package/templates/tower-defense/index.html +12 -0
- package/templates/tower-defense/kit.json +7 -0
- package/templates/tower-defense/opencode.json +41 -0
- package/templates/tower-defense/package.json +56 -0
- package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
- package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
- package/templates/tower-defense/playtests/look.playtest.json +130 -0
- package/templates/tower-defense/playtests/performance.playtest.json +77 -0
- package/templates/tower-defense/playtests/placement.playtest.json +115 -0
- package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
- package/templates/tower-defense/playtests/strike.playtest.json +98 -0
- package/templates/tower-defense/playtests/survives.playtest.json +85 -0
- package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
- package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
- package/templates/tower-defense/playtests/victory.playtest.json +810 -0
- package/templates/tower-defense/src/balance.ts +187 -0
- package/templates/tower-defense/src/board/Board.ts +100 -0
- package/templates/tower-defense/src/board/Route.ts +84 -0
- package/templates/tower-defense/src/camera-rig.ts +62 -0
- package/templates/tower-defense/src/economy.ts +64 -0
- package/templates/tower-defense/src/effects/Effects.ts +284 -0
- package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
- package/templates/tower-defense/src/game.ts +72 -0
- package/templates/tower-defense/src/intents.ts +21 -0
- package/templates/tower-defense/src/main.ts +15 -0
- package/templates/tower-defense/src/physics.ts +6 -0
- package/templates/tower-defense/src/render/camera.ts +38 -0
- package/templates/tower-defense/src/render/lighting.ts +42 -0
- package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
- package/templates/tower-defense/src/render/materials.ts +103 -0
- package/templates/tower-defense/src/render/palette.ts +58 -0
- package/templates/tower-defense/src/render/postprocessing.ts +46 -0
- package/templates/tower-defense/src/render/quality.ts +128 -0
- package/templates/tower-defense/src/render/shapes.ts +550 -0
- package/templates/tower-defense/src/render/sky.ts +27 -0
- package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
- package/templates/tower-defense/src/scenes/Battle.ts +539 -0
- package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
- package/templates/tower-defense/src/state.ts +88 -0
- package/templates/tower-defense/src/style.css +137 -0
- package/templates/tower-defense/src/towers/Tower.ts +230 -0
- package/templates/tower-defense/src/towers/targeting.ts +97 -0
- package/templates/tower-defense/src/ui/Hud.tsx +270 -0
- package/templates/tower-defense/src/ui/Menu.tsx +134 -0
- package/templates/tower-defense/src/ui/icons.tsx +54 -0
- package/templates/tower-defense/src/ui/main.tsx +14 -0
- package/templates/tower-defense/src/waves.ts +90 -0
- package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
- package/templates/tower-defense/vite.config.ts +41 -0
- package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
- package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
- package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -45
- package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
- package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -57
- package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -42
- package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
- package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
- package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
- package/agent-files/AGENT-ROLES.md +0 -26
- package/templates/action-rpg/src/render/shapes.ts +0 -269
- package/templates/action-rpg/src/render/types.ts +0 -3
- package/templates/action-rpg/src/scenes/Boot.ts +0 -12
- package/templates/defense/README.md +0 -10
- package/templates/defense/kit.json +0 -7
- package/templates/defense/playtests/leak.playtest.json +0 -23
- package/templates/defense/playtests/placement.playtest.json +0 -40
- package/templates/defense/playtests/scan.playtest.json +0 -20
- package/templates/defense/playtests/survive.playtest.json +0 -45
- package/templates/defense/playtests/survives.playtest.json +0 -36
- package/templates/defense/src/attackers/Attacker.ts +0 -120
- package/templates/defense/src/board/Route.ts +0 -94
- package/templates/defense/src/conventions.ts +0 -18
- package/templates/defense/src/economy.ts +0 -36
- package/templates/defense/src/entities/Player.ts +0 -52
- package/templates/defense/src/game.ts +0 -51
- package/templates/defense/src/physics.ts +0 -13
- package/templates/defense/src/placement/Buildable.ts +0 -49
- package/templates/defense/src/render/camera.ts +0 -16
- package/templates/defense/src/render/lighting.ts +0 -37
- package/templates/defense/src/render/materials.ts +0 -22
- package/templates/defense/src/render/palette.ts +0 -28
- package/templates/defense/src/render/quality.ts +0 -170
- package/templates/defense/src/render/shapes.ts +0 -246
- package/templates/defense/src/render/sky.ts +0 -45
- package/templates/defense/src/scenes/Boot.ts +0 -12
- package/templates/defense/src/scenes/Defense.ts +0 -231
- package/templates/defense/src/state.ts +0 -56
- package/templates/defense/src/towers/Tower.ts +0 -95
- package/templates/defense/src/towers/targeting.ts +0 -53
- package/templates/defense/src/ui/Hud.tsx +0 -62
- package/templates/defense/src/ui/Menu.tsx +0 -7
- package/templates/defense/src/waves.ts +0 -40
- package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
- package/templates/minimal/src/render/hud.ts +0 -69
- package/templates/platformer/playtests/avoidance.playtest.json +0 -28
- package/templates/platformer/playtests/chase.playtest.json +0 -21
- package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
- package/templates/platformer/playtests/oneway.playtest.json +0 -44
- package/templates/platformer/playtests/patrol.playtest.json +0 -13
- package/templates/platformer/playtests/physics.playtest.json +0 -14
- package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
- package/templates/platformer/src/conventions.ts +0 -18
- package/templates/platformer/src/entities/Character.ts +0 -286
- package/templates/platformer/src/entities/Chaser.ts +0 -118
- package/templates/platformer/src/entities/Patrol.ts +0 -93
- package/templates/platformer/src/level/Platform.ts +0 -46
- package/templates/platformer/src/render/rig.ts +0 -60
- package/templates/platformer/src/render/terrain.ts +0 -31
- package/templates/platformer/src/scenes/Level.ts +0 -241
- package/templates/puzzle/README.md +0 -43
- package/templates/puzzle/playtests/carry.playtest.json +0 -71
- package/templates/puzzle/playtests/swing.playtest.json +0 -38
- package/templates/puzzle/src/conventions.ts +0 -25
- package/templates/puzzle/src/entities/Ball.ts +0 -70
- package/templates/puzzle/src/entities/Gripper.ts +0 -69
- package/templates/puzzle/src/entities/Pendulum.ts +0 -89
- package/templates/puzzle/src/physics.ts +0 -19
- package/templates/puzzle/src/room.ts +0 -83
- package/templates/puzzle/src/scenes/Boot.ts +0 -12
- package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
- package/templates/shooter/playtests/combat.playtest.json +0 -48
- package/templates/shooter/playtests/fail.playtest.json +0 -31
- package/templates/shooter/playtests/per-item.playtest.json +0 -59
- package/templates/shooter/playtests/shooter.playtest.json +0 -99
- package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
- package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
- package/templates/shooter/src/combat/damage.ts +0 -40
- package/templates/shooter/src/conventions.ts +0 -51
- package/templates/shooter/src/entities/Pickup.ts +0 -70
- package/templates/shooter/src/entities/Player.ts +0 -310
- package/templates/shooter/src/level/SpawnPoints.ts +0 -28
- package/templates/shooter/src/playtest-events.ts +0 -15
- package/templates/shooter/src/render/touch-controls.ts +0 -305
- package/templates/shooter/src/render/types.ts +0 -3
- package/templates/shooter/src/render/ui.css +0 -330
- package/templates/shooter/src/render/ui.ts +0 -75
- package/templates/shooter/src/render/vfx.ts +0 -215
- package/templates/shooter/src/ui/Menu.tsx +0 -41
- package/templates/shooter/src/waves.ts +0 -50
- package/templates/shooter/src/weapons/Hitscan.ts +0 -42
- package/templates/shooter/src/weapons/Projectile.ts +0 -92
- package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
- package/templates/starter/playtests/assets.playtest.json +0 -65
- package/templates/starter/playtests/buffer.playtest.json +0 -79
- package/templates/starter/playtests/cloth.playtest.json +0 -113
- package/templates/starter/playtests/coyote.playtest.json +0 -87
- package/templates/starter/playtests/gameover.playtest.json +0 -66
- package/templates/starter/playtests/goal.playtest.json +0 -67
- package/templates/starter/playtests/look.playtest.json +0 -175
- package/templates/starter/playtests/models-baseline.png +0 -0
- package/templates/starter/playtests/models.playtest.json +0 -74
- package/templates/starter/playtests/monitoring.playtest.json +0 -72
- package/templates/starter/playtests/odometer.playtest.json +0 -54
- package/templates/starter/playtests/seed.playtest.json +0 -54
- package/templates/starter/playtests/textures-baseline.png +0 -0
- package/templates/starter/playtests/textures.playtest.json +0 -74
- package/templates/starter/playtests/touch-controls.playtest.json +0 -42
- package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
- package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
- package/templates/starter/src/render/coast.ts +0 -199
- package/templates/starter/src/render/hero.ts +0 -88
- package/templates/starter/src/render/implicitSurface.ts +0 -199
- package/templates/starter/src/render/kuwahara.ts +0 -174
- package/templates/starter/src/render/outline.ts +0 -141
- package/templates/starter/src/render/painterly.ts +0 -86
- package/templates/starter/src/render/rockRidge.ts +0 -198
- package/templates/starter/src/render/rockRidge.worker.ts +0 -77
- package/templates/starter/src/render/scenery.ts +0 -40
- package/templates/starter/src/render/textureLifetime.ts +0 -53
- package/templates/starter/src/render/water.ts +0 -38
- package/templates/starter/src/render/watercolor.ts +0 -85
- /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
- /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
- /package/templates/{defense → rts}/.codex/config.toml +0 -0
- /package/templates/{defense → rts}/.cursor/mcp.json +0 -0
- /package/templates/{defense → rts}/.gemini/settings.json +0 -0
- /package/templates/{defense → rts}/.mcp.json +0 -0
- /package/templates/{defense → rts}/.vscode/mcp.json +0 -0
- /package/templates/{defense → rts}/.zed/settings.json +0 -0
- /package/templates/{defense → rts}/index.html +0 -0
- /package/templates/{defense → rts}/opencode.json +0 -0
- /package/templates/{defense → rts}/src/main.ts +0 -0
- /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
- /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
- /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
- /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
- /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
- /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
- /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated for you. The sea's tuning and its entire look live in this file, and ThreeNative does
|
|
2
2
|
// not read it. `SpectralOcean` runs the simulation and draws nothing: the mesh, the material, the
|
|
3
|
-
// colours, the foam line and the tessellation are all decisions this game makes
|
|
3
|
+
// colours, the reflection, the foam line and the tessellation are all decisions this game makes
|
|
4
|
+
// here.
|
|
4
5
|
//
|
|
5
6
|
// This replaces a two-wave `WaveField` under a `MeshBasicNodeMaterial`. Both halves of that were
|
|
6
7
|
// the problem. Two analytic waves plus one domain warp is a corrugated sheet — it repeats visibly
|
|
@@ -13,20 +14,45 @@
|
|
|
13
14
|
// A spectral ocean is cascaded wave spectra inverse-transformed on the GPU every frame, which is
|
|
14
15
|
// what real water is, and a standard node material puts it back under the scene's own lights.
|
|
15
16
|
import { type ISpectralOceanOptions, SpectralOcean } from "@threenative/core";
|
|
16
|
-
import { Mesh, PlaneGeometry } from "three";
|
|
17
17
|
import {
|
|
18
|
+
BufferGeometry,
|
|
19
|
+
DataTexture,
|
|
20
|
+
Float32BufferAttribute,
|
|
21
|
+
LinearFilter,
|
|
22
|
+
LinearMipmapLinearFilter,
|
|
23
|
+
Mesh,
|
|
24
|
+
type Object3D,
|
|
25
|
+
RepeatWrapping,
|
|
26
|
+
Vector2,
|
|
27
|
+
} from "three";
|
|
28
|
+
import {
|
|
29
|
+
Fn,
|
|
30
|
+
If,
|
|
31
|
+
abs,
|
|
32
|
+
cameraPosition,
|
|
18
33
|
color,
|
|
34
|
+
dot,
|
|
19
35
|
float,
|
|
36
|
+
max,
|
|
20
37
|
mix,
|
|
38
|
+
normalWorld,
|
|
39
|
+
oneMinus,
|
|
21
40
|
positionLocal,
|
|
22
41
|
positionWorld,
|
|
42
|
+
pow,
|
|
43
|
+
reflect,
|
|
44
|
+
saturate,
|
|
23
45
|
smoothstep,
|
|
46
|
+
texture,
|
|
24
47
|
transformNormalToView,
|
|
48
|
+
uniform,
|
|
49
|
+
vec2,
|
|
25
50
|
vec3,
|
|
26
51
|
} from "three/tsl";
|
|
27
52
|
import type { Node } from "three/webgpu";
|
|
28
53
|
import { MeshStandardNodeMaterial } from "three/webgpu";
|
|
29
54
|
import { palette } from "./palette.js";
|
|
55
|
+
import { SUN_DIRECTION } from "./sky.js";
|
|
30
56
|
|
|
31
57
|
/**
|
|
32
58
|
* The sea state. Every number is this game's.
|
|
@@ -36,10 +62,28 @@ import { palette } from "./palette.js";
|
|
|
36
62
|
* vertically, which is what sharpens a crest into something a hull can be thrown by.
|
|
37
63
|
*/
|
|
38
64
|
export const SEA = {
|
|
39
|
-
|
|
65
|
+
// Sea state, and the two numbers that decide whether this reads as a passage or as a puddle.
|
|
66
|
+
//
|
|
67
|
+
// The frame this replaces was a mirror, and the spectrum is why. `windSpeed` sets where the
|
|
68
|
+
// Phillips spectrum's energy sits, through the largest wave `U²/g`: at 10.5 that is an eleven-metre
|
|
69
|
+
// scale, the energy-weighted mean wavelength came out at **42 m**, and a two-metre wave 42 m long
|
|
70
|
+
// is a 5% slope — a mirror with a texture on it. Nothing downstream can rescue that, because the
|
|
71
|
+
// normals really are almost flat. At 6 the mean wavelength is 13 m and the same height is a 15%
|
|
72
|
+
// slope, which is a sea with a shape.
|
|
73
|
+
//
|
|
74
|
+
// `amplitude` is the spectrum's scale, and height goes as its square root, so it was raised 15x
|
|
75
|
+
// to put the crest-to-trough back where it was. Calibrated against the field the CPU actually
|
|
76
|
+
// reads back, over a 70 m patch: 0.026 measured **3.15 m** trough to crest, which threw the ship
|
|
77
|
+
// bodily out of the water — the line of sight to its own keel cleared the sea half a metre astern
|
|
78
|
+
// and the whole hull, rudder and all, hung above the surface in almost every frame. 0.0038
|
|
79
|
+
// measures about 1.3 m, against 0.7 m of freeboard: the caravel is thrown, its rail is awash on
|
|
80
|
+
// the biggest crests, and its keel is under the water.
|
|
81
|
+
amplitude: 0.0046,
|
|
40
82
|
// Largest patch first, and the bands do not overlap. One cascade is a toy — the join between
|
|
41
83
|
// bands is where a spectral ocean visibly fails, so there is nothing to look at until there are
|
|
42
|
-
// two.
|
|
84
|
+
// two. A third was measured and carries 0.01 m of the total: the 1/k⁴ term has already spent the
|
|
85
|
+
// short waves by the time a 9 m patch's band begins, so it buys nothing and costs two more reads
|
|
86
|
+
// in the vertex stage.
|
|
43
87
|
cascades: [{ patchSize: 190 }, { patchSize: 37 }],
|
|
44
88
|
choppiness: 1.2,
|
|
45
89
|
directionality: 2.6,
|
|
@@ -54,19 +98,188 @@ export const SEA = {
|
|
|
54
98
|
// calmer sea state below closes the rest of the gap. This is the cost of a spectral ocean over
|
|
55
99
|
// an analytic one, and it is worth paying — but it has to be paid.
|
|
56
100
|
readbackEveryFrames: 3,
|
|
57
|
-
|
|
101
|
+
// 64, and the paragraph above is the reason: at 32 the copy carried one height every six metres
|
|
102
|
+
// across the broad cascade, which is coarser than the ship is long, so both hull probes landed
|
|
103
|
+
// in the same cell and the ship barely answered the sea it was in.
|
|
104
|
+
readbackResolution: 64,
|
|
58
105
|
resolution: 128,
|
|
59
106
|
seed: 20_260_906,
|
|
60
|
-
|
|
107
|
+
// The length below which the spectrum is damped out, in metres. 0.32 was a 2 m wavelength, which
|
|
108
|
+
// is where the geometric ripple normals already take over, so the sea was throwing away its whole
|
|
109
|
+
// last octave and reading as glass. 0.12 keeps it to about 1.2 m: short enough to carry a
|
|
110
|
+
// glitter path, long enough that the surface is not aliased into sparkle as the camera moves.
|
|
111
|
+
smallWaveCutoff: 0.12,
|
|
61
112
|
windDirection: 0.55,
|
|
62
|
-
windSpeed:
|
|
113
|
+
windSpeed: 6,
|
|
63
114
|
} satisfies ISpectralOceanOptions;
|
|
64
115
|
|
|
65
|
-
/**
|
|
66
|
-
|
|
116
|
+
/**
|
|
117
|
+
* How fast the sea's dominant waves travel, and which way they run.
|
|
118
|
+
*
|
|
119
|
+
* A spectral ocean has no closed-form height, so the CPU copy a hull floats on is always some
|
|
120
|
+
* frames behind the field the GPU is drawing — the API says so, and reports the age. This is what
|
|
121
|
+
* a reader needs to *use* that age: deep-water waves travel, so the field at time `t + d` is very
|
|
122
|
+
* nearly the field at time `t` shifted downwind by `speed * d`. Sampling that far **upwind** of a
|
|
123
|
+
* point therefore reads what the water there is about to be doing.
|
|
124
|
+
*
|
|
125
|
+
* The peak angular frequency is the Pierson-Moskowitz one, `0.855 g / U`, and a deep-water wave's
|
|
126
|
+
* phase speed is `g / w`. Both come straight out of `SEA` above, so retuning the wind retunes
|
|
127
|
+
* this with it.
|
|
128
|
+
*/
|
|
129
|
+
const PEAK_ANGULAR_FREQUENCY = (0.855 * SEA.gravity) / SEA.windSpeed;
|
|
130
|
+
export const SWELL = {
|
|
131
|
+
/** Metres per second. */
|
|
132
|
+
speed: SEA.gravity / PEAK_ANGULAR_FREQUENCY,
|
|
133
|
+
x: Math.cos(SEA.windDirection),
|
|
134
|
+
z: Math.sin(SEA.windDirection),
|
|
135
|
+
} as const;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The most wave-time any reader will extrapolate over, in seconds. See `surfaceHeight`.
|
|
139
|
+
*
|
|
140
|
+
* The lag being corrected for is a few frames in a real session and an order of magnitude worse
|
|
141
|
+
* inside a playtest, where the fixed step runs far faster than wall-clock and a copy in flight
|
|
142
|
+
* covers a hundred ticks. Correcting the first is what a floating thing needs; chasing the second
|
|
143
|
+
* would sample far upwind, where a spectral field has already decorrelated and the "prediction" is
|
|
144
|
+
* just a different wave.
|
|
145
|
+
*
|
|
146
|
+
* It is also short because the lead is measured in wavelengths, not in seconds. This sea state's
|
|
147
|
+
* dominant wavelength is 13 m, so a quarter of a second is 1.75 m upwind — an eighth of a wave, and
|
|
148
|
+
* the height comes back half a metre from the truth, which floats the drawn hull on water that is
|
|
149
|
+
* not being drawn. An eighth of a second is 0.9 m, or a fifteenth of a wave: worth correcting, and
|
|
150
|
+
* small enough not to invent a wave.
|
|
151
|
+
*/
|
|
152
|
+
const MAX_LEAD_SECONDS = 0.12;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The sea's height at a world point, corrected for the age of the copy it came from.
|
|
156
|
+
*
|
|
157
|
+
* This is the call anything that floats should use, rather than `sampleHeight` raw: a hull, a
|
|
158
|
+
* buoy or a bit of flotsam put straight onto the returned number rides water the renderer stopped
|
|
159
|
+
* drawing several frames ago, and the tell is a hull that cuts down through a crest and then hangs
|
|
160
|
+
* over the following trough.
|
|
161
|
+
*
|
|
162
|
+
* `undefined` before the first copy lands, exactly as `sampleHeight` is, so a caller still has to
|
|
163
|
+
* decide what an unknown sea level means for it.
|
|
164
|
+
*/
|
|
165
|
+
export function surfaceHeight(
|
|
166
|
+
ocean: SpectralOcean,
|
|
167
|
+
x: number,
|
|
168
|
+
z: number,
|
|
169
|
+
deltaTime: number,
|
|
170
|
+
): number | undefined {
|
|
171
|
+
const probe = ocean.sampleHeight(x, z);
|
|
172
|
+
if (probe === undefined) return undefined;
|
|
173
|
+
const lead = Math.min(MAX_LEAD_SECONDS, Math.max(0, probe.staleFrames) * deltaTime);
|
|
174
|
+
const run = SWELL.speed * lead;
|
|
175
|
+
return ocean.sampleHeight(x - SWELL.x * run, z - SWELL.z * run)?.height ?? probe.height;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The drawn surface, as a logarithmic disc: rings of quads whose spacing grows with the radius.
|
|
180
|
+
*
|
|
181
|
+
* A square patch cannot do this job at any size. A 300 m square nailed to the ship puts its far
|
|
182
|
+
* edge a hundred and fifty metres out, which is inside the haze, so the player sails to a visible
|
|
183
|
+
* rectangular hem where the sea stops and the photograph starts; and a square big enough to reach
|
|
184
|
+
* the horizon needs 300 m quads near the ship, which is coarser than the waves and throws away
|
|
185
|
+
* everything the cascade buffers are carrying. Rings solve both at once: the innermost quad is a
|
|
186
|
+
* third of a metre beside the hull and the outermost is half a kilometre at the horizon, for
|
|
187
|
+
* *fewer* triangles than the 128×128 grid this replaced.
|
|
188
|
+
*/
|
|
189
|
+
export const SURFACE = {
|
|
190
|
+
/** Quads around the circle. */
|
|
191
|
+
segments: 160,
|
|
192
|
+
/** Rings from the ship to the horizon. */
|
|
193
|
+
rings: 96,
|
|
194
|
+
/** Radius of the first ring, in metres. */
|
|
195
|
+
inner: 1.5,
|
|
196
|
+
/** Radius of the last ring. Past the eye's own horizon at this height, and fully hazed. */
|
|
197
|
+
reach: 6_000,
|
|
198
|
+
} as const;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The step the surface normal is differenced over, in metres.
|
|
202
|
+
*
|
|
203
|
+
* Deliberately finer than the mesh's own quad, which is a third of a metre here. Differencing at
|
|
204
|
+
* the quad size throws away every wave shorter than about four metres *before it can shade
|
|
205
|
+
* anything*, and a sea with no short waves in its normals has no glitter: the sun arrives as one
|
|
206
|
+
* smooth mirror lobe a third of the frame wide, blooms, and blows out. Shading detail below the
|
|
207
|
+
* geometric resolution is the whole point of a normal, and the fine cascade already carries it at
|
|
208
|
+
* 0.29 m per texel. This sits between the two: fine enough to break the highlight into a glitter
|
|
209
|
+
* path, coarse enough not to alias into sparkle noise as the camera moves.
|
|
210
|
+
*/
|
|
211
|
+
const NORMAL_STEP = 0.7;
|
|
212
|
+
|
|
213
|
+
/** Crest foam, whitecap and hull wash. Near-white, and not a seventh palette role: the sea's look is owned here. */
|
|
214
|
+
const FOAM = 0xd6e6ea;
|
|
67
215
|
|
|
68
|
-
/**
|
|
69
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Light coming **through** a wave, which is what makes a crest read as water and not as a ridge.
|
|
218
|
+
*
|
|
219
|
+
* A backlit crest is lit from behind by the sun under the water, and that light is green. It only
|
|
220
|
+
* shows where the face is turned away from the sun and high enough to be near the surface, so it
|
|
221
|
+
* is a product of the face's own slope and its height — which is why it costs two nodes and no
|
|
222
|
+
* texture.
|
|
223
|
+
*/
|
|
224
|
+
const SUBSURFACE = 0x1f6a4c;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* How much of the mirror the sea shows.
|
|
228
|
+
*
|
|
229
|
+
* The mirrored pass draws the world *and the sky behind it*, so what arrives in this texture is a
|
|
230
|
+
* photograph of the clouds. That is the whole defect the owner is looking at: a planar mirror of a
|
|
231
|
+
* partly-cloudy sky reflects every cumulus crisply across six kilometres of water, and a sea that
|
|
232
|
+
* does that is a lake. The sky is therefore **not in the mirror** — see `sky.ts`, where the dome
|
|
233
|
+
* lives on layer 0 and the mirror draws layer 1 only — so what is left in here is the hull, the
|
|
234
|
+
* marks and the headland: the silhouettes a player reads in the water, and the one thing a
|
|
235
|
+
* prefiltered environment cannot do for a sea.
|
|
236
|
+
*
|
|
237
|
+
* Below one because a render target is written linear, where the screen is tone-mapped, so what
|
|
238
|
+
* arrives is the raw 2.5-range photograph and the water would mirror it at full stops.
|
|
239
|
+
*/
|
|
240
|
+
const MIRROR_GAIN = 0.55;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The layer the water's mirror draws. An object on it is **also** on layer 0, so the main camera
|
|
244
|
+
* is unaffected and only the mirrored pass narrows.
|
|
245
|
+
*
|
|
246
|
+
* It is the hull, the marks and the headland — the silhouettes a player actually reads in the
|
|
247
|
+
* water. The sea itself is not on it, which is what stops the mirror from redrawing the mirror,
|
|
248
|
+
* and the sky is not on it because the sky arrives through `reflectedSky` instead: the mirrored
|
|
249
|
+
* pass is a second draw of the world, and putting a 4096-wide photograph in it would buy a
|
|
250
|
+
* lower-resolution copy of a lookup this material can already do for free.
|
|
251
|
+
*/
|
|
252
|
+
export const REFLECTED_LAYER = 1;
|
|
253
|
+
/**
|
|
254
|
+
* How the sea's mirror is built. The *decision* lives here; the construction is the scene's,
|
|
255
|
+
* because `src/render/` reaches the engine only for the wave simulation it draws.
|
|
256
|
+
*
|
|
257
|
+
* Half is the honest resolution for a reflection seen through moving water — the surface itself is
|
|
258
|
+
* the blur, and a sharp half-res copy of a hull in a swell reads no better than a soft full-res
|
|
259
|
+
* one. The layer mask is what keeps the pass affordable: it is a second draw of the world, so
|
|
260
|
+
* `markReflected` is what names the handful of objects worth paying for.
|
|
261
|
+
*/
|
|
262
|
+
export const SEA_MIRROR = {
|
|
263
|
+
level: 0,
|
|
264
|
+
// Never read: this sea is deep everywhere and has no bed to see. The option is required, and
|
|
265
|
+
// this is the depth of water a fully hazed fragment stands behind.
|
|
266
|
+
maxThickness: 24,
|
|
267
|
+
reflection: { resolutionScale: 0.5, layers: 1 << REFLECTED_LAYER },
|
|
268
|
+
} as const;
|
|
269
|
+
|
|
270
|
+
/** The one thing this material asks of the mirror. Structural, so the type is not an import. */
|
|
271
|
+
interface ISeaMirror {
|
|
272
|
+
reflectionAt(offset?: Node<"vec2">): Node<"vec3">;
|
|
273
|
+
dispose(): void;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Put an object in the mirror, and every child of it. Layers are not inherited in three, so a
|
|
278
|
+
* merged hull of seven meshes needs the walk.
|
|
279
|
+
*/
|
|
280
|
+
export function markReflected(object: Object3D): void {
|
|
281
|
+
object.traverse((part) => part.layers.enable(REFLECTED_LAYER));
|
|
282
|
+
}
|
|
70
283
|
|
|
71
284
|
export function createOcean(): SpectralOcean {
|
|
72
285
|
return new SpectralOcean(SEA);
|
|
@@ -76,7 +289,7 @@ export function createOcean(): SpectralOcean {
|
|
|
76
289
|
* Read one cascade's displacement at a world position, **bilinearly**.
|
|
77
290
|
*
|
|
78
291
|
* Nearest-texel sampling is the obvious way to write this and it is visibly wrong here. The mesh
|
|
79
|
-
* carries one vertex per
|
|
292
|
+
* carries one vertex per 0.3 m while the fine cascade's texel is 0.29 m, so every vertex grabbed a
|
|
80
293
|
* different texel of a field it was far too coarse to resolve — and the normal, being a difference
|
|
81
294
|
* of two of those, came out piecewise-constant. The frame showed the sun's reflection broken into
|
|
82
295
|
* hard axis-aligned white rectangles, which is a sampling artefact and reads as a bug in the water.
|
|
@@ -112,68 +325,442 @@ function displacementAt(ocean: SpectralOcean, x: Node<"float">, z: Node<"float">
|
|
|
112
325
|
return vec3(broad.x.add(fine.x), broad.y.add(fine.y), broad.z.add(fine.z));
|
|
113
326
|
}
|
|
114
327
|
|
|
328
|
+
/** A sea surface, and the handle that keeps it under the ship. */
|
|
329
|
+
export interface IWaterSurface {
|
|
330
|
+
readonly mesh: Mesh;
|
|
331
|
+
/** Move the drawn sea to follow a position, keeping the wave field anchored to the world. */
|
|
332
|
+
follow(x: number, z: number): void;
|
|
333
|
+
/** The sea's own clock, for the ripple normals. The wave field has the game's `advance`. */
|
|
334
|
+
advance(elapsed: number): void;
|
|
335
|
+
/**
|
|
336
|
+
* Where the ship is, which way it is pointing, and how hard it is pushing water aside.
|
|
337
|
+
*
|
|
338
|
+
* `strength` is 0..1 and is the speed made good over the hull's own maximum: a ship lying to
|
|
339
|
+
* with no way on leaves no wake, which is the point.
|
|
340
|
+
*/
|
|
341
|
+
wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void;
|
|
342
|
+
/** Releases the mirror's render target. The scene calls this on `exit`. */
|
|
343
|
+
dispose(): void;
|
|
344
|
+
}
|
|
345
|
+
|
|
115
346
|
/**
|
|
116
|
-
* The
|
|
347
|
+
* The wake's shape: how far astern it reaches in metres, how fast the wedge opens, and how wide it
|
|
348
|
+
* is at the transom.
|
|
117
349
|
*
|
|
118
|
-
* The
|
|
119
|
-
*
|
|
120
|
-
*
|
|
350
|
+
* The half-angle of a real Kelvin wedge is about nineteen degrees whatever the hull is doing,
|
|
351
|
+
* which is a `spread` near 0.34 — and at that width, over thirty-four metres, the wake covers so
|
|
352
|
+
* much of a low-camera frame that it stops reading as a wake and becomes a pale smear across the
|
|
353
|
+
* bottom third. Narrower and shorter is the lie worth telling.
|
|
121
354
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
355
|
+
const WAKE = { length: 26, spread: 0.21, waist: 0.5 } as const;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The wash the hull stands in, as half of the hull's length and beam in metres.
|
|
359
|
+
*
|
|
360
|
+
* A ship that leaves the surface exactly as it found it is a model on a backdrop. This is the ring
|
|
361
|
+
* of broken water at its own waterline: the ellipse is the hull's plan, `wash` is the band just
|
|
362
|
+
* outside it, and it is strongest under way because it is `wakeStrength` — a ship lying to with no
|
|
363
|
+
* way on stops pushing water aside, which is the point. The numbers are the hull's own, from
|
|
364
|
+
* `HULL_STATIONS` in `props.ts` after the 4.6 m normalisation.
|
|
365
|
+
*/
|
|
366
|
+
const HULL_WASH = { halfBeam: 0.62, halfLength: 2.35 } as const;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The ripples, as a 256² normal map made of periodic value noise — no file, no fetch, no bytes.
|
|
370
|
+
*
|
|
371
|
+
* The FFT carries energy down to 0.29 m and the geometry can only be tessellated so far, so the
|
|
372
|
+
* last two octaves of a real sea — the chop between the wave crests — have to come from somewhere
|
|
373
|
+
* that is not the mesh. Two scrolling octaves of this are what break the sun's highlight into a
|
|
374
|
+
* glitter path instead of one blown lobe, and they are the reason a wave crest has a skin on it.
|
|
375
|
+
*/
|
|
376
|
+
function rippleNormals(): DataTexture {
|
|
377
|
+
const n = 256;
|
|
378
|
+
const data = new Uint8Array(n * n * 4);
|
|
379
|
+
// Periodic value noise on a `k`-cell grid, so the texture tiles without a visible seam.
|
|
380
|
+
const hash = (x: number, z: number): number => {
|
|
381
|
+
const a = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
|
|
382
|
+
return a - Math.floor(a);
|
|
383
|
+
};
|
|
384
|
+
const noise = (u: number, v: number, k: number): number => {
|
|
385
|
+
const x = u * k;
|
|
386
|
+
const z = v * k;
|
|
387
|
+
const i = Math.floor(x);
|
|
388
|
+
const j = Math.floor(z);
|
|
389
|
+
let a = x - i;
|
|
390
|
+
let b = z - j;
|
|
391
|
+
a = a * a * a * (a * (a * 6 - 15) + 10);
|
|
392
|
+
b = b * b * b * (b * (b * 6 - 15) + 10);
|
|
393
|
+
const h = (hx: number, hz: number): number => hash(((hx % k) + k) % k, ((hz % k) + k) % k);
|
|
394
|
+
return (
|
|
395
|
+
(h(i, j) * (1 - a) + h(i + 1, j) * a) * (1 - b) +
|
|
396
|
+
(h(i, j + 1) * (1 - a) + h(i + 1, j + 1) * a) * b
|
|
397
|
+
);
|
|
398
|
+
};
|
|
399
|
+
const height = (u: number, v: number): number =>
|
|
400
|
+
noise(u, v, 8) * 0.58 +
|
|
401
|
+
noise(u, v, 16) * 0.28 +
|
|
402
|
+
noise(u, v, 32) * 0.11 +
|
|
403
|
+
noise(u, v, 64) * 0.03;
|
|
404
|
+
for (let j = 0; j < n; j += 1) {
|
|
405
|
+
for (let i = 0; i < n; i += 1) {
|
|
406
|
+
const u = i / n;
|
|
407
|
+
const v = j / n;
|
|
408
|
+
const e = 1 / n;
|
|
409
|
+
const nx = (height(u + e, v) - height(u - e, v)) * 6;
|
|
410
|
+
const nz = (height(u, v + e) - height(u, v - e)) * 6;
|
|
411
|
+
const at = (j * n + i) * 4;
|
|
412
|
+
data[at] = Math.max(0, Math.min(255, (nx * 0.5 + 0.5) * 255));
|
|
413
|
+
data[at + 1] = Math.max(0, Math.min(255, (nz * 0.5 + 0.5) * 255));
|
|
414
|
+
data[at + 2] = 240;
|
|
415
|
+
data[at + 3] = height(u, v) * 255;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const map = new DataTexture(data, n, n);
|
|
419
|
+
map.wrapS = RepeatWrapping;
|
|
420
|
+
map.wrapT = RepeatWrapping;
|
|
421
|
+
map.magFilter = LinearFilter;
|
|
422
|
+
map.minFilter = LinearMipmapLinearFilter;
|
|
423
|
+
map.generateMipmaps = true;
|
|
424
|
+
map.needsUpdate = true;
|
|
425
|
+
return map;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** The logarithmic disc, in the sea patch's own space: one vertex at the centre, then the rings. */
|
|
429
|
+
function seaDisc(): BufferGeometry {
|
|
430
|
+
const { inner, reach, rings, segments } = SURFACE;
|
|
431
|
+
const growth = Math.log(1 + reach / inner) / rings;
|
|
432
|
+
const positions: number[] = [0, 0, 0];
|
|
433
|
+
const indices: number[] = [];
|
|
434
|
+
for (let ring = 0; ring < rings; ring += 1) {
|
|
435
|
+
const radius = inner * (Math.exp((ring + 1) * growth) - 1);
|
|
436
|
+
for (let step = 0; step < segments; step += 1) {
|
|
437
|
+
const angle = (step / segments) * Math.PI * 2;
|
|
438
|
+
positions.push(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
for (let step = 0; step < segments; step += 1) {
|
|
442
|
+
indices.push(0, 1 + ((step + 1) % segments), 1 + step);
|
|
443
|
+
}
|
|
444
|
+
for (let ring = 1; ring < rings; ring += 1) {
|
|
445
|
+
for (let step = 0; step < segments; step += 1) {
|
|
446
|
+
const near = 1 + (ring - 1) * segments + step;
|
|
447
|
+
const nearNext = 1 + (ring - 1) * segments + ((step + 1) % segments);
|
|
448
|
+
const far = 1 + ring * segments + step;
|
|
449
|
+
const farNext = 1 + ring * segments + ((step + 1) % segments);
|
|
450
|
+
indices.push(near, farNext, far, near, nearNext, farNext);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const geometry = new BufferGeometry();
|
|
454
|
+
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
455
|
+
geometry.setIndex(indices);
|
|
456
|
+
geometry.computeBoundingSphere();
|
|
457
|
+
return geometry;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The slope of the swell at a world position, by central difference.
|
|
462
|
+
*
|
|
463
|
+
* Without this the surface is lit by the flat plane's normals — every vertex pointing straight up
|
|
464
|
+
* — and a perfectly simulated ocean shades like a sheet of paper. The step is `NORMAL_STEP`, not
|
|
465
|
+
* the mesh's quad; see the note on that constant.
|
|
466
|
+
*/
|
|
467
|
+
function surfaceSlope(ocean: SpectralOcean, x: Node<"float">, z: Node<"float">): Node<"vec2"> {
|
|
468
|
+
const step = float(NORMAL_STEP);
|
|
469
|
+
const east = displacementAt(ocean, x.add(step), z);
|
|
470
|
+
const west = displacementAt(ocean, x.sub(step), z);
|
|
471
|
+
const north = displacementAt(ocean, x, z.add(step));
|
|
472
|
+
const south = displacementAt(ocean, x, z.sub(step));
|
|
473
|
+
const twice = step.mul(2);
|
|
474
|
+
return vec2(west.y.sub(east.y).div(twice), south.y.sub(north.y).div(twice));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Two scrolling octaves of the ripple map, as a slope in the same units as `surfaceSlope`.
|
|
479
|
+
*
|
|
480
|
+
* Only ever called inside an `Fn`, because `If` needs a shader stage to build against — and it is
|
|
481
|
+
* called from two of them, one per stage, which is why it returns a graph rather than a value.
|
|
482
|
+
*/
|
|
483
|
+
function rippleSlope(ripples: DataTexture, time: Node<"float">, fade: Node<"float">): Node<"vec2"> {
|
|
484
|
+
const slope = vec2(0, 0).toVar();
|
|
485
|
+
If(fade.greaterThan(0.02), () => {
|
|
486
|
+
const micro = texture(
|
|
487
|
+
ripples,
|
|
488
|
+
vec2(positionWorld.x, positionWorld.z)
|
|
489
|
+
.mul(vec2(0.022, 0.045))
|
|
490
|
+
.add(time.mul(vec2(0.006, 0.003))),
|
|
491
|
+
);
|
|
492
|
+
const finer = texture(
|
|
493
|
+
ripples,
|
|
494
|
+
vec2(positionWorld.x, positionWorld.z)
|
|
495
|
+
.mul(vec2(0.1, 0.075))
|
|
496
|
+
.add(time.mul(vec2(-0.014, 0.009))),
|
|
497
|
+
);
|
|
498
|
+
slope.assign(micro.rg.mul(2).sub(1).add(finer.rg.mul(2).sub(1).mul(0.32)));
|
|
499
|
+
});
|
|
500
|
+
return slope;
|
|
501
|
+
}
|
|
130
502
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
503
|
+
export function createWaterMesh(
|
|
504
|
+
ocean: SpectralOcean,
|
|
505
|
+
mirror: ISeaMirror,
|
|
506
|
+
options: { readonly software?: boolean } = {},
|
|
507
|
+
): IWaterSurface {
|
|
508
|
+
// A CPU rasteriser draws this material's full graph (cascade normals, foam, wake, mirror) so
|
|
509
|
+
// slowly that the sea-height readback never lands inside a scenario's ticks (measured on four
|
|
510
|
+
// cores: `readbackStaleFrames` stays -1 with the full graph and lands with this one).
|
|
511
|
+
// `ctx.renderer.softwareAdapter` names that machine; the swell, the readback and the hull still
|
|
512
|
+
// run, and only the shading that needs a GPU is left off.
|
|
513
|
+
const cheap = options.software === true;
|
|
514
|
+
const geometry = seaDisc();
|
|
515
|
+
const ripples = rippleNormals();
|
|
516
|
+
|
|
517
|
+
// Where the drawn patch sits in the world.
|
|
518
|
+
//
|
|
519
|
+
// The disc is nailed to the ship rather than to the origin, and the field it reads does **not**
|
|
520
|
+
// travel with it — the cascade lookup adds this offset back, so a wave stays where it is in the
|
|
521
|
+
// world while the mesh slides underneath it. Without that the whole ocean would be dragged along
|
|
522
|
+
// by the ship and the sea would appear to stand still.
|
|
523
|
+
const seaOrigin = uniform(new Vector2());
|
|
524
|
+
const seaTime = uniform(0);
|
|
525
|
+
const shipOrigin = uniform(new Vector2());
|
|
526
|
+
const shipForward = uniform(new Vector2(0, -1));
|
|
527
|
+
const wakeStrength = uniform(0);
|
|
528
|
+
|
|
529
|
+
// Standard, not basic. This is the whole reason the sea has a sun on it rather than a
|
|
530
|
+
// hand-rolled `pow()` blob: a lit material gets the scene's key light and its specular response
|
|
531
|
+
// for free, and gets them consistent with the hull floating on it.
|
|
134
532
|
const material = new MeshStandardNodeMaterial({
|
|
135
|
-
metalness: 0
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
533
|
+
metalness: 0,
|
|
534
|
+
// The sun's own highlight is the one term this material does **not** need help with, and it is
|
|
535
|
+
// the term that ruins the frame when it is too sharp. A GGX lobe at 0.16 peaks thousands of
|
|
536
|
+
// times brighter than its own average, and a low chase camera sees most of the sea at a
|
|
537
|
+
// grazing angle — so the peak lands across a third of the water at once and ACES turns the
|
|
538
|
+
// whole middle distance into a white sheet. The sea is rough instead (see `roughnessNode`),
|
|
539
|
+
// which spreads the same energy over several times the area: the glitter path is still a
|
|
540
|
+
// glitter path, and the sea around it is still sea.
|
|
541
|
+
roughness: 0.13,
|
|
139
542
|
});
|
|
543
|
+
// **On**, and this is the fix for the mirror the owner is looking at. `scene.environment` is the
|
|
544
|
+
// sky photograph, three prefilters it, and a standard material's image-based specular then reads
|
|
545
|
+
// that prefiltered sky *at this fragment's own roughness* — a rough, blurred sky reflection,
|
|
546
|
+
// Fresnel-weighted by the same Schlick curve the rest of the scene's materials use. Looked
|
|
547
|
+
// straight down into, water reflects about 2%; looked along, it reflects nearly all of it. A
|
|
548
|
+
// hand-written `pow(1 - N·V, 5)` on a planar mirror photograph cannot do either of those things
|
|
549
|
+
// and is why every sea past a hundred metres was one even sheet of cloud.
|
|
550
|
+
material.envMapIntensity = 0.32;
|
|
140
551
|
|
|
141
|
-
const
|
|
552
|
+
const worldX = positionLocal.x.add(seaOrigin.x);
|
|
553
|
+
const worldZ = positionLocal.z.add(seaOrigin.y);
|
|
554
|
+
const offset = displacementAt(ocean, worldX, worldZ);
|
|
142
555
|
material.positionNode = positionLocal.add(offset);
|
|
143
556
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
const step = float(SURFACE.size / SURFACE.segments);
|
|
151
|
-
const east = displacementAt(ocean, positionLocal.x.add(step), positionLocal.z);
|
|
152
|
-
const west = displacementAt(ocean, positionLocal.x.sub(step), positionLocal.z);
|
|
153
|
-
const north = displacementAt(ocean, positionLocal.x, positionLocal.z.add(step));
|
|
154
|
-
const south = displacementAt(ocean, positionLocal.x, positionLocal.z.sub(step));
|
|
155
|
-
const twice = step.mul(2);
|
|
156
|
-
// `transformNormalToView`, not the raw vector. `normalNode` overrides `normalView`, so a
|
|
157
|
-
// material handed a world-space normal lights the surface in the camera's frame instead of the
|
|
158
|
-
// world's: the sun's reflection stopped being a place on the sea and became a column of glare
|
|
159
|
-
// pointing at the camera, sliding across the water as the ship turned.
|
|
160
|
-
material.normalNode = transformNormalToView(
|
|
161
|
-
vec3(west.y.sub(east.y).div(twice), float(1), south.y.sub(north.y).div(twice)).normalize(),
|
|
162
|
-
);
|
|
557
|
+
const eye = cameraPosition.sub(positionWorld);
|
|
558
|
+
const distance = eye.length();
|
|
559
|
+
// How far off the ship a ripple can still be told apart, from range alone. A vertex shader cannot
|
|
560
|
+
// ask how big its own fragment is, so this is the vertex stage's half of the answer and
|
|
561
|
+
// `subpixel` below is the fragment stage's.
|
|
562
|
+
const far = float(1).div(distance.mul(0.003).add(1));
|
|
163
563
|
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
|
|
564
|
+
// How much of a wave a pixel can still resolve, as a 0..1 fraction. Past a ~4 m footprint the
|
|
565
|
+
// swell is sub-pixel and the ripples mip to flat, which is what turned every sea beyond ~130 m
|
|
566
|
+
// into a mirror. The slope that is lost does not vanish physically, it becomes roughness — so it
|
|
567
|
+
// is spent as roughness below, on both the mirror and the sun.
|
|
568
|
+
const footprint = positionWorld.dFdx().length().max(positionWorld.dFdy().length());
|
|
569
|
+
const subpixel = smoothstep(0.4, 4, footprint);
|
|
570
|
+
const detail = far.mul(oneMinus(subpixel));
|
|
571
|
+
|
|
572
|
+
// The swell's own slope, once, in the vertex stage. `transformNormalToView`, not the raw vector:
|
|
573
|
+
// `normalNode` overrides `normalView`, so a material handed a world-space normal lights the
|
|
574
|
+
// surface in the camera's frame instead of the world's — the sun's reflection stopped being a
|
|
575
|
+
// place on the sea and became a column of glare pointing at the camera.
|
|
576
|
+
if (!cheap)
|
|
577
|
+
material.normalNode = Fn(() => {
|
|
578
|
+
const slope = surfaceSlope(ocean, worldX, worldZ);
|
|
579
|
+
return transformNormalToView(vec3(slope.x.negate(), 1, slope.y.negate()).normalize());
|
|
580
|
+
})();
|
|
581
|
+
|
|
582
|
+
// Colour by height: deep blue-green in the troughs, lit water on the shoulders, foam on the
|
|
583
|
+
// crests.
|
|
584
|
+
//
|
|
585
|
+
// These numbers are in metres of wave height, so they move with `SEA.amplitude` and are wrong the
|
|
586
|
+
// moment it changes. The sea state above measures 1.99 m crest to trough, so the surface runs
|
|
587
|
+
// about -0.65 m to +0.65 m and the band has to sit inside that: a band centred on zero is above its
|
|
588
|
+
// own threshold across half the sea and the water comes back one even mid teal from bow to
|
|
589
|
+
// horizon. Put the band where the crests are and the sea is deep water everywhere except its
|
|
590
|
+
// tops, which is the only way a height ramp reads as a swell.
|
|
591
|
+
const shade = smoothstep(float(-0.5), float(0.4), positionWorld.y);
|
|
168
592
|
const water = mix(color(palette.floor), color(palette.accent), shade);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
//
|
|
172
|
-
|
|
593
|
+
// The light coming through a wave from behind, which is green and is the difference between a
|
|
594
|
+
// crest and a ridge. It needs a face turned away from the sun and a height near the surface, so
|
|
595
|
+
// it is the product of the two, and it is added rather than mixed so a deep trough stays deep.
|
|
596
|
+
const through = saturate(
|
|
597
|
+
normalWorld.dot(vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z).negate()),
|
|
598
|
+
)
|
|
599
|
+
.mul(shade)
|
|
600
|
+
.mul(0.26);
|
|
601
|
+
// Foam on the tops, not on the faces. The band has to sit near the **highest** water the field
|
|
602
|
+
// reaches, not near its mean: a threshold clearing across whole wave faces at once reads as snow
|
|
603
|
+
// rather than as sea. A field this size is a normal distribution about its mean with a standard
|
|
604
|
+
// deviation near 0.25 m, and at 0.46 m and 0.74 m that is the top one to three per cent of the
|
|
605
|
+
// surface — which is what whitecaps are, and it is the top of the distribution that breaks, not
|
|
606
|
+
// the mean. The band that came back first was at 0.55 m on a field twice this size, which is barely
|
|
607
|
+
// one deviation: a third of the sea came back white and the frame read as pack ice.
|
|
608
|
+
//
|
|
609
|
+
// A height band alone gives foam a *contour line*, because a smooth wave crossing a smooth
|
|
610
|
+
// threshold is a smooth curve: the crests came back as glossy white ribbons laid along the sea,
|
|
611
|
+
// which read as plastic rather than as water. One more octave of the ripple map tears the edge,
|
|
612
|
+
// and it is the same texture the normals already read, so it costs one fetch.
|
|
613
|
+
//
|
|
614
|
+
// **Remapped so it reaches zero.** It used to run 0.45 to 1.0, which is a tint and not a tear:
|
|
615
|
+
// multiplied into the wake it left every fragment of foam at least 45% opaque, and a hard white
|
|
616
|
+
// U came down the frame from under the stern of a ship making no way at all. Foam is patches —
|
|
617
|
+
// there is water between them, and the mask has to say so or it is a decal.
|
|
618
|
+
const torn = Fn(() => {
|
|
619
|
+
const grain = texture(
|
|
620
|
+
ripples,
|
|
621
|
+
vec2(positionWorld.x, positionWorld.z).mul(0.26).add(seaTime.mul(0.02)),
|
|
622
|
+
).a;
|
|
623
|
+
return smoothstep(float(0.4), float(0.74), grain);
|
|
624
|
+
})();
|
|
625
|
+
const crest = smoothstep(float(0.46), float(0.74), positionWorld.y).mul(torn);
|
|
626
|
+
|
|
627
|
+
// The wake, computed rather than drawn.
|
|
628
|
+
//
|
|
629
|
+
// A hull moving through water at six knots that leaves the surface exactly as it found it is the
|
|
630
|
+
// single clearest tell that a sea is a backdrop rather than something the ship is in — and it
|
|
631
|
+
// was, because nothing in this material knew the ship existed. This costs no geometry, no
|
|
632
|
+
// particles and no second pass: the surface already knows its own world position, so it can be
|
|
633
|
+
// told where the ship is and work out whether it is standing in its wake.
|
|
634
|
+
//
|
|
635
|
+
// Everything is in the ship's frame. `astern` is metres behind it and `across` is metres off its
|
|
636
|
+
// centreline, so the wedge is a comparison rather than a rotation.
|
|
637
|
+
const toShip = vec2(positionWorld.x.sub(shipOrigin.x), positionWorld.z.sub(shipOrigin.y));
|
|
638
|
+
const starboardAxis = vec2(shipForward.y.negate(), shipForward.x);
|
|
639
|
+
const astern = dot(toShip, shipForward).negate();
|
|
640
|
+
const across = abs(dot(toShip, starboardAxis));
|
|
641
|
+
// A Kelvin wedge, and it needs both of its parts.
|
|
642
|
+
//
|
|
643
|
+
// Filling the wedge evenly gives a soft triangle that reads as haze on the water. What a wake
|
|
644
|
+
// actually looks like from astern is a churned band directly behind the transom with two bright
|
|
645
|
+
// arms running out from it at the edges of the wedge, and the arms are the half of it the eye
|
|
646
|
+
// recognises: they are the only straight lines in a scene made entirely of swell.
|
|
647
|
+
const halfWidth = astern.mul(WAKE.spread).add(WAKE.waist);
|
|
648
|
+
const churn = smoothstep(halfWidth.mul(0.62), halfWidth.mul(0.12), across).mul(0.6);
|
|
649
|
+
const arms = smoothstep(halfWidth.mul(0.5), float(0), abs(across.sub(halfWidth)));
|
|
650
|
+
const reach = smoothstep(float(WAKE.length), float(0), astern);
|
|
651
|
+
const begins = smoothstep(float(-1.4), float(1.6), astern);
|
|
652
|
+
// Never quite to full foam. At 1.0 the arms are the brightest thing in the frame and read as two
|
|
653
|
+
// searchlights laid on the sea rather than as broken water.
|
|
654
|
+
//
|
|
655
|
+
// Torn by the same grain as the whitecaps, and this is the term that has to have it. `arms` is
|
|
656
|
+
// the only straight line in a scene made entirely of swell, so an untiled one is read as a line
|
|
657
|
+
// somebody drew: the frame came back with a hard white U running from under the stern to the
|
|
658
|
+
// bottom edge, off a hull making no way at all.
|
|
659
|
+
const wake = max(churn, arms).mul(reach).mul(begins).mul(wakeStrength).mul(torn).mul(0.78);
|
|
660
|
+
// The wash at the hull's own waterline: an ellipse in the ship's plan, and a band just outside
|
|
661
|
+
// it. Cheaper than the wake and it is the half the player is closest to — without it the hull
|
|
662
|
+
// meets the sea on a clean line, and a clean line is the tell that nothing here is water.
|
|
663
|
+
const plan = vec2(astern.div(HULL_WASH.halfLength), across.div(HULL_WASH.halfBeam));
|
|
664
|
+
//
|
|
665
|
+
// **Gated on way on**, which it was not, and that was the other half of the U. A hull lying to
|
|
666
|
+
// is not working water against its own topsides — it is sitting in it — and the lie this told
|
|
667
|
+
// was a bright unbroken annulus around a stationary ship, which the eye reads as a decal rather
|
|
668
|
+
// than as a wake no matter how well it is torn. Under way it is a ring of broken water at the
|
|
669
|
+
// waterline; at rest there is nothing, and the hull sits in a swell like anything else.
|
|
670
|
+
//
|
|
671
|
+
// The band is a quarter as wide as the ellipse's own radius and the edges are soft, because a
|
|
672
|
+
// narrow hard ring at this distance photographs as a drawn circle however broken its fill is.
|
|
673
|
+
const wash = smoothstep(float(1.34), float(0.94), plan.length()).mul(
|
|
674
|
+
smoothstep(float(0.62), float(0.94), plan.length()),
|
|
675
|
+
);
|
|
676
|
+
// Plus a little standing white at the bow, where the stem pushes a bow wave ahead of it.
|
|
677
|
+
//
|
|
678
|
+
// Bounded ahead as well: `smoothstep` with its edges reversed clamps to 1 on the far side, so
|
|
679
|
+
// without the second ramp this was a strip of foam from the stem to the horizon.
|
|
680
|
+
const bow = smoothstep(float(-1.4), float(-2.5), astern)
|
|
681
|
+
.mul(smoothstep(float(-5), float(-3.5), astern))
|
|
682
|
+
.mul(smoothstep(float(1.3), float(0.2), across))
|
|
683
|
+
.mul(wakeStrength)
|
|
684
|
+
.mul(torn);
|
|
685
|
+
const broken = max(max(wake, bow), wash.mul(torn).mul(wakeStrength));
|
|
686
|
+
material.colorNode = cheap
|
|
687
|
+
? water
|
|
688
|
+
: mix(water.add(color(SUBSURFACE).mul(through)), color(FOAM), max(crest, broken));
|
|
689
|
+
|
|
690
|
+
// The one thing the prefiltered environment cannot do: the hull, the marks and the headland, in
|
|
691
|
+
// the water, sharp.
|
|
692
|
+
//
|
|
693
|
+
// Fresnel is the term that decides how much. The sky's own reflection is already handled above by
|
|
694
|
+
// the material's image-based specular, which applies the same Schlick curve on its own; this
|
|
695
|
+
// applies the same one to the mirror, so the two agree at the horizon and the silhouettes fade
|
|
696
|
+
// out as the eye comes down onto the water.
|
|
697
|
+
if (!cheap)
|
|
698
|
+
material.emissiveNode = Fn(() => {
|
|
699
|
+
// The interpolated vertex normal, which is the swell, plus this fragment's own ripple. Adding
|
|
700
|
+
// the ripple here rather than in the vertex stage is what makes it affordable: the swell's
|
|
701
|
+
// central difference is four cascade reads, and doing that per *fragment* on a full-screen sea
|
|
702
|
+
// cost sixteen texture fetches a pixel to arrive at a vector the vertex stage had already
|
|
703
|
+
// computed. The ripple is a texture read either way, and per fragment is finer, which is the
|
|
704
|
+
// whole point of a normal map.
|
|
705
|
+
const normal = normalWorld
|
|
706
|
+
.add(vec3(rippleSlope(ripples, seaTime, detail).mul(-0.47).mul(detail), 0))
|
|
707
|
+
.normalize();
|
|
708
|
+
const facing = saturate(dot(normal, eye.normalize()));
|
|
709
|
+
// Exponent five is water's own Schlick curve, and the 0.97963/0.02037 pair is its reflectance
|
|
710
|
+
// at the horizon and at normal incidence.
|
|
711
|
+
const fresnel = pow(oneMinus(facing), float(5)).mul(0.97963).add(0.02037);
|
|
712
|
+
// The normal's own slope is the offset: it is the same slope that is bending the light, so the
|
|
713
|
+
// mirror wobbles with the wave it is standing on.
|
|
714
|
+
const reflected = mirror.reflectionAt(normal.xz.mul(0.02)).mul(MIRROR_GAIN);
|
|
715
|
+
// Rough water does not mirror at grazing angles the way a flat facet does: the microfacets that
|
|
716
|
+
// survive are not aligned with the view, so reflectance falls off with roughness.
|
|
717
|
+
const rough = max(crest, broken);
|
|
718
|
+
return reflected.mul(fresnel).mul(oneMinus(max(subpixel, rough).mul(0.75)));
|
|
719
|
+
})();
|
|
720
|
+
// Roughness is spent, not lost: the slope a distant pixel can no longer resolve reappears here.
|
|
721
|
+
//
|
|
722
|
+
// This is now the term that decides the whole look, because it is what the prefiltered sky is
|
|
723
|
+
// sampled at. A sea at 0.13 returns a sharp horizon and a broken cloud; at 0.5 it returns a broad
|
|
724
|
+
// luminous sheet, which is a mirror again. **Sharp is the word that matters here**: a rough
|
|
725
|
+
// surface *averages* the sky over a wide cone, so every facet returns nearly the same pale value
|
|
726
|
+
// and the wave shape disappears into a field of ice — which is exactly what the first two frames
|
|
727
|
+
// looked like. A sharp one returns a different piece of sky per facet and the shape comes back.
|
|
728
|
+
// Near the ship the ripple normals carry the detail, and past the point where a pixel can no
|
|
729
|
+
// longer resolve a metre of wave the roughness takes over and the middle distance turns into the
|
|
730
|
+
// soft band a real sea shows. Broken water is not a mirror either, and roughening it is what
|
|
731
|
+
// stops the foam reading as chrome.
|
|
732
|
+
if (!cheap)
|
|
733
|
+
material.roughnessNode = max(float(0.13).add(subpixel.mul(0.3)), max(crest, broken).mul(0.9));
|
|
173
734
|
|
|
174
735
|
const mesh = new Mesh(geometry, material);
|
|
175
736
|
mesh.receiveShadow = true;
|
|
176
737
|
mesh.frustumCulled = false;
|
|
177
738
|
mesh.name = "sea-surface";
|
|
178
|
-
|
|
739
|
+
|
|
740
|
+
// Snapped, because following continuously would slide every vertex through the wave field by a
|
|
741
|
+
// fraction of its size every frame and the surface would visibly crawl. A whole-metre step is
|
|
742
|
+
// coarse enough to stop the crawl and fine enough that the snap itself cannot be seen.
|
|
743
|
+
return {
|
|
744
|
+
mesh,
|
|
745
|
+
advance(elapsed: number): void {
|
|
746
|
+
seaTime.value = elapsed;
|
|
747
|
+
},
|
|
748
|
+
wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void {
|
|
749
|
+
shipOrigin.value.set(x, z);
|
|
750
|
+
shipForward.value.set(forwardX, forwardZ);
|
|
751
|
+
wakeStrength.value = Math.max(0, Math.min(1, strength));
|
|
752
|
+
},
|
|
753
|
+
follow(x: number, z: number): void {
|
|
754
|
+
const snappedX = Math.round(x);
|
|
755
|
+
const snappedZ = Math.round(z);
|
|
756
|
+
mesh.position.set(snappedX, 0, snappedZ);
|
|
757
|
+
seaOrigin.value.set(snappedX, snappedZ);
|
|
758
|
+
},
|
|
759
|
+
dispose(): void {
|
|
760
|
+
mirror.dispose();
|
|
761
|
+
ripples.dispose();
|
|
762
|
+
geometry.dispose();
|
|
763
|
+
material.dispose();
|
|
764
|
+
},
|
|
765
|
+
};
|
|
179
766
|
}
|