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
|
+
}
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
//
|
|
14
14
|
// A spectral ocean is cascaded wave spectra inverse-transformed on the GPU every frame, which is
|
|
15
15
|
// what real water is, and a standard node material puts it back under the scene's own lights.
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
type ISpectralOceanHeight,
|
|
18
|
+
type ISpectralOceanOptions,
|
|
19
|
+
SpectralOcean,
|
|
20
|
+
} from "@threenative/core";
|
|
17
21
|
import {
|
|
18
22
|
BufferGeometry,
|
|
19
23
|
DataTexture,
|
|
@@ -113,55 +117,7 @@ export const SEA = {
|
|
|
113
117
|
windSpeed: 6,
|
|
114
118
|
} satisfies ISpectralOceanOptions;
|
|
115
119
|
|
|
116
|
-
/**
|
|
117
|
-
* How fast the sea's dominant waves travel, and which way they run.
|
|
118
|
-
*
|
|
119
|
-
* A spectral ocean has no closed-form height, so the CPU copy a hull floats on is always some
|
|
120
|
-
* frames behind the field the GPU is drawing — the API says so, and reports the age. This is what
|
|
121
|
-
* a reader needs to *use* that age: deep-water waves travel, so the field at time `t + d` is very
|
|
122
|
-
* nearly the field at time `t` shifted downwind by `speed * d`. Sampling that far **upwind** of a
|
|
123
|
-
* point therefore reads what the water there is about to be doing.
|
|
124
|
-
*
|
|
125
|
-
* The peak angular frequency is the Pierson-Moskowitz one, `0.855 g / U`, and a deep-water wave's
|
|
126
|
-
* phase speed is `g / w`. Both come straight out of `SEA` above, so retuning the wind retunes
|
|
127
|
-
* this with it.
|
|
128
|
-
*/
|
|
129
|
-
const PEAK_ANGULAR_FREQUENCY = (0.855 * SEA.gravity) / SEA.windSpeed;
|
|
130
|
-
export const SWELL = {
|
|
131
|
-
/** Metres per second. */
|
|
132
|
-
speed: SEA.gravity / PEAK_ANGULAR_FREQUENCY,
|
|
133
|
-
x: Math.cos(SEA.windDirection),
|
|
134
|
-
z: Math.sin(SEA.windDirection),
|
|
135
|
-
} as const;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* The most wave-time any reader will extrapolate over, in seconds. See `surfaceHeight`.
|
|
139
|
-
*
|
|
140
|
-
* The lag being corrected for is a few frames in a real session and an order of magnitude worse
|
|
141
|
-
* inside a playtest, where the fixed step runs far faster than wall-clock and a copy in flight
|
|
142
|
-
* covers a hundred ticks. Correcting the first is what a floating thing needs; chasing the second
|
|
143
|
-
* would sample far upwind, where a spectral field has already decorrelated and the "prediction" is
|
|
144
|
-
* just a different wave.
|
|
145
|
-
*
|
|
146
|
-
* It is also short because the lead is measured in wavelengths, not in seconds. This sea state's
|
|
147
|
-
* dominant wavelength is 13 m, so a quarter of a second is 1.75 m upwind — an eighth of a wave, and
|
|
148
|
-
* the height comes back half a metre from the truth, which floats the drawn hull on water that is
|
|
149
|
-
* not being drawn. An eighth of a second is 0.9 m, or a fifteenth of a wave: worth correcting, and
|
|
150
|
-
* small enough not to invent a wave.
|
|
151
|
-
*/
|
|
152
|
-
const MAX_LEAD_SECONDS = 0.12;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The sea's height at a world point, corrected for the age of the copy it came from.
|
|
156
|
-
*
|
|
157
|
-
* This is the call anything that floats should use, rather than `sampleHeight` raw: a hull, a
|
|
158
|
-
* buoy or a bit of flotsam put straight onto the returned number rides water the renderer stopped
|
|
159
|
-
* drawing several frames ago, and the tell is a hull that cuts down through a crest and then hangs
|
|
160
|
-
* over the following trough.
|
|
161
|
-
*
|
|
162
|
-
* `undefined` before the first copy lands, exactly as `sampleHeight` is, so a caller still has to
|
|
163
|
-
* decide what an unknown sea level means for it.
|
|
164
|
-
*/
|
|
120
|
+
/** Predict this point's current height from its measured local vertical velocity. */
|
|
165
121
|
export function surfaceHeight(
|
|
166
122
|
ocean: SpectralOcean,
|
|
167
123
|
x: number,
|
|
@@ -170,9 +126,71 @@ export function surfaceHeight(
|
|
|
170
126
|
): number | undefined {
|
|
171
127
|
const probe = ocean.sampleHeight(x, z);
|
|
172
128
|
if (probe === undefined) return undefined;
|
|
173
|
-
const lead = Math.
|
|
174
|
-
|
|
175
|
-
|
|
129
|
+
const lead = Math.max(0, probe.staleFrames) * deltaTime;
|
|
130
|
+
return probe.height + probe.verticalVelocity * lead;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A new asynchronous copy corrects the predicted height and velocity. Carry that innovation
|
|
135
|
+
* continuously to the new prediction over its measured copy interval, rather than teleporting
|
|
136
|
+
* the hull or damping the wave itself. Each ship owns its history; attitude probes stay raw.
|
|
137
|
+
*/
|
|
138
|
+
export function createHeightReconciler() {
|
|
139
|
+
let previous:
|
|
140
|
+
| { height: number; velocity: number; copy: number; time: number; step: number }
|
|
141
|
+
| undefined;
|
|
142
|
+
let curve: { start: number; duration: number; height: number; velocity: number } | undefined;
|
|
143
|
+
const correction = (time: number) => {
|
|
144
|
+
if (curve === undefined || time >= curve.start + curve.duration)
|
|
145
|
+
return { height: 0, velocity: 0 };
|
|
146
|
+
const t = Math.max(0, (time - curve.start) / curve.duration);
|
|
147
|
+
return {
|
|
148
|
+
height:
|
|
149
|
+
(2 * t ** 3 - 3 * t ** 2 + 1) * curve.height +
|
|
150
|
+
(t ** 3 - 2 * t ** 2 + t) * curve.duration * curve.velocity,
|
|
151
|
+
velocity:
|
|
152
|
+
((6 * t ** 2 - 6 * t) * curve.height) / curve.duration +
|
|
153
|
+
(3 * t ** 2 - 4 * t + 1) * curve.velocity,
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
return (sample: ISpectralOceanHeight, frame: number, step: number) => {
|
|
157
|
+
if (
|
|
158
|
+
![frame, step, sample.height, sample.verticalVelocity, sample.staleFrames].every(
|
|
159
|
+
Number.isFinite,
|
|
160
|
+
) ||
|
|
161
|
+
frame < 0 ||
|
|
162
|
+
step <= 0 ||
|
|
163
|
+
sample.staleFrames < 0
|
|
164
|
+
)
|
|
165
|
+
throw new Error("Invalid sailing height prediction clock or sample.");
|
|
166
|
+
const time = frame * step;
|
|
167
|
+
const copy = (frame - sample.staleFrames) * step;
|
|
168
|
+
const height = sample.height + sample.verticalVelocity * (time - copy);
|
|
169
|
+
if (
|
|
170
|
+
previous !== undefined &&
|
|
171
|
+
(time < previous.time || step !== previous.step || copy < previous.copy)
|
|
172
|
+
) {
|
|
173
|
+
previous = undefined;
|
|
174
|
+
curve = undefined;
|
|
175
|
+
}
|
|
176
|
+
if (previous !== undefined && copy !== previous.copy) {
|
|
177
|
+
const carried = correction(time);
|
|
178
|
+
curve = {
|
|
179
|
+
start: time,
|
|
180
|
+
duration: copy - previous.copy,
|
|
181
|
+
height:
|
|
182
|
+
previous.height + previous.velocity * (time - previous.copy) + carried.height - height,
|
|
183
|
+
velocity: previous.velocity + carried.velocity - sample.verticalVelocity,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
previous = { height: sample.height, velocity: sample.verticalVelocity, copy, time, step };
|
|
187
|
+
const carried = correction(time);
|
|
188
|
+
return {
|
|
189
|
+
height: height + carried.height,
|
|
190
|
+
verticalVelocity: sample.verticalVelocity + carried.velocity,
|
|
191
|
+
correction: carried.height,
|
|
192
|
+
};
|
|
193
|
+
};
|
|
176
194
|
}
|
|
177
195
|
|
|
178
196
|
/**
|
|
@@ -24,12 +24,16 @@ 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
|
+
onTierChanged?: (tier: QualityTier) => void;
|
|
29
32
|
} = {},
|
|
30
|
-
): void {
|
|
33
|
+
): { readonly tier: QualityTier; dispose(): void } {
|
|
31
34
|
const tier = resolveQualityTier({
|
|
32
35
|
mobile: environment.mobile,
|
|
36
|
+
gpuClass: environment.gpuClass,
|
|
33
37
|
software: environment.software,
|
|
34
38
|
tier: environment.tier,
|
|
35
39
|
});
|
|
@@ -40,5 +44,15 @@ export function setupPost(
|
|
|
40
44
|
} source=${source}`,
|
|
41
45
|
);
|
|
42
46
|
const world = new WorldEnvironment(qualityPreset(tier));
|
|
43
|
-
world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
|
|
47
|
+
const applied = world.apply(renderer, scene, camera, { godraysLight: environment.godraysLight });
|
|
48
|
+
environment.onTierChanged?.(tier);
|
|
49
|
+
let disposed = false;
|
|
50
|
+
return {
|
|
51
|
+
tier,
|
|
52
|
+
dispose(): void {
|
|
53
|
+
if (disposed) return;
|
|
54
|
+
disposed = true;
|
|
55
|
+
applied.dispose?.();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
44
58
|
}
|
|
@@ -61,51 +61,6 @@ function belliedSail(width: number, height: number, belly: number, taper = 1): B
|
|
|
61
61
|
return geometry;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/**
|
|
65
|
-
* A swallow-tailed pennant, the tail cut back to the middle of the hoist instead of squared off.
|
|
66
|
-
*
|
|
67
|
-
* The notch is the whole difference: a rectangular flag reads as a card, and at the chase camera's
|
|
68
|
-
* distance the shape is all there is. Cutting the last fifth of the fly into two points turns the
|
|
69
|
-
* same four columns of canvas into the shape a player has seen on every ship ever drawn.
|
|
70
|
-
*/
|
|
71
|
-
function swallowtail(width: number, height: number, belly: number): BufferGeometry {
|
|
72
|
-
const positions: number[] = [];
|
|
73
|
-
// The notch: past 0.8 of the length the fly narrows to a point, so the tail is two points.
|
|
74
|
-
const fly = (u: number, v: number): number => (u < 0.8 ? v : v * (1 - (u - 0.8) * 5));
|
|
75
|
-
const at = (u: number, v: number): [number, number, number] => [
|
|
76
|
-
u * width,
|
|
77
|
-
(v - 0.5) * height,
|
|
78
|
-
Math.sin(Math.PI * u) * Math.sin(Math.PI * v) * belly,
|
|
79
|
-
];
|
|
80
|
-
for (let row = 0; row < 3; row += 1) {
|
|
81
|
-
for (let column = 0; column < 4; column += 1) {
|
|
82
|
-
const u0 = column / 4;
|
|
83
|
-
const u1 = (column + 1) / 4;
|
|
84
|
-
const v0 = row / 3;
|
|
85
|
-
const v1 = (row + 1) / 3;
|
|
86
|
-
const corners = [
|
|
87
|
-
at(u0, fly(u0, v0)),
|
|
88
|
-
at(u1, fly(u1, v0)),
|
|
89
|
-
at(u1, fly(u1, v1)),
|
|
90
|
-
at(u0, fly(u0, v1)),
|
|
91
|
-
];
|
|
92
|
-
for (const triangle of [
|
|
93
|
-
[0, 1, 2],
|
|
94
|
-
[0, 2, 3],
|
|
95
|
-
] as const) {
|
|
96
|
-
for (const index of triangle) {
|
|
97
|
-
const corner = corners[index] as [number, number, number];
|
|
98
|
-
positions.push(...corner);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const geometry = new BufferGeometry();
|
|
104
|
-
geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
|
|
105
|
-
geometry.computeVertexNormals();
|
|
106
|
-
return geometry;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
64
|
/**
|
|
110
65
|
* One sail, authored flat, ready for `SoftBody3D` to put the wind in it.
|
|
111
66
|
*
|
|
@@ -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
|
|
|
@@ -85,6 +110,7 @@ const high: IWorldEnvironmentOptions = {
|
|
|
85
110
|
bloomStrength: 0.38,
|
|
86
111
|
// No SSGI runs here, so there is nothing for the denoiser to clean up. Off, explicitly.
|
|
87
112
|
denoiseEnabled: false,
|
|
113
|
+
autoExposureEnabled: false,
|
|
88
114
|
exposure: 0.9,
|
|
89
115
|
// Off at every tier — see the note at the top of this file.
|
|
90
116
|
ssgiEnabled: false,
|
|
@@ -100,6 +126,8 @@ const high: IWorldEnvironmentOptions = {
|
|
|
100
126
|
* the water material is where the frame actually goes.
|
|
101
127
|
*/
|
|
102
128
|
const medium: IWorldEnvironmentOptions = {
|
|
129
|
+
// The chain's own quality tier: without it the renderer keeps its `high` default at this tier.
|
|
130
|
+
renderChainTier: "medium",
|
|
103
131
|
// Strength, radius and threshold are a look decision already tuned to this scene's palette.
|
|
104
132
|
// Bloom: ~4.6 ms — the second most expensive stage in the chain, and the one nobody expects
|
|
105
133
|
// to be.
|
|
@@ -148,3 +176,35 @@ export function qualityPreset(tier: string): IWorldEnvironmentOptions {
|
|
|
148
176
|
}
|
|
149
177
|
return preset;
|
|
150
178
|
}
|
|
179
|
+
|
|
180
|
+
export interface IMaterialLightingEnvironment {
|
|
181
|
+
readonly web: boolean;
|
|
182
|
+
readonly rendererKind: string;
|
|
183
|
+
readonly mobile?: boolean;
|
|
184
|
+
readonly software?: boolean;
|
|
185
|
+
readonly webglFallback?: boolean;
|
|
186
|
+
}
|
|
187
|
+
export function materialLightingEnabled(
|
|
188
|
+
tier: QualityTier,
|
|
189
|
+
environment: IMaterialLightingEnvironment,
|
|
190
|
+
): boolean {
|
|
191
|
+
return (
|
|
192
|
+
tier === "high" &&
|
|
193
|
+
environment.web &&
|
|
194
|
+
environment.rendererKind === "webgpu" &&
|
|
195
|
+
environment.mobile !== true &&
|
|
196
|
+
environment.software !== true &&
|
|
197
|
+
environment.webglFallback !== true
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A WebGPURenderer wrapper may run an ordinary WebGL fallback backend. */
|
|
202
|
+
export function isWebGLFallbackRenderer(renderer: unknown): boolean {
|
|
203
|
+
if (renderer === null || typeof renderer !== "object") return false;
|
|
204
|
+
const backend = Reflect.get(renderer, "backend");
|
|
205
|
+
return (
|
|
206
|
+
backend !== null &&
|
|
207
|
+
typeof backend === "object" &&
|
|
208
|
+
Reflect.get(backend, "isWebGLBackend") === true
|
|
209
|
+
);
|
|
210
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type Texture,
|
|
19
19
|
Vector3,
|
|
20
20
|
} from "three";
|
|
21
|
+
import { HEIGHT_FOG, type HeightFogParams, heightFogDepth, heightFogNode } from "./heightFog.js";
|
|
21
22
|
import { palette } from "./palette.js";
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -76,6 +77,22 @@ export async function loadSky(assets: { texture(path: string): Promise<Texture>
|
|
|
76
77
|
sky = await assets.texture("sky.jpg");
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
/** The look this fog replaced: FogExp2 at 0.003, measured at 150 m from 2 m up. */
|
|
81
|
+
const EYE_LEVEL = { density: 0.003, distance: 150, cameraHeight: 2 };
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The distance term's density that, with the height term, keeps the old eye-level haze: at
|
|
85
|
+
* `EYE_LEVEL.distance` along the horizon from `EYE_LEVEL.cameraHeight` the two together transmit what
|
|
86
|
+
* FogExp2 at `EYE_LEVEL.density` did. The distance term is lowered, never removed, so the ground
|
|
87
|
+
* still ends in fog at a kilometre.
|
|
88
|
+
*/
|
|
89
|
+
function distanceDensity(p: HeightFogParams = HEIGHT_FOG): number {
|
|
90
|
+
const { distance, density, cameraHeight } = EYE_LEVEL;
|
|
91
|
+
const old = (density * distance) ** 2;
|
|
92
|
+
const height = heightFogDepth(p, cameraHeight, cameraHeight, distance) * Math.LN2;
|
|
93
|
+
return Math.sqrt(Math.max(0, old - height)) / distance;
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
export function setupSky(scene: Scene, options: { readonly software?: boolean } = {}): void {
|
|
80
97
|
if (sky === undefined) throw new Error("setupSky must run after loadSky.");
|
|
81
98
|
sky.mapping = EquirectangularReflectionMapping;
|
|
@@ -126,5 +143,8 @@ export function setupSky(scene: Scene, options: { readonly software?: boolean }
|
|
|
126
143
|
// Open sea, so the far water is nearly all haze. At 0.003 the sea is half gone by 300 m and gone
|
|
127
144
|
// by a kilometre, and the colour it goes to is the photograph's own horizon measured off this
|
|
128
145
|
// file — which is why the water and the sky meet in one line instead of in a seam.
|
|
129
|
-
scene.fog
|
|
146
|
+
// `scene.fog` stays the distance term; `scene.fogNode` is what three applies and adds the height term.
|
|
147
|
+
const distanceFog = new FogExp2(palette.skyLow, distanceDensity());
|
|
148
|
+
scene.fog = distanceFog;
|
|
149
|
+
scene.fogNode = heightFogNode(distanceFog, HEIGHT_FOG, SUN_DIRECTION);
|
|
130
150
|
}
|