create-threenative 0.2.10 → 0.2.12
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 +109 -3
- package/agent-docs/references/auto-exposure.md +28 -45
- package/agent-docs/references/build-profiles.md +1 -1
- package/agent-docs/references/capability-reference.md +527 -44
- package/agent-docs/references/debug-surface.md +64 -0
- package/agent-docs/references/finding-assets.md +11 -12
- package/agent-docs/references/performance-basics.md +19 -0
- package/agent-docs/references/trace-a-slow-frame.md +21 -0
- package/agent-docs/references/visual-baseline.md +23 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +17 -6
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +87 -23
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +12 -11
- package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
- package/agent-files/scripts/reference.mjs +9 -4
- package/capabilities.json +739 -50
- package/dist/index.d.ts +40 -6
- package/dist/index.js +227 -34
- package/dist/quality.d.ts +12 -0
- package/dist/quality.js +166747 -0
- package/dist/threenative.js +60 -44
- package/dist/web-engine-gltf-loader.js +2 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +1 -1
- package/dist/web-engine-mesh-bvh.js +7 -0
- package/dist/web-engine-post-effects.js +645 -19
- package/dist/web-engine-runtime.js +3528 -343
- package/package.json +19 -9
- package/template-assets/assets/bay-PROVENANCE.md +21 -0
- package/template-assets/assets/bay-ground.webp +0 -0
- package/template-assets/assets/bay-metal.webp +0 -0
- package/template-assets/assets/bay-pavement-normal.webp +0 -0
- package/template-assets/assets/bay-pavement.webp +0 -0
- package/template-assets/assets/bay-plaster-normal.webp +0 -0
- package/template-assets/assets/bay-plaster.webp +0 -0
- package/template-assets/assets/bay-wood-normal.webp +0 -0
- package/template-assets/assets/bay-wood.webp +0 -0
- package/template-assets/assets/tex-PROVENANCE.md +25 -0
- package/template-assets/assets/tex-bark-normal.webp +0 -0
- package/template-assets/assets/tex-bark.webp +0 -0
- package/template-assets/assets/tex-birch-bark.webp +0 -0
- package/template-assets/assets/tex-grass.webp +0 -0
- package/template-assets/assets/tex-planks-normal.webp +0 -0
- package/template-assets/assets/tex-planks.webp +0 -0
- package/template-assets/assets/tex-rock-normal.webp +0 -0
- package/template-assets/assets/tex-rock.webp +0 -0
- package/template-assets/assets/tex-roof-tiles-normal.webp +0 -0
- package/template-assets/assets/tex-roof-tiles.webp +0 -0
- package/template-assets/assets/tex-sand-normal.webp +0 -0
- package/template-assets/assets/tex-sand.webp +0 -0
- package/template-assets/assets/tex-stone-wall-normal.webp +0 -0
- package/template-assets/assets/tex-stone-wall.webp +0 -0
- package/template-assets/kitExposure.ts +20 -0
- package/template-assets/patches/three@0.185.1.patch +481 -272
- package/template-assets/quality/biome.json +7 -0
- package/template-assets/quality/eslint.config.js +3 -0
- package/template-assets/realistic-ocean/README.md +113 -0
- package/template-assets/realistic-ocean/install.mjs +56 -0
- package/template-assets/realistic-ocean/src/realisticOcean.ts +151 -0
- package/template-assets/realistic-ocean/src/realisticOceanLifetime.ts +29 -0
- package/template-assets/realistic-ocean/src/render/REALISTIC-OCEAN-LICENSE.txt +25 -0
- package/template-assets/realistic-ocean/src/render/realisticSea.ts +642 -0
- package/template-assets/realistic-ocean/src/render/realisticSeaMaps.ts +311 -0
- package/template-assets/realistic-ocean/src/render/realisticSpectrum.ts +289 -0
- package/templates/AGENTS.md +21 -0
- package/templates/CLAUDE.md +23 -0
- package/templates/action-rpg/.codex/config.toml +6 -2
- package/templates/action-rpg/.cursor/mcp.json +8 -2
- package/templates/action-rpg/.gemini/settings.json +8 -2
- package/templates/action-rpg/.mcp.json +8 -2
- package/templates/action-rpg/.vscode/mcp.json +9 -2
- package/templates/action-rpg/.zed/settings.json +9 -2
- package/templates/action-rpg/AGENTS.md +11 -11
- package/templates/action-rpg/CLAUDE.md +11 -11
- package/templates/action-rpg/opencode.json +10 -2
- package/templates/action-rpg/package.json +15 -10
- package/templates/action-rpg/playtests/combat.playtest.json +6 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +22 -0
- package/templates/action-rpg/playtests/performance.playtest.json +1 -1
- package/templates/action-rpg/playtests/roll.playtest.json +112 -0
- package/templates/action-rpg/playtests/swing.playtest.json +55 -0
- package/templates/action-rpg/playtests/win.playtest.json +4 -4
- package/templates/action-rpg/src/entities/Fighter.ts +44 -4
- package/templates/action-rpg/src/entities/Player.ts +64 -12
- package/templates/action-rpg/src/render/atmosphere.ts +444 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +49 -18
- package/templates/action-rpg/src/render/clouds.ts +605 -0
- package/templates/action-rpg/src/render/dungeon.ts +8 -6
- package/templates/action-rpg/src/render/exposure.ts +11 -109
- package/templates/action-rpg/src/render/gpuSky.ts +752 -0
- package/templates/action-rpg/src/render/lighting.ts +27 -4
- package/templates/action-rpg/src/render/materialLighting.ts +2 -11
- package/templates/action-rpg/src/render/palette.ts +1 -0
- package/templates/action-rpg/src/render/postprocessing.ts +4 -4
- package/templates/action-rpg/src/render/props.ts +10 -8
- package/templates/action-rpg/src/render/quality.ts +56 -108
- package/templates/action-rpg/src/render/sky.ts +74 -1
- package/templates/action-rpg/src/scenes/Play.ts +16 -12
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +7 -2
- package/templates/action-rpg/src/ui/Hud.tsx +5 -7
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +14 -14
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/adventure/.codex/config.toml +23 -0
- package/templates/adventure/.cursor/mcp.json +38 -0
- package/templates/adventure/.gemini/settings.json +38 -0
- package/templates/adventure/.mcp.json +38 -0
- package/templates/adventure/.vscode/mcp.json +43 -0
- package/templates/adventure/.zed/settings.json +43 -0
- package/templates/adventure/AGENTS.md +60 -0
- package/templates/adventure/CLAUDE.md +62 -0
- package/templates/adventure/index.html +14 -0
- package/templates/adventure/kit.json +8 -0
- package/templates/adventure/native-playtests/survives.playtest.json +52 -0
- package/templates/adventure/opencode.json +49 -0
- package/templates/adventure/package.json +65 -0
- package/templates/adventure/playtests/boss.playtest.json +406 -0
- package/templates/adventure/playtests/combat.playtest.json +342 -0
- package/templates/adventure/playtests/controls.playtest.json +142 -0
- package/templates/adventure/playtests/explore.playtest.json +45 -0
- package/templates/adventure/playtests/flicker.playtest.json +206 -0
- package/templates/adventure/playtests/hearts.playtest.json +171 -0
- package/templates/adventure/playtests/lockon.playtest.json +256 -0
- package/templates/adventure/playtests/look.playtest.json +72 -0
- package/templates/adventure/playtests/move-hollow.playtest.json +106 -0
- package/templates/adventure/playtests/move.playtest.json +84 -0
- package/templates/adventure/playtests/performance.playtest.json +55 -0
- package/templates/adventure/playtests/puzzle.playtest.json +250 -0
- package/templates/adventure/playtests/stride.playtest.json +67 -0
- package/templates/adventure/playtests/survives.playtest.json +171 -0
- package/templates/adventure/playtests/thornback.playtest.json +267 -0
- package/templates/adventure/public/favicon.svg +4 -0
- package/templates/adventure/src/entities/Block.ts +114 -0
- package/templates/adventure/src/entities/Chest.ts +69 -0
- package/templates/adventure/src/entities/Door.ts +81 -0
- package/templates/adventure/src/entities/Dummy.ts +69 -0
- package/templates/adventure/src/entities/Flicker.ts +239 -0
- package/templates/adventure/src/entities/Hero.ts +561 -0
- package/templates/adventure/src/entities/LockOn.ts +180 -0
- package/templates/adventure/src/entities/Mossling.ts +249 -0
- package/templates/adventure/src/entities/Switch.ts +49 -0
- package/templates/adventure/src/entities/Thornback.ts +238 -0
- package/templates/adventure/src/entities/Warden.ts +196 -0
- package/templates/adventure/src/game.ts +65 -0
- package/templates/adventure/src/interact.ts +63 -0
- package/templates/adventure/src/level/Hollow.ts +240 -0
- package/templates/adventure/src/level/Vale.ts +383 -0
- package/templates/adventure/src/main.ts +18 -0
- package/templates/adventure/src/render/camera.ts +416 -0
- package/templates/adventure/src/render/creatures.ts +405 -0
- package/templates/adventure/src/render/effects.ts +333 -0
- package/templates/adventure/src/render/foliage.ts +1072 -0
- package/templates/adventure/src/render/hero.ts +1447 -0
- package/templates/adventure/src/render/kitExposure.ts +20 -0
- package/templates/adventure/src/render/lighting.ts +74 -0
- package/templates/adventure/src/render/loading.ts +332 -0
- package/templates/adventure/src/render/materials.ts +179 -0
- package/templates/adventure/src/render/palette.ts +137 -0
- package/templates/adventure/src/render/postprocessing.ts +70 -0
- package/templates/adventure/src/render/props.ts +383 -0
- package/templates/adventure/src/render/quality.ts +46 -0
- package/templates/adventure/src/render/sky.ts +271 -0
- package/templates/adventure/src/render/surface.ts +259 -0
- package/templates/adventure/src/render/touch-controls.ts +137 -0
- package/templates/adventure/src/scenes/Play.ts +959 -0
- package/templates/adventure/src/state.ts +113 -0
- package/templates/adventure/src/style.css +98 -0
- package/templates/adventure/src/ui/App.tsx +22 -0
- package/templates/adventure/src/ui/GameUi.tsx +20 -0
- package/templates/adventure/src/ui/Hud.tsx +70 -0
- package/templates/adventure/src/ui/Menu.tsx +15 -0
- package/templates/adventure/src/ui/main.tsx +14 -0
- package/templates/adventure/tailwind.config.ts +2 -0
- package/templates/adventure/threenative.config.ts +62 -0
- package/templates/adventure/tsconfig.json +17 -0
- package/templates/adventure/vite.config.ts +49 -0
- package/templates/collectathon/.codex/config.toml +23 -0
- package/templates/collectathon/.cursor/mcp.json +38 -0
- package/templates/collectathon/.gemini/settings.json +38 -0
- package/templates/collectathon/.mcp.json +38 -0
- package/templates/collectathon/.vscode/mcp.json +43 -0
- package/templates/collectathon/.zed/settings.json +43 -0
- package/templates/collectathon/AGENTS.md +58 -0
- package/templates/collectathon/CLAUDE.md +60 -0
- package/templates/collectathon/index.html +14 -0
- package/templates/collectathon/kit.json +8 -0
- package/templates/collectathon/native-playtests/survives.playtest.json +52 -0
- package/templates/collectathon/opencode.json +49 -0
- package/templates/collectathon/package.json +65 -0
- package/templates/collectathon/playtests/acrobatics.playtest.json +238 -0
- package/templates/collectathon/playtests/camera.playtest.json +80 -0
- package/templates/collectathon/playtests/clipped-probe.playtest.json +101 -0
- package/templates/collectathon/playtests/collect.playtest.json +196 -0
- package/templates/collectathon/playtests/combat.playtest.json +246 -0
- package/templates/collectathon/playtests/double-tap-air.playtest.json +198 -0
- package/templates/collectathon/playtests/double-tap.playtest.json +136 -0
- package/templates/collectathon/playtests/effects.playtest.json +124 -0
- package/templates/collectathon/playtests/enemies.playtest.json +295 -0
- package/templates/collectathon/playtests/explore.playtest.json +45 -0
- package/templates/collectathon/playtests/hop-reach.playtest.json +117 -0
- package/templates/collectathon/playtests/jump-chain.playtest.json +274 -0
- package/templates/collectathon/playtests/ledge-angle.playtest.json +107 -0
- package/templates/collectathon/playtests/ledge-too-high.playtest.json +115 -0
- package/templates/collectathon/playtests/ledge.playtest.json +100 -0
- package/templates/collectathon/playtests/look.playtest.json +64 -0
- package/templates/collectathon/playtests/performance.playtest.json +55 -0
- package/templates/collectathon/playtests/stride.playtest.json +111 -0
- package/templates/collectathon/playtests/survives.playtest.json +123 -0
- package/templates/collectathon/playtests/telegraphs.playtest.json +132 -0
- package/templates/collectathon/playtests/thornback.playtest.json +157 -0
- package/templates/collectathon/playtests/wall-kick.playtest.json +206 -0
- package/templates/collectathon/playtests/win.playtest.json +166 -0
- package/templates/collectathon/public/favicon.svg +4 -0
- package/templates/collectathon/src/entities/Hero.ts +915 -0
- package/templates/collectathon/src/entities/Pickup.ts +63 -0
- package/templates/collectathon/src/entities/Walker.ts +248 -0
- package/templates/collectathon/src/game.ts +51 -0
- package/templates/collectathon/src/level/Course.ts +590 -0
- package/templates/collectathon/src/level/terrain.ts +144 -0
- package/templates/collectathon/src/main.ts +14 -0
- package/templates/collectathon/src/playtest-events.ts +15 -0
- package/templates/collectathon/src/render/camera.ts +163 -0
- package/templates/collectathon/src/render/castle.ts +408 -0
- package/templates/collectathon/src/render/effects.ts +284 -0
- package/templates/collectathon/src/render/foliage.ts +744 -0
- package/templates/collectathon/src/render/ground.ts +139 -0
- package/templates/collectathon/src/render/hero.ts +452 -0
- package/templates/collectathon/src/render/kitExposure.ts +20 -0
- package/templates/collectathon/src/render/lighting.ts +65 -0
- package/templates/collectathon/src/render/loading.ts +332 -0
- package/templates/collectathon/src/render/materials.ts +196 -0
- package/templates/collectathon/src/render/palette.ts +82 -0
- package/templates/collectathon/src/render/postprocessing.ts +79 -0
- package/templates/collectathon/src/render/props.ts +218 -0
- package/templates/collectathon/src/render/quality.ts +54 -0
- package/templates/collectathon/src/render/sky.ts +262 -0
- package/templates/collectathon/src/render/surface.ts +269 -0
- package/templates/collectathon/src/render/touch-controls.ts +179 -0
- package/templates/collectathon/src/render/touch-layout.ts +48 -0
- package/templates/collectathon/src/render/water.ts +191 -0
- package/templates/collectathon/src/scenes/Play.ts +481 -0
- package/templates/collectathon/src/state.ts +38 -0
- package/templates/collectathon/src/style.css +106 -0
- package/templates/collectathon/src/ui/App.tsx +22 -0
- package/templates/collectathon/src/ui/GameUi.tsx +20 -0
- package/templates/collectathon/src/ui/Hud.tsx +77 -0
- package/templates/collectathon/src/ui/Menu.tsx +13 -0
- package/templates/collectathon/src/ui/main.tsx +14 -0
- package/templates/collectathon/tailwind.config.ts +2 -0
- package/templates/collectathon/threenative.config.ts +62 -0
- package/templates/collectathon/tsconfig.json +17 -0
- package/templates/collectathon/vite.config.ts +49 -0
- package/templates/kart/.codex/config.toml +23 -0
- package/templates/kart/.cursor/mcp.json +38 -0
- package/templates/kart/.gemini/settings.json +38 -0
- package/templates/kart/.mcp.json +38 -0
- package/templates/kart/.vscode/mcp.json +43 -0
- package/templates/kart/.zed/settings.json +43 -0
- package/templates/kart/AGENTS.md +58 -0
- package/templates/kart/CLAUDE.md +60 -0
- package/templates/kart/index.html +14 -0
- package/templates/kart/kit.json +8 -0
- package/templates/kart/native-playtests/survives.playtest.json +65 -0
- package/templates/kart/opencode.json +49 -0
- package/templates/kart/package.json +64 -0
- package/templates/kart/playtests/drift.playtest.json +226 -0
- package/templates/kart/playtests/explore.playtest.json +45 -0
- package/templates/kart/playtests/hit-stays-above-road.playtest.json +92 -0
- package/templates/kart/playtests/item-key.playtest.json +108 -0
- package/templates/kart/playtests/items.playtest.json +143 -0
- package/templates/kart/playtests/lap-times.playtest.json +138 -0
- package/templates/kart/playtests/laps.playtest.json +149 -0
- package/templates/kart/playtests/performance.playtest.json +57 -0
- package/templates/kart/playtests/race.playtest.json +294 -0
- package/templates/kart/playtests/restart.playtest.json +87 -0
- package/templates/kart/playtests/rocket-start.playtest.json +56 -0
- package/templates/kart/playtests/smooth-drive.playtest.json +101 -0
- package/templates/kart/playtests/surfaces.playtest.json +113 -0
- package/templates/kart/playtests/survives.playtest.json +116 -0
- package/templates/kart/playtests/wall.playtest.json +118 -0
- package/templates/kart/public/favicon.svg +4 -0
- package/templates/kart/src/entities/Driver.ts +123 -0
- package/templates/kart/src/entities/Items.ts +194 -0
- package/templates/kart/src/entities/Kart.ts +517 -0
- package/templates/kart/src/game.ts +45 -0
- package/templates/kart/src/main.ts +14 -0
- package/templates/kart/src/playtest-events.ts +15 -0
- package/templates/kart/src/render/camera.ts +83 -0
- package/templates/kart/src/render/course.ts +579 -0
- package/templates/kart/src/render/effects.ts +266 -0
- package/templates/kart/src/render/items.ts +163 -0
- package/templates/kart/src/render/kart.ts +256 -0
- package/templates/kart/src/render/kitExposure.ts +20 -0
- package/templates/kart/src/render/lighting.ts +58 -0
- package/templates/kart/src/render/loading.ts +332 -0
- package/templates/kart/src/render/materials.ts +119 -0
- package/templates/kart/src/render/palette.ts +74 -0
- package/templates/kart/src/render/postprocessing.ts +79 -0
- package/templates/kart/src/render/quality.ts +54 -0
- package/templates/kart/src/render/skids.ts +86 -0
- package/templates/kart/src/render/sky.ts +105 -0
- package/templates/kart/src/render/touch-controls.ts +168 -0
- package/templates/kart/src/render/touch-layout.ts +48 -0
- package/templates/kart/src/scenes/Race.ts +850 -0
- package/templates/kart/src/state.ts +53 -0
- package/templates/kart/src/style.css +106 -0
- package/templates/kart/src/track/Course.ts +276 -0
- package/templates/kart/src/track/Race.ts +133 -0
- package/templates/kart/src/ui/App.tsx +21 -0
- package/templates/kart/src/ui/GameUi.tsx +20 -0
- package/templates/kart/src/ui/Hud.tsx +172 -0
- package/templates/kart/src/ui/Menu.tsx +13 -0
- package/templates/kart/src/ui/main.tsx +14 -0
- package/templates/kart/tailwind.config.ts +2 -0
- package/templates/kart/threenative.config.ts +62 -0
- package/templates/kart/tsconfig.json +17 -0
- package/templates/kart/vite.config.ts +49 -0
- package/templates/minimal/.codex/config.toml +6 -2
- package/templates/minimal/.cursor/mcp.json +8 -2
- package/templates/minimal/.gemini/settings.json +8 -2
- package/templates/minimal/.mcp.json +8 -2
- package/templates/minimal/.vscode/mcp.json +9 -2
- package/templates/minimal/.zed/settings.json +9 -2
- package/templates/minimal/AGENTS.md +11 -13
- package/templates/minimal/CLAUDE.md +11 -13
- package/templates/minimal/opencode.json +10 -2
- package/templates/minimal/package.json +14 -9
- package/templates/minimal/playtests/camera-wall.playtest.json +36 -0
- package/templates/minimal/playtests/jump.playtest.json +45 -0
- package/templates/minimal/playtests/play.playtest.json +1 -1
- package/templates/minimal/src/game.ts +2 -0
- package/templates/minimal/src/render/atmosphere.ts +444 -0
- package/templates/minimal/src/render/backlightMaterial.ts +49 -18
- package/templates/minimal/src/render/camera.ts +35 -4
- package/templates/minimal/src/render/clouds.ts +605 -0
- package/templates/minimal/src/render/exposure.ts +7 -111
- package/templates/minimal/src/render/gpuSky.ts +752 -0
- package/templates/minimal/src/render/lighting.ts +26 -4
- package/templates/minimal/src/render/materialLighting.ts +2 -10
- package/templates/minimal/src/render/postprocessing.ts +4 -4
- package/templates/minimal/src/render/quality.ts +10 -116
- package/templates/minimal/src/render/sky.ts +73 -1
- package/templates/minimal/src/scenes/Play.ts +18 -7
- package/templates/platformer/.codex/config.toml +6 -2
- package/templates/platformer/.cursor/mcp.json +8 -2
- package/templates/platformer/.gemini/settings.json +8 -2
- package/templates/platformer/.mcp.json +8 -2
- package/templates/platformer/.vscode/mcp.json +9 -2
- package/templates/platformer/.zed/settings.json +9 -2
- package/templates/platformer/AGENTS.md +13 -9
- package/templates/platformer/CLAUDE.md +13 -9
- package/templates/platformer/opencode.json +10 -2
- package/templates/platformer/package.json +15 -10
- package/templates/platformer/playtests/dash-jump.playtest.json +34 -0
- package/templates/platformer/playtests/finish.playtest.json +58 -0
- package/templates/platformer/playtests/idle.playtest.json +44 -0
- package/templates/platformer/playtests/performance.playtest.json +1 -1
- package/templates/platformer/src/entities/Fox.ts +19 -6
- package/templates/platformer/src/game.ts +1 -0
- package/templates/platformer/src/level/Stage.ts +4 -1
- package/templates/platformer/src/render/backlightMaterial.ts +49 -18
- package/templates/platformer/src/render/camera.ts +30 -1
- package/templates/platformer/src/render/exposure.ts +6 -111
- package/templates/platformer/src/render/fox.ts +5 -2
- package/templates/platformer/src/render/kitExposure.ts +20 -0
- package/templates/platformer/src/render/materialLighting.ts +2 -11
- package/templates/platformer/src/render/postprocessing.ts +4 -4
- package/templates/platformer/src/render/props.ts +1 -2
- package/templates/platformer/src/render/quality.ts +10 -118
- package/templates/platformer/src/scenes/Play.ts +31 -15
- package/templates/platformer/src/ui/Menu.tsx +1 -1
- package/templates/puzzle/.codex/config.toml +6 -2
- package/templates/puzzle/.cursor/mcp.json +8 -2
- package/templates/puzzle/.gemini/settings.json +8 -2
- package/templates/puzzle/.mcp.json +8 -2
- package/templates/puzzle/.vscode/mcp.json +9 -2
- package/templates/puzzle/.zed/settings.json +9 -2
- package/templates/puzzle/AGENTS.md +14 -17
- package/templates/puzzle/CLAUDE.md +14 -17
- package/templates/puzzle/opencode.json +10 -2
- package/templates/puzzle/package.json +15 -10
- package/templates/puzzle/playtests/performance.playtest.json +1 -1
- package/templates/puzzle/playtests/replay-keeps-progress.playtest.json +78 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +49 -18
- package/templates/puzzle/src/render/exposure.ts +11 -109
- package/templates/puzzle/src/render/lighting.ts +3 -3
- package/templates/puzzle/src/render/materialLighting.ts +2 -11
- package/templates/puzzle/src/render/palette.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +4 -4
- package/templates/puzzle/src/render/quality.ts +44 -153
- package/templates/puzzle/src/render/vault.ts +18 -6
- package/templates/puzzle/src/scenes/Play.ts +6 -1
- package/templates/puzzle/src/ui/Hud.tsx +8 -43
- package/templates/racing/.codex/config.toml +6 -2
- package/templates/racing/.cursor/mcp.json +8 -2
- package/templates/racing/.gemini/settings.json +8 -2
- package/templates/racing/.mcp.json +8 -2
- package/templates/racing/.vscode/mcp.json +9 -2
- package/templates/racing/.zed/settings.json +9 -2
- package/templates/racing/AGENTS.md +10 -12
- package/templates/racing/CLAUDE.md +10 -12
- package/templates/racing/opencode.json +10 -2
- package/templates/racing/package.json +15 -10
- package/templates/racing/playtests/brake.playtest.json +54 -0
- package/templates/racing/playtests/outcome.playtest.json +19 -0
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/stopped-car-is-not-rescued.playtest.json +59 -0
- package/templates/racing/src/entities/RacingCar.ts +12 -3
- package/templates/racing/src/entities/Rival.ts +11 -2
- package/templates/racing/src/render/atmosphere.ts +444 -0
- package/templates/racing/src/render/backlightMaterial.ts +49 -18
- package/templates/racing/src/render/clouds.ts +605 -0
- package/templates/racing/src/render/exposure.ts +6 -111
- package/templates/racing/src/render/gpuSky.ts +752 -0
- package/templates/racing/src/render/kitExposure.ts +20 -0
- package/templates/racing/src/render/lighting.ts +26 -4
- package/templates/racing/src/render/materialLighting.ts +2 -11
- package/templates/racing/src/render/materials.ts +2 -1
- package/templates/racing/src/render/postprocessing.ts +4 -4
- package/templates/racing/src/render/quality.ts +27 -115
- package/templates/racing/src/render/sky.ts +72 -1
- package/templates/racing/src/scenes/Race.ts +9 -7
- package/templates/racing/src/track/TrackSector.ts +5 -2
- package/templates/racing/src/ui/Hud.tsx +12 -7
- package/templates/rain/.codex/config.toml +6 -2
- package/templates/rain/.cursor/mcp.json +8 -2
- package/templates/rain/.gemini/settings.json +8 -2
- package/templates/rain/.mcp.json +8 -2
- package/templates/rain/.vscode/mcp.json +9 -2
- package/templates/rain/.zed/settings.json +9 -2
- package/templates/rain/AGENTS.md +12 -12
- package/templates/rain/CLAUDE.md +12 -12
- package/templates/rain/opencode.json +10 -2
- package/templates/rain/package.json +14 -9
- package/templates/rain/playtests/performance.playtest.json +1 -1
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/render/bloom-shader.ts +1 -1
- package/templates/rain/src/render/clouds-shader.ts +2 -2
- package/templates/rain/src/render/clouds.ts +2 -1
- package/templates/rain/src/render/exposure.ts +11 -109
- package/templates/rain/src/render/post-shader.ts +7 -11
- package/templates/rain/src/render/postprocessing.ts +8 -24
- package/templates/rain/src/render/quality.ts +44 -98
- package/templates/rain/src/render/world-shader.ts +281 -97
- package/templates/rain/src/render/world.ts +82 -2
- package/templates/rain/src/style.css +1 -1
- package/templates/rain/src/ui/GameUi.tsx +6 -2
- package/templates/rain/src/ui/Hud.tsx +1 -1
- package/templates/rain/tools/generate-shaders.mjs +2 -2
- package/templates/rain/tools/tempest-post.frag +4 -6
- package/templates/rain/tools/tempest-world.frag +80 -12
- package/templates/rts/.codex/config.toml +6 -2
- package/templates/rts/.cursor/mcp.json +8 -2
- package/templates/rts/.gemini/settings.json +8 -2
- package/templates/rts/.mcp.json +8 -2
- package/templates/rts/.vscode/mcp.json +9 -2
- package/templates/rts/.zed/settings.json +9 -2
- package/templates/rts/AGENTS.md +15 -16
- package/templates/rts/CLAUDE.md +15 -16
- package/templates/rts/opencode.json +10 -2
- package/templates/rts/package.json +14 -9
- package/templates/rts/playtests/performance.playtest.json +1 -1
- package/templates/rts/playtests/rts-attack.playtest.json +5 -0
- package/templates/rts/playtests/rts-build.playtest.json +20 -1
- package/templates/rts/playtests/rts-orders.playtest.json +1 -1
- package/templates/rts/playtests/rts-pause.playtest.json +112 -0
- package/templates/rts/playtests/rts-train.playtest.json +1 -1
- package/templates/rts/playtests/rts-zoom.playtest.json +81 -0
- package/templates/rts/src/game.ts +29 -7
- package/templates/rts/src/render/army.ts +181 -49
- package/templates/rts/src/render/backlightMaterial.ts +49 -18
- package/templates/rts/src/render/environment.ts +276 -0
- package/templates/rts/src/render/exposure.ts +3 -65
- package/templates/rts/src/render/ground.ts +478 -0
- package/templates/rts/src/render/lighting.ts +62 -11
- package/templates/rts/src/render/materialLighting.ts +2 -11
- package/templates/rts/src/render/materials.ts +47 -118
- package/templates/rts/src/render/palette.ts +30 -13
- package/templates/rts/src/render/picking.ts +18 -0
- package/templates/rts/src/render/postprocessing.ts +4 -4
- package/templates/rts/src/render/quality.ts +64 -85
- package/templates/rts/src/render/resources.ts +21 -22
- package/templates/rts/src/render/sky.ts +9 -12
- package/templates/rts/src/render/terrain.ts +36 -11
- package/templates/rts/src/scenes/Play.ts +373 -38
- package/templates/rts/src/sim/ai.ts +0 -11
- package/templates/rts/src/state.ts +46 -0
- package/templates/rts/src/style.css +1543 -0
- package/templates/rts/src/ui/Commands.tsx +204 -107
- package/templates/rts/src/ui/GameUi.tsx +12 -5
- package/templates/rts/src/ui/Hud.tsx +611 -116
- package/templates/rts/src/ui/Minimap.tsx +103 -37
- package/templates/rts/src/ui/icons.tsx +116 -0
- package/templates/rts/src/ui/labels.ts +73 -0
- package/templates/rts/src/ui/minimapPoint.ts +30 -0
- package/templates/rts/threenative.config.ts +1 -1
- package/templates/runner/.codex/config.toml +6 -2
- package/templates/runner/.cursor/mcp.json +8 -2
- package/templates/runner/.gemini/settings.json +8 -2
- package/templates/runner/.mcp.json +8 -2
- package/templates/runner/.vscode/mcp.json +9 -2
- package/templates/runner/.zed/settings.json +9 -2
- package/templates/runner/AGENTS.md +12 -12
- package/templates/runner/CLAUDE.md +12 -12
- package/templates/runner/opencode.json +10 -2
- package/templates/runner/package.json +15 -10
- package/templates/runner/playtests/near-miss.playtest.json +48 -0
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/playtests/stride.playtest.json +27 -0
- package/templates/runner/playtests/survives.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +3 -1
- package/templates/runner/src/entities/Runner.ts +11 -5
- package/templates/runner/src/render/atmosphere.ts +444 -0
- package/templates/runner/src/render/backlightMaterial.ts +49 -18
- package/templates/runner/src/render/clouds.ts +605 -0
- package/templates/runner/src/render/exposure.ts +6 -111
- package/templates/runner/src/render/gpuSky.ts +752 -0
- package/templates/runner/src/render/kitExposure.ts +20 -0
- package/templates/runner/src/render/lighting.ts +26 -4
- package/templates/runner/src/render/materialLighting.ts +2 -11
- package/templates/runner/src/render/postprocessing.ts +4 -4
- package/templates/runner/src/render/quality.ts +26 -114
- package/templates/runner/src/render/sky.ts +73 -1
- package/templates/runner/src/scenes/Run.ts +19 -15
- package/templates/runner/src/track.ts +12 -3
- package/templates/sailing/.codex/config.toml +6 -2
- package/templates/sailing/.cursor/mcp.json +8 -2
- package/templates/sailing/.gemini/settings.json +8 -2
- package/templates/sailing/.mcp.json +8 -2
- package/templates/sailing/.vscode/mcp.json +9 -2
- package/templates/sailing/.zed/settings.json +9 -2
- package/templates/sailing/AGENTS.md +10 -11
- package/templates/sailing/CLAUDE.md +10 -11
- package/templates/sailing/opencode.json +10 -2
- package/templates/sailing/package.json +15 -10
- package/templates/sailing/playtests/fail.playtest.json +46 -5
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +7 -0
- package/templates/sailing/playtests/performance.playtest.json +1 -1
- package/templates/sailing/src/game.ts +1 -0
- package/templates/sailing/src/render/backlightMaterial.ts +49 -18
- package/templates/sailing/src/render/exposure.ts +6 -111
- package/templates/sailing/src/render/kitExposure.ts +20 -0
- package/templates/sailing/src/render/materialLighting.ts +2 -11
- package/templates/sailing/src/render/ocean.ts +0 -1
- package/templates/sailing/src/render/postprocessing.ts +4 -4
- package/templates/sailing/src/render/quality.ts +31 -138
- package/templates/sailing/src/scenes/Sailing.ts +12 -4
- package/templates/sailing/src/ui/Hud.tsx +6 -2
- package/templates/sailing/src/ui/Menu.tsx +1 -1
- package/templates/shooter/.codex/config.toml +6 -2
- package/templates/shooter/.cursor/mcp.json +8 -2
- package/templates/shooter/.gemini/settings.json +8 -2
- package/templates/shooter/.mcp.json +8 -2
- package/templates/shooter/.vscode/mcp.json +9 -2
- package/templates/shooter/.zed/settings.json +9 -2
- package/templates/shooter/AGENTS.md +13 -12
- package/templates/shooter/CLAUDE.md +13 -12
- package/templates/shooter/index.html +1 -1
- package/templates/shooter/main.html +13 -0
- package/templates/shooter/opencode.json +10 -2
- package/templates/shooter/package.json +15 -10
- package/templates/shooter/playtests/breakable-shatters.playtest.json +6 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +6 -0
- package/templates/shooter/playtests/hands-authored-rate.playtest.json +54 -0
- package/templates/shooter/playtests/movement-eases.playtest.json +53 -0
- package/templates/shooter/playtests/performance.playtest.json +3 -3
- package/templates/shooter/playtests/stairs-smooth-the-eye.playtest.json +56 -0
- package/templates/shooter/playtests/weapon-sharp-while-turning.playtest.json +206 -0
- package/templates/shooter/src/entities/Breakables.ts +34 -10
- package/templates/shooter/src/entities/Enemy.ts +176 -54
- package/templates/shooter/src/entities/FpsPlayer.ts +55 -16
- package/templates/shooter/src/entities/Rifle.ts +83 -9
- package/templates/shooter/src/entities/movement.ts +96 -0
- package/templates/shooter/src/render/atmosphere.ts +444 -0
- package/templates/shooter/src/render/backlightMaterial.ts +49 -18
- package/templates/shooter/src/render/camera.ts +3 -1
- package/templates/shooter/src/render/clouds.ts +605 -0
- package/templates/shooter/src/render/exposure.ts +10 -109
- package/templates/shooter/src/render/facade.ts +26 -68
- package/templates/shooter/src/render/gpuSky.ts +752 -0
- package/templates/shooter/src/render/lighting.ts +27 -4
- package/templates/shooter/src/render/materialAssignments.ts +9 -1
- package/templates/shooter/src/render/materialLighting.ts +2 -11
- package/templates/shooter/src/render/occlusion.ts +13 -4
- package/templates/shooter/src/render/palette.ts +1 -0
- package/templates/shooter/src/render/postprocessing.ts +4 -4
- package/templates/shooter/src/render/quality.ts +50 -108
- package/templates/shooter/src/render/scale.ts +0 -11
- package/templates/shooter/src/render/sky.ts +103 -2
- package/templates/shooter/src/render/surface.ts +140 -0
- package/templates/shooter/src/render/town.ts +3 -6
- package/templates/shooter/src/render/townMaterials.ts +95 -42
- package/templates/shooter/src/render/vehicles.ts +2 -0
- package/templates/shooter/src/scenes/Play.ts +83 -23
- package/templates/shooter/src/ui/Hud.tsx +268 -193
- package/templates/shooter/src/worker-page.ts +29 -0
- package/templates/shooter/src/worker.ts +5 -0
- package/templates/shooter/threenative.config.ts +3 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/.codex/config.toml +6 -2
- package/templates/snow/.cursor/mcp.json +8 -2
- package/templates/snow/.gemini/settings.json +8 -2
- package/templates/snow/.mcp.json +8 -2
- package/templates/snow/.vscode/mcp.json +9 -2
- package/templates/snow/.zed/settings.json +9 -2
- package/templates/snow/AGENTS.md +12 -10
- package/templates/snow/CLAUDE.md +12 -10
- package/templates/snow/opencode.json +10 -2
- package/templates/snow/package.json +15 -10
- package/templates/snow/playtests/performance.playtest.json +1 -1
- package/templates/snow/src/render/backlightMaterial.ts +49 -18
- package/templates/snow/src/render/exposure.ts +17 -106
- package/templates/snow/src/render/materialLighting.ts +2 -11
- package/templates/snow/src/render/postprocessing.ts +11 -5
- package/templates/snow/src/render/quality.ts +46 -126
- package/templates/snow/src/render/snowSurface.ts +32 -15
- package/templates/snow/src/scenes/Snow.ts +2 -1
- package/templates/starter/.codex/config.toml +6 -2
- package/templates/starter/.cursor/mcp.json +8 -2
- package/templates/starter/.gemini/settings.json +8 -2
- package/templates/starter/.mcp.json +8 -2
- package/templates/starter/.vscode/mcp.json +9 -2
- package/templates/starter/.zed/settings.json +9 -2
- package/templates/starter/AGENTS.md +18 -14
- package/templates/starter/CLAUDE.md +18 -14
- package/templates/starter/index.html +1 -1
- package/templates/starter/main.html +12 -0
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -0
- package/templates/starter/native-playtests/render-chain.playtest.json +34 -21
- package/templates/starter/opencode.json +10 -2
- package/templates/starter/package.json +15 -10
- package/templates/starter/playtests/play.playtest.json +22 -2
- package/templates/starter/playtests/production-readiness.playtest.json +14 -0
- package/templates/starter/src/entities/Crate.ts +19 -1
- package/templates/starter/src/render/arena.ts +2 -2
- package/templates/starter/src/render/atmosphere.ts +444 -0
- package/templates/starter/src/render/backlightMaterial.ts +49 -18
- package/templates/starter/src/render/camera.ts +28 -0
- package/templates/starter/src/render/clouds.ts +605 -0
- package/templates/starter/src/render/contactShadow.ts +50 -0
- package/templates/starter/src/render/exposure.ts +9 -111
- package/templates/starter/src/render/gpuSky.ts +752 -0
- package/templates/starter/src/render/grade.ts +1 -1
- package/templates/starter/src/render/lighting.ts +34 -6
- package/templates/starter/src/render/materialLighting.ts +2 -11
- package/templates/starter/src/render/postprocessing.ts +27 -14
- package/templates/starter/src/render/quality.ts +18 -147
- package/templates/starter/src/render/sky.ts +90 -40
- package/templates/starter/src/render/temporalAA.ts +1 -1
- package/templates/starter/src/render/temporalAAStage.ts +1 -1
- package/templates/starter/src/render/temporalCurrentFootprint.ts +0 -1
- package/templates/starter/src/render/temporalDetailStage.ts +106 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +2 -2
- package/templates/starter/src/render/volumetricFogCamera.ts +32 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +7 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +27 -19
- package/templates/starter/src/render/volumetricFogVolume.ts +31 -7
- package/templates/starter/src/scenes/Play.ts +11 -8
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/worker-page.ts +29 -0
- package/templates/starter/src/worker.ts +5 -0
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/.codex/config.toml +6 -2
- package/templates/tower-defense/.cursor/mcp.json +8 -2
- package/templates/tower-defense/.gemini/settings.json +8 -2
- package/templates/tower-defense/.mcp.json +8 -2
- package/templates/tower-defense/.vscode/mcp.json +9 -2
- package/templates/tower-defense/.zed/settings.json +9 -2
- package/templates/tower-defense/AGENTS.md +10 -12
- package/templates/tower-defense/CLAUDE.md +10 -12
- package/templates/tower-defense/opencode.json +10 -2
- package/templates/tower-defense/package.json +15 -10
- package/templates/tower-defense/playtests/chill-tint.playtest.json +387 -0
- package/templates/tower-defense/playtests/performance.playtest.json +1 -1
- package/templates/tower-defense/src/enemies/Enemy.ts +9 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +49 -18
- package/templates/tower-defense/src/render/exposure.ts +11 -109
- package/templates/tower-defense/src/render/lighting.ts +4 -2
- package/templates/tower-defense/src/render/materialLighting.ts +2 -11
- package/templates/tower-defense/src/render/postprocessing.ts +4 -4
- package/templates/tower-defense/src/render/quality.ts +10 -116
- package/templates/tower-defense/src/render/sky.ts +2 -2
- package/templates/tower-defense/src/scenes/Battle.ts +4 -0
- package/template-assets/autoExposure.ts +0 -225
- package/template-assets/exposureGraph.ts +0 -178
- package/template-assets/exposureReadback.ts +0 -79
- package/template-assets/worldEnvironment.ts +0 -1212
- package/templates/action-rpg/src/render/autoExposure.ts +0 -225
- package/templates/action-rpg/src/render/exposureGraph.ts +0 -178
- package/templates/action-rpg/src/render/exposureReadback.ts +0 -79
- package/templates/action-rpg/src/render/worldEnvironment.ts +0 -1212
- package/templates/minimal/src/render/autoExposure.ts +0 -225
- package/templates/minimal/src/render/exposureGraph.ts +0 -178
- package/templates/minimal/src/render/exposureReadback.ts +0 -79
- package/templates/minimal/src/render/worldEnvironment.ts +0 -1212
- package/templates/platformer/src/render/autoExposure.ts +0 -225
- package/templates/platformer/src/render/exposureGraph.ts +0 -178
- package/templates/platformer/src/render/exposureReadback.ts +0 -79
- package/templates/platformer/src/render/worldEnvironment.ts +0 -1212
- package/templates/puzzle/src/render/autoExposure.ts +0 -225
- package/templates/puzzle/src/render/exposureGraph.ts +0 -178
- package/templates/puzzle/src/render/exposureReadback.ts +0 -79
- package/templates/puzzle/src/render/worldEnvironment.ts +0 -1212
- package/templates/racing/src/render/autoExposure.ts +0 -225
- package/templates/racing/src/render/exposureGraph.ts +0 -178
- package/templates/racing/src/render/exposureReadback.ts +0 -79
- package/templates/racing/src/render/worldEnvironment.ts +0 -1212
- package/templates/rain/src/render/autoExposure.ts +0 -225
- package/templates/rain/src/render/exposureGraph.ts +0 -178
- package/templates/rain/src/render/exposureReadback.ts +0 -79
- package/templates/rain/src/render/worldEnvironment.ts +0 -1212
- package/templates/rts/src/render/autoExposure.ts +0 -225
- package/templates/rts/src/render/exposureGraph.ts +0 -178
- package/templates/rts/src/render/exposureReadback.ts +0 -79
- package/templates/rts/src/render/worldEnvironment.ts +0 -1212
- package/templates/runner/src/render/autoExposure.ts +0 -225
- package/templates/runner/src/render/exposureGraph.ts +0 -178
- package/templates/runner/src/render/exposureReadback.ts +0 -79
- package/templates/runner/src/render/worldEnvironment.ts +0 -1212
- package/templates/sailing/src/render/autoExposure.ts +0 -225
- package/templates/sailing/src/render/exposureGraph.ts +0 -178
- package/templates/sailing/src/render/exposureReadback.ts +0 -79
- package/templates/sailing/src/render/worldEnvironment.ts +0 -1212
- package/templates/shooter/src/render/autoExposure.ts +0 -225
- package/templates/shooter/src/render/exposureGraph.ts +0 -178
- package/templates/shooter/src/render/exposureReadback.ts +0 -79
- package/templates/shooter/src/render/worldEnvironment.ts +0 -1212
- package/templates/snow/src/render/autoExposure.ts +0 -225
- package/templates/snow/src/render/exposureGraph.ts +0 -178
- package/templates/snow/src/render/exposureReadback.ts +0 -79
- package/templates/snow/src/render/worldEnvironment.ts +0 -1212
- package/templates/starter/src/render/autoExposure.ts +0 -225
- package/templates/starter/src/render/exposureGraph.ts +0 -178
- package/templates/starter/src/render/exposureReadback.ts +0 -79
- package/templates/starter/src/render/worldEnvironment.ts +0 -1212
- package/templates/tower-defense/src/render/autoExposure.ts +0 -225
- package/templates/tower-defense/src/render/exposureGraph.ts +0 -178
- package/templates/tower-defense/src/render/exposureReadback.ts +0 -79
- package/templates/tower-defense/src/render/worldEnvironment.ts +0 -1212
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
// Generated for you. Ordinary Three.js and TSL: the sky your sun lights; edit or delete it freely.
|
|
2
|
+
// Independent model port, no Unreal code: Engine/Shaders/Private/SkyAtmosphere.usf,
|
|
3
|
+
// VolumetricCloud.usf, and Source/Runtime/Renderer/Private/{SkyAtmosphere,VolumetricCloud}Rendering.cpp
|
|
4
|
+
// under ~/UnrealEngine-5.8.3/Engine. Physical constants remain in atmosphere.ts and clouds.ts.
|
|
5
|
+
import {
|
|
6
|
+
ClampToEdgeWrapping,
|
|
7
|
+
Color,
|
|
8
|
+
Data3DTexture,
|
|
9
|
+
DataTexture,
|
|
10
|
+
FloatType,
|
|
11
|
+
HalfFloatType,
|
|
12
|
+
LinearFilter,
|
|
13
|
+
RGBAFormat,
|
|
14
|
+
RenderTarget,
|
|
15
|
+
RepeatWrapping,
|
|
16
|
+
type Scene,
|
|
17
|
+
UnsignedByteType,
|
|
18
|
+
Vector3,
|
|
19
|
+
} from "three";
|
|
20
|
+
import {
|
|
21
|
+
Fn,
|
|
22
|
+
If,
|
|
23
|
+
Loop,
|
|
24
|
+
cameraPosition,
|
|
25
|
+
clamp,
|
|
26
|
+
float,
|
|
27
|
+
mix,
|
|
28
|
+
nodeObject,
|
|
29
|
+
positionWorldDirection,
|
|
30
|
+
texture,
|
|
31
|
+
texture3D,
|
|
32
|
+
uniform,
|
|
33
|
+
uv,
|
|
34
|
+
vec2,
|
|
35
|
+
vec3,
|
|
36
|
+
vec4,
|
|
37
|
+
} from "three/tsl";
|
|
38
|
+
import {
|
|
39
|
+
type Node,
|
|
40
|
+
type NodeBuilder,
|
|
41
|
+
type NodeFrame,
|
|
42
|
+
NodeMaterial,
|
|
43
|
+
NodeUpdateType,
|
|
44
|
+
QuadMesh,
|
|
45
|
+
RendererUtils,
|
|
46
|
+
TempNode,
|
|
47
|
+
} from "three/webgpu";
|
|
48
|
+
import {
|
|
49
|
+
BOTTOM_KM,
|
|
50
|
+
CAMERA_KM,
|
|
51
|
+
GROUND_ALBEDO,
|
|
52
|
+
MIE_ABSORB,
|
|
53
|
+
MIE_G,
|
|
54
|
+
MIE_SCATTER,
|
|
55
|
+
OZONE,
|
|
56
|
+
RAYLEIGH,
|
|
57
|
+
SKY_TO_SUN,
|
|
58
|
+
SUN_ILLUMINANCE,
|
|
59
|
+
SUN_KELVIN,
|
|
60
|
+
TOP_KM,
|
|
61
|
+
bakeSkyRadiance,
|
|
62
|
+
sunLight,
|
|
63
|
+
sunLightTransmittance,
|
|
64
|
+
sunTransmittance,
|
|
65
|
+
temperatureColour,
|
|
66
|
+
viewDistanceSkyLight,
|
|
67
|
+
} from "./atmosphere.js";
|
|
68
|
+
import {
|
|
69
|
+
CLOUD_BOTTOM_KM,
|
|
70
|
+
CLOUD_MATERIAL,
|
|
71
|
+
CLOUD_MODEL,
|
|
72
|
+
CLOUD_TOP_KM,
|
|
73
|
+
PATTERN_SIZE,
|
|
74
|
+
VOLUME_SIZE,
|
|
75
|
+
bakeCloudRadiance,
|
|
76
|
+
cloudOctaves,
|
|
77
|
+
cloudProfileTexture,
|
|
78
|
+
cloudTextures,
|
|
79
|
+
} from "./clouds.js";
|
|
80
|
+
|
|
81
|
+
/** Exponential height fog, in metres: density at `fogHeight` (base 2) and falloff per metre. */
|
|
82
|
+
export interface ISkyFog {
|
|
83
|
+
readonly density: number;
|
|
84
|
+
readonly heightFalloff: number;
|
|
85
|
+
readonly fogHeight: number;
|
|
86
|
+
}
|
|
87
|
+
const HEIGHT_FOG_DEFAULT: ISkyFog = { density: 0.0021, heightFalloff: 0.08, fogHeight: 0 };
|
|
88
|
+
|
|
89
|
+
const GPU_SKY_SIZES = {
|
|
90
|
+
transmittance: [256, 64],
|
|
91
|
+
multi: [32, 32],
|
|
92
|
+
sky: [192, 108],
|
|
93
|
+
clouds: [4096, 2048],
|
|
94
|
+
} as const;
|
|
95
|
+
const GPU_CLOUD_STEPS = {
|
|
96
|
+
view: CLOUD_MODEL.maxViewSteps,
|
|
97
|
+
light: CLOUD_MODEL.lightSteps,
|
|
98
|
+
} as const;
|
|
99
|
+
const R0 = BOTTOM_KM + CAMERA_KM;
|
|
100
|
+
const HORIZON = Math.acos(-Math.sqrt(R0 * R0 - BOTTOM_KM * BOTTOM_KM) / R0);
|
|
101
|
+
const SUN_RADIUS = (0.7357000112533569 * Math.PI) / 360;
|
|
102
|
+
const PI = Math.PI;
|
|
103
|
+
type Scalar = Node<"float">;
|
|
104
|
+
type Direction = Node<"vec3">;
|
|
105
|
+
|
|
106
|
+
function skyDirection(at: Node<"vec2">): Direction {
|
|
107
|
+
const z = at.y.lessThan(0.5).select(
|
|
108
|
+
float(1)
|
|
109
|
+
.sub(float(1).sub(at.y.mul(2)).pow(2))
|
|
110
|
+
.mul(HORIZON),
|
|
111
|
+
at.y
|
|
112
|
+
.mul(2)
|
|
113
|
+
.sub(1)
|
|
114
|
+
.pow(2)
|
|
115
|
+
.mul(PI - HORIZON)
|
|
116
|
+
.add(HORIZON),
|
|
117
|
+
);
|
|
118
|
+
const a = at.x.mul(2 * PI);
|
|
119
|
+
return vec3(z.sin().mul(a.cos()), z.cos(), z.sin().mul(a.sin()));
|
|
120
|
+
}
|
|
121
|
+
function skyUv(d: Direction) {
|
|
122
|
+
const z = clamp(d.y, -1, 1).acos();
|
|
123
|
+
const v = z.lessThan(HORIZON).select(
|
|
124
|
+
float(1)
|
|
125
|
+
.sub(float(1).sub(z.div(HORIZON)).max(0).sqrt())
|
|
126
|
+
.mul(0.5),
|
|
127
|
+
z
|
|
128
|
+
.sub(HORIZON)
|
|
129
|
+
.max(0)
|
|
130
|
+
.div(PI - HORIZON)
|
|
131
|
+
.sqrt()
|
|
132
|
+
.add(1)
|
|
133
|
+
.mul(0.5),
|
|
134
|
+
);
|
|
135
|
+
return vec2(
|
|
136
|
+
d.z
|
|
137
|
+
.atan(d.x)
|
|
138
|
+
.div(2 * PI)
|
|
139
|
+
.add(1)
|
|
140
|
+
.fract(),
|
|
141
|
+
v,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function exit(r: Scalar, mu: Scalar, radius: number) {
|
|
145
|
+
return r
|
|
146
|
+
.mul(mu)
|
|
147
|
+
.negate()
|
|
148
|
+
.add(
|
|
149
|
+
r
|
|
150
|
+
.mul(mu)
|
|
151
|
+
.pow(2)
|
|
152
|
+
.add(radius * radius)
|
|
153
|
+
.sub(r.mul(r))
|
|
154
|
+
.max(0)
|
|
155
|
+
.sqrt(),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
function ground(r: Scalar, mu: Scalar) {
|
|
159
|
+
const disc = r
|
|
160
|
+
.mul(mu)
|
|
161
|
+
.pow(2)
|
|
162
|
+
.sub(r.mul(r))
|
|
163
|
+
.add(BOTTOM_KM * BOTTOM_KM);
|
|
164
|
+
return mu.lessThan(0).and(disc.greaterThanEqual(0));
|
|
165
|
+
}
|
|
166
|
+
/** Same local medium as atmosphere.medium, in inverse kilometres. */
|
|
167
|
+
function gpuMedium(h: Scalar) {
|
|
168
|
+
const ray = vec3(...RAYLEIGH).mul(h.div(-8).exp());
|
|
169
|
+
const mie = h.div(-1.2).exp().mul(MIE_SCATTER);
|
|
170
|
+
const ozone = clamp(h.lessThan(25).select(h.div(15).sub(2 / 3), h.div(-15).add(8 / 3)), 0, 1);
|
|
171
|
+
return {
|
|
172
|
+
ray,
|
|
173
|
+
mie,
|
|
174
|
+
ext: ray.add(mie.mul((MIE_SCATTER + MIE_ABSORB) / MIE_SCATTER)).add(vec3(...OZONE).mul(ozone)),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function gpuHg(c: Scalar, g: number): Scalar {
|
|
178
|
+
return float((1 - g * g) / (4 * PI)).div(
|
|
179
|
+
float(1 + g * g)
|
|
180
|
+
.sub(c.mul(2 * g))
|
|
181
|
+
.pow(1.5),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function target(size: readonly [number, number]) {
|
|
185
|
+
return new RenderTarget(...size, {
|
|
186
|
+
type: HalfFloatType,
|
|
187
|
+
depthBuffer: false,
|
|
188
|
+
minFilter: LinearFilter,
|
|
189
|
+
magFilter: LinearFilter,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function material(colour: Node) {
|
|
193
|
+
const m = new NodeMaterial();
|
|
194
|
+
m.fragmentNode = colour;
|
|
195
|
+
m.toneMapped = false;
|
|
196
|
+
m.depthTest = false;
|
|
197
|
+
m.depthWrite = false;
|
|
198
|
+
return m;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The cloud material's density on the GPU: the same generated textures as cloudDensityField. */
|
|
202
|
+
function cloudNoise() {
|
|
203
|
+
const { pattern, volume } = cloudTextures();
|
|
204
|
+
const rgba = new Float32Array(VOLUME_SIZE ** 3 * 4);
|
|
205
|
+
for (let i = 0; i < VOLUME_SIZE ** 3; i++) {
|
|
206
|
+
rgba[i * 4] = volume[i * 2] ?? 0;
|
|
207
|
+
rgba[i * 4 + 1] = volume[i * 2 + 1] ?? 0;
|
|
208
|
+
}
|
|
209
|
+
const map = new Data3DTexture(rgba, VOLUME_SIZE, VOLUME_SIZE, VOLUME_SIZE);
|
|
210
|
+
const patternMap = new DataTexture(pattern, PATTERN_SIZE, PATTERN_SIZE, RGBAFormat, FloatType);
|
|
211
|
+
const profileMap = new DataTexture(cloudProfileTexture(), 64, 64, RGBAFormat, FloatType);
|
|
212
|
+
for (const t of [map, patternMap, profileMap]) {
|
|
213
|
+
t.minFilter = t.magFilter = LinearFilter;
|
|
214
|
+
t.wrapS = t.wrapT = RepeatWrapping;
|
|
215
|
+
t.needsUpdate = true;
|
|
216
|
+
}
|
|
217
|
+
map.type = FloatType;
|
|
218
|
+
map.format = RGBAFormat;
|
|
219
|
+
map.wrapR = RepeatWrapping;
|
|
220
|
+
profileMap.wrapS = profileMap.wrapT = ClampToEdgeWrapping;
|
|
221
|
+
const volumeSample = texture3D(map);
|
|
222
|
+
const patternSample = texture(patternMap);
|
|
223
|
+
const profileSample = texture(profileMap);
|
|
224
|
+
const m = CLOUD_MATERIAL;
|
|
225
|
+
const volumeAt = (p: Direction) => volumeSample.sample(p).level(float(0));
|
|
226
|
+
return {
|
|
227
|
+
map,
|
|
228
|
+
patternMap,
|
|
229
|
+
profileMap,
|
|
230
|
+
/** Extinction per metre at planet-centred p in km. */
|
|
231
|
+
density: (p: Direction) => {
|
|
232
|
+
const altitude = p.length().sub(BOTTOM_KM);
|
|
233
|
+
const h = altitude.sub(CLOUD_BOTTOM_KM).div(CLOUD_TOP_KM - CLOUD_BOTTOM_KM);
|
|
234
|
+
const uv = vec2(p.x, p.z).div(m.layoutKm);
|
|
235
|
+
const pat = patternSample.sample(uv).level(float(0)).rgb;
|
|
236
|
+
const coverage = pat.x.max(pat.y).max(pat.z);
|
|
237
|
+
const profileAt = (channel: "x" | "y" | "z") =>
|
|
238
|
+
profileSample.sample(vec2(h, pat[channel])).level(float(0))[channel];
|
|
239
|
+
const profile = profileAt("x").max(profileAt("y")).max(profileAt("z")).sub(0.5);
|
|
240
|
+
const sky = vec3(uv.x.add(0.5), uv.y.add(0.5), p.y.sub(BOTTOM_KM).div(m.layoutKm));
|
|
241
|
+
const a = h.mul(0.95).add(0.05);
|
|
242
|
+
const c = a.sub(0.5).abs().mul(2).pow(2);
|
|
243
|
+
const warp = volumeAt(sky.mul(vec3(...m.noise2Scale)))
|
|
244
|
+
.r.sub(m.noiseBias[1])
|
|
245
|
+
.mul(m.noiseStrength[1]);
|
|
246
|
+
const shape = volumeAt(sky.mul(vec3(...m.noise1Scale)).add(vec3(a, a, c).mul(warp))).g;
|
|
247
|
+
const noise = shape.sub(m.noiseBias[0]).add(m.coverage).mul(m.noiseStrength[0]);
|
|
248
|
+
const inside = h.greaterThanEqual(m.insideLayer[0]).and(h.lessThanEqual(m.insideLayer[1]));
|
|
249
|
+
return inside.select(clamp(coverage.mul(profile.add(noise)).mul(m.density), 0, 1), float(0));
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 1 draws the analytic sun disc, 0 hides it. Unreal draws no disc into a reflection capture, so the
|
|
256
|
+
* chrome sphere shows the sky and its clouds but no hard flare (SkyAtmosphereRendering.cpp, the
|
|
257
|
+
* SourceDiskEnabled pass parameter); `captureReflections` switches it off for its faces.
|
|
258
|
+
*/
|
|
259
|
+
const skyDisc = uniform(1);
|
|
260
|
+
|
|
261
|
+
/** Cached passes: only texture reads and the analytic disc run at screen resolution. */
|
|
262
|
+
class GpuSkyNode extends TempNode<"vec3"> {
|
|
263
|
+
static get type(): string {
|
|
264
|
+
return "GpuSkyNode";
|
|
265
|
+
}
|
|
266
|
+
readonly targets = {
|
|
267
|
+
transmittance: target(GPU_SKY_SIZES.transmittance),
|
|
268
|
+
multi: target(GPU_SKY_SIZES.multi),
|
|
269
|
+
sky: target(GPU_SKY_SIZES.sky),
|
|
270
|
+
clouds: target(GPU_SKY_SIZES.clouds),
|
|
271
|
+
};
|
|
272
|
+
readonly materials: NodeMaterial[] = [];
|
|
273
|
+
readonly sun = uniform(new Vector3());
|
|
274
|
+
readonly #quad = new QuadMesh();
|
|
275
|
+
readonly #noise = cloudNoise();
|
|
276
|
+
readonly #fog = uniform(new Color());
|
|
277
|
+
readonly #scale = vec3(...temperatureColour(SUN_KELVIN)).mul(SUN_ILLUMINANCE * SKY_TO_SUN);
|
|
278
|
+
readonly #light = uniform(new Vector3());
|
|
279
|
+
readonly #ambient = uniform(new Vector3());
|
|
280
|
+
#last = new Vector3(Number.NaN, 0, 0);
|
|
281
|
+
#ready = false;
|
|
282
|
+
#disposed = false;
|
|
283
|
+
/** CPU submission time; GPU execution is asynchronous and must be measured by the coordinator. */
|
|
284
|
+
lastSubmissionMs = 0;
|
|
285
|
+
constructor(
|
|
286
|
+
readonly direction: Vector3,
|
|
287
|
+
readonly scene: Scene,
|
|
288
|
+
readonly fogged: boolean,
|
|
289
|
+
readonly clouds: boolean,
|
|
290
|
+
readonly refreshEnvironment?: () => void,
|
|
291
|
+
readonly fog?: ISkyFog,
|
|
292
|
+
) {
|
|
293
|
+
super("vec3");
|
|
294
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
295
|
+
const trans = texture(this.targets.transmittance.texture);
|
|
296
|
+
// Distance-to-top parametrisation resolves the grazing optical depth without a discontinuity.
|
|
297
|
+
const maxRho = Math.sqrt(TOP_KM * TOP_KM - BOTTOM_KM * BOTTOM_KM);
|
|
298
|
+
const transmission = (r: Scalar, mu: Scalar) => {
|
|
299
|
+
const rho = r
|
|
300
|
+
.mul(r)
|
|
301
|
+
.sub(BOTTOM_KM * BOTTOM_KM)
|
|
302
|
+
.max(0)
|
|
303
|
+
.sqrt();
|
|
304
|
+
const distance = exit(r, mu, TOP_KM);
|
|
305
|
+
const min = float(TOP_KM).sub(r);
|
|
306
|
+
const max = rho.add(maxRho);
|
|
307
|
+
const at = vec2(distance.sub(min).div(max.sub(min)), rho.div(maxRho));
|
|
308
|
+
return ground(r, mu).select(vec3(0), trans.sample(at).level(float(0)).rgb);
|
|
309
|
+
};
|
|
310
|
+
this.materials.push(
|
|
311
|
+
material(
|
|
312
|
+
Fn(() => {
|
|
313
|
+
const rho = uv().y.mul(maxRho);
|
|
314
|
+
const r = rho
|
|
315
|
+
.mul(rho)
|
|
316
|
+
.add(BOTTOM_KM * BOTTOM_KM)
|
|
317
|
+
.sqrt();
|
|
318
|
+
const min = float(TOP_KM).sub(r);
|
|
319
|
+
const distance = mix(min, rho.add(maxRho), uv().x).max(1e-6);
|
|
320
|
+
const mu = float(TOP_KM * TOP_KM)
|
|
321
|
+
.sub(r.mul(r))
|
|
322
|
+
.sub(distance.mul(distance))
|
|
323
|
+
.div(r.mul(distance).mul(2));
|
|
324
|
+
// Unreal's transmittance pass: ten equal segments, each read 0.3 of the way in
|
|
325
|
+
// (r.SkyAtmosphere.TransmittanceLUT.SampleCount, DEFAULT_SAMPLE_OFFSET in SkyAtmosphere.usf).
|
|
326
|
+
const depth = vec3(0).toVar();
|
|
327
|
+
Loop(10, ({ i }) => {
|
|
328
|
+
const t = float(i).add(0.3).div(10).mul(distance);
|
|
329
|
+
const h = r
|
|
330
|
+
.mul(r)
|
|
331
|
+
.add(r.mul(mu).mul(t).mul(2))
|
|
332
|
+
.add(t.mul(t))
|
|
333
|
+
.sqrt()
|
|
334
|
+
.sub(BOTTOM_KM)
|
|
335
|
+
.max(0);
|
|
336
|
+
depth.addAssign(gpuMedium(h).ext.mul(distance.div(10)));
|
|
337
|
+
});
|
|
338
|
+
return vec4(depth.negate().exp(), 1);
|
|
339
|
+
})(),
|
|
340
|
+
),
|
|
341
|
+
);
|
|
342
|
+
const multi = texture(this.targets.multi.texture);
|
|
343
|
+
const march = (r: Scalar, d: Direction, sun: Direction, iso: boolean) => {
|
|
344
|
+
const isGround = ground(r, d.y);
|
|
345
|
+
const length = isGround.select(
|
|
346
|
+
r
|
|
347
|
+
.mul(d.y)
|
|
348
|
+
.negate()
|
|
349
|
+
.sub(
|
|
350
|
+
r
|
|
351
|
+
.mul(d.y)
|
|
352
|
+
.pow(2)
|
|
353
|
+
.sub(r.mul(r))
|
|
354
|
+
.add(BOTTOM_KM * BOTTOM_KM)
|
|
355
|
+
.max(0)
|
|
356
|
+
.sqrt(),
|
|
357
|
+
),
|
|
358
|
+
exit(r, d.y, TOP_KM),
|
|
359
|
+
);
|
|
360
|
+
const cosine = d.dot(sun);
|
|
361
|
+
const phaseR = iso
|
|
362
|
+
? float(1 / (4 * PI))
|
|
363
|
+
: cosine
|
|
364
|
+
.pow(2)
|
|
365
|
+
.add(1)
|
|
366
|
+
.mul(3 / (16 * PI));
|
|
367
|
+
const phaseM = iso ? float(1 / (4 * PI)) : gpuHg(cosine, MIE_G);
|
|
368
|
+
const radiance = vec3(0).toVar();
|
|
369
|
+
const transfer = vec3(0).toVar();
|
|
370
|
+
const through = vec3(1).toVar();
|
|
371
|
+
// Unreal's counts: the multiple-scattering pass takes 15 equal segments read 0.3 of the way in; the
|
|
372
|
+
// sky pass takes 4 to 32 (by the ray's length over 150 km) with segments that grow with the square of
|
|
373
|
+
// the distance, the last one running on to the end of the ray (SamplingSetup in SkyAtmosphere.usf).
|
|
374
|
+
const count = iso ? float(15) : mix(float(4), float(32), clamp(length.div(150), 0, 1));
|
|
375
|
+
const whole = count.floor();
|
|
376
|
+
const lengthWhole = length.mul(whole).div(count);
|
|
377
|
+
const body = (i: Scalar) => {
|
|
378
|
+
const u0 = i.div(whole).pow(2);
|
|
379
|
+
const u1 = i.add(1).div(whole).pow(2);
|
|
380
|
+
const a = iso ? i.div(15).mul(length) : lengthWhole.mul(u0);
|
|
381
|
+
const b = iso
|
|
382
|
+
? i.add(1).div(15).mul(length)
|
|
383
|
+
: u1.greaterThan(1).select(length, lengthWhole.mul(u1));
|
|
384
|
+
const t = iso ? i.add(0.3).div(15).mul(length) : a.add(b.sub(a).mul(0.3));
|
|
385
|
+
const p = vec3(0, r, 0).add(d.mul(t));
|
|
386
|
+
const rr = p.length();
|
|
387
|
+
const h = rr.sub(BOTTOM_KM).max(0);
|
|
388
|
+
const mu = p.dot(sun).div(rr);
|
|
389
|
+
const m = gpuMedium(h);
|
|
390
|
+
const scatter = m.ray.add(m.mie);
|
|
391
|
+
const stepT = m.ext.mul(b.sub(a)).negate().exp();
|
|
392
|
+
const integral = vec3(1).sub(stepT).div(m.ext.max(1e-12));
|
|
393
|
+
const source = transmission(rr, mu)
|
|
394
|
+
.mul(m.ray.mul(phaseR).add(m.mie.mul(phaseM)))
|
|
395
|
+
.toVar();
|
|
396
|
+
if (!iso)
|
|
397
|
+
source.addAssign(
|
|
398
|
+
multi
|
|
399
|
+
.sample(vec2(mu.add(1).mul(0.5), h.div(TOP_KM - BOTTOM_KM).sqrt()))
|
|
400
|
+
.level(float(0))
|
|
401
|
+
.rgb.mul(scatter),
|
|
402
|
+
);
|
|
403
|
+
radiance.addAssign(through.mul(source).mul(integral));
|
|
404
|
+
transfer.addAssign(through.mul(scatter).mul(integral));
|
|
405
|
+
through.mulAssign(stepT);
|
|
406
|
+
};
|
|
407
|
+
if (iso) Loop(15, ({ i }) => body(float(i)));
|
|
408
|
+
else
|
|
409
|
+
Loop(32, ({ i }) => {
|
|
410
|
+
If(float(i).lessThan(count.ceil()), () => body(float(i)));
|
|
411
|
+
});
|
|
412
|
+
if (iso) {
|
|
413
|
+
const p = vec3(0, r, 0).add(d.mul(length));
|
|
414
|
+
const rr = p.length();
|
|
415
|
+
const mu = p.dot(sun).div(rr);
|
|
416
|
+
radiance.addAssign(
|
|
417
|
+
isGround.select(
|
|
418
|
+
through
|
|
419
|
+
.mul(transmission(rr, mu))
|
|
420
|
+
.mul(mu.max(0))
|
|
421
|
+
.mul(GROUND_ALBEDO / PI),
|
|
422
|
+
vec3(0),
|
|
423
|
+
),
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
return { radiance, transfer };
|
|
427
|
+
};
|
|
428
|
+
this.materials.push(
|
|
429
|
+
material(
|
|
430
|
+
Fn(() => {
|
|
431
|
+
const r = uv()
|
|
432
|
+
.y.pow(2)
|
|
433
|
+
.mul(TOP_KM - BOTTOM_KM)
|
|
434
|
+
.add(BOTTOM_KM);
|
|
435
|
+
const mu = uv().x.mul(2).sub(1);
|
|
436
|
+
const sun = vec3(float(1).sub(mu.pow(2)).max(0).sqrt(), mu, 0);
|
|
437
|
+
const up = march(r, vec3(0, 1, 0), sun, true);
|
|
438
|
+
const down = march(r, vec3(0, -1, 0), sun, true);
|
|
439
|
+
return vec4(
|
|
440
|
+
up.radiance
|
|
441
|
+
.add(down.radiance)
|
|
442
|
+
.mul(0.5)
|
|
443
|
+
.div(vec3(1).sub(up.transfer.add(down.transfer).mul(0.5).min(0.99))),
|
|
444
|
+
1,
|
|
445
|
+
);
|
|
446
|
+
})(),
|
|
447
|
+
),
|
|
448
|
+
);
|
|
449
|
+
this.materials.push(
|
|
450
|
+
material(Fn(() => vec4(march(float(R0), skyDirection(uv()), this.sun, false).radiance, 1))()),
|
|
451
|
+
);
|
|
452
|
+
this.targets.sky.texture.wrapS = RepeatWrapping;
|
|
453
|
+
this.targets.clouds.texture.wrapS = RepeatWrapping;
|
|
454
|
+
const sky = texture(this.targets.sky.texture);
|
|
455
|
+
this.materials.push(
|
|
456
|
+
material(
|
|
457
|
+
Fn(() => {
|
|
458
|
+
// Equirectangular cloud target; sky-view keeps its own horizon-focused parametrisation.
|
|
459
|
+
const theta = uv().y.mul(PI);
|
|
460
|
+
const phi = uv()
|
|
461
|
+
.x.sub(0.5)
|
|
462
|
+
.mul(2 * PI);
|
|
463
|
+
const d = vec3(theta.sin().mul(phi.cos()), theta.cos(), theta.sin().mul(phi.sin()));
|
|
464
|
+
const clear = sky.sample(skyUv(d)).level(float(0)).rgb.toVar();
|
|
465
|
+
const result = clear.toVar();
|
|
466
|
+
const cloudThrough = float(1).toVar();
|
|
467
|
+
const entry = exit(float(R0), d.y, BOTTOM_KM + CLOUD_BOTTOM_KM);
|
|
468
|
+
If(d.y.greaterThan(0).and(entry.lessThanEqual(350)), () => {
|
|
469
|
+
const length = exit(float(R0), d.y, BOTTOM_KM + CLOUD_TOP_KM)
|
|
470
|
+
.sub(entry)
|
|
471
|
+
.min(CLOUD_MODEL.tracingKm);
|
|
472
|
+
const steps = clamp(
|
|
473
|
+
length.mul(1000 / CLOUD_MODEL.viewStepMetres).ceil(),
|
|
474
|
+
CLOUD_MODEL.minViewSteps,
|
|
475
|
+
GPU_CLOUD_STEPS.view,
|
|
476
|
+
);
|
|
477
|
+
const dt = length.div(steps);
|
|
478
|
+
const fadeT = clamp(
|
|
479
|
+
entry
|
|
480
|
+
.sub(CLOUD_MODEL.horizonFadeStartKm)
|
|
481
|
+
.div(CLOUD_MODEL.horizonFadeEndKm - CLOUD_MODEL.horizonFadeStartKm),
|
|
482
|
+
0,
|
|
483
|
+
1,
|
|
484
|
+
);
|
|
485
|
+
const fade = float(1).sub(fadeT.mul(fadeT).mul(float(3).sub(fadeT.mul(2))));
|
|
486
|
+
const through = float(1).toVar();
|
|
487
|
+
const light = vec3(0).toVar();
|
|
488
|
+
const forward = gpuHg(d.dot(this.sun), CLOUD_MATERIAL.phase.g);
|
|
489
|
+
const phase = forward.add(
|
|
490
|
+
gpuHg(d.dot(this.sun), CLOUD_MATERIAL.phase.g2)
|
|
491
|
+
.sub(forward)
|
|
492
|
+
.mul(CLOUD_MATERIAL.phase.blend),
|
|
493
|
+
);
|
|
494
|
+
const airDepth = vec3(0).toVar();
|
|
495
|
+
Loop(8, ({ i }) => {
|
|
496
|
+
const p = vec3(0, R0, 0).add(d.mul(entry.mul(float(i).add(0.5).div(8))));
|
|
497
|
+
const h = p.length().sub(BOTTOM_KM);
|
|
498
|
+
airDepth.addAssign(
|
|
499
|
+
vec3(...RAYLEIGH)
|
|
500
|
+
.mul(h.div(-8).exp())
|
|
501
|
+
.add(
|
|
502
|
+
h
|
|
503
|
+
.div(-1.2)
|
|
504
|
+
.exp()
|
|
505
|
+
.mul(MIE_SCATTER + MIE_ABSORB),
|
|
506
|
+
)
|
|
507
|
+
.mul(entry.div(8)),
|
|
508
|
+
);
|
|
509
|
+
});
|
|
510
|
+
Loop(GPU_CLOUD_STEPS.view, ({ i }) => {
|
|
511
|
+
If(float(i).lessThan(steps).and(through.greaterThan(0.005)), () => {
|
|
512
|
+
const p = vec3(0, R0, 0).add(d.mul(entry.add(float(i).add(0.5).mul(dt))));
|
|
513
|
+
const extinction = this.#noise.density(p).mul(1000).mul(fade);
|
|
514
|
+
If(extinction.greaterThan(0), () => {
|
|
515
|
+
const rr = p.length();
|
|
516
|
+
const shadowLength = exit(
|
|
517
|
+
rr,
|
|
518
|
+
p.dot(this.sun).div(rr),
|
|
519
|
+
BOTTOM_KM + CLOUD_TOP_KM,
|
|
520
|
+
).min(15);
|
|
521
|
+
const shadow = float(0).toVar();
|
|
522
|
+
Loop(GPU_CLOUD_STEPS.light, ({ i: j }) => {
|
|
523
|
+
const s = float(j).add(0.5).div(GPU_CLOUD_STEPS.light).pow(2).mul(shadowLength);
|
|
524
|
+
const ds = float(j)
|
|
525
|
+
.mul(2)
|
|
526
|
+
.add(1)
|
|
527
|
+
.mul(shadowLength)
|
|
528
|
+
.div(GPU_CLOUD_STEPS.light ** 2);
|
|
529
|
+
shadow.addAssign(
|
|
530
|
+
this.#noise
|
|
531
|
+
.density(p.add(this.sun.mul(s)))
|
|
532
|
+
.mul(1000)
|
|
533
|
+
.mul(ds),
|
|
534
|
+
);
|
|
535
|
+
});
|
|
536
|
+
const direct = float(0).toVar();
|
|
537
|
+
for (const o of cloudOctaves())
|
|
538
|
+
direct.addAssign(
|
|
539
|
+
shadow
|
|
540
|
+
.mul(-o.extinction)
|
|
541
|
+
.exp()
|
|
542
|
+
.mul(o.scatter)
|
|
543
|
+
.mul(float(1 / (4 * PI)).add(phase.sub(1 / (4 * PI)).mul(o.anisotropy))),
|
|
544
|
+
);
|
|
545
|
+
const source = this.#light
|
|
546
|
+
.mul(direct)
|
|
547
|
+
.add(this.#ambient.mul(CLOUD_MATERIAL.skyOcclusion));
|
|
548
|
+
const stepT = extinction.mul(dt).negate().exp();
|
|
549
|
+
light.addAssign(
|
|
550
|
+
through.mul(float(1).sub(stepT)).mul(CLOUD_MATERIAL.albedo).mul(source),
|
|
551
|
+
);
|
|
552
|
+
through.mulAssign(stepT);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
cloudThrough.assign(through);
|
|
557
|
+
result.addAssign(
|
|
558
|
+
airDepth
|
|
559
|
+
.negate()
|
|
560
|
+
.exp()
|
|
561
|
+
.mul(light.sub(clear.mul(float(1).sub(through)))),
|
|
562
|
+
);
|
|
563
|
+
});
|
|
564
|
+
// Alpha carries cloud transmission for the separately drawn analytic sun disc.
|
|
565
|
+
return vec4(result, cloudThrough);
|
|
566
|
+
})(),
|
|
567
|
+
),
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
override setup(_builder: NodeBuilder): Direction {
|
|
571
|
+
const d = positionWorldDirection.normalize();
|
|
572
|
+
const cloud = texture(this.targets.clouds.texture)
|
|
573
|
+
.sample(
|
|
574
|
+
vec2(
|
|
575
|
+
d.z
|
|
576
|
+
.atan(d.x)
|
|
577
|
+
.div(2 * PI)
|
|
578
|
+
.add(0.5),
|
|
579
|
+
clamp(d.y, -1, 1).acos().div(PI),
|
|
580
|
+
),
|
|
581
|
+
)
|
|
582
|
+
.level(float(0));
|
|
583
|
+
const sky = this.clouds
|
|
584
|
+
? cloud.rgb
|
|
585
|
+
: texture(this.targets.sky.texture).sample(skyUv(d)).level(float(0)).rgb;
|
|
586
|
+
const disc = d
|
|
587
|
+
.dot(this.sun)
|
|
588
|
+
.greaterThanEqual(Math.cos(SUN_RADIUS))
|
|
589
|
+
.and(skyDisc.greaterThan(0.5))
|
|
590
|
+
.select(
|
|
591
|
+
this.#light
|
|
592
|
+
.mul(this.clouds ? cloud.a : float(1))
|
|
593
|
+
.div(PI * Math.sin(SUN_RADIUS) ** 2 * SKY_TO_SUN),
|
|
594
|
+
vec3(0),
|
|
595
|
+
);
|
|
596
|
+
const colour = sky.add(disc).mul(this.#scale);
|
|
597
|
+
if (!this.fogged) return colour;
|
|
598
|
+
// Unreal fogs the sky like any far pixel: the exponential height fog's optical depth along a ray
|
|
599
|
+
// that rises at sin(e) and never ends is density_at_camera / (falloff ln2 sin e), base 2 as in
|
|
600
|
+
// HeightFogCommon.ush. A ray at or below the horizon sees the full depth, so the void is opaque.
|
|
601
|
+
const fog = this.fog ?? HEIGHT_FOG_DEFAULT;
|
|
602
|
+
const density = float(fog.density).mul(
|
|
603
|
+
float(-fog.heightFalloff).mul(cameraPosition.y.sub(fog.fogHeight)).exp2(),
|
|
604
|
+
);
|
|
605
|
+
const depth = density.div(fog.heightFalloff * Math.LN2).div(d.y.max(1e-4));
|
|
606
|
+
return mix(colour, this.#fog, float(1).sub(depth.negate().exp2()));
|
|
607
|
+
}
|
|
608
|
+
get backgroundNode(): Direction {
|
|
609
|
+
return nodeObject(this);
|
|
610
|
+
}
|
|
611
|
+
override updateBefore(frame: NodeFrame): undefined {
|
|
612
|
+
if (this.#disposed) throw new Error("GPU sky is disposed");
|
|
613
|
+
const renderer = frame.renderer;
|
|
614
|
+
if (renderer === null) throw new Error("GPU sky requires a renderer");
|
|
615
|
+
if (this.scene.fog) this.#fog.value.copy(this.scene.fog.color);
|
|
616
|
+
if (this.#last.equals(this.direction)) return;
|
|
617
|
+
const length = this.direction.length();
|
|
618
|
+
if (!Number.isFinite(length) || Math.abs(length - 1) > 0.001)
|
|
619
|
+
throw new Error("GPU sky requires a finite unit sun");
|
|
620
|
+
if (this.#ready) this.refreshEnvironment?.();
|
|
621
|
+
if (this.scene.fog) this.#fog.value.copy(this.scene.fog.color);
|
|
622
|
+
this.sun.value.copy(this.direction);
|
|
623
|
+
const through = sunTransmittance(Math.asin(this.direction.y));
|
|
624
|
+
this.#light.value.set(...through);
|
|
625
|
+
const tint = temperatureColour(SUN_KELVIN);
|
|
626
|
+
// The directional light takes Unreal's coarser CPU estimate; the disc and the clouds read the LUT's.
|
|
627
|
+
const lit = sunLightTransmittance(Math.asin(this.direction.y));
|
|
628
|
+
sunLight.current?.color.setRGB(tint[0] * lit[0], tint[1] * lit[1], tint[2] * lit[2]);
|
|
629
|
+
const start = performance.now();
|
|
630
|
+
const state = RendererUtils.resetRendererState(
|
|
631
|
+
renderer,
|
|
632
|
+
RendererUtils.saveRendererState(renderer),
|
|
633
|
+
);
|
|
634
|
+
try {
|
|
635
|
+
const targets = Object.values(this.targets);
|
|
636
|
+
for (let i = this.#ready ? 2 : 0; i < (this.clouds ? 4 : 3); i++) {
|
|
637
|
+
this.#quad.material = this.materials[i] as NodeMaterial;
|
|
638
|
+
renderer.setRenderTarget(targets[i] as RenderTarget);
|
|
639
|
+
this.#quad.render(renderer);
|
|
640
|
+
}
|
|
641
|
+
this.#ready = true;
|
|
642
|
+
this.#last.copy(this.direction);
|
|
643
|
+
this.lastSubmissionMs = performance.now() - start;
|
|
644
|
+
console.info(
|
|
645
|
+
`GPU sky LUT submission: ${this.lastSubmissionMs.toFixed(1)} ms (GPU completion unmeasured)`,
|
|
646
|
+
);
|
|
647
|
+
} finally {
|
|
648
|
+
RendererUtils.restoreRendererState(renderer, state);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
setAmbient(rgb: readonly number[]): void {
|
|
652
|
+
this.#ambient.value.set(rgb[0] ?? 0, rgb[1] ?? 0, rgb[2] ?? 0);
|
|
653
|
+
}
|
|
654
|
+
override dispose(): void {
|
|
655
|
+
if (this.#disposed) return;
|
|
656
|
+
this.#disposed = true;
|
|
657
|
+
for (const t of Object.values(this.targets)) t.dispose();
|
|
658
|
+
for (const m of this.materials) m.dispose();
|
|
659
|
+
this.#noise.map.dispose();
|
|
660
|
+
super.dispose();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** Height fog and void colour: Unreal's distant sky light, scaled to scene radiance like the sky. */
|
|
665
|
+
function distantFogColour(sun: Vector3): Color {
|
|
666
|
+
const tint = temperatureColour(SUN_KELVIN);
|
|
667
|
+
const light = viewDistanceSkyLight(sun);
|
|
668
|
+
return new Color(
|
|
669
|
+
...([0, 1, 2].map((c) => (light[c] ?? 0) * (tint[c] ?? 1) * SUN_ILLUMINANCE * SKY_TO_SUN) as [
|
|
670
|
+
number,
|
|
671
|
+
number,
|
|
672
|
+
number,
|
|
673
|
+
]),
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* The composited sky radiance of one sun, kept for the next scene that asks for the same sky: a scene
|
|
679
|
+
* that restarts (load, then enter) would otherwise march the same 2048 rays twice, seconds of one
|
|
680
|
+
* thread on a slow interpreter. Keyed by everything the bake reads; a moved sun misses and bakes.
|
|
681
|
+
* Callers only read the result. Only the newest few suns are kept.
|
|
682
|
+
*/
|
|
683
|
+
const radianceCache = new Map<string, Float32Array>();
|
|
684
|
+
const RADIANCE_CACHE_SUNS = 8;
|
|
685
|
+
function bakedRadiance(
|
|
686
|
+
sun: Vector3,
|
|
687
|
+
w: number,
|
|
688
|
+
h: number,
|
|
689
|
+
ground: boolean,
|
|
690
|
+
clouds: boolean,
|
|
691
|
+
): Float32Array {
|
|
692
|
+
const key = `${sun.x},${sun.y},${sun.z},${w},${h},${ground},${clouds}`;
|
|
693
|
+
const cached = radianceCache.get(key);
|
|
694
|
+
if (cached) return cached;
|
|
695
|
+
const data = bakeSkyRadiance(sun, w, h, ground);
|
|
696
|
+
if (clouds) bakeCloudRadiance(data, sun, w, h);
|
|
697
|
+
radianceCache.set(key, data);
|
|
698
|
+
if (radianceCache.size > RADIANCE_CACHE_SUNS)
|
|
699
|
+
radianceCache.delete(radianceCache.keys().next().value as string);
|
|
700
|
+
return data;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** CPU pixels are still needed by the owned PMREM.
|
|
704
|
+
* Renderer::beginEnvironment rejects GPU-only textures (renderer.cpp: decoded RGBA pixels).
|
|
705
|
+
* At 64x32 this avoids the full 256x128 bake; both paths use the same radiometric scale.
|
|
706
|
+
* Plain bytes, no canvas: the bake runs wherever the game's JavaScript runs.
|
|
707
|
+
*/
|
|
708
|
+
export function createGpuSky(
|
|
709
|
+
scene: Scene,
|
|
710
|
+
sun: Vector3,
|
|
711
|
+
fogged: boolean,
|
|
712
|
+
clouds: boolean,
|
|
713
|
+
fog: ISkyFog | undefined,
|
|
714
|
+
ground: boolean,
|
|
715
|
+
): { node: GpuSkyNode; environment: DataTexture } {
|
|
716
|
+
const w = 64;
|
|
717
|
+
const h = 32;
|
|
718
|
+
const pixels = new Uint8Array(w * h * 4);
|
|
719
|
+
const environment = new DataTexture(pixels, w, h, RGBAFormat, UnsignedByteType);
|
|
720
|
+
environment.minFilter = environment.magFilter = LinearFilter;
|
|
721
|
+
const refresh = () => {
|
|
722
|
+
const start = performance.now();
|
|
723
|
+
const data = bakedRadiance(sun, w, h, ground, clouds);
|
|
724
|
+
const scale = temperatureColour(SUN_KELVIN).map((v) => v * SUN_ILLUMINANCE * SKY_TO_SUN) as [
|
|
725
|
+
number,
|
|
726
|
+
number,
|
|
727
|
+
number,
|
|
728
|
+
];
|
|
729
|
+
for (let y = 0; y < h; y++) {
|
|
730
|
+
// The bake's row 0 is the zenith; a data texture's row 0 is v = 0, the nadir.
|
|
731
|
+
const row = h - 1 - y;
|
|
732
|
+
for (let x = 0; x < w; x++) {
|
|
733
|
+
for (let c = 0; c < 3; c++) {
|
|
734
|
+
const value = data[(y * w + x) * 3 + c] ?? 0;
|
|
735
|
+
const v = Math.min(1, (value * (scale[c] ?? 1)) / 4);
|
|
736
|
+
pixels[(row * w + x) * 4 + c] = Math.round(
|
|
737
|
+
255 * (v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055),
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
pixels[(row * w + x) * 4 + 3] = 255;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
environment.needsUpdate = true;
|
|
744
|
+
node.setAmbient(viewDistanceSkyLight(sun));
|
|
745
|
+
// The height fog takes its colour from the same sky light (Unreal's fog has none of its own).
|
|
746
|
+
scene.fog?.color.copy(distantFogColour(sun));
|
|
747
|
+
console.info(`CPU environment sky 64x32: ${(performance.now() - start).toFixed(1)} ms`);
|
|
748
|
+
};
|
|
749
|
+
const node = new GpuSkyNode(sun, scene, fogged, clouds, refresh, fog);
|
|
750
|
+
refresh();
|
|
751
|
+
return { node, environment };
|
|
752
|
+
}
|