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,142 @@
|
|
|
1
|
+
// Generated for you. Ordinary Three.js, and the whole storm ceiling lives in this file.
|
|
2
|
+
//
|
|
3
|
+
// The clouds are not part of the coast's raymarch: the source rendered them into a screen-sized
|
|
4
|
+
// target first and handed that target to the world shader as its sky and its wet reflections, which
|
|
5
|
+
// is what makes the reflections carry the same cloud shapes the sky does. This is that pass. The
|
|
6
|
+
// shader itself is `clouds-shader.ts`, transpiled from `tools/tempest-clouds.frag`; the maths of the
|
|
7
|
+
// volume is there and the only decision here is where the march happens.
|
|
8
|
+
//
|
|
9
|
+
// The pass is a `PassNode` over a scene holding one screen quad, so the engine's own renderer owns
|
|
10
|
+
// the render target, its size and its per-frame update — there is no second render loop here, and
|
|
11
|
+
// nothing about the target is copied out by hand.
|
|
12
|
+
import {
|
|
13
|
+
DoubleSide,
|
|
14
|
+
Mesh,
|
|
15
|
+
OrthographicCamera,
|
|
16
|
+
type PerspectiveCamera,
|
|
17
|
+
PlaneGeometry,
|
|
18
|
+
Scene,
|
|
19
|
+
Vector3,
|
|
20
|
+
} from "three";
|
|
21
|
+
import { positionGeometry, texture3D, uv, vec4 } from "three/tsl";
|
|
22
|
+
import { MeshBasicNodeMaterial, PassNode } from "three/webgpu";
|
|
23
|
+
import type { QualityName, Weather } from "../state.js";
|
|
24
|
+
import {
|
|
25
|
+
setNoise,
|
|
26
|
+
tempestClouds,
|
|
27
|
+
uAspect,
|
|
28
|
+
uCam,
|
|
29
|
+
uCloud,
|
|
30
|
+
uFlash,
|
|
31
|
+
uForward,
|
|
32
|
+
uRight,
|
|
33
|
+
uSteps,
|
|
34
|
+
uStrike,
|
|
35
|
+
uTan,
|
|
36
|
+
uTime,
|
|
37
|
+
uUp,
|
|
38
|
+
uWind,
|
|
39
|
+
} from "./clouds-shader.js";
|
|
40
|
+
import { createNoiseVolume } from "./noise-volume.js";
|
|
41
|
+
import { studyTier } from "./quality.js";
|
|
42
|
+
import { setSky } from "./world-shader.js";
|
|
43
|
+
|
|
44
|
+
export interface ICloudPassOptions {
|
|
45
|
+
readonly camera: PerspectiveCamera;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ICloudPass {
|
|
49
|
+
/** The node the world shader samples for its sky and its reflections. */
|
|
50
|
+
readonly sky: ReturnType<PassNode["getTextureNode"]>;
|
|
51
|
+
/** The cloud target as the renderer last sized it, and the march steps it ran: read, not asked. */
|
|
52
|
+
measured(): { readonly height: number; readonly steps: number; readonly width: number };
|
|
53
|
+
dispose(): void;
|
|
54
|
+
update(options: {
|
|
55
|
+
readonly elapsed: number;
|
|
56
|
+
readonly flash: number;
|
|
57
|
+
readonly quality: QualityName;
|
|
58
|
+
readonly strike: Vector3;
|
|
59
|
+
readonly weather: Weather;
|
|
60
|
+
}): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createCloudPass({ camera }: ICloudPassOptions): ICloudPass {
|
|
64
|
+
const volume = createNoiseVolume();
|
|
65
|
+
setNoise(texture3D(volume.texture));
|
|
66
|
+
|
|
67
|
+
// The source's cloud quad filled the frame from clip-space corners, so the camera on this pass is
|
|
68
|
+
// a formality: the vertex stage writes the corners and nothing reads the projection.
|
|
69
|
+
const cloudScene = new Scene();
|
|
70
|
+
const cloudCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
71
|
+
const geometry = new PlaneGeometry(2, 2);
|
|
72
|
+
const material = new MeshBasicNodeMaterial();
|
|
73
|
+
material.side = DoubleSide;
|
|
74
|
+
material.vertexNode = vec4(positionGeometry.xy, 0, 1);
|
|
75
|
+
material.fragmentNode = tempestClouds(uv());
|
|
76
|
+
const quad = new Mesh(geometry, material);
|
|
77
|
+
// Same as the coast quad: its own bounds are two metres wide at the origin, and the projection it
|
|
78
|
+
// is drawn with has no use for them.
|
|
79
|
+
quad.frustumCulled = false;
|
|
80
|
+
cloudScene.add(quad);
|
|
81
|
+
|
|
82
|
+
const pass = new PassNode(PassNode.COLOR, cloudScene, cloudCamera);
|
|
83
|
+
// The world's shader has to reach the pass through the node graph, not through a copied texture:
|
|
84
|
+
// a pass that is not in the graph the renderer walks is never asked for a frame.
|
|
85
|
+
const sky = pass.getTextureNode();
|
|
86
|
+
setSky(sky);
|
|
87
|
+
|
|
88
|
+
const forward = new Vector3();
|
|
89
|
+
const right = new Vector3();
|
|
90
|
+
const up = new Vector3();
|
|
91
|
+
let steps = 0;
|
|
92
|
+
let scale = 0;
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
sky,
|
|
96
|
+
measured: () => ({
|
|
97
|
+
height: pass.renderTarget.height,
|
|
98
|
+
steps: uSteps.value,
|
|
99
|
+
width: pass.renderTarget.width,
|
|
100
|
+
}),
|
|
101
|
+
dispose(): void {
|
|
102
|
+
pass.dispose();
|
|
103
|
+
geometry.dispose();
|
|
104
|
+
material.dispose();
|
|
105
|
+
volume.texture.dispose();
|
|
106
|
+
},
|
|
107
|
+
update({ elapsed, flash, quality, strike, weather }): void {
|
|
108
|
+
// The same basis the world marches from, and the same field of view, so the clouds and the
|
|
109
|
+
// coast agree on where the horizon is.
|
|
110
|
+
camera.getWorldDirection(forward);
|
|
111
|
+
right.set(1, 0, 0).applyQuaternion(camera.quaternion);
|
|
112
|
+
up.set(0, 1, 0).applyQuaternion(camera.quaternion);
|
|
113
|
+
uCam.value.copy(camera.position);
|
|
114
|
+
uForward.value.copy(forward);
|
|
115
|
+
uRight.value.copy(right);
|
|
116
|
+
uUp.value.copy(up);
|
|
117
|
+
uAspect.value = camera.aspect;
|
|
118
|
+
uTan.value = Math.tan((camera.fov * Math.PI) / 360);
|
|
119
|
+
|
|
120
|
+
uTime.value = elapsed;
|
|
121
|
+
uCloud.value = weather.cloud;
|
|
122
|
+
uWind.value = weather.wind;
|
|
123
|
+
uFlash.value = flash;
|
|
124
|
+
uStrike.value.copy(strike);
|
|
125
|
+
|
|
126
|
+
const tier = studyTier(quality);
|
|
127
|
+
const next = tier.cloudSteps;
|
|
128
|
+
if (next !== steps) {
|
|
129
|
+
steps = next;
|
|
130
|
+
uSteps.value = next;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The pass renders at this share of the frame's resolution: the cloud march is smooth and
|
|
134
|
+
// low-frequency next to the coast it backs, so a lower tier costs it little and buys a lot.
|
|
135
|
+
const nextScale = tier.cloudScale;
|
|
136
|
+
if (nextScale !== scale) {
|
|
137
|
+
scale = nextScale;
|
|
138
|
+
pass.setResolutionScale(nextScale);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Generated for you: these controls and this metric are the game's look. Edit freely.
|
|
2
|
+
import { dot, float, vec2, vec3 } from "three/tsl";
|
|
3
|
+
import type { Node } from "three/webgpu";
|
|
4
|
+
|
|
5
|
+
export interface IExposureSettings {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** Middle-grey target; increase to brighten the metered subject. */
|
|
8
|
+
key: number;
|
|
9
|
+
/** Exposure limits in stops. Expand only if the scene needs more range. */
|
|
10
|
+
minStops: number;
|
|
11
|
+
maxStops: number;
|
|
12
|
+
/**
|
|
13
|
+
* Percent of metered weight, dark to bright, ignored at each end of the histogram.
|
|
14
|
+
* Raise highPercent's gap (lower it) when a large bright backdrop still sets the exposure.
|
|
15
|
+
*/
|
|
16
|
+
lowPercent: number;
|
|
17
|
+
highPercent: number;
|
|
18
|
+
/** Exponential response per second in log2 space. Up opens the eye; down squints. */
|
|
19
|
+
rateUp: number;
|
|
20
|
+
rateDown: number;
|
|
21
|
+
/** Stop error where cut acceleration begins / reaches its authored maximum. */
|
|
22
|
+
snapLo: number;
|
|
23
|
+
snapHi: number;
|
|
24
|
+
snapGain: number;
|
|
25
|
+
/** Seed for known cuts. reset() without a value adopts the next measured target. */
|
|
26
|
+
initialExposure: number;
|
|
27
|
+
settleStops: number;
|
|
28
|
+
/** Limit catch-up after a suspended frame, avoiding an unrequested cut. */
|
|
29
|
+
maxDelta: number;
|
|
30
|
+
/** Readback/marker cadence in seconds. Metering still runs on every drawn frame. */
|
|
31
|
+
reportInterval: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const exposureSettings: Readonly<IExposureSettings> = {
|
|
35
|
+
enabled: false, // Opt in after qualifying this game's bright and dark captures.
|
|
36
|
+
key: 0.18,
|
|
37
|
+
minStops: -12,
|
|
38
|
+
maxStops: 12,
|
|
39
|
+
lowPercent: 10,
|
|
40
|
+
highPercent: 90,
|
|
41
|
+
rateUp: 2,
|
|
42
|
+
rateDown: 4,
|
|
43
|
+
snapLo: 3,
|
|
44
|
+
snapHi: 8,
|
|
45
|
+
snapGain: 1,
|
|
46
|
+
initialExposure: 1,
|
|
47
|
+
settleStops: 0.25,
|
|
48
|
+
maxDelta: 0.1,
|
|
49
|
+
reportInterval: 0.5,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return weighted luminance and weight. The histogram's percent clip, not a clamp here, rejects
|
|
54
|
+
* small bright sources. The upper bound only keeps a half-float overflow from poisoning a block.
|
|
55
|
+
*/
|
|
56
|
+
export function exposureMeter(colour: Node<"vec4">, uv: Node<"vec2">): Node<"vec2"> {
|
|
57
|
+
const luminance = dot(colour.rgb, vec3(0.2126, 0.7152, 0.0722)).clamp(0.0001, 65504);
|
|
58
|
+
// Larger bottom-of-frame preference favours ground over bright sky (WebGPU UV y is down).
|
|
59
|
+
const weight = float(1).add(uv.y);
|
|
60
|
+
return vec2(luminance.mul(weight), weight);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Receives the clipped histogram's linear mean luminance. Change it if the game encodes RMS. */
|
|
64
|
+
export function exposureLuminance(mean: Node<"float">): Node<"float"> {
|
|
65
|
+
return mean.max(0.0001);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function validateExposureSettings(value: IExposureSettings): void {
|
|
69
|
+
for (const key of Object.keys(exposureSettings) as (keyof IExposureSettings)[]) {
|
|
70
|
+
if (key === "enabled") continue;
|
|
71
|
+
const number = value[key];
|
|
72
|
+
if (typeof number !== "number" || !Number.isFinite(Math.fround(number)))
|
|
73
|
+
throw new Error(`Invalid exposure ${key}: expected a finite float32 number.`);
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
typeof value.enabled !== "boolean" ||
|
|
77
|
+
Math.fround(value.key) <= 0 ||
|
|
78
|
+
Math.fround(value.initialExposure) <= 0 ||
|
|
79
|
+
value.rateUp < 0 ||
|
|
80
|
+
value.rateDown < 0 ||
|
|
81
|
+
value.snapLo < 0 ||
|
|
82
|
+
value.snapHi <= value.snapLo ||
|
|
83
|
+
value.snapGain < 0 ||
|
|
84
|
+
value.snapGain > 1 ||
|
|
85
|
+
value.lowPercent < 0 ||
|
|
86
|
+
value.highPercent > 100 ||
|
|
87
|
+
value.lowPercent >= value.highPercent ||
|
|
88
|
+
value.minStops >= value.maxStops ||
|
|
89
|
+
value.minStops < -126 ||
|
|
90
|
+
value.maxStops > 126 ||
|
|
91
|
+
value.settleStops < 0 ||
|
|
92
|
+
value.maxDelta <= 0 ||
|
|
93
|
+
value.reportInterval <= 0
|
|
94
|
+
)
|
|
95
|
+
throw new Error("Invalid exposure settings: check limits, rates and thresholds.");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Resize only the meter. The separate history targets always remain 1x1. */
|
|
99
|
+
export function exposureReductionSizes(width: number, height: number): [number, number][] {
|
|
100
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1)
|
|
101
|
+
throw new Error("Exposure drawing buffer dimensions must be positive integers.");
|
|
102
|
+
const sizes: [number, number][] = [];
|
|
103
|
+
let w = width;
|
|
104
|
+
let h = height;
|
|
105
|
+
do {
|
|
106
|
+
w = Math.ceil(w / 4);
|
|
107
|
+
h = Math.ceil(h / 4);
|
|
108
|
+
sizes.push([w, h]);
|
|
109
|
+
} while (w > 1 || h > 1);
|
|
110
|
+
return sizes;
|
|
111
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Generated for you: GPU reduction and adaptation; exposure.ts owns the game's look.
|
|
2
|
+
import { FloatType, NearestFilter, RenderTarget } from "three";
|
|
3
|
+
import {
|
|
4
|
+
Fn,
|
|
5
|
+
If,
|
|
6
|
+
Loop,
|
|
7
|
+
float,
|
|
8
|
+
int,
|
|
9
|
+
ivec2,
|
|
10
|
+
mix,
|
|
11
|
+
screenCoordinate,
|
|
12
|
+
smoothstep,
|
|
13
|
+
type texture,
|
|
14
|
+
textureLoad,
|
|
15
|
+
vec2,
|
|
16
|
+
vec4,
|
|
17
|
+
} from "three/tsl";
|
|
18
|
+
import type { Node } from "three/webgpu";
|
|
19
|
+
import type { IExposureSettings } from "./exposure.js";
|
|
20
|
+
|
|
21
|
+
export type ColourTexture = ReturnType<typeof texture>;
|
|
22
|
+
export type Meter = (colour: Node<"vec4">, uv: Node<"vec2">) => Node<"vec2">;
|
|
23
|
+
export type Decode = (mean: Node<"float">) => Node<"float">;
|
|
24
|
+
|
|
25
|
+
export function exposureTarget(): RenderTarget {
|
|
26
|
+
return new RenderTarget(1, 1, {
|
|
27
|
+
type: FloatType,
|
|
28
|
+
minFilter: NearestFilter,
|
|
29
|
+
magFilter: NearestFilter,
|
|
30
|
+
depthBuffer: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Sum/16 at each level keeps values bounded. Mask partial blocks; never replicate edge texels. */
|
|
35
|
+
export function reduceExposure(
|
|
36
|
+
input: ColourTexture,
|
|
37
|
+
size: Node<"vec2">,
|
|
38
|
+
meter?: Meter,
|
|
39
|
+
): Node<"vec4"> {
|
|
40
|
+
return Fn(() => {
|
|
41
|
+
const sum = vec2(0).toVar();
|
|
42
|
+
const origin = screenCoordinate.xy.floor().mul(4);
|
|
43
|
+
for (let y = 0; y < 4; y++)
|
|
44
|
+
for (let x = 0; x < 4; x++) {
|
|
45
|
+
const pixel = origin.add(vec2(x, y));
|
|
46
|
+
If(pixel.x.lessThan(size.x).and(pixel.y.lessThan(size.y)), () => {
|
|
47
|
+
const colour = textureLoad(input, ivec2(pixel));
|
|
48
|
+
sum.addAssign(meter === undefined ? colour.rg : meter(colour, pixel.add(0.5).div(size)));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return vec4(sum.div(16), 0, 1);
|
|
52
|
+
})();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The histogram has 64 bins. Each bin spans (maxStops - minStops) / 64 stops of scene luminance. */
|
|
56
|
+
export const exposureBins = 64;
|
|
57
|
+
/** The gather splits the blocks over 64 tiles, so a bin is summed by 64 short loops, not one long. */
|
|
58
|
+
export const exposureTiles = 64;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Stage one of the histogram, drawn as a 64 (bins) x 64 (tiles) target. Texel (bin, tile) gathers
|
|
62
|
+
* its tile of the block means of `blocks` (the second reduction level, about 8 000 texels at
|
|
63
|
+
* 1080p, so about 130 per tile) that fall in its bin.
|
|
64
|
+
* r = summed weight, g = summed weight * log2 luminance, so a bin keeps its exact mean.
|
|
65
|
+
*/
|
|
66
|
+
export function histogramTiles(
|
|
67
|
+
blocks: ColourTexture,
|
|
68
|
+
size: Node<"vec2">,
|
|
69
|
+
policy: Readonly<IExposureSettings>,
|
|
70
|
+
): Node<"vec4"> {
|
|
71
|
+
// Range follows the authored stops: goal = log2(key) - log2(L), clamped to [min, max].
|
|
72
|
+
const low = Math.log2(policy.key) - policy.maxStops;
|
|
73
|
+
const span = policy.maxStops - policy.minStops;
|
|
74
|
+
return Fn(() => {
|
|
75
|
+
const bin = screenCoordinate.x.floor();
|
|
76
|
+
const weight = float(0).toVar();
|
|
77
|
+
const logSum = float(0).toVar();
|
|
78
|
+
const width = int(size.x);
|
|
79
|
+
const total = int(size.x.mul(size.y));
|
|
80
|
+
const perTile = total.add(exposureTiles - 1).div(exposureTiles);
|
|
81
|
+
const first = int(screenCoordinate.y.floor()).mul(perTile);
|
|
82
|
+
Loop({ start: 0, end: perTile }, ({ i: offset }) => {
|
|
83
|
+
const i = first.add(offset);
|
|
84
|
+
If(i.lessThan(total), () => {
|
|
85
|
+
const block = textureLoad(blocks, ivec2(i.mod(width), i.div(width)));
|
|
86
|
+
const log = block.r
|
|
87
|
+
.div(block.g.max(1e-20))
|
|
88
|
+
.max(1e-20)
|
|
89
|
+
.log2()
|
|
90
|
+
.clamp(low, low + span);
|
|
91
|
+
const index = log
|
|
92
|
+
.sub(low)
|
|
93
|
+
.mul(exposureBins / span)
|
|
94
|
+
.floor()
|
|
95
|
+
.min(exposureBins - 1);
|
|
96
|
+
If(block.g.greaterThan(0).and(index.equal(bin)), () => {
|
|
97
|
+
weight.addAssign(block.g);
|
|
98
|
+
logSum.addAssign(block.g.mul(log));
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return vec4(weight, logSum, 0, 1);
|
|
103
|
+
})();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Stage two, drawn as a 64x1 target: one texel per bin, summing that bin over every tile. */
|
|
107
|
+
export function histogramExposure(tiles: ColourTexture): Node<"vec4"> {
|
|
108
|
+
return Fn(() => {
|
|
109
|
+
const bin = int(screenCoordinate.x.floor());
|
|
110
|
+
const sum = vec2(0).toVar();
|
|
111
|
+
Loop(exposureTiles, ({ i }) => {
|
|
112
|
+
sum.addAssign(textureLoad(tiles, ivec2(bin, i)).rg);
|
|
113
|
+
});
|
|
114
|
+
return vec4(sum, 0, 1);
|
|
115
|
+
})();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* UE's average without outliers: drop the darkest lowPercent of the weight, stop at
|
|
120
|
+
* highPercent, take the weighted log2 mean of what is left. Returns (log2 mean, kept weight).
|
|
121
|
+
*/
|
|
122
|
+
function clippedLog2Mean(
|
|
123
|
+
histogram: ColourTexture,
|
|
124
|
+
policy: Readonly<IExposureSettings>,
|
|
125
|
+
): Node<"vec2"> {
|
|
126
|
+
const total = float(0).toVar();
|
|
127
|
+
Loop(exposureBins, ({ i }) => {
|
|
128
|
+
total.addAssign(textureLoad(histogram, ivec2(i, 0)).r);
|
|
129
|
+
});
|
|
130
|
+
const dropLow = total.mul(policy.lowPercent / 100).toVar();
|
|
131
|
+
const keepUpTo = total.mul(policy.highPercent / 100).toVar();
|
|
132
|
+
const kept = float(0).toVar();
|
|
133
|
+
const logSum = float(0).toVar();
|
|
134
|
+
Loop(exposureBins, ({ i }) => {
|
|
135
|
+
const bin = textureLoad(histogram, ivec2(i, 0));
|
|
136
|
+
const removed = bin.r.min(dropLow);
|
|
137
|
+
dropLow.subAssign(removed);
|
|
138
|
+
keepUpTo.subAssign(removed);
|
|
139
|
+
const keep = bin.r.sub(removed).min(keepUpTo);
|
|
140
|
+
keepUpTo.subAssign(keep);
|
|
141
|
+
kept.addAssign(keep);
|
|
142
|
+
logSum.addAssign(bin.g.mul(keep.div(bin.r.max(1e-20))));
|
|
143
|
+
});
|
|
144
|
+
return vec2(logSum.div(kept.max(1e-20)), kept);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function adaptExposure(
|
|
148
|
+
histogram: ColourTexture,
|
|
149
|
+
previous: ColourTexture,
|
|
150
|
+
resetMode: Node<"float">,
|
|
151
|
+
seed: Node<"float">,
|
|
152
|
+
delta: Node<"float">,
|
|
153
|
+
policy: Readonly<IExposureSettings>,
|
|
154
|
+
decode: Decode,
|
|
155
|
+
): Node<"vec4"> {
|
|
156
|
+
return Fn(() => {
|
|
157
|
+
const measure = clippedLog2Mean(histogram, policy);
|
|
158
|
+
const luminance = decode(measure.x.exp2());
|
|
159
|
+
const valid = measure.y
|
|
160
|
+
.greaterThan(0)
|
|
161
|
+
.and(luminance.greaterThan(0))
|
|
162
|
+
.and(luminance.lessThan(3.4e38));
|
|
163
|
+
const goal = float(Math.log2(policy.key))
|
|
164
|
+
.sub(luminance.max(1e-20).log2())
|
|
165
|
+
.clamp(policy.minStops, policy.maxStops);
|
|
166
|
+
const old = resetMode.equal(1).select(seed, textureLoad(previous, ivec2(0)).r);
|
|
167
|
+
const error = goal.sub(old);
|
|
168
|
+
const rate = error.greaterThan(0).select(float(policy.rateUp), float(policy.rateDown));
|
|
169
|
+
const normal = float(1).sub(delta.mul(rate).negate().exp());
|
|
170
|
+
const cut = smoothstep(policy.snapLo, policy.snapHi, error.abs()).mul(policy.snapGain);
|
|
171
|
+
const adapted = valid.select(
|
|
172
|
+
resetMode.equal(2).select(goal, mix(old, goal, mix(normal, float(1), cut))),
|
|
173
|
+
old,
|
|
174
|
+
);
|
|
175
|
+
const settled = goal.sub(adapted).abs().lessThanEqual(policy.settleStops).select(1, 0);
|
|
176
|
+
return vec4(adapted, valid.select(luminance, -1), goal, settled);
|
|
177
|
+
})();
|
|
178
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Generated for you: async GPU observations stay tied to their owner's live generation.
|
|
2
|
+
import type { RenderTarget } from "three";
|
|
3
|
+
import type { Renderer } from "three/webgpu";
|
|
4
|
+
|
|
5
|
+
export class ExposureReadback {
|
|
6
|
+
#pending = false;
|
|
7
|
+
#generation = 0;
|
|
8
|
+
#lastReport = Number.NEGATIVE_INFINITY;
|
|
9
|
+
#disposed = false;
|
|
10
|
+
#value: Record<string, unknown>;
|
|
11
|
+
constructor(
|
|
12
|
+
readonly constant: number,
|
|
13
|
+
readonly enabled: () => boolean,
|
|
14
|
+
) {
|
|
15
|
+
this.#value = { measured: false, applied: enabled() };
|
|
16
|
+
}
|
|
17
|
+
invalidate(): void {
|
|
18
|
+
this.#generation++;
|
|
19
|
+
this.#value = { measured: false, applied: this.enabled() };
|
|
20
|
+
this.#lastReport = Number.NEGATIVE_INFINITY;
|
|
21
|
+
}
|
|
22
|
+
get(): Record<string, unknown> {
|
|
23
|
+
return { ...this.#value };
|
|
24
|
+
}
|
|
25
|
+
dispose(): void {
|
|
26
|
+
this.#disposed = true;
|
|
27
|
+
this.#generation++;
|
|
28
|
+
}
|
|
29
|
+
report(renderer: Renderer, result: RenderTarget, time: number, interval: number): void {
|
|
30
|
+
if (this.#pending || time - this.#lastReport < interval) return;
|
|
31
|
+
this.#pending = true;
|
|
32
|
+
this.#lastReport = time;
|
|
33
|
+
const generation = this.#generation;
|
|
34
|
+
const current = () => !this.#disposed && generation === this.#generation;
|
|
35
|
+
const enabled = this.enabled;
|
|
36
|
+
const constant = this.constant;
|
|
37
|
+
const publish = (observation: Record<string, unknown>) => {
|
|
38
|
+
this.#value = observation;
|
|
39
|
+
};
|
|
40
|
+
const finished = () => {
|
|
41
|
+
this.#pending = false;
|
|
42
|
+
};
|
|
43
|
+
void renderer
|
|
44
|
+
.readRenderTargetPixelsAsync(result, 0, 0, 1, 1)
|
|
45
|
+
.then((values) => {
|
|
46
|
+
if (!current()) return;
|
|
47
|
+
if (
|
|
48
|
+
!(values instanceof Float32Array) ||
|
|
49
|
+
values.length < 4 ||
|
|
50
|
+
!Array.from(values).every(Number.isFinite) ||
|
|
51
|
+
(values[1] ?? 0) <= 0
|
|
52
|
+
)
|
|
53
|
+
throw new Error("Exposure readback is invalid; measurement is unavailable.");
|
|
54
|
+
const observation = {
|
|
55
|
+
measured: true,
|
|
56
|
+
applied: enabled(),
|
|
57
|
+
luminance: values[1],
|
|
58
|
+
exposureStops: enabled() ? values[0] : Math.log2(constant),
|
|
59
|
+
targetStops: values[2],
|
|
60
|
+
settled: values[3] === 1,
|
|
61
|
+
};
|
|
62
|
+
publish(observation);
|
|
63
|
+
console.info(`TN_AUTO_EXPOSURE:${JSON.stringify(observation)}`);
|
|
64
|
+
})
|
|
65
|
+
.catch((error: unknown) => {
|
|
66
|
+
if (!current()) return;
|
|
67
|
+
const observation = {
|
|
68
|
+
measured: false,
|
|
69
|
+
applied: enabled(),
|
|
70
|
+
reason: String(error),
|
|
71
|
+
};
|
|
72
|
+
publish(observation);
|
|
73
|
+
console.error(`TN_AUTO_EXPOSURE:${JSON.stringify(observation)}`);
|
|
74
|
+
})
|
|
75
|
+
.finally(() => {
|
|
76
|
+
finished();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js; tune the storm's light here.
|
|
2
|
+
//
|
|
3
|
+
// The coast is ray-marched, so nothing here is added to the scene: these are Three's own light
|
|
4
|
+
// objects used as the place the storm's lighting is decided, and `setupLighting` hands their
|
|
5
|
+
// direction and colour × intensity to the two shaders. No shadow map is involved — the march
|
|
6
|
+
// computes its own occlusion — so there is nothing to tune for one.
|
|
7
|
+
import { Color, DirectionalLight, HemisphereLight, LinearSRGBColorSpace } from "three";
|
|
8
|
+
import * as clouds from "./clouds-shader.js";
|
|
9
|
+
import * as world from "./world-shader.js";
|
|
10
|
+
|
|
11
|
+
/** The study's colours are linear RGB; these keep them exact instead of converting from sRGB. */
|
|
12
|
+
const linear = (r: number, g: number, b: number): Color =>
|
|
13
|
+
new Color().setRGB(r, g, b, LinearSRGBColorSpace);
|
|
14
|
+
|
|
15
|
+
export interface IStormLighting {
|
|
16
|
+
/** The low storm sun behind the deck: its direction lights the clouds and the coast. */
|
|
17
|
+
readonly key: DirectionalLight;
|
|
18
|
+
/** The lightning's own light. Its intensity is scaled by the flash every frame in the shader. */
|
|
19
|
+
readonly rim: DirectionalLight;
|
|
20
|
+
/** The overcast sky light; the shader weights it `0.45 + 0.55 · n.y`, like a hemisphere. */
|
|
21
|
+
readonly fill: HemisphereLight;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setupLighting(): IStormLighting {
|
|
25
|
+
const key = new DirectionalLight(linear(0.56, 0.61, 0.67), 0.35);
|
|
26
|
+
key.position.set(-0.62, 0.34, -0.71).normalize();
|
|
27
|
+
const rim = new DirectionalLight(linear(0.8 / 1.4, 1.04 / 1.4, 1), 1.4);
|
|
28
|
+
const fill = new HemisphereLight(linear(0.64, 0.86, 1.03), linear(0.29, 0.39, 0.46), 0.65);
|
|
29
|
+
|
|
30
|
+
world.uSunDir.value.copy(key.position);
|
|
31
|
+
clouds.uSunDir.value.copy(key.position);
|
|
32
|
+
const sun = key.color.clone().multiplyScalar(key.intensity);
|
|
33
|
+
world.uSunColor.value.set(sun.r, sun.g, sun.b);
|
|
34
|
+
const flash = rim.color.clone().multiplyScalar(rim.intensity);
|
|
35
|
+
world.uFlashLight.value.set(flash.r, flash.g, flash.b);
|
|
36
|
+
const sky = fill.color.clone().multiplyScalar(fill.intensity);
|
|
37
|
+
world.uFill.value.set(sky.r, sky.g, sky.b);
|
|
38
|
+
return { fill, key, rim };
|
|
39
|
+
}
|