create-threenative 0.2.8 → 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/agent-docs/references/assertion-reference.md +87 -35
- package/agent-docs/references/auto-exposure.md +57 -0
- package/agent-docs/references/capability-reference.md +1097 -23
- 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 +1210 -27
- package/dist/index.d.ts +28 -3
- package/dist/index.js +396 -166
- package/dist/threenative.js +986 -235
- 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/AGENTS.md +8 -9
- package/templates/rain/CLAUDE.md +8 -9
- package/templates/rain/native-playtests/boot.playtest.json +11 -1
- package/templates/rain/package.json +12 -9
- package/templates/rain/playtests/automation.playtest.json +1 -1
- package/templates/rain/playtests/performance.playtest.json +11 -1
- package/templates/rain/playtests/tiers.playtest.json +15 -0
- package/templates/rain/playtests/weather.playtest.json +1 -1
- package/templates/rain/src/game.ts +1 -34
- package/templates/rain/src/render/autoExposure.ts +225 -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/postprocessing.ts +3 -0
- package/templates/rain/src/render/quality.ts +27 -1
- package/templates/rain/src/render/worldEnvironment.ts +433 -30
- package/templates/rain/src/scenes/Boot.ts +14 -0
- package/templates/rain/src/state.ts +5 -1
- package/templates/rain/src/ui/GameUi.tsx +6 -6
- package/templates/rain/tools/generate-shaders.mjs +1 -1
- package/templates/rain/vite.config.ts +10 -2
- 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/AGENTS.md +8 -6
- package/templates/snow/CLAUDE.md +8 -6
- package/templates/snow/package.json +11 -9
- 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/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/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 +33 -1
- package/templates/snow/src/render/materialAssignments.ts +160 -0
- package/templates/snow/src/render/materialLighting.ts +155 -0
- package/templates/snow/src/render/postprocessing.ts +16 -2
- package/templates/snow/src/render/quality.ts +59 -1
- package/templates/snow/src/render/sky.ts +21 -2
- package/templates/snow/src/render/worldEnvironment.ts +433 -30
- package/templates/snow/src/scenes/Snow.ts +29 -1
- package/templates/snow/threenative.config.ts +3 -0
- package/templates/snow/vite.config.ts +10 -2
- 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,155 @@
|
|
|
1
|
+
// Generated for you. Scene-owned material assignments; no engine appearance hooks.
|
|
2
|
+
import {
|
|
3
|
+
type Camera,
|
|
4
|
+
type DirectionalLight,
|
|
5
|
+
Material,
|
|
6
|
+
Mesh,
|
|
7
|
+
MeshStandardMaterial,
|
|
8
|
+
type Object3D,
|
|
9
|
+
type Scene,
|
|
10
|
+
type Texture,
|
|
11
|
+
} from "three";
|
|
12
|
+
import { type IBacklightControls, backlightMaterial } from "./backlightMaterial.js";
|
|
13
|
+
import {
|
|
14
|
+
type IEnvironmentMeasurement,
|
|
15
|
+
measureEnvironment,
|
|
16
|
+
reportEnvironmentContribution,
|
|
17
|
+
} from "./environmentContribution.js";
|
|
18
|
+
import {
|
|
19
|
+
type IEnvironmentSourceSnapshot,
|
|
20
|
+
captureEnvironmentSnapshot,
|
|
21
|
+
environmentSnapshotCurrent,
|
|
22
|
+
} from "./environmentSnapshot.js";
|
|
23
|
+
import { type ILightingConvention, createLightingConvention } from "./lighting.js";
|
|
24
|
+
import { createMaterialAssignments } from "./materialAssignments.js";
|
|
25
|
+
import { type IMaterialLightingEnvironment, materialLightingEnabled } from "./quality.js";
|
|
26
|
+
interface IMaterialLightingOptions extends IMaterialLightingEnvironment {
|
|
27
|
+
readonly enabled: boolean;
|
|
28
|
+
readonly overrides?: Partial<ILightingConvention>;
|
|
29
|
+
}
|
|
30
|
+
/** Call once AFTER the scene's loaded character, arena and props are attached. */
|
|
31
|
+
export function createMaterialLighting(
|
|
32
|
+
scene: Scene,
|
|
33
|
+
camera: Camera,
|
|
34
|
+
key: DirectionalLight,
|
|
35
|
+
options: IMaterialLightingOptions,
|
|
36
|
+
) {
|
|
37
|
+
const settings = createLightingConvention(options.overrides);
|
|
38
|
+
let enabled = false;
|
|
39
|
+
let disposed = false;
|
|
40
|
+
let fillApproved = false;
|
|
41
|
+
let measured = measureEnvironment(scene, settings.maxSourceTexels);
|
|
42
|
+
let measurementSnapshot = captureEnvironmentSnapshot(scene);
|
|
43
|
+
const controls: IBacklightControls = {
|
|
44
|
+
key,
|
|
45
|
+
scene,
|
|
46
|
+
camera,
|
|
47
|
+
get rimGain() {
|
|
48
|
+
return settings.rimGain;
|
|
49
|
+
},
|
|
50
|
+
set rimGain(value) {
|
|
51
|
+
settings.rimGain = value;
|
|
52
|
+
},
|
|
53
|
+
get fillGain() {
|
|
54
|
+
return settings.fillGain;
|
|
55
|
+
},
|
|
56
|
+
set fillGain(value) {
|
|
57
|
+
settings.fillGain = value;
|
|
58
|
+
},
|
|
59
|
+
fillColor: settings.fillColor,
|
|
60
|
+
fillDirection: settings.fillDirection,
|
|
61
|
+
get fillAngularSize() {
|
|
62
|
+
return settings.fillAngularSize;
|
|
63
|
+
},
|
|
64
|
+
set fillAngularSize(value) {
|
|
65
|
+
settings.fillAngularSize = value;
|
|
66
|
+
},
|
|
67
|
+
get fillAdmitted() {
|
|
68
|
+
return enabled && fillApproved && environmentSnapshotCurrent(scene, measurementSnapshot);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const assignments = createMaterialAssignments(scene, controls);
|
|
72
|
+
function report() {
|
|
73
|
+
if (!environmentSnapshotCurrent(scene, measurementSnapshot)) {
|
|
74
|
+
measured = measureEnvironment(scene, settings.maxSourceTexels);
|
|
75
|
+
measurementSnapshot = captureEnvironmentSnapshot(scene);
|
|
76
|
+
}
|
|
77
|
+
fillApproved =
|
|
78
|
+
measured.status === "measured" &&
|
|
79
|
+
measured.meanRadiance !== null &&
|
|
80
|
+
measured.meanRadiance <= settings.darkThreshold;
|
|
81
|
+
return reportEnvironmentContribution(
|
|
82
|
+
scene,
|
|
83
|
+
{
|
|
84
|
+
...settings,
|
|
85
|
+
rimGain: controls.rimGain,
|
|
86
|
+
fillGain: controls.fillGain,
|
|
87
|
+
fillColor: controls.fillColor,
|
|
88
|
+
fillAdmitted: controls.fillAdmitted,
|
|
89
|
+
},
|
|
90
|
+
measured,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
let observation: ReturnType<typeof report>;
|
|
94
|
+
function setEnabled(requested: boolean): void {
|
|
95
|
+
if (disposed) return;
|
|
96
|
+
enabled = requested && materialLightingEnabled("high", options);
|
|
97
|
+
assignments.setEnabled(enabled);
|
|
98
|
+
observation = report();
|
|
99
|
+
}
|
|
100
|
+
setEnabled(options.enabled);
|
|
101
|
+
return {
|
|
102
|
+
controls,
|
|
103
|
+
setEnabled,
|
|
104
|
+
/** Enroll a newly attached game-owned subtree. */
|
|
105
|
+
enroll(root: Object3D): void {
|
|
106
|
+
if (!disposed) assignments.enroll(root);
|
|
107
|
+
},
|
|
108
|
+
/** Restore assignments before removing a subtree or disposing borrowed materials. */
|
|
109
|
+
release(root: Object3D): void {
|
|
110
|
+
if (!disposed) assignments.release(root);
|
|
111
|
+
},
|
|
112
|
+
report() {
|
|
113
|
+
observation = report();
|
|
114
|
+
return observation;
|
|
115
|
+
},
|
|
116
|
+
/** Root's later GPU sampler can provide a measured snapshot of the current environment. */
|
|
117
|
+
setEnvironmentMeasurement(
|
|
118
|
+
measurement: IEnvironmentMeasurement,
|
|
119
|
+
source: Texture | null = scene.environment,
|
|
120
|
+
intensity = scene.environmentIntensity,
|
|
121
|
+
snapshot: IEnvironmentSourceSnapshot = captureEnvironmentSnapshot(scene),
|
|
122
|
+
): void {
|
|
123
|
+
if (disposed) return;
|
|
124
|
+
if (
|
|
125
|
+
measurement.status === "measured" &&
|
|
126
|
+
(measurement.meanRadiance === null ||
|
|
127
|
+
!Number.isFinite(measurement.meanRadiance) ||
|
|
128
|
+
measurement.meanRadiance < 0 ||
|
|
129
|
+
measurement.meanRGB === null ||
|
|
130
|
+
!measurement.meanRGB.every((value) => Number.isFinite(value) && value >= 0))
|
|
131
|
+
)
|
|
132
|
+
throw new Error("Measured environment radiance must be finite and nonnegative.");
|
|
133
|
+
if (
|
|
134
|
+
source !== snapshot.source ||
|
|
135
|
+
intensity !== snapshot.intensity ||
|
|
136
|
+
!environmentSnapshotCurrent(scene, snapshot)
|
|
137
|
+
)
|
|
138
|
+
return;
|
|
139
|
+
measured = measurement;
|
|
140
|
+
measurementSnapshot = snapshot;
|
|
141
|
+
observation = report();
|
|
142
|
+
},
|
|
143
|
+
debug: () => ({
|
|
144
|
+
...observation,
|
|
145
|
+
enabled,
|
|
146
|
+
...assignments.debug(),
|
|
147
|
+
}),
|
|
148
|
+
dispose(): void {
|
|
149
|
+
if (disposed) return;
|
|
150
|
+
enabled = false;
|
|
151
|
+
disposed = true;
|
|
152
|
+
assignments.dispose();
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -24,12 +24,17 @@ export function setupPost(
|
|
|
24
24
|
mobile?: boolean;
|
|
25
25
|
/** The renderer named a software adapter; this game's answer is its `low` tier. */
|
|
26
26
|
software?: boolean;
|
|
27
|
+
/** The renderer's GPU family (`ctx.renderer.gpuClass?.class`); `quality.ts` maps it to a start tier. */
|
|
28
|
+
gpuClass?: string;
|
|
27
29
|
/** Forces a tier, ignoring `mobile`. An unknown name throws rather than falling back. */
|
|
28
30
|
tier?: QualityTier;
|
|
31
|
+
/** Scene-owned material assignments follow the resolved tier. */
|
|
32
|
+
onTierChanged?: (tier: QualityTier) => void;
|
|
29
33
|
} = {},
|
|
30
|
-
): void {
|
|
34
|
+
): { readonly tier: QualityTier; dispose(): void } {
|
|
31
35
|
const tier = resolveQualityTier({
|
|
32
36
|
mobile: environment.mobile,
|
|
37
|
+
gpuClass: environment.gpuClass,
|
|
33
38
|
software: environment.software,
|
|
34
39
|
tier: environment.tier,
|
|
35
40
|
});
|
|
@@ -40,5 +45,15 @@ export function setupPost(
|
|
|
40
45
|
} source=${source}`,
|
|
41
46
|
);
|
|
42
47
|
const world = new WorldEnvironment(qualityPreset(tier));
|
|
43
|
-
world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
|
|
48
|
+
const applied = world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
|
|
49
|
+
environment.onTierChanged?.(tier);
|
|
50
|
+
let disposed = false;
|
|
51
|
+
return {
|
|
52
|
+
tier,
|
|
53
|
+
dispose(): void {
|
|
54
|
+
if (disposed) return;
|
|
55
|
+
disposed = true;
|
|
56
|
+
applied.dispose?.();
|
|
57
|
+
},
|
|
58
|
+
};
|
|
44
59
|
}
|
|
@@ -46,6 +46,23 @@ function isQualityTier(value: string): value is QualityTier {
|
|
|
46
46
|
return (QUALITY_TIERS as readonly string[]).includes(value);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Where each GPU family starts, from `ctx.renderer.gpuClass`.
|
|
51
|
+
*
|
|
52
|
+
* A start, not a ceiling: the measured frame-budget windows move the look from here, and an
|
|
53
|
+
* explicit `tier` above still wins. A class absent from this table — `unknown`, an adapter no
|
|
54
|
+
* family rule matched — falls back to the `mobile` flag, exactly as before families existed.
|
|
55
|
+
* Edit the right-hand side to change what a family looks like; nothing outside this file reads it.
|
|
56
|
+
*/
|
|
57
|
+
const START_TIER_BY_GPU_CLASS: Readonly<Record<string, QualityTier | undefined>> = {
|
|
58
|
+
software: "low",
|
|
59
|
+
"mobile-low": "low",
|
|
60
|
+
"mobile-mid": "low",
|
|
61
|
+
"mobile-high": "medium",
|
|
62
|
+
integrated: "medium",
|
|
63
|
+
discrete: "high",
|
|
64
|
+
};
|
|
65
|
+
|
|
49
66
|
/**
|
|
50
67
|
* Picks the tier: an explicit `tier` always wins, otherwise the platform decides.
|
|
51
68
|
*
|
|
@@ -54,7 +71,12 @@ function isQualityTier(value: string): value is QualityTier {
|
|
|
54
71
|
* turned out to have no effect.
|
|
55
72
|
*/
|
|
56
73
|
export function resolveQualityTier(
|
|
57
|
-
request: {
|
|
74
|
+
request: {
|
|
75
|
+
readonly gpuClass?: string;
|
|
76
|
+
readonly mobile?: boolean;
|
|
77
|
+
readonly software?: boolean;
|
|
78
|
+
readonly tier?: string;
|
|
79
|
+
} = {},
|
|
58
80
|
): QualityTier {
|
|
59
81
|
const requested = request.tier;
|
|
60
82
|
if (requested !== undefined) {
|
|
@@ -71,6 +93,9 @@ export function resolveQualityTier(
|
|
|
71
93
|
// fact the renderer read from `adapter.info`, not a guess from a driver string, and an explicit
|
|
72
94
|
// `tier` above still wins over it.
|
|
73
95
|
if (request.software === true) return "low";
|
|
96
|
+
const family =
|
|
97
|
+
request.gpuClass === undefined ? undefined : START_TIER_BY_GPU_CLASS[request.gpuClass];
|
|
98
|
+
if (family !== undefined) return family;
|
|
74
99
|
return request.mobile === true ? "low" : "high";
|
|
75
100
|
}
|
|
76
101
|
|
|
@@ -90,6 +115,7 @@ const shared: IWorldEnvironmentOptions = {
|
|
|
90
115
|
bloomRadius: 0.6,
|
|
91
116
|
bloomStrength: 0.22,
|
|
92
117
|
bloomThreshold: 1,
|
|
118
|
+
autoExposureEnabled: false,
|
|
93
119
|
exposure: 0.62,
|
|
94
120
|
tonemapMode: "aces",
|
|
95
121
|
vignetteAmount: 0.22,
|
|
@@ -109,7 +135,7 @@ const high: IWorldEnvironmentOptions = {
|
|
|
109
135
|
};
|
|
110
136
|
|
|
111
137
|
/** The rung in between: the same occlusion at half the directions. Saving unmeasured. */
|
|
112
|
-
const medium: IWorldEnvironmentOptions = { ...high, gtaoSamples: 8 };
|
|
138
|
+
const medium: IWorldEnvironmentOptions = { ...high, gtaoSamples: 8, renderChainTier: "medium" };
|
|
113
139
|
|
|
114
140
|
/** What a phone gets: bloom, vignette and the tone curve, nothing screen-space. */
|
|
115
141
|
const low: IWorldEnvironmentOptions = { ...shared, renderChainTier: "low" };
|
|
@@ -126,3 +152,36 @@ export function qualityPreset(tier: string): IWorldEnvironmentOptions {
|
|
|
126
152
|
}
|
|
127
153
|
return preset;
|
|
128
154
|
}
|
|
155
|
+
|
|
156
|
+
/** First admitted material lane: high desktop hardware WebGPU in the browser only. */
|
|
157
|
+
export interface IMaterialLightingEnvironment {
|
|
158
|
+
readonly web: boolean;
|
|
159
|
+
readonly rendererKind: string;
|
|
160
|
+
readonly mobile?: boolean;
|
|
161
|
+
readonly software?: boolean;
|
|
162
|
+
readonly webglFallback?: boolean;
|
|
163
|
+
}
|
|
164
|
+
export function materialLightingEnabled(
|
|
165
|
+
tier: QualityTier,
|
|
166
|
+
environment: IMaterialLightingEnvironment,
|
|
167
|
+
): boolean {
|
|
168
|
+
return (
|
|
169
|
+
tier === "high" &&
|
|
170
|
+
environment.web &&
|
|
171
|
+
environment.rendererKind === "webgpu" &&
|
|
172
|
+
environment.mobile !== true &&
|
|
173
|
+
environment.software !== true &&
|
|
174
|
+
environment.webglFallback !== true
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A WebGPURenderer wrapper may run an ordinary WebGL fallback backend. */
|
|
179
|
+
export function isWebGLFallbackRenderer(renderer: unknown): boolean {
|
|
180
|
+
if (renderer === null || typeof renderer !== "object") return false;
|
|
181
|
+
const backend = Reflect.get(renderer, "backend");
|
|
182
|
+
return (
|
|
183
|
+
backend !== null &&
|
|
184
|
+
typeof backend === "object" &&
|
|
185
|
+
Reflect.get(backend, "isWebGLBackend") === true
|
|
186
|
+
);
|
|
187
|
+
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type Texture,
|
|
14
14
|
Vector3,
|
|
15
15
|
} from "three";
|
|
16
|
+
import { HEIGHT_FOG, type HeightFogParams, heightFogDepth, heightFogNode } from "./heightFog.js";
|
|
16
17
|
import { palette } from "./palette.js";
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -25,6 +26,22 @@ const SKY_RANGE = 2.5;
|
|
|
25
26
|
/** Unit vector toward the photographed sun: 47.9° up, measured from the source HDR. */
|
|
26
27
|
export const SUN_DIRECTION = new Vector3(0.555, 0.742, 0.38).normalize();
|
|
27
28
|
|
|
29
|
+
/** The look this fog replaced: FogExp2 at 0.003, measured at 150 m from 2 m up. */
|
|
30
|
+
const EYE_LEVEL = { density: 0.003, distance: 150, cameraHeight: 2 };
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The distance term's density that, with the height term, keeps the old eye-level haze: at
|
|
34
|
+
* `EYE_LEVEL.distance` along the horizon from `EYE_LEVEL.cameraHeight` the two together transmit what
|
|
35
|
+
* FogExp2 at `EYE_LEVEL.density` did. The distance term is lowered, never removed, so the ground
|
|
36
|
+
* still ends in fog at a kilometre.
|
|
37
|
+
*/
|
|
38
|
+
function distanceDensity(p: HeightFogParams = HEIGHT_FOG): number {
|
|
39
|
+
const { distance, density, cameraHeight } = EYE_LEVEL;
|
|
40
|
+
const old = (density * distance) ** 2;
|
|
41
|
+
const height = heightFogDepth(p, cameraHeight, cameraHeight, distance) * Math.LN2;
|
|
42
|
+
return Math.sqrt(Math.max(0, old - height)) / distance;
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
export function setupSky(scene: Scene, sky: Texture): void {
|
|
29
46
|
sky.mapping = EquirectangularReflectionMapping;
|
|
30
47
|
sky.colorSpace = SRGBColorSpace;
|
|
@@ -37,5 +54,8 @@ export function setupSky(scene: Scene, sky: Texture): void {
|
|
|
37
54
|
scene.environmentIntensity = SKY_RANGE;
|
|
38
55
|
// Almost nothing inside the arena (1.4% at 30 m), and the ground plane gone into the horizon by
|
|
39
56
|
// a kilometre — so the floor meets the sky instead of ending at a line.
|
|
40
|
-
scene.fog
|
|
57
|
+
// `scene.fog` stays the distance term; `scene.fogNode` is what three applies and adds the height term.
|
|
58
|
+
const distanceFog = new FogExp2(palette.horizon, distanceDensity());
|
|
59
|
+
scene.fog = distanceFog;
|
|
60
|
+
scene.fogNode = heightFogNode(distanceFog, HEIGHT_FOG, SUN_DIRECTION);
|
|
41
61
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Fn,
|
|
3
|
+
If,
|
|
3
4
|
abs,
|
|
4
5
|
atan,
|
|
5
6
|
cos,
|
|
6
7
|
cross,
|
|
7
8
|
exp,
|
|
8
9
|
float,
|
|
9
|
-
fract,
|
|
10
10
|
hash,
|
|
11
11
|
instanceIndex,
|
|
12
12
|
mix,
|
|
13
13
|
normalize,
|
|
14
14
|
sin,
|
|
15
15
|
smoothstep,
|
|
16
|
+
step,
|
|
16
17
|
time,
|
|
18
|
+
uint,
|
|
17
19
|
uv,
|
|
18
20
|
varying,
|
|
19
21
|
vec2,
|
|
@@ -22,24 +24,48 @@ import {
|
|
|
22
24
|
} from "three/tsl";
|
|
23
25
|
import {
|
|
24
26
|
type ComputeNode,
|
|
27
|
+
type Node,
|
|
25
28
|
SpriteNodeMaterial as SpriteMaterial,
|
|
26
29
|
type SpriteNodeMaterial,
|
|
27
30
|
type StorageBufferNode,
|
|
31
|
+
type UniformNode,
|
|
28
32
|
} from "three/webgpu";
|
|
29
33
|
import * as THREE from "three/webgpu";
|
|
30
34
|
|
|
35
|
+
/** `positions` hold world positions; `velocities` hold each particle's burst origin. */
|
|
31
36
|
export interface IActionRpgVfxBuffers {
|
|
32
37
|
readonly positions: StorageBufferNode<"vec3">;
|
|
33
38
|
readonly velocities: StorageBufferNode<"vec3">;
|
|
39
|
+
readonly births: StorageBufferNode<"float">;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IActionRpgVfxSpawnRequest {
|
|
43
|
+
readonly first: UniformNode<"uint", number>;
|
|
44
|
+
readonly count: UniformNode<"uint", number>;
|
|
45
|
+
readonly origin: UniformNode<"vec3", THREE.Vector3>;
|
|
34
46
|
}
|
|
35
47
|
|
|
36
48
|
export interface IActionRpgVfxOptions {
|
|
49
|
+
/** Ring capacity: room for `RING_BURSTS` overlapping bursts. Emit `burstCount` per hit. */
|
|
37
50
|
readonly amount: number;
|
|
51
|
+
readonly burstCount: number;
|
|
52
|
+
/** Longest particle life in seconds, so the engine can report slots recycled while alive. */
|
|
53
|
+
readonly lifetime: number;
|
|
38
54
|
readonly material: SpriteNodeMaterial;
|
|
39
|
-
readonly
|
|
40
|
-
|
|
55
|
+
readonly spawn: (
|
|
56
|
+
buffers: IActionRpgVfxBuffers,
|
|
57
|
+
request: IActionRpgVfxSpawnRequest,
|
|
58
|
+
) => ComputeNode;
|
|
59
|
+
readonly process: (
|
|
60
|
+
buffers: IActionRpgVfxBuffers,
|
|
61
|
+
runtime: { readonly time: Node<"float"> },
|
|
62
|
+
) => ComputeNode;
|
|
63
|
+
readonly onCull?: "pause" | "clear";
|
|
41
64
|
}
|
|
42
65
|
|
|
66
|
+
/** The ring holds this many overlapping bursts before a new one takes the oldest slots. */
|
|
67
|
+
const RING_BURSTS = 4;
|
|
68
|
+
|
|
43
69
|
type DonorRecipe = {
|
|
44
70
|
readonly amount: number;
|
|
45
71
|
readonly lifetime: readonly [number, number];
|
|
@@ -61,44 +87,64 @@ type DonorRecipe = {
|
|
|
61
87
|
|
|
62
88
|
const TAU = Math.PI * 2;
|
|
63
89
|
|
|
64
|
-
|
|
65
|
-
|
|
90
|
+
/** Each burst reads its own random stream: the key is the engine's birth stamp of the slot. */
|
|
91
|
+
function burstKey(born: Node<"float">) {
|
|
92
|
+
return born.max(0).mul(1000).toUint();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type Key = ReturnType<typeof burstKey>;
|
|
96
|
+
|
|
97
|
+
function random(seed: number, salt: number, key: Key) {
|
|
98
|
+
return hash(instanceIndex.add(seed + salt).add(key));
|
|
66
99
|
}
|
|
67
100
|
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
random(seed, 13).mul(recipe.lifetime[1] - recipe.lifetime[0]),
|
|
101
|
+
function lifetimeOf(recipe: DonorRecipe, seed: number, key: Key) {
|
|
102
|
+
return float(recipe.lifetime[0]).add(
|
|
103
|
+
random(seed, 13, key).mul(recipe.lifetime[1] - recipe.lifetime[0]),
|
|
71
104
|
);
|
|
72
|
-
return fract(time.div(lifetime).add(random(seed, 19)));
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
function spawnPosition(recipe: DonorRecipe, seed: number) {
|
|
107
|
+
function spawnPosition(recipe: DonorRecipe, seed: number, key: Key) {
|
|
76
108
|
const lineStart = recipe.lineStart ?? [0, 0, 0];
|
|
77
109
|
const lineEnd = recipe.lineEnd ?? [0, 0, 0];
|
|
78
|
-
const along = random(seed, 3);
|
|
110
|
+
const along = random(seed, 3, key);
|
|
79
111
|
if (recipe.shape === "line") {
|
|
80
112
|
return vec3(...lineStart)
|
|
81
113
|
.mul(float(1).sub(along))
|
|
82
114
|
.add(vec3(...lineEnd).mul(along));
|
|
83
115
|
}
|
|
84
|
-
const angle = random(seed, 7).mul(TAU);
|
|
85
|
-
const radius = random(seed, 11).sqrt().mul(recipe.radius);
|
|
116
|
+
const angle = random(seed, 7, key).mul(TAU);
|
|
117
|
+
const radius = random(seed, 11, key).sqrt().mul(recipe.radius);
|
|
86
118
|
return vec3(
|
|
87
119
|
cos(angle).mul(radius),
|
|
88
120
|
sin(angle).mul(radius),
|
|
89
|
-
random(seed, 17)
|
|
121
|
+
random(seed, 17, key)
|
|
90
122
|
.sub(0.5)
|
|
91
123
|
.mul(recipe.radius * 0.16),
|
|
92
124
|
);
|
|
93
125
|
}
|
|
94
126
|
|
|
95
|
-
|
|
96
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The axis a burst's cone is built around `direction` with. It must not be parallel to `direction`:
|
|
129
|
+
* `cross(direction, tangent)` is then zero, its `normalize` is NaN, every launch velocity is NaN, and
|
|
130
|
+
* the three.js arm's GPU hangs on the first frame the NaN reaches a sprite (VK_ERROR_DEVICE_LOST).
|
|
131
|
+
* The test is on the *normalised* direction, so `[0, 0.2, 0]` is straight up like `[0, 1, 0]`.
|
|
132
|
+
*/
|
|
133
|
+
export function launchTangent(
|
|
134
|
+
direction: readonly [number, number, number],
|
|
135
|
+
): readonly [number, number, number] {
|
|
136
|
+
return Math.abs(direction[1] / Math.hypot(...direction)) > 0.9 ? [1, 0, 0] : [0, 1, 0];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function launch(recipe: DonorRecipe, seed: number, key: Key) {
|
|
140
|
+
const speed = float(recipe.speed[0]).add(
|
|
141
|
+
random(seed, 23, key).mul(recipe.speed[1] - recipe.speed[0]),
|
|
142
|
+
);
|
|
97
143
|
const direction = normalize(vec3(...recipe.direction));
|
|
98
|
-
const tangent =
|
|
144
|
+
const tangent = vec3(...launchTangent(recipe.direction));
|
|
99
145
|
const bitangent = normalize(cross(direction, tangent));
|
|
100
|
-
const cone = float(recipe.cone).mul(random(seed, 29).sqrt());
|
|
101
|
-
const azimuth = random(seed, 31).mul(TAU);
|
|
146
|
+
const cone = float(recipe.cone).mul(random(seed, 29, key).sqrt());
|
|
147
|
+
const azimuth = random(seed, 31, key).mul(TAU);
|
|
102
148
|
return normalize(
|
|
103
149
|
direction
|
|
104
150
|
.mul(cos(cone))
|
|
@@ -136,52 +182,81 @@ function mask(style: DonorRecipe["style"]) {
|
|
|
136
182
|
|
|
137
183
|
function createDonorEmitter(recipe: DonorRecipe, seed: number): IActionRpgVfxOptions {
|
|
138
184
|
const material = new SpriteMaterial({
|
|
139
|
-
blending:
|
|
185
|
+
blending: THREE.AdditiveBlending,
|
|
140
186
|
depthWrite: false,
|
|
141
187
|
toneMapped: false,
|
|
142
188
|
transparent: true,
|
|
143
189
|
});
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
190
|
+
const capacity = recipe.amount * RING_BURSTS;
|
|
191
|
+
// The material reads the birth stamp the engine writes, so it binds once the engine has made the buffer.
|
|
192
|
+
const bindMaterial = (born: Node<"float">): void => {
|
|
193
|
+
const key = burstKey(born);
|
|
194
|
+
const age = time.sub(born);
|
|
195
|
+
const lifetime = lifetimeOf(recipe, seed, key);
|
|
196
|
+
const alive = varying(step(0, age).mul(step(age, lifetime)));
|
|
197
|
+
const particlePhase = varying(age.div(lifetime).clamp(0, 1));
|
|
198
|
+
const scale =
|
|
199
|
+
recipe.shape === "line"
|
|
200
|
+
? vec2(
|
|
201
|
+
Math.max(recipe.size * 3.8, recipe.lineEnd?.[0] ?? recipe.size),
|
|
202
|
+
recipe.ribbonWidth ?? recipe.size,
|
|
203
|
+
)
|
|
204
|
+
: vec2(recipe.size);
|
|
205
|
+
material.scaleNode = scale
|
|
206
|
+
.mul(
|
|
207
|
+
recipe.style === "glow" ? mix(1.08, 0.66, particlePhase) : mix(1.16, 0.36, particlePhase),
|
|
208
|
+
)
|
|
209
|
+
.mul(0.52)
|
|
210
|
+
.mul(alive);
|
|
211
|
+
material.colorNode = vec4(
|
|
212
|
+
mix(vec3(...recipe.colour), vec3(...recipe.highlight), particlePhase),
|
|
213
|
+
mask(recipe.style)
|
|
214
|
+
.mul(float(1).sub(smoothstep(0.96, 1, particlePhase)))
|
|
215
|
+
.mul(0.96)
|
|
216
|
+
.mul(alive),
|
|
217
|
+
);
|
|
218
|
+
const direction = launch(recipe, seed, key);
|
|
219
|
+
material.rotationNode = atan(direction.y, direction.x);
|
|
220
|
+
};
|
|
221
|
+
const spawn = (
|
|
222
|
+
{ positions, velocities, births }: IActionRpgVfxBuffers,
|
|
223
|
+
request: IActionRpgVfxSpawnRequest,
|
|
224
|
+
): ComputeNode => {
|
|
225
|
+
bindMaterial(births.toAttribute());
|
|
226
|
+
return Fn(() => {
|
|
227
|
+
If(instanceIndex.lessThan(request.count), () => {
|
|
228
|
+
const slot = request.first.add(instanceIndex).mod(uint(capacity));
|
|
229
|
+
velocities.element(slot).assign(request.origin);
|
|
230
|
+
positions.element(slot).assign(request.origin);
|
|
231
|
+
});
|
|
232
|
+
})().compute(capacity);
|
|
233
|
+
};
|
|
234
|
+
const process = (
|
|
235
|
+
{ positions, velocities, births }: IActionRpgVfxBuffers,
|
|
236
|
+
runtime: { readonly time: Node<"float"> },
|
|
237
|
+
): ComputeNode =>
|
|
168
238
|
Fn(() => {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const lifetime =
|
|
172
|
-
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
const nextPosition = spawn
|
|
176
|
-
.add(velocity.mul(elapsed))
|
|
239
|
+
const born = births.element(instanceIndex);
|
|
240
|
+
const key = burstKey(born);
|
|
241
|
+
const lifetime = lifetimeOf(recipe, seed, key);
|
|
242
|
+
const elapsed = runtime.time.sub(born).clamp(0, lifetime);
|
|
243
|
+
const local = spawnPosition(recipe, seed, key)
|
|
244
|
+
.add(launch(recipe, seed, key).mul(elapsed))
|
|
177
245
|
.add(vec3(...recipe.acceleration).mul(elapsed.mul(elapsed).mul(0.5)))
|
|
178
246
|
.mul(exp(float(-recipe.drag).mul(elapsed)));
|
|
179
|
-
positions.element(instanceIndex).assign(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
247
|
+
positions.element(instanceIndex).assign(velocities.element(instanceIndex).add(local));
|
|
248
|
+
})().compute(capacity);
|
|
249
|
+
// A burst ages on the engine clock, so one that expires while the camera is away stays gone.
|
|
250
|
+
// emitParticle still writes a burst emitted off-screen; it shows when the camera returns.
|
|
251
|
+
return {
|
|
252
|
+
amount: capacity,
|
|
253
|
+
burstCount: recipe.amount,
|
|
254
|
+
lifetime: recipe.lifetime[1],
|
|
255
|
+
material,
|
|
256
|
+
onCull: "pause",
|
|
257
|
+
process,
|
|
258
|
+
spawn,
|
|
259
|
+
};
|
|
185
260
|
}
|
|
186
261
|
|
|
187
262
|
/** The attack arc uses the Kenney particle-pack slash-arc layer: line, width, colour and timing. */
|