create-threenative 0.2.7 → 0.2.9
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 +3 -1
- package/agent-docs/references/assertion-reference.md +87 -35
- package/agent-docs/references/auto-exposure.md +57 -0
- package/agent-docs/references/capability-reference.md +1306 -62
- package/agent-docs/references/debug-surface.md +6 -0
- package/agent-docs/references/finding-assets.md +46 -10
- package/agent-docs/references/performance-basics.md +5 -4
- package/agent-docs/references/terrain-authoring.md +140 -0
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +2 -1
- package/capabilities.json +1505 -79
- package/dist/index.d.ts +28 -3
- package/dist/index.js +402 -167
- package/dist/threenative.js +989 -237
- package/dist/web-engine-buffer-geometry-utils.js +281 -0
- package/dist/web-engine-decal-geometry.js +184 -0
- package/dist/web-engine-gltf-loader.js +196 -0
- package/dist/web-engine-hdr-loader.js +190 -0
- package/dist/web-engine-lut-cube-loader.js +122 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +29 -0
- package/dist/web-engine-mesh-bvh.js +32 -0
- package/dist/web-engine-post-effects.js +168 -0
- package/dist/web-engine-runtime.js +42506 -0
- package/package.json +11 -8
- package/template-assets/autoExposure.ts +225 -0
- package/template-assets/exposure.ts +111 -0
- package/template-assets/exposureGraph.ts +178 -0
- package/template-assets/exposureReadback.ts +79 -0
- package/template-assets/patches/@tailwindcss__node@4.3.3.patch +22 -0
- package/template-assets/patches/three@0.185.1.patch +6594 -700
- package/template-assets/patches/vite@8.2.0.patch +422 -0
- package/template-assets/worldEnvironment.ts +433 -30
- package/templates/action-rpg/AGENTS.md +11 -10
- package/templates/action-rpg/CLAUDE.md +11 -10
- package/templates/action-rpg/package.json +11 -9
- package/templates/action-rpg/playtests/performance.playtest.json +7 -1
- package/templates/action-rpg/src/progress.ts +0 -4
- package/templates/action-rpg/src/render/autoExposure.ts +225 -0
- package/templates/action-rpg/src/render/backlightControls.ts +66 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +147 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +188 -0
- package/templates/action-rpg/src/render/environmentRadiance.ts +36 -0
- package/templates/action-rpg/src/render/environmentSampleCache.ts +43 -0
- package/templates/action-rpg/src/render/environmentSampling.ts +193 -0
- package/templates/action-rpg/src/render/environmentSnapshot.ts +53 -0
- package/templates/action-rpg/src/render/exposure.ts +111 -0
- package/templates/action-rpg/src/render/exposureGraph.ts +178 -0
- package/templates/action-rpg/src/render/exposureReadback.ts +79 -0
- package/templates/action-rpg/src/render/heightFog.ts +118 -0
- package/templates/action-rpg/src/render/lighting.ts +26 -1
- package/templates/action-rpg/src/render/materialAssignments.ts +160 -0
- package/templates/action-rpg/src/render/materialLighting.ts +155 -0
- package/templates/action-rpg/src/render/postprocessing.ts +17 -2
- package/templates/action-rpg/src/render/quality.ts +61 -2
- package/templates/action-rpg/src/render/sky.ts +21 -1
- package/templates/action-rpg/src/render/vfx.ts +133 -58
- package/templates/action-rpg/src/render/worldEnvironment.ts +433 -30
- package/templates/action-rpg/src/scenes/Play.ts +81 -16
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/action-rpg/vite.config.ts +10 -2
- package/templates/minimal/AGENTS.md +9 -10
- package/templates/minimal/CLAUDE.md +9 -10
- package/templates/minimal/package.json +9 -8
- package/templates/minimal/playtests/play.playtest.json +7 -1
- package/templates/minimal/playtests/sky.playtest.json +10 -1
- package/templates/minimal/src/render/autoExposure.ts +225 -0
- package/templates/minimal/src/render/backlightControls.ts +66 -0
- package/templates/minimal/src/render/backlightMaterial.ts +147 -0
- package/templates/minimal/src/render/environmentContribution.ts +188 -0
- package/templates/minimal/src/render/environmentRadiance.ts +36 -0
- package/templates/minimal/src/render/environmentSampleCache.ts +43 -0
- package/templates/minimal/src/render/environmentSampling.ts +193 -0
- package/templates/minimal/src/render/environmentSnapshot.ts +53 -0
- package/templates/minimal/src/render/exposure.ts +111 -0
- package/templates/minimal/src/render/exposureGraph.ts +178 -0
- package/templates/minimal/src/render/exposureReadback.ts +79 -0
- package/templates/minimal/src/render/heightFog.ts +118 -0
- package/templates/minimal/src/render/lighting.ts +25 -1
- package/templates/minimal/src/render/materialAssignments.ts +102 -0
- package/templates/minimal/src/render/materialLighting.ts +146 -0
- package/templates/minimal/src/render/postprocessing.ts +16 -2
- package/templates/minimal/src/render/quality.ts +60 -2
- package/templates/minimal/src/render/sky.ts +21 -1
- package/templates/minimal/src/render/worldEnvironment.ts +433 -30
- package/templates/minimal/src/scenes/Play.ts +50 -1
- package/templates/minimal/vite.config.ts +10 -2
- package/templates/platformer/AGENTS.md +7 -5
- package/templates/platformer/CLAUDE.md +7 -5
- package/templates/platformer/package.json +11 -9
- package/templates/platformer/playtests/performance.playtest.json +7 -1
- package/templates/platformer/src/render/autoExposure.ts +225 -0
- package/templates/platformer/src/render/backlightControls.ts +66 -0
- package/templates/platformer/src/render/backlightMaterial.ts +147 -0
- package/templates/platformer/src/render/environmentContribution.ts +188 -0
- package/templates/platformer/src/render/environmentRadiance.ts +36 -0
- package/templates/platformer/src/render/environmentSampleCache.ts +43 -0
- package/templates/platformer/src/render/environmentSampling.ts +193 -0
- package/templates/platformer/src/render/environmentSnapshot.ts +53 -0
- package/templates/platformer/src/render/exposure.ts +111 -0
- package/templates/platformer/src/render/exposureGraph.ts +178 -0
- package/templates/platformer/src/render/exposureReadback.ts +79 -0
- package/templates/platformer/src/render/heightFog.ts +118 -0
- package/templates/platformer/src/render/lighting.ts +26 -1
- package/templates/platformer/src/render/materialAssignments.ts +160 -0
- package/templates/platformer/src/render/materialLighting.ts +155 -0
- package/templates/platformer/src/render/materials.ts +7 -2
- package/templates/platformer/src/render/palette.ts +3 -3
- package/templates/platformer/src/render/postprocessing.ts +17 -2
- package/templates/platformer/src/render/quality.ts +61 -2
- package/templates/platformer/src/render/sky.ts +72 -23
- package/templates/platformer/src/render/skyEnvironment.ts +50 -0
- package/templates/platformer/src/render/worldEnvironment.ts +433 -30
- package/templates/platformer/src/scenes/Play.ts +70 -6
- package/templates/platformer/vite.config.ts +10 -2
- package/templates/puzzle/AGENTS.md +10 -9
- package/templates/puzzle/CLAUDE.md +10 -9
- package/templates/puzzle/package.json +11 -9
- package/templates/puzzle/playtests/boot-failure.playtest.json +2 -2
- package/templates/puzzle/playtests/lit.playtest.json +7 -1
- package/templates/puzzle/playtests/performance.playtest.json +7 -1
- package/templates/puzzle/src/render/autoExposure.ts +225 -0
- package/templates/puzzle/src/render/backlightControls.ts +66 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +147 -0
- package/templates/puzzle/src/render/environmentContribution.ts +188 -0
- package/templates/puzzle/src/render/environmentRadiance.ts +36 -0
- package/templates/puzzle/src/render/environmentSampleCache.ts +43 -0
- package/templates/puzzle/src/render/environmentSampling.ts +193 -0
- package/templates/puzzle/src/render/environmentSnapshot.ts +53 -0
- package/templates/puzzle/src/render/exposure.ts +111 -0
- package/templates/puzzle/src/render/exposureGraph.ts +178 -0
- package/templates/puzzle/src/render/exposureReadback.ts +79 -0
- package/templates/puzzle/src/render/heightFog.ts +118 -0
- package/templates/puzzle/src/render/lighting.ts +33 -1
- package/templates/puzzle/src/render/materialAssignments.ts +160 -0
- package/templates/puzzle/src/render/materialLighting.ts +155 -0
- package/templates/puzzle/src/render/materials.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +8 -2
- package/templates/puzzle/src/render/quality.ts +62 -1
- package/templates/puzzle/src/render/sky.ts +20 -1
- package/templates/puzzle/src/render/worldEnvironment.ts +433 -30
- package/templates/puzzle/src/scenes/Play.ts +51 -2
- package/templates/puzzle/vite.config.ts +10 -2
- package/templates/racing/AGENTS.md +8 -7
- package/templates/racing/CLAUDE.md +8 -7
- package/templates/racing/package.json +11 -9
- package/templates/racing/playtests/performance.playtest.json +7 -1
- package/templates/racing/playtests/survives.playtest.json +6 -0
- package/templates/racing/src/render/autoExposure.ts +225 -0
- package/templates/racing/src/render/backlightControls.ts +66 -0
- package/templates/racing/src/render/backlightMaterial.ts +147 -0
- package/templates/racing/src/render/environmentContribution.ts +188 -0
- package/templates/racing/src/render/environmentRadiance.ts +36 -0
- package/templates/racing/src/render/environmentSampleCache.ts +43 -0
- package/templates/racing/src/render/environmentSampling.ts +193 -0
- package/templates/racing/src/render/environmentSnapshot.ts +53 -0
- package/templates/racing/src/render/exposure.ts +111 -0
- package/templates/racing/src/render/exposureGraph.ts +178 -0
- package/templates/racing/src/render/exposureReadback.ts +79 -0
- package/templates/racing/src/render/heightFog.ts +118 -0
- package/templates/racing/src/render/lighting.ts +29 -1
- package/templates/racing/src/render/materialAssignments.ts +160 -0
- package/templates/racing/src/render/materialLighting.ts +155 -0
- package/templates/racing/src/render/palette.ts +1 -10
- package/templates/racing/src/render/postprocessing.ts +17 -2
- package/templates/racing/src/render/quality.ts +61 -2
- package/templates/racing/src/render/shapes.ts +0 -25
- package/templates/racing/src/render/sky.ts +21 -1
- package/templates/racing/src/render/worldEnvironment.ts +433 -30
- package/templates/racing/src/scenes/Race.ts +91 -3
- package/templates/racing/src/track/circuit.ts +0 -9
- package/templates/racing/vite.config.ts +10 -2
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +95 -0
- package/templates/rain/CLAUDE.md +97 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +23 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +59 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +32 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +194 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +81 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/autoExposure.ts +225 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/exposure.ts +111 -0
- package/templates/rain/src/render/exposureGraph.ts +178 -0
- package/templates/rain/src/render/exposureReadback.ts +79 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +229 -0
- package/templates/rain/src/render/quality.ts +161 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +1212 -0
- package/templates/rain/src/scenes/Boot.ts +348 -0
- package/templates/rain/src/state.ts +261 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +45 -0
- package/templates/rts/AGENTS.md +10 -11
- package/templates/rts/CLAUDE.md +10 -11
- package/templates/rts/package.json +10 -8
- package/templates/rts/playtests/performance.playtest.json +7 -1
- package/templates/rts/playtests/rts-ai-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-build.playtest.json +10 -1
- package/templates/rts/playtests/rts-orders.playtest.json +7 -1
- package/templates/rts/playtests/rts-train.playtest.json +10 -1
- package/templates/rts/src/render/army.ts +10 -2
- package/templates/rts/src/render/autoExposure.ts +225 -0
- package/templates/rts/src/render/backlightControls.ts +66 -0
- package/templates/rts/src/render/backlightMaterial.ts +147 -0
- package/templates/rts/src/render/environmentContribution.ts +188 -0
- package/templates/rts/src/render/environmentRadiance.ts +36 -0
- package/templates/rts/src/render/environmentSampleCache.ts +43 -0
- package/templates/rts/src/render/environmentSampling.ts +193 -0
- package/templates/rts/src/render/environmentSnapshot.ts +53 -0
- package/templates/rts/src/render/exposure.ts +111 -0
- package/templates/rts/src/render/exposureGraph.ts +178 -0
- package/templates/rts/src/render/exposureReadback.ts +79 -0
- package/templates/rts/src/render/heightFog.ts +118 -0
- package/templates/rts/src/render/lighting.ts +26 -1
- package/templates/rts/src/render/materialAssignments.ts +160 -0
- package/templates/rts/src/render/materialLighting.ts +155 -0
- package/templates/rts/src/render/postprocessing.ts +8 -2
- package/templates/rts/src/render/quality.ts +61 -2
- package/templates/rts/src/render/sky.ts +21 -1
- package/templates/rts/src/render/worldEnvironment.ts +433 -30
- package/templates/rts/src/scenes/Play.ts +54 -3
- package/templates/rts/src/sim/ai.ts +0 -1
- package/templates/rts/src/sim/terrain.ts +0 -4
- package/templates/rts/vite.config.ts +10 -2
- package/templates/runner/AGENTS.md +10 -8
- package/templates/runner/CLAUDE.md +10 -8
- package/templates/runner/package.json +11 -9
- package/templates/runner/playtests/performance.playtest.json +10 -1
- package/templates/runner/src/physics.ts +0 -1
- package/templates/runner/src/render/autoExposure.ts +225 -0
- package/templates/runner/src/render/backlightControls.ts +66 -0
- package/templates/runner/src/render/backlightMaterial.ts +147 -0
- package/templates/runner/src/render/environmentContribution.ts +188 -0
- package/templates/runner/src/render/environmentRadiance.ts +36 -0
- package/templates/runner/src/render/environmentSampleCache.ts +43 -0
- package/templates/runner/src/render/environmentSampling.ts +193 -0
- package/templates/runner/src/render/environmentSnapshot.ts +53 -0
- package/templates/runner/src/render/exposure.ts +111 -0
- package/templates/runner/src/render/exposureGraph.ts +178 -0
- package/templates/runner/src/render/exposureReadback.ts +79 -0
- package/templates/runner/src/render/heightFog.ts +118 -0
- package/templates/runner/src/render/lighting.ts +26 -1
- package/templates/runner/src/render/materialAssignments.ts +160 -0
- package/templates/runner/src/render/materialLighting.ts +155 -0
- package/templates/runner/src/render/postprocessing.ts +17 -2
- package/templates/runner/src/render/quality.ts +61 -2
- package/templates/runner/src/render/sky.ts +21 -1
- package/templates/runner/src/render/worldEnvironment.ts +433 -30
- package/templates/runner/src/scenes/Run.ts +67 -2
- package/templates/runner/threenative.config.ts +3 -0
- package/templates/runner/vite.config.ts +10 -2
- package/templates/sailing/AGENTS.md +14 -13
- package/templates/sailing/CLAUDE.md +14 -13
- package/templates/sailing/native-playtests/survives.playtest.json +7 -0
- package/templates/sailing/package.json +11 -9
- package/templates/sailing/playtests/live/render-motion.playtest.json +30 -0
- package/templates/sailing/src/entities/Ship.ts +38 -18
- package/templates/sailing/src/render/autoExposure.ts +225 -0
- package/templates/sailing/src/render/backlightControls.ts +66 -0
- package/templates/sailing/src/render/backlightMaterial.ts +147 -0
- package/templates/sailing/src/render/camera.ts +12 -4
- package/templates/sailing/src/render/environmentContribution.ts +188 -0
- package/templates/sailing/src/render/environmentRadiance.ts +36 -0
- package/templates/sailing/src/render/environmentSampleCache.ts +43 -0
- package/templates/sailing/src/render/environmentSampling.ts +193 -0
- package/templates/sailing/src/render/environmentSetup.ts +24 -0
- package/templates/sailing/src/render/environmentSnapshot.ts +53 -0
- package/templates/sailing/src/render/exposure.ts +111 -0
- package/templates/sailing/src/render/exposureGraph.ts +178 -0
- package/templates/sailing/src/render/exposureReadback.ts +79 -0
- package/templates/sailing/src/render/heightFog.ts +118 -0
- package/templates/sailing/src/render/lighting.ts +26 -1
- package/templates/sailing/src/render/materialAssignments.ts +160 -0
- package/templates/sailing/src/render/materialLighting.ts +155 -0
- package/templates/sailing/src/render/ocean.ts +71 -53
- package/templates/sailing/src/render/postprocessing.ts +16 -2
- package/templates/sailing/src/render/props.ts +0 -45
- package/templates/sailing/src/render/quality.ts +61 -1
- package/templates/sailing/src/render/sky.ts +21 -1
- package/templates/sailing/src/render/worldEnvironment.ts +433 -30
- package/templates/sailing/src/scenes/Boot.ts +12 -1
- package/templates/sailing/src/scenes/Sailing.ts +87 -2
- package/templates/sailing/src/scenes/ocean-readiness.ts +68 -0
- package/templates/sailing/threenative.config.ts +3 -0
- package/templates/sailing/vite.config.ts +10 -2
- package/templates/shooter/AGENTS.md +8 -6
- package/templates/shooter/CLAUDE.md +8 -6
- package/templates/shooter/package.json +11 -9
- package/templates/shooter/playtests/performance.playtest.json +7 -1
- package/templates/shooter/src/entities/Enemy.ts +0 -15
- package/templates/shooter/src/entities/Rifle.ts +38 -1
- package/templates/shooter/src/render/autoExposure.ts +225 -0
- package/templates/shooter/src/render/backlightControls.ts +66 -0
- package/templates/shooter/src/render/backlightMaterial.ts +147 -0
- package/templates/shooter/src/render/camera.ts +1 -12
- package/templates/shooter/src/render/decals.ts +299 -5
- package/templates/shooter/src/render/environmentContribution.ts +188 -0
- package/templates/shooter/src/render/environmentRadiance.ts +36 -0
- package/templates/shooter/src/render/environmentSampleCache.ts +43 -0
- package/templates/shooter/src/render/environmentSampling.ts +193 -0
- package/templates/shooter/src/render/environmentSnapshot.ts +53 -0
- package/templates/shooter/src/render/exposure.ts +111 -0
- package/templates/shooter/src/render/exposureGraph.ts +178 -0
- package/templates/shooter/src/render/exposureReadback.ts +79 -0
- package/templates/shooter/src/render/gunfx.ts +0 -1
- package/templates/shooter/src/render/heightFog.ts +118 -0
- package/templates/shooter/src/render/lighting.ts +26 -1
- package/templates/shooter/src/render/materialAssignments.ts +160 -0
- package/templates/shooter/src/render/materialLighting.ts +155 -0
- package/templates/shooter/src/render/postprocessing.ts +17 -2
- package/templates/shooter/src/render/quality.ts +61 -2
- package/templates/shooter/src/render/scale.ts +2 -93
- package/templates/shooter/src/render/sky.ts +21 -1
- package/templates/shooter/src/render/vehicles.ts +0 -17
- package/templates/shooter/src/render/worldEnvironment.ts +433 -30
- package/templates/shooter/src/scenes/Play.ts +64 -2
- package/templates/shooter/vite.config.ts +10 -2
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +90 -0
- package/templates/snow/CLAUDE.md +92 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +60 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/autoExposure.ts +225 -0
- package/templates/snow/src/render/backlightControls.ts +66 -0
- package/templates/snow/src/render/backlightMaterial.ts +147 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/environmentContribution.ts +188 -0
- package/templates/snow/src/render/environmentRadiance.ts +36 -0
- package/templates/snow/src/render/environmentSampleCache.ts +43 -0
- package/templates/snow/src/render/environmentSampling.ts +193 -0
- package/templates/snow/src/render/environmentSnapshot.ts +53 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/exposure.ts +111 -0
- package/templates/snow/src/render/exposureGraph.ts +178 -0
- package/templates/snow/src/render/exposureReadback.ts +79 -0
- package/templates/snow/src/render/heightFog.ts +118 -0
- package/templates/snow/src/render/lighting.ts +82 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materialAssignments.ts +160 -0
- package/templates/snow/src/render/materialLighting.ts +155 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +58 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +193 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +76 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +1212 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +663 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +54 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +45 -0
- package/templates/starter/AGENTS.md +11 -16
- package/templates/starter/CLAUDE.md +11 -16
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -1
- package/templates/starter/native-playtests/render-chain.playtest.json +51 -8
- package/templates/starter/native-playtests/smooth-motion.playtest.json +64 -0
- package/templates/starter/package.json +11 -9
- package/templates/starter/playtests/live/smooth-motion.playtest.json +63 -0
- package/templates/starter/playtests/movement.playtest.json +192 -0
- package/templates/starter/playtests/play.playtest.json +18 -2
- package/templates/starter/playtests/production-readiness.playtest.json +1 -1
- package/templates/starter/public/grade.cube +735 -0
- package/templates/starter/src/entities/Crate.ts +4 -0
- package/templates/starter/src/entities/Player.ts +79 -18
- package/templates/starter/src/game.ts +1 -0
- package/templates/starter/src/render/adaptiveQuality.ts +28 -41
- package/templates/starter/src/render/autoExposure.ts +225 -0
- package/templates/starter/src/render/backlightControls.ts +66 -0
- package/templates/starter/src/render/backlightMaterial.ts +147 -0
- package/templates/starter/src/render/environmentContribution.ts +188 -0
- package/templates/starter/src/render/environmentRadiance.ts +36 -0
- package/templates/starter/src/render/environmentSampleCache.ts +43 -0
- package/templates/starter/src/render/environmentSampling.ts +193 -0
- package/templates/starter/src/render/environmentSnapshot.ts +53 -0
- package/templates/starter/src/render/exposure.ts +111 -0
- package/templates/starter/src/render/exposureGraph.ts +178 -0
- package/templates/starter/src/render/exposureReadback.ts +79 -0
- package/templates/starter/src/render/grade.ts +157 -0
- package/templates/starter/src/render/heightFog.ts +118 -0
- package/templates/starter/src/render/lighting.ts +26 -1
- package/templates/starter/src/render/materialAssignments.ts +160 -0
- package/templates/starter/src/render/materialLighting.ts +155 -0
- package/templates/starter/src/render/postprocessing.ts +84 -4
- package/templates/starter/src/render/quality.ts +80 -8
- package/templates/starter/src/render/qualityPolicy.ts +54 -0
- package/templates/starter/src/render/rendererGate.ts +36 -0
- package/templates/starter/src/render/sky.ts +23 -1
- package/templates/starter/src/render/temporalAA.ts +197 -0
- package/templates/starter/src/render/temporalAAFrame.ts +179 -0
- package/templates/starter/src/render/temporalAAHooks.ts +101 -0
- package/templates/starter/src/render/temporalAAInput.ts +56 -0
- package/templates/starter/src/render/temporalAAResolve.ts +65 -0
- package/templates/starter/src/render/temporalAAStage.ts +76 -0
- package/templates/starter/src/render/temporalCurrentArea.ts +31 -0
- package/templates/starter/src/render/temporalCurrentFootprint.ts +198 -0
- package/templates/starter/src/render/temporalCurrentFootprintMath.ts +41 -0
- package/templates/starter/src/render/temporalCurrentProducer.ts +161 -0
- package/templates/starter/src/render/temporalCurrentReplay.ts +160 -0
- package/templates/starter/src/render/temporalCurrentSelection.ts +89 -0
- package/templates/starter/src/render/temporalCurrentVisibility.ts +170 -0
- package/templates/starter/src/render/temporalDepthSamples.ts +34 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +179 -0
- package/templates/starter/src/render/temporalResolve.ts +139 -0
- package/templates/starter/src/render/temporalResolveDepth.ts +193 -0
- package/templates/starter/src/render/temporalResolveMath.ts +196 -0
- package/templates/starter/src/render/volumetricFog.ts +124 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +96 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +176 -0
- package/templates/starter/src/render/volumetricFogVolume.ts +139 -0
- package/templates/starter/src/render/worldEnvironment.ts +433 -30
- package/templates/starter/src/scenes/Play.ts +110 -1
- package/templates/starter/src/state.ts +1 -0
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/ui/Menu.tsx +1 -1
- package/templates/starter/tools/make-grade-lut.mjs +101 -0
- package/templates/starter/vite.config.ts +10 -2
- package/templates/tower-defense/AGENTS.md +10 -9
- package/templates/tower-defense/CLAUDE.md +10 -9
- package/templates/tower-defense/package.json +11 -9
- package/templates/tower-defense/playtests/performance.playtest.json +7 -1
- package/templates/tower-defense/src/render/autoExposure.ts +225 -0
- package/templates/tower-defense/src/render/backlightControls.ts +66 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +147 -0
- package/templates/tower-defense/src/render/environmentContribution.ts +188 -0
- package/templates/tower-defense/src/render/environmentRadiance.ts +36 -0
- package/templates/tower-defense/src/render/environmentSampleCache.ts +43 -0
- package/templates/tower-defense/src/render/environmentSampling.ts +193 -0
- package/templates/tower-defense/src/render/environmentSnapshot.ts +53 -0
- package/templates/tower-defense/src/render/exposure.ts +111 -0
- package/templates/tower-defense/src/render/exposureGraph.ts +178 -0
- package/templates/tower-defense/src/render/exposureReadback.ts +79 -0
- package/templates/tower-defense/src/render/lighting.ts +33 -1
- package/templates/tower-defense/src/render/materialAssignments.ts +160 -0
- package/templates/tower-defense/src/render/materialLighting.ts +155 -0
- package/templates/tower-defense/src/render/postprocessing.ts +8 -2
- package/templates/tower-defense/src/render/quality.ts +61 -2
- package/templates/tower-defense/src/render/shapes.ts +0 -3
- package/templates/tower-defense/src/render/worldEnvironment.ts +433 -30
- package/templates/tower-defense/src/scenes/Battle.ts +65 -2
- package/templates/tower-defense/vite.config.ts +10 -2
- package/templates/minimal/src/scenes/Boot.ts +0 -5
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CircleGeometry,
|
|
3
|
+
type ColorRepresentation,
|
|
4
|
+
Group,
|
|
5
|
+
MathUtils,
|
|
6
|
+
Mesh,
|
|
7
|
+
MeshBasicMaterial,
|
|
8
|
+
type PerspectiveCamera,
|
|
9
|
+
RingGeometry,
|
|
10
|
+
Vector2,
|
|
11
|
+
} from "three";
|
|
12
|
+
import { palette } from "./palette.js";
|
|
13
|
+
|
|
14
|
+
const MOVE_RADIUS = 72;
|
|
15
|
+
const EDGE = 36;
|
|
16
|
+
|
|
17
|
+
export interface ITouchPointer {
|
|
18
|
+
readonly position: Vector2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ITouchViewport {
|
|
22
|
+
readonly height: number;
|
|
23
|
+
readonly width: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ITouchInput {
|
|
27
|
+
readonly move: Vector2;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function overlayMaterial(color: ColorRepresentation, opacity: number): MeshBasicMaterial {
|
|
31
|
+
return new MeshBasicMaterial({
|
|
32
|
+
color,
|
|
33
|
+
depthTest: false,
|
|
34
|
+
depthWrite: false,
|
|
35
|
+
opacity,
|
|
36
|
+
transparent: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ringMesh(radius: number, material: MeshBasicMaterial): Mesh {
|
|
41
|
+
return new Mesh(new RingGeometry(radius - 5, radius, 32), material);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function place(mesh: Mesh, point: Vector2): void {
|
|
45
|
+
mesh.position.set(point.x, point.y, 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function movementPoint(size: ITouchViewport): Vector2 {
|
|
49
|
+
return new Vector2(MOVE_RADIUS + EDGE, size.height - MOVE_RADIUS - EDGE);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class TouchControls {
|
|
53
|
+
readonly root = new Group();
|
|
54
|
+
readonly object = this.root;
|
|
55
|
+
#camera: PerspectiveCamera;
|
|
56
|
+
#input: { move: Vector2 } = { move: new Vector2() };
|
|
57
|
+
#moveAnchor = new Vector2();
|
|
58
|
+
#resting = new Vector2();
|
|
59
|
+
#hasMoveAnchor = false;
|
|
60
|
+
#lastWidth = -1;
|
|
61
|
+
#lastHeight = -1;
|
|
62
|
+
#moveBase: Mesh;
|
|
63
|
+
#moveKnob: Mesh;
|
|
64
|
+
#idleMaterial: MeshBasicMaterial;
|
|
65
|
+
#activeMaterial: MeshBasicMaterial;
|
|
66
|
+
|
|
67
|
+
constructor(camera: PerspectiveCamera) {
|
|
68
|
+
this.#camera = camera;
|
|
69
|
+
// On white snow a faint ring vanishes: a dark stick ring and an accent knob.
|
|
70
|
+
this.#idleMaterial = overlayMaterial(palette.floor, 0.6);
|
|
71
|
+
this.#activeMaterial = overlayMaterial(palette.accent, 0.8);
|
|
72
|
+
this.#moveBase = ringMesh(MOVE_RADIUS, this.#idleMaterial);
|
|
73
|
+
this.#moveKnob = new Mesh(new CircleGeometry(28, 24), this.#activeMaterial);
|
|
74
|
+
this.root.add(this.#moveBase, this.#moveKnob);
|
|
75
|
+
this.root.renderOrder = 10_001;
|
|
76
|
+
camera.add(this.root);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
update(pointers: ReadonlyMap<number, ITouchPointer>, size: ITouchViewport): ITouchInput {
|
|
80
|
+
this.#ensureLayout(size);
|
|
81
|
+
let movement: ITouchPointer | undefined;
|
|
82
|
+
for (const pointer of pointers.values()) {
|
|
83
|
+
if (pointer.position.x < size.width * 0.5) {
|
|
84
|
+
movement = pointer;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (movement === undefined) {
|
|
90
|
+
this.#hasMoveAnchor = false;
|
|
91
|
+
this.#input.move.set(0, 0);
|
|
92
|
+
} else {
|
|
93
|
+
if (!this.#hasMoveAnchor) {
|
|
94
|
+
this.#moveAnchor.copy(movement.position);
|
|
95
|
+
this.#hasMoveAnchor = true;
|
|
96
|
+
}
|
|
97
|
+
this.#input.move.set(
|
|
98
|
+
MathUtils.clamp((movement.position.x - this.#moveAnchor.x) / MOVE_RADIUS, -1, 1),
|
|
99
|
+
MathUtils.clamp((this.#moveAnchor.y - movement.position.y) / MOVE_RADIUS, -1, 1),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
|
|
104
|
+
place(
|
|
105
|
+
this.#moveKnob,
|
|
106
|
+
new Vector2(
|
|
107
|
+
center.x + this.#input.move.x * MOVE_RADIUS,
|
|
108
|
+
center.y - this.#input.move.y * MOVE_RADIUS,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
this.#moveKnob.material = this.#hasMoveAnchor ? this.#activeMaterial : this.#idleMaterial;
|
|
112
|
+
this.#layout(size);
|
|
113
|
+
return this.#input;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
debug(): Record<string, unknown> {
|
|
117
|
+
return { move: this.#input.move.toArray() };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
dispose(): void {
|
|
121
|
+
this.root.removeFromParent();
|
|
122
|
+
for (const child of this.root.children) {
|
|
123
|
+
if (child instanceof Mesh) child.geometry.dispose();
|
|
124
|
+
}
|
|
125
|
+
this.#idleMaterial.dispose();
|
|
126
|
+
this.#activeMaterial.dispose();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#ensureLayout(size: ITouchViewport): void {
|
|
130
|
+
if (size.width === this.#lastWidth && size.height === this.#lastHeight) return;
|
|
131
|
+
this.#lastWidth = size.width;
|
|
132
|
+
this.#lastHeight = size.height;
|
|
133
|
+
this.#resting.copy(movementPoint(size));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#layout(size: ITouchViewport): void {
|
|
137
|
+
const worldHeight = 2 * Math.tan(MathUtils.degToRad(this.#camera.fov / 2));
|
|
138
|
+
const pixels = worldHeight / Math.max(1, size.height);
|
|
139
|
+
this.root.position.set(-(size.width * pixels) / 2, worldHeight / 2, -1);
|
|
140
|
+
this.root.scale.set(pixels, -pixels, 1);
|
|
141
|
+
place(this.#moveBase, this.#hasMoveAnchor ? this.#moveAnchor : this.#resting);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Generated for you. Snowfall, the blizzard and the powder a boot kicks up. `GPUParticles3D` (the
|
|
2
|
+
// scene passes it in) owns
|
|
3
|
+
// the buffers, dispatch and lifetime; the flake's shape, colour, size, drift and fall are here.
|
|
4
|
+
import { type Sprite, Vector2 } from "three";
|
|
5
|
+
import {
|
|
6
|
+
Fn,
|
|
7
|
+
atan,
|
|
8
|
+
cameraPosition,
|
|
9
|
+
cos,
|
|
10
|
+
exp,
|
|
11
|
+
float,
|
|
12
|
+
fract,
|
|
13
|
+
hash,
|
|
14
|
+
instanceIndex,
|
|
15
|
+
mod,
|
|
16
|
+
pow,
|
|
17
|
+
sin,
|
|
18
|
+
smoothstep,
|
|
19
|
+
step,
|
|
20
|
+
uniform,
|
|
21
|
+
uv,
|
|
22
|
+
vec2,
|
|
23
|
+
vec3,
|
|
24
|
+
vec4,
|
|
25
|
+
} from "three/tsl";
|
|
26
|
+
import {
|
|
27
|
+
AdditiveBlending,
|
|
28
|
+
type ComputeNode,
|
|
29
|
+
type Node,
|
|
30
|
+
NormalBlending,
|
|
31
|
+
SpriteNodeMaterial,
|
|
32
|
+
type StorageBufferNode,
|
|
33
|
+
} from "three/webgpu";
|
|
34
|
+
|
|
35
|
+
/** Half the width of the box of air around the explorer that flakes fall through, metres. */
|
|
36
|
+
const SPAN = 21;
|
|
37
|
+
const CEILING = 19;
|
|
38
|
+
/** The widest a flake may be drawn, in screen pixels — the study's point-size clamp. */
|
|
39
|
+
const MAX_FLAKE_PIXELS = 24;
|
|
40
|
+
const BURST_PARTICLES = 96;
|
|
41
|
+
const BURST_LIFETIME = 1.05;
|
|
42
|
+
|
|
43
|
+
const random = (salt: number) => hash(instanceIndex.add(salt));
|
|
44
|
+
|
|
45
|
+
/** What a particle mechanism takes: a pool size, a sprite material and two compute passes. */
|
|
46
|
+
export interface IParticleOptions {
|
|
47
|
+
readonly amount: number;
|
|
48
|
+
readonly material: SpriteNodeMaterial;
|
|
49
|
+
readonly start: (buffers: { readonly positions: StorageBufferNode<"vec3"> }) => ComputeNode;
|
|
50
|
+
readonly process: (buffers: { readonly positions: StorageBufferNode<"vec3"> }) => ComputeNode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The pooled sprite the scene builds from those options — `GPUParticles3D` in this game. */
|
|
54
|
+
export type ParticleSystem = Sprite & {
|
|
55
|
+
readonly buffers: { readonly positions: StorageBufferNode<"vec3"> };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export interface ISnowWeather {
|
|
59
|
+
readonly snowfall: ParticleSystem;
|
|
60
|
+
readonly bursts: readonly ParticleSystem[];
|
|
61
|
+
/** Live wind at the snowfield, m/s, gusts included. */
|
|
62
|
+
readonly wind: number;
|
|
63
|
+
/** 0 clear .. 1 blizzard, eased. */
|
|
64
|
+
readonly storm: number;
|
|
65
|
+
update(
|
|
66
|
+
dt: number,
|
|
67
|
+
centre: { readonly x: number; readonly z: number },
|
|
68
|
+
/** Screen pixels per metre at one metre from the camera: `height / (2 tan(fov / 2))`. */
|
|
69
|
+
pixelScale: number,
|
|
70
|
+
settings: {
|
|
71
|
+
readonly blizzard: boolean;
|
|
72
|
+
readonly snowfall: number;
|
|
73
|
+
readonly fallSpeed: number;
|
|
74
|
+
readonly wind: number;
|
|
75
|
+
},
|
|
76
|
+
): void;
|
|
77
|
+
/** Kick up powder where a boot landed, deeper prints throwing more. */
|
|
78
|
+
burst(at: { readonly x: number; readonly y: number; readonly z: number }, strength: number): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const floatUniform = (value: number) => uniform(value);
|
|
82
|
+
type FloatUniform = ReturnType<typeof floatUniform>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The flake sprite. `at` is each flake's world position and `pixelScale` the screen's pixels per
|
|
86
|
+
* metre at one metre: a flake is never drawn wider than `MAX_FLAKE_PIXELS`, and fades out right
|
|
87
|
+
* in front of the lens, so the air between the camera and the forest never turns to haze.
|
|
88
|
+
*/
|
|
89
|
+
function flakeMaterial(
|
|
90
|
+
storm: FloatUniform,
|
|
91
|
+
visible: FloatUniform,
|
|
92
|
+
at: Node<"vec3">,
|
|
93
|
+
pixelScale: FloatUniform,
|
|
94
|
+
) {
|
|
95
|
+
const material = new SpriteNodeMaterial({
|
|
96
|
+
blending: NormalBlending,
|
|
97
|
+
depthWrite: false,
|
|
98
|
+
transparent: true,
|
|
99
|
+
});
|
|
100
|
+
// A soft disc with six faint arms, squashed sideways as the storm drives it.
|
|
101
|
+
const p = uv()
|
|
102
|
+
.sub(0.5)
|
|
103
|
+
.mul(vec2(float(1).sub(storm.mul(0.32)), 1));
|
|
104
|
+
const r = p.length();
|
|
105
|
+
const disc = exp(r.mul(r).mul(-18)).mul(float(1).sub(smoothstep(0.36, 0.5, r)));
|
|
106
|
+
const arms = pow(cos(atan(p.y, p.x).mul(3)).abs(), 12)
|
|
107
|
+
.mul(0.2)
|
|
108
|
+
.add(0.8);
|
|
109
|
+
const shown = step(float(instanceIndex).add(1), visible);
|
|
110
|
+
const distance = cameraPosition.distance(at);
|
|
111
|
+
const opacity = random(11)
|
|
112
|
+
.mul(0.55)
|
|
113
|
+
.add(0.28)
|
|
114
|
+
.mul(smoothstep(0.35, 1.2, distance));
|
|
115
|
+
material.colorNode = vec4(0.95, 0.977, 1, disc.mul(arms).mul(opacity).mul(shown));
|
|
116
|
+
const size = pow(random(13), 3).mul(0.063).add(0.016);
|
|
117
|
+
const widest = distance.mul(MAX_FLAKE_PIXELS).div(pixelScale);
|
|
118
|
+
// In a storm each flake streaks along the wind, the study's squashed-disc look made longer.
|
|
119
|
+
const drawn = size.mul(storm.mul(0.5).add(1)).min(widest).mul(shown);
|
|
120
|
+
material.scaleNode = vec2(drawn.mul(storm.mul(1.6).add(1)), drawn);
|
|
121
|
+
return material;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Every flake's position is a function of how far the air has carried it, not a stored velocity:
|
|
126
|
+
* `drift` and `fall` are integrated on the CPU from the live wind and fall speed, so changing a
|
|
127
|
+
* slider never teleports the flakes, and the box wraps around the explorer wherever they walk.
|
|
128
|
+
*/
|
|
129
|
+
function createSnowfall(
|
|
130
|
+
amount: number,
|
|
131
|
+
particlesFor: (options: IParticleOptions) => ParticleSystem,
|
|
132
|
+
) {
|
|
133
|
+
const storm = floatUniform(0);
|
|
134
|
+
const visible = floatUniform(amount);
|
|
135
|
+
const drift = uniform(new Vector2());
|
|
136
|
+
const fall = uniform(0);
|
|
137
|
+
const centre = uniform(new Vector2());
|
|
138
|
+
const swirl = uniform(0);
|
|
139
|
+
const pixelScale = floatUniform(800);
|
|
140
|
+
const place = (positions: StorageBufferNode<"vec3">): ComputeNode =>
|
|
141
|
+
Fn(() => {
|
|
142
|
+
const seed = random(3).mul(100);
|
|
143
|
+
const start = vec3(random(5), random(7), random(9));
|
|
144
|
+
const speed = fract(seed).add(0.58);
|
|
145
|
+
const height = mod(start.y.mul(CEILING).sub(fall.mul(speed)), CEILING).sub(0.5);
|
|
146
|
+
const phase = swirl.add(seed);
|
|
147
|
+
// Air near the ground is slower than air aloft, as the study's coupling had it.
|
|
148
|
+
const coupling = height.div(7).clamp(0.18, 1);
|
|
149
|
+
const wander = vec2(
|
|
150
|
+
sin(phase.add(start.z.mul(4))),
|
|
151
|
+
cos(phase.mul(0.86).add(start.x.mul(4))),
|
|
152
|
+
).mul(storm.mul(0.7).add(0.16));
|
|
153
|
+
const span = float(SPAN * 2);
|
|
154
|
+
const raw = start.xz.mul(span).add(drift.mul(coupling)).add(wander);
|
|
155
|
+
const wrapped = mod(raw.sub(centre).add(SPAN), span).sub(SPAN).add(centre);
|
|
156
|
+
positions.element(instanceIndex).assign(vec3(wrapped.x, height, wrapped.y));
|
|
157
|
+
})().compute(amount);
|
|
158
|
+
const material = new SpriteNodeMaterial();
|
|
159
|
+
const particles = particlesFor({
|
|
160
|
+
amount,
|
|
161
|
+
material,
|
|
162
|
+
process: ({ positions }) => place(positions),
|
|
163
|
+
start: ({ positions }) => place(positions),
|
|
164
|
+
});
|
|
165
|
+
// The flake look needs each flake's position, which exists once the particle buffers do.
|
|
166
|
+
const flake = flakeMaterial(
|
|
167
|
+
storm,
|
|
168
|
+
visible,
|
|
169
|
+
particles.buffers.positions.toAttribute(),
|
|
170
|
+
pixelScale,
|
|
171
|
+
);
|
|
172
|
+
flake.positionNode = material.positionNode;
|
|
173
|
+
particles.material = flake;
|
|
174
|
+
particles.renderOrder = 3;
|
|
175
|
+
return { centre, drift, fall, particles, pixelScale, storm, swirl, visible };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** One pooled burst: every particle leaves the boot at once and fades by its own lifetime. */
|
|
179
|
+
function createBurst(particlesFor: (options: IParticleOptions) => ParticleSystem) {
|
|
180
|
+
const age = uniform(BURST_LIFETIME);
|
|
181
|
+
const kick = uniform(1);
|
|
182
|
+
const wind = uniform(0);
|
|
183
|
+
const material = new SpriteNodeMaterial({
|
|
184
|
+
blending: AdditiveBlending,
|
|
185
|
+
depthWrite: false,
|
|
186
|
+
transparent: true,
|
|
187
|
+
});
|
|
188
|
+
const life = random(17).mul(0.65).add(0.38);
|
|
189
|
+
const t = age.min(life);
|
|
190
|
+
const fade = float(1).sub(t.div(life)).max(0);
|
|
191
|
+
const p = uv().sub(0.5);
|
|
192
|
+
const puff = exp(p.dot(p).mul(-16)).mul(float(1).sub(smoothstep(0.34, 0.5, p.length())));
|
|
193
|
+
const alive = step(age, life);
|
|
194
|
+
material.colorNode = vec4(0.9, 0.94, 1, puff.mul(pow(fade, 1.5)).mul(0.5).mul(alive));
|
|
195
|
+
material.scaleNode = vec2(random(19).mul(0.048).add(0.025).mul(t.div(life).mul(1.9).add(1)));
|
|
196
|
+
const place = (positions: StorageBufferNode<"vec3">): ComputeNode =>
|
|
197
|
+
Fn(() => {
|
|
198
|
+
const angle = random(23).mul(Math.PI * 2);
|
|
199
|
+
const outward = random(29).mul(0.58).add(0.22).mul(kick);
|
|
200
|
+
const rise = random(31).mul(0.85).add(0.4).mul(kick);
|
|
201
|
+
const launch = vec3(cos(angle).mul(0.13), 0.035, sin(angle).mul(0.2));
|
|
202
|
+
const across = vec3(cos(angle).mul(outward).add(wind.mul(0.12)), 0, sin(angle).mul(outward));
|
|
203
|
+
// Air drag slows the spray; gravity brings it back to the snow, where it rests.
|
|
204
|
+
const travelled = float(1)
|
|
205
|
+
.sub(exp(t.mul(-1.8)))
|
|
206
|
+
.div(1.8);
|
|
207
|
+
const height = rise.mul(t).sub(t.mul(t).mul(1.25)).max(0);
|
|
208
|
+
positions
|
|
209
|
+
.element(instanceIndex)
|
|
210
|
+
.assign(launch.add(across.mul(travelled)).add(vec3(0, height, 0)));
|
|
211
|
+
})().compute(BURST_PARTICLES);
|
|
212
|
+
const particles = particlesFor({
|
|
213
|
+
amount: BURST_PARTICLES,
|
|
214
|
+
material,
|
|
215
|
+
process: ({ positions }) => place(positions),
|
|
216
|
+
start: ({ positions }) => place(positions),
|
|
217
|
+
});
|
|
218
|
+
particles.renderOrder = 4;
|
|
219
|
+
particles.visible = false;
|
|
220
|
+
return { age, kick, particles, wind };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function createWeather(options: {
|
|
224
|
+
readonly flakes: number;
|
|
225
|
+
/** Builds a pooled particle system; the scene passes `GPUParticles3D`. */
|
|
226
|
+
readonly particles: (options: IParticleOptions) => ParticleSystem;
|
|
227
|
+
}): ISnowWeather {
|
|
228
|
+
const fall = createSnowfall(options.flakes, options.particles);
|
|
229
|
+
const bursts = Array.from({ length: 8 }, () => createBurst(options.particles));
|
|
230
|
+
let cursor = 0;
|
|
231
|
+
let time = 0;
|
|
232
|
+
let storm = 0;
|
|
233
|
+
let wind = 0.4;
|
|
234
|
+
let drifted = { x: 0, z: 0 };
|
|
235
|
+
let fallen = 0;
|
|
236
|
+
const damp = (a: number, b: number, rate: number, dt: number) =>
|
|
237
|
+
a + (b - a) * (1 - Math.exp(-rate * Math.max(0, dt)));
|
|
238
|
+
return {
|
|
239
|
+
bursts: bursts.map((burst) => burst.particles),
|
|
240
|
+
burst(at, strength) {
|
|
241
|
+
const burst = bursts[cursor % bursts.length];
|
|
242
|
+
cursor += 1;
|
|
243
|
+
if (burst === undefined) return;
|
|
244
|
+
burst.particles.position.set(at.x, at.y, at.z);
|
|
245
|
+
burst.particles.visible = true;
|
|
246
|
+
burst.age.value = 0;
|
|
247
|
+
burst.kick.value = 0.8 + Math.min(1, strength * 4);
|
|
248
|
+
},
|
|
249
|
+
snowfall: fall.particles,
|
|
250
|
+
get storm() {
|
|
251
|
+
return storm;
|
|
252
|
+
},
|
|
253
|
+
update(dt, centre, pixelScale, settings) {
|
|
254
|
+
fall.pixelScale.value = pixelScale;
|
|
255
|
+
time += dt;
|
|
256
|
+
storm = damp(storm, settings.blizzard ? 1 : 0, 0.95, dt);
|
|
257
|
+
const gust = 1 + 0.22 * Math.sin(time * 1.1) + 0.12 * Math.sin(time * 2.73 + 1.6);
|
|
258
|
+
const target = (settings.wind * (1 - storm) + (9.5 + settings.wind * 0.5) * storm) * gust;
|
|
259
|
+
wind = damp(wind, target, 2.3, dt);
|
|
260
|
+
drifted = { x: drifted.x + wind * dt, z: drifted.z + wind * 0.24 * dt };
|
|
261
|
+
fallen += settings.fallSpeed * (0.95 + storm * 0.7) * dt;
|
|
262
|
+
fall.drift.value.set(drifted.x, drifted.z);
|
|
263
|
+
fall.fall.value = fallen;
|
|
264
|
+
fall.swirl.value = time * 0.7;
|
|
265
|
+
fall.centre.value.set(centre.x, centre.z);
|
|
266
|
+
fall.storm.value = storm;
|
|
267
|
+
fall.visible.value = Math.round(options.flakes * settings.snowfall * (0.24 + 0.76 * storm));
|
|
268
|
+
for (const burst of bursts) {
|
|
269
|
+
if (!burst.particles.visible) continue;
|
|
270
|
+
burst.age.value += dt;
|
|
271
|
+
burst.wind.value = wind;
|
|
272
|
+
if (burst.age.value > BURST_LIFETIME) burst.particles.visible = false;
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
get wind() {
|
|
276
|
+
return wind;
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|