@call-me-sensei/toonlab 0.3.0 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +549 -184
- package/agents/README.md +59 -0
- package/agents/references/anime-art-direction.md +24 -0
- package/agents/references/asset-sourcing-policy.md +23 -0
- package/agents/references/custom-gap-report.md +16 -0
- package/agents/references/geology-playbook.md +118 -0
- package/agents/references/mcp-asset-discovery.md +104 -0
- package/agents/references/runtime-entry-points.md +174 -0
- package/agents/references/style-bundles.md +71 -0
- package/agents/skills/claude/asset-sourcing/SKILL.md +275 -0
- package/agents/skills/claude/environment/SKILL.md +59 -0
- package/agents/skills/claude/game-dev/SKILL.md +100 -0
- package/agents/skills/claude/karst-cliff-construction/SKILL.md +258 -0
- package/agents/skills/claude/outdoor-world/SKILL.md +492 -0
- package/agents/skills/claude/outdoor-world/references/coastal-landform-formation.md +100 -0
- package/agents/skills/claude/post-processing/SKILL.md +44 -0
- package/agents/skills/claude/rock-ground-shaders/SKILL.md +118 -0
- package/agents/skills/claude/rockgen/SKILL.md +30 -0
- package/agents/skills/claude/scene-style-application/SKILL.md +74 -0
- package/agents/skills/claude/style-presets/SKILL.md +101 -0
- package/agents/skills/claude/toon-shading/SKILL.md +44 -0
- package/agents/skills/claude/vegetation-sky/SKILL.md +167 -0
- package/agents/skills/claude/visual-verification/SKILL.md +136 -0
- package/agents/skills/claude/water/SKILL.md +105 -0
- package/agents/skills/codex/asset-sourcing/SKILL.md +275 -0
- package/agents/skills/codex/environment/SKILL.md +59 -0
- package/agents/skills/codex/game-dev/SKILL.md +100 -0
- package/agents/skills/codex/karst-cliff-construction/SKILL.md +258 -0
- package/agents/skills/codex/outdoor-world/SKILL.md +492 -0
- package/agents/skills/codex/outdoor-world/references/coastal-landform-formation.md +100 -0
- package/agents/skills/codex/post-processing/SKILL.md +44 -0
- package/agents/skills/codex/rock-ground-shaders/SKILL.md +118 -0
- package/agents/skills/codex/rockgen/SKILL.md +30 -0
- package/agents/skills/codex/scene-style-application/SKILL.md +74 -0
- package/agents/skills/codex/style-presets/SKILL.md +101 -0
- package/agents/skills/codex/toon-shading/SKILL.md +44 -0
- package/agents/skills/codex/vegetation-sky/SKILL.md +167 -0
- package/agents/skills/codex/visual-verification/SKILL.md +136 -0
- package/agents/skills/codex/water/SKILL.md +105 -0
- package/cli/toonlab.mjs +52 -0
- package/compose.yaml +20 -0
- package/database/apply-sql.mjs +141 -0
- package/database/client.mjs +39 -0
- package/database/creation-tags.mjs +23 -0
- package/database/env.mjs +16 -0
- package/database/generation-service.mjs +314 -0
- package/database/migrations/0001_local_workspace.sql +120 -0
- package/database/migrations/0002_file_ownership.sql +11 -0
- package/database/migrations/0003_remove_autosaves_from_library.sql +7 -0
- package/database/migrations/0004_catalog_asset_packs.sql +39 -0
- package/database/migrations/0005_creation_tag_discovery.sql +1 -0
- package/database/migrations/0006_normalize_creation_tags.sql +28 -0
- package/database/providers.mjs +465 -0
- package/database/repository.mjs +625 -0
- package/database/seeds/catalog/0001_empty_official_catalog.sql +4 -0
- package/database/seeds/catalog/0002_2026-08.sql +19454 -0
- package/mcp/lab-management.mjs +629 -0
- package/mcp/public-catalog.mjs +168 -0
- package/mcp/server.mjs +1026 -63
- package/mcp/vite-plugin.mjs +443 -26
- package/mcp/workspace.mjs +26 -1
- package/package.json +312 -45
- package/scripts/generate-catalog-seed.mjs +297 -0
- package/scripts/setup-local.mjs +128 -0
- package/src/agents/index.js +7 -0
- package/src/agents/sceneStyleOperations.js +169 -0
- package/src/asset-policy/catalogLicenses.js +44 -0
- package/src/asset-policy/index.js +315 -0
- package/src/assetlib/assetRef.js +1 -1
- package/src/assetlib/galleryMaterialFamily.js +165 -0
- package/src/assetlib/index.js +6 -2
- package/src/assetlib/plateau.js +188 -0
- package/src/assetlib/plateauLandmarks.js +144 -0
- package/src/assetlib/plateauViewer.js +348 -0
- package/src/assetlib/sources.js +16 -2
- package/src/catalog/manifest.js +11 -1
- package/src/catalog/officialCatalog.js +4 -0
- package/src/catalog/officialCatalogAssetRuntime.js +313 -0
- package/src/catalog/officialCatalogLod.js +150 -0
- package/src/catalog/officialCatalogPlacement.js +228 -0
- package/src/catalog/officialCatalogProvider.js +334 -0
- package/src/character/animationRetarget.js +1082 -0
- package/src/character/characterRuntime.js +376 -0
- package/src/character/groundStabilizer.js +137 -0
- package/src/character/index.js +8 -0
- package/src/character/locomotionActions.js +74 -0
- package/src/character/locomotionStateMachine.js +241 -0
- package/src/character/mannequinAsset.js +15 -0
- package/src/character/mannequinAssetUrl.browser.js +4 -0
- package/src/character/mannequinAssetUrl.node.js +3 -0
- package/src/character/modelLoader.js +92 -12
- package/src/character/walkableCharacterRuntime.js +284 -0
- package/src/character/waterInteractionController.js +217 -0
- package/src/cloud/ambientSkyBaker.js +248 -0
- package/src/cloud/cloudLighting.js +1114 -0
- package/src/cloud/cloudParams.js +819 -0
- package/src/cloud/cloudReprojection.js +563 -0
- package/src/cloud/cloudStyle.js +780 -0
- package/src/cloud/cloudStyleSnapshots.js +387 -0
- package/src/cloud/cloudVolume.js +1903 -0
- package/src/cloud/heroCloudRecipe.js +404 -0
- package/src/cloud/index.js +42 -0
- package/src/cloud/noise/baseShapeVolume.js +331 -0
- package/src/cloud/noise/cirrusMap.js +131 -0
- package/src/cloud/noise/curlNoise.js +289 -0
- package/src/cloud/noise/erosionVolume.js +188 -0
- package/src/cloud/noise/noiseVolume.js +202 -0
- package/src/cloud/noise/periodicNoise3.js +295 -0
- package/src/cloud/noise/weatherMap.js +470 -0
- package/src/cloud/paramSchema.js +458 -0
- package/src/collisionMetadata.js +320 -0
- package/src/core/systemStylePolicy.js +32 -0
- package/src/environment/dayCurves.js +146 -0
- package/src/environment/environmentGroundFieldPass.js +354 -0
- package/src/environment/environmentMaterialAdapter.js +114 -6
- package/src/environment/environmentPresets.js +396 -90
- package/src/environment/environmentRigs.js +17 -2
- package/src/environment/environmentSettings.js +37 -1
- package/src/environment/environmentShaderMaterials.js +37 -6
- package/src/environment/environmentState.js +133 -0
- package/src/environment/environmentSunShadowPass.js +357 -6
- package/src/environment/environmentTextureResolver.js +7 -0
- package/src/environment/index.js +51 -0
- package/src/environment/manufacturedMaterialContract.js +837 -0
- package/src/environment/manufacturedReflectionProvider.js +114 -0
- package/src/environment/scanAssetStylize.js +4 -4
- package/src/environment/surfaceMaterialModes.js +71 -0
- package/src/environment/toonLabEnvironmentMaterials.js +353 -0
- package/src/environment/toonLabMaterialPassCoupling.js +347 -0
- package/src/environment/toonLabNormalIntegration.js +171 -0
- package/src/environment/toonLabRockMaterialResolver.js +592 -0
- package/src/environment/toonLabSourceDefaultLit.js +444 -0
- package/src/environment/toonLabSourceLibrary.js +762 -0
- package/src/environment/toonLabSourceMaterials.js +3718 -0
- package/src/environment/toonLabSourceSubsurfaceLighting.js +415 -0
- package/src/environment/toonLabSourceTemporal.js +717 -0
- package/src/environment/toonLabSurfaceLighting.js +364 -0
- package/src/environment/toonLabTextureReadiness.js +105 -0
- package/src/environment/toonLabTreeMaterials.js +450 -0
- package/src/environment/transparentMaterialProfile.js +87 -0
- package/src/environment/urbanPropMaterial.js +2874 -0
- package/src/ground-shader/groundPrintLayer.js +375 -0
- package/src/ground-shader/groundShaderMaterial.js +851 -0
- package/src/ground-shader/groundShaderSettings.js +468 -0
- package/src/ground-shader/index.js +3 -0
- package/src/index.js +52 -22
- package/src/lighting/callMeSenseiLightingContract.js +163 -0
- package/src/lighting/index.js +14 -7
- package/src/lighting/lightingCapabilities.js +2 -2
- package/src/lighting/lightingPresets.js +6 -3
- package/src/lighting/lightingStyle.js +41 -6
- package/src/lighting/lightingSystem.js +140 -1
- package/src/lighting/{unrealExport.js → toonLabExport.js} +40 -41
- package/src/post/postProcessing.js +71 -12
- package/src/react/index.js +66 -0
- package/src/renderer/index.js +9 -0
- package/src/renderer/rendererConfiguration.js +250 -0
- package/src/rock-shader/index.js +3 -0
- package/src/rock-shader/rockMaterial.js +1843 -0
- package/src/rock-shader/rockShaderRuntime.js +494 -0
- package/src/rock-shader/rockShaderSettings.js +869 -0
- package/src/rockgen/export/glbExport.js +104 -14
- package/src/rockgen/index.js +4 -3
- package/src/rockgen/lod/index.js +6 -0
- package/src/rockgen/lod/rockLodMetrics.js +168 -0
- package/src/rockgen/lod/rockLodPlanner.js +372 -0
- package/src/rockgen/lod/rockLodPolicy.js +235 -0
- package/src/rockgen/lod/rockLodRuntime.js +124 -0
- package/src/rockgen/lod/rockLodSimplifier.js +173 -0
- package/src/rockgen/lod/rockLodValidation.js +113 -0
- package/src/rockgen/mesh/meshAttributes.js +17 -0
- package/src/rockgen/mesh/meshDocument.js +6 -0
- package/src/rockgen/rockDocument.js +352 -9
- package/src/rockgen/rockgenPresets.js +114 -13
- package/src/rockgen/rockgenSettings.js +62 -11
- package/src/runtime/index.js +14 -0
- package/src/runtime/sceneCollisionRuntime.js +317 -0
- package/src/runtime/sceneSurfaceRuntime.js +451 -0
- package/src/runtime/sceneUpdateScheduler.js +203 -0
- package/src/shaders-tsl/anime.js +9 -2
- package/src/shaders-tsl/chunks/environment-ground-field.js +174 -0
- package/src/shaders-tsl/chunks/environment-state.js +79 -0
- package/src/shaders-tsl/chunks/environment-sun-shadow.js +99 -32
- package/src/shaders-tsl/chunks/normalized-hue.js +41 -0
- package/src/shaders-tsl/chunks/pass-depth-color.js +4 -2
- package/src/shaders-tsl/chunks/scene-depth-color-pass.js +273 -0
- package/src/shaders-tsl/chunks/vegetation-style.js +116 -8
- package/src/shaders-tsl/chunks/water-color.js +19 -5
- package/src/shaders-tsl/chunks/water-shore-state.js +8 -1
- package/src/shaders-tsl/chunks/world-noise.js +30 -0
- package/src/shaders-tsl/environment.js +123 -17
- package/src/shaders-tsl/flower.js +51 -8
- package/src/shaders-tsl/grass.js +194 -29
- package/src/shaders-tsl/post-composite.js +83 -2
- package/src/shaders-tsl/tree-leaf.js +107 -16
- package/src/shaders-tsl/water-breaker.js +18 -4
- package/src/shaders-tsl/water.js +43 -3
- package/src/shaders-tsl/woody-surface.js +59 -7
- package/src/sky/atmosphereDome.js +193 -0
- package/src/sky/atmosphereParams.js +396 -0
- package/src/sky/atmosphereScattering.js +593 -0
- package/src/sky/atmosphereSky.js +371 -0
- package/src/sky/cloudShadow.js +355 -0
- package/src/sky/godRays.js +257 -0
- package/src/sky/index.js +55 -1
- package/src/sky/nightSky.js +1190 -0
- package/src/sky/renderLayers.js +120 -0
- package/src/sky/skyColor.js +582 -0
- package/src/sky/skyDayCycle.js +244 -0
- package/src/sky/skyParams.js +661 -0
- package/src/sky/skyPresets.js +772 -0
- package/src/sky/skyQualityTiers.js +383 -0
- package/src/sky/skyShaderSettings.js +699 -0
- package/src/sky/skyStyleSnapshots.js +211 -0
- package/src/sky/skySystem.js +1438 -0
- package/src/sky/skyTimeKeyframes.js +361 -0
- package/src/sky/stylizedSky.js +405 -116
- package/src/sky/sunDriver.js +499 -0
- package/src/sky/timeOfDay.js +335 -0
- package/src/styles/animeGameProfile.js +44 -0
- package/src/styles/index.js +134 -0
- package/src/styles/manufacturedStyleLabeling.js +204 -0
- package/src/styles/sceneLayerDocuments.js +185 -0
- package/src/styles/sceneLookComposition.js +156 -0
- package/src/styles/sceneQualityApplication.js +152 -0
- package/src/styles/sceneQualityProfiles.js +268 -0
- package/src/styles/sceneStyleAudit.js +512 -0
- package/src/styles/sceneStyleRuntime.js +876 -0
- package/src/styles/styleAdapters.js +166 -0
- package/src/styles/styleApplication.js +369 -0
- package/src/styles/styleBundle.js +444 -91
- package/src/styles/styleBundleProvider.js +83 -0
- package/src/styles/styleDomains.js +21 -0
- package/src/styles/styleInspector.js +262 -0
- package/src/styles/styleMaterialContract.js +375 -0
- package/src/styles/styleMetadata.js +73 -0
- package/src/styles/styleTargetDiscovery.js +162 -0
- package/src/styles/styleTargetLabels.js +206 -0
- package/src/styles/styleTargetMaterialCoverage.js +137 -0
- package/src/styles/styleTransaction.js +272 -0
- package/src/texgen/textureGenerators.js +21 -5
- package/src/toon/toonSettings.js +4 -0
- package/src/vegetation/branchTree.js +302 -0
- package/src/vegetation/callMeSenseiGrass.js +183 -0
- package/src/vegetation/compiledTree.js +506 -0
- package/src/vegetation/contactShadowField.js +107 -0
- package/src/vegetation/flowerSpecies.js +10 -2
- package/src/vegetation/grass.js +13 -0
- package/src/vegetation/grassClump.js +1179 -0
- package/src/vegetation/importedVegetationMaterial.js +183 -0
- package/src/vegetation/index.js +15 -1
- package/src/vegetation/legacyTreePresets.js +120 -0
- package/src/vegetation/scatter.js +322 -3
- package/src/vegetation/stylizedBush.js +14 -0
- package/src/vegetation/stylizedFlower.js +31 -0
- package/src/vegetation/stylizedFlowers.js +59 -7
- package/src/vegetation/stylizedForest.js +455 -147
- package/src/vegetation/stylizedGrass.js +188 -24
- package/src/vegetation/stylizedTree.js +378 -46
- package/src/vegetation/stylizedTreeFoliage.js +889 -38
- package/src/vegetation/stylizedUnderstory.js +230 -0
- package/src/vegetation/treeExport.js +262 -47
- package/src/vegetation/treeSurfaceTextures.js +337 -0
- package/src/vegetation/vegetationShaders.js +617 -28
- package/src/version.js +3 -0
- package/src/water/water.js +2 -0
- package/src/water/waterBreakerSystem.js +2 -0
- package/src/water/waterCurrentField.js +1 -0
- package/src/water/waterMaterial.js +3 -0
- package/src/water/waterRain.js +2 -0
- package/src/water/waterScenePasses.js +170 -7
- package/src/water/waterSettings.js +235 -43
- package/src/water/waterShoreMaterial.js +16 -2
- package/src/water/waterShoreStateField.js +1 -1
- package/src/water/waterSplashSystem.js +2 -0
- package/src/water/waterStageSettings.js +60 -0
- package/src/water/waterSurface.js +144 -4
- package/src/water/waterUnderwaterAtmosphere.js +288 -0
- package/src/water/waterVegetation.js +20 -4
- package/src/worldCollision.js +64 -9
- package/types/agents/index.d.ts +1 -0
- package/types/agents/sceneStyleOperations.d.ts +484 -0
- package/types/asset-policy/catalogLicenses.d.ts +5 -0
- package/types/asset-policy/index.d.ts +18 -0
- package/types/assetlib/ambientcg.d.ts +81 -0
- package/types/assetlib/assetRef.d.ts +26 -0
- package/types/assetlib/galleryMaterialFamily.d.ts +13 -0
- package/types/assetlib/importedEntry.d.ts +18 -0
- package/types/assetlib/index.d.ts +16 -0
- package/types/assetlib/kaykit.d.ts +112 -0
- package/types/assetlib/kaykitStaticIndex.d.ts +38 -0
- package/types/assetlib/loadImported.d.ts +54 -0
- package/types/assetlib/opensource3d.d.ts +55 -0
- package/types/assetlib/plateau.d.ts +67 -0
- package/types/assetlib/plateauLandmarks.d.ts +238 -0
- package/types/assetlib/plateauViewer.d.ts +3 -0
- package/types/assetlib/polyhaven.d.ts +90 -0
- package/types/assetlib/polypizza.d.ts +10 -0
- package/types/assetlib/smithsonian.d.ts +9 -0
- package/types/assetlib/sources.d.ts +22 -0
- package/types/assetlib/zip.d.ts +8 -0
- package/types/catalog/manifest.d.ts +26 -0
- package/types/catalog/officialCatalog.d.ts +4 -0
- package/types/catalog/officialCatalogAssetRuntime.d.ts +2 -0
- package/types/catalog/officialCatalogLod.d.ts +5 -0
- package/types/catalog/officialCatalogPlacement.d.ts +49 -0
- package/types/catalog/officialCatalogProvider.d.ts +7 -0
- package/types/character/animationRetarget.d.ts +20 -0
- package/types/character/characterRig.d.ts +28 -0
- package/types/character/characterRuntime.d.ts +4 -0
- package/types/character/freestyleSwimClip.d.ts +5 -0
- package/types/character/groundStabilizer.d.ts +55 -0
- package/types/character/index.d.ts +10 -0
- package/types/character/locomotionActions.d.ts +4 -0
- package/types/character/locomotionStateMachine.d.ts +62 -0
- package/types/character/mannequinAsset.d.ts +12 -0
- package/types/character/mannequinAssetUrl.node.d.ts +1 -0
- package/types/character/modelLoader.d.ts +7 -0
- package/types/character/walkableCharacterRuntime.d.ts +343 -0
- package/types/character/waterInteractionController.d.ts +114 -0
- package/types/cloud/ambientSkyBaker.d.ts +18 -0
- package/types/cloud/cloudLighting.d.ts +38 -0
- package/types/cloud/cloudParams.d.ts +18 -0
- package/types/cloud/cloudReprojection.d.ts +15 -0
- package/types/cloud/cloudStyle.d.ts +1380 -0
- package/types/cloud/cloudStyleSnapshots.d.ts +10 -0
- package/types/cloud/cloudVolume.d.ts +43 -0
- package/types/cloud/heroCloudRecipe.d.ts +167 -0
- package/types/cloud/index.d.ts +12 -0
- package/types/cloud/noise/baseShapeVolume.d.ts +86 -0
- package/types/cloud/noise/cirrusMap.d.ts +24 -0
- package/types/cloud/noise/curlNoise.d.ts +106 -0
- package/types/cloud/noise/erosionVolume.d.ts +58 -0
- package/types/cloud/noise/noiseVolume.d.ts +63 -0
- package/types/cloud/noise/periodicNoise3.d.ts +75 -0
- package/types/cloud/noise/weatherMap.d.ts +227 -0
- package/types/cloud/paramSchema.d.ts +142 -0
- package/types/collisionMetadata.d.ts +11 -0
- package/types/core/generation.d.ts +95 -0
- package/types/core/materialRoles.d.ts +102 -0
- package/types/core/presetDocuments.d.ts +25 -0
- package/types/core/systemStylePolicy.d.ts +4 -0
- package/types/environment/dayCurves.d.ts +47 -0
- package/types/environment/environmentAmbientProbe.d.ts +2 -0
- package/types/environment/environmentGroundFieldPass.d.ts +2 -0
- package/types/environment/environmentMaterialAdapter.d.ts +42 -0
- package/types/environment/environmentMaterialClassifier.d.ts +26 -0
- package/types/environment/environmentPlanarReflection.d.ts +3 -0
- package/types/environment/environmentPresets.d.ts +171 -0
- package/types/environment/environmentRigs.d.ts +13 -0
- package/types/environment/environmentSettings.d.ts +161 -0
- package/types/environment/environmentShaderMaterials.d.ts +14 -0
- package/types/environment/environmentState.d.ts +6 -0
- package/types/environment/environmentSunShadowPass.d.ts +2 -0
- package/types/environment/environmentTextureResolver.d.ts +30 -0
- package/types/environment/environmentTimeOfDay.d.ts +25 -0
- package/types/environment/environmentVertexAo.d.ts +18 -0
- package/types/environment/index.d.ts +27 -0
- package/types/environment/manufacturedMaterialContract.d.ts +129 -0
- package/types/environment/manufacturedReflectionProvider.d.ts +3 -0
- package/types/environment/scanAssetStylize.d.ts +43 -0
- package/types/environment/surfaceMaterialModes.d.ts +14 -0
- package/types/environment/toonLabEnvironmentMaterials.d.ts +139 -0
- package/types/environment/toonLabMaterialPassCoupling.d.ts +7 -0
- package/types/environment/toonLabNormalIntegration.d.ts +29 -0
- package/types/environment/toonLabRockMaterialResolver.d.ts +270 -0
- package/types/environment/toonLabSourceDefaultLit.d.ts +136 -0
- package/types/environment/toonLabSourceLibrary.d.ts +19 -0
- package/types/environment/toonLabSourceMaterials.d.ts +14 -0
- package/types/environment/toonLabSourceSubsurfaceLighting.d.ts +85 -0
- package/types/environment/toonLabSourceTemporal.d.ts +20 -0
- package/types/environment/toonLabSurfaceLighting.d.ts +136 -0
- package/types/environment/toonLabTextureReadiness.d.ts +8 -0
- package/types/environment/toonLabTreeMaterials.d.ts +7 -0
- package/types/environment/transparentMaterialProfile.d.ts +76 -0
- package/types/environment/urbanPropMaterial.d.ts +25 -0
- package/types/ground-shader/groundPrintLayer.d.ts +4 -0
- package/types/ground-shader/groundShaderMaterial.d.ts +11 -0
- package/types/ground-shader/groundShaderSettings.d.ts +90 -0
- package/types/ground-shader/index.d.ts +3 -0
- package/types/index.d.ts +1502 -0
- package/types/lighting/callMeSenseiLightingContract.d.ts +14 -0
- package/types/lighting/colorIntensity.d.ts +44 -0
- package/types/lighting/index.d.ts +12 -0
- package/types/lighting/lightDescriptors.d.ts +803 -0
- package/types/lighting/lightingCapabilities.d.ts +85 -0
- package/types/lighting/lightingDocuments.d.ts +140 -0
- package/types/lighting/lightingFixtures.d.ts +171 -0
- package/types/lighting/lightingGenerator.d.ts +403 -0
- package/types/lighting/lightingPresets.d.ts +264 -0
- package/types/lighting/lightingRuntime.d.ts +401 -0
- package/types/lighting/lightingStyle.d.ts +156 -0
- package/types/lighting/lightingSystem.d.ts +433 -0
- package/types/lighting/toonLabExport.d.ts +46 -0
- package/types/lighting/utils.d.ts +18 -0
- package/types/loaders/index.d.ts +1 -0
- package/types/post/index.d.ts +2 -0
- package/types/post/postGenerator.d.ts +282 -0
- package/types/post/postProcessing.d.ts +16 -0
- package/types/react/index.d.ts +1765 -0
- package/types/renderer/index.d.ts +1 -0
- package/types/renderer/rendererConfiguration.d.ts +8 -0
- package/types/rock-shader/index.d.ts +3 -0
- package/types/rock-shader/rockMaterial.d.ts +18 -0
- package/types/rock-shader/rockShaderRuntime.d.ts +8 -0
- package/types/rock-shader/rockShaderSettings.d.ts +170 -0
- package/types/rockgen/export/glbExport.d.ts +58 -0
- package/types/rockgen/heightfield/heightfieldErosion.d.ts +10 -0
- package/types/rockgen/heightfield/heightfieldPatch.d.ts +15 -0
- package/types/rockgen/heightfield/stylizedErosionSim.d.ts +41 -0
- package/types/rockgen/index.d.ts +11 -0
- package/types/rockgen/lod/index.d.ts +6 -0
- package/types/rockgen/lod/rockLodMetrics.d.ts +62 -0
- package/types/rockgen/lod/rockLodPlanner.d.ts +86 -0
- package/types/rockgen/lod/rockLodPolicy.d.ts +76 -0
- package/types/rockgen/lod/rockLodRuntime.d.ts +95 -0
- package/types/rockgen/lod/rockLodSimplifier.d.ts +15 -0
- package/types/rockgen/lod/rockLodValidation.d.ts +16 -0
- package/types/rockgen/mesh/meshAttributes.d.ts +32 -0
- package/types/rockgen/mesh/meshDocument.d.ts +40 -0
- package/types/rockgen/mesh/surfaceNets.d.ts +42 -0
- package/types/rockgen/noise/cellularNoise3.d.ts +24 -0
- package/types/rockgen/noise/prng.d.ts +16 -0
- package/types/rockgen/noise/simplexNoise3.d.ts +2 -0
- package/types/rockgen/noise/valueNoise3.d.ts +12 -0
- package/types/rockgen/rockDocument.d.ts +215 -0
- package/types/rockgen/rockHelpers.d.ts +2 -0
- package/types/rockgen/rockgenPresets.d.ts +10 -0
- package/types/rockgen/rockgenSettings.d.ts +531 -0
- package/types/rockgen/sdf/fieldCompiler.d.ts +20 -0
- package/types/rockgen/sdf/sculptEdits.d.ts +30 -0
- package/types/rockgen/sdf/sdfModifiers.d.ts +19 -0
- package/types/rockgen/sdf/sdfOps.d.ts +8 -0
- package/types/rockgen/sdf/sdfPrimitives.d.ts +22 -0
- package/types/runtime/index.d.ts +3 -0
- package/types/runtime/sceneCollisionRuntime.d.ts +94 -0
- package/types/runtime/sceneSurfaceRuntime.d.ts +90 -0
- package/types/runtime/sceneUpdateScheduler.d.ts +28 -0
- package/types/shaders-tsl/anime.d.ts +9 -0
- package/types/shaders-tsl/chunks/character-color.d.ts +6 -0
- package/types/shaders-tsl/chunks/character-highlights.d.ts +12 -0
- package/types/shaders-tsl/chunks/character-lighting.d.ts +20 -0
- package/types/shaders-tsl/chunks/character-material-maps.d.ts +18 -0
- package/types/shaders-tsl/chunks/character-roles.d.ts +21 -0
- package/types/shaders-tsl/chunks/character-scene-lights.d.ts +48 -0
- package/types/shaders-tsl/chunks/character-shadow-color.d.ts +5 -0
- package/types/shaders-tsl/chunks/character-skinning.d.ts +23 -0
- package/types/shaders-tsl/chunks/environment-color.d.ts +9 -0
- package/types/shaders-tsl/chunks/environment-debug.d.ts +24 -0
- package/types/shaders-tsl/chunks/environment-ground-field.d.ts +40 -0
- package/types/shaders-tsl/chunks/environment-lighting.d.ts +22 -0
- package/types/shaders-tsl/chunks/environment-state.d.ts +42 -0
- package/types/shaders-tsl/chunks/environment-sun-shadow.d.ts +19 -0
- package/types/shaders-tsl/chunks/foliage-fog.d.ts +21 -0
- package/types/shaders-tsl/chunks/normalized-hue.d.ts +1 -0
- package/types/shaders-tsl/chunks/pass-depth-color.d.ts +20 -0
- package/types/shaders-tsl/chunks/projected-water-caustics.d.ts +24 -0
- package/types/shaders-tsl/chunks/scene-depth-color-pass.d.ts +39 -0
- package/types/shaders-tsl/chunks/stylized-cloud-shadow.d.ts +9 -0
- package/types/shaders-tsl/chunks/vegetation-style.d.ts +60 -0
- package/types/shaders-tsl/chunks/water-color.d.ts +15 -0
- package/types/shaders-tsl/chunks/water-common.d.ts +9 -0
- package/types/shaders-tsl/chunks/water-foam.d.ts +8 -0
- package/types/shaders-tsl/chunks/water-lighting.d.ts +9 -0
- package/types/shaders-tsl/chunks/water-ripple.d.ts +8 -0
- package/types/shaders-tsl/chunks/water-shore-state.d.ts +7 -0
- package/types/shaders-tsl/chunks/water-waves.d.ts +18 -0
- package/types/shaders-tsl/chunks/world-noise.d.ts +4 -0
- package/types/shaders-tsl/environment-ao-overlay.d.ts +5 -0
- package/types/shaders-tsl/environment.d.ts +34 -0
- package/types/shaders-tsl/flower.d.ts +6 -0
- package/types/shaders-tsl/grass.d.ts +4 -0
- package/types/shaders-tsl/post-composite.d.ts +25 -0
- package/types/shaders-tsl/sky.d.ts +4 -0
- package/types/shaders-tsl/tree-leaf.d.ts +2 -0
- package/types/shaders-tsl/water-breaker.d.ts +15 -0
- package/types/shaders-tsl/water-kelp.d.ts +5 -0
- package/types/shaders-tsl/water-rain.d.ts +10 -0
- package/types/shaders-tsl/water-shore-state-simulation.d.ts +12 -0
- package/types/shaders-tsl/water-simulation.d.ts +5 -0
- package/types/shaders-tsl/water-splash.d.ts +12 -0
- package/types/shaders-tsl/water.d.ts +22 -0
- package/types/shaders-tsl/woody-surface.d.ts +3 -0
- package/types/sky/atmosphereDome.d.ts +2 -0
- package/types/sky/atmosphereParams.d.ts +185 -0
- package/types/sky/atmosphereScattering.d.ts +11 -0
- package/types/sky/atmosphereSky.d.ts +2 -0
- package/types/sky/cloudShadow.d.ts +68 -0
- package/types/sky/godRays.d.ts +5 -0
- package/types/sky/index.d.ts +18 -0
- package/types/sky/nightSky.d.ts +22 -0
- package/types/sky/renderLayers.d.ts +59 -0
- package/types/sky/sceneOverrideLayers.d.ts +10 -0
- package/types/sky/skyColor.d.ts +704 -0
- package/types/sky/skyDayCycle.d.ts +86 -0
- package/types/sky/skyParams.d.ts +3407 -0
- package/types/sky/skyPresets.d.ts +160 -0
- package/types/sky/skyQuality.d.ts +21 -0
- package/types/sky/skyQualityTiers.d.ts +223 -0
- package/types/sky/skyShaderSettings.d.ts +152 -0
- package/types/sky/skyStyleSnapshots.d.ts +11 -0
- package/types/sky/skySystem.d.ts +3 -0
- package/types/sky/skyTimeKeyframes.d.ts +230 -0
- package/types/sky/stylizedSky.d.ts +341 -0
- package/types/sky/sunDriver.d.ts +15 -0
- package/types/sky/timeOfDay.d.ts +145 -0
- package/types/styles/animeGameProfile.d.ts +27 -0
- package/types/styles/index.d.ts +17 -0
- package/types/styles/manufacturedStyleLabeling.d.ts +119 -0
- package/types/styles/sceneLayerDocuments.d.ts +145 -0
- package/types/styles/sceneLookComposition.d.ts +53 -0
- package/types/styles/sceneQualityApplication.d.ts +34 -0
- package/types/styles/sceneQualityProfiles.d.ts +13 -0
- package/types/styles/sceneStyleAudit.d.ts +80 -0
- package/types/styles/sceneStyleRuntime.d.ts +1782 -0
- package/types/styles/styleAdapters.d.ts +14 -0
- package/types/styles/styleApplication.d.ts +47 -0
- package/types/styles/styleBundle.d.ts +19 -0
- package/types/styles/styleBundleProvider.d.ts +44 -0
- package/types/styles/styleDomains.d.ts +18 -0
- package/types/styles/styleInspector.d.ts +59 -0
- package/types/styles/styleMaterialContract.d.ts +46 -0
- package/types/styles/styleMetadata.d.ts +11 -0
- package/types/styles/styleTargetDiscovery.d.ts +48 -0
- package/types/styles/styleTargetLabels.d.ts +32 -0
- package/types/styles/styleTargetMaterialCoverage.d.ts +20 -0
- package/types/styles/styleTransaction.d.ts +10 -0
- package/types/styles/styleTypes.d.ts +66 -0
- package/types/texgen/evaluateTexture.d.ts +40 -0
- package/types/texgen/index.d.ts +7 -0
- package/types/texgen/noise2.d.ts +46 -0
- package/types/texgen/textureAi.d.ts +6 -0
- package/types/texgen/textureGenerators.d.ts +261 -0
- package/types/texgen/texturePresets.d.ts +45 -0
- package/types/texgen/textureSettings.d.ts +121 -0
- package/types/texgen/textureThree.d.ts +13 -0
- package/types/toon/characterRenderPasses.d.ts +3 -0
- package/types/toon/index.d.ts +3 -0
- package/types/toon/settings/alphaSettings.d.ts +125 -0
- package/types/toon/settings/averageShadowSettings.d.ts +39 -0
- package/types/toon/settings/baseTextureSettings.d.ts +39 -0
- package/types/toon/settings/celShadeSettings.d.ts +37 -0
- package/types/toon/settings/contactShadowSettings.d.ts +30 -0
- package/types/toon/settings/eyeHighlightSettings.d.ts +55 -0
- package/types/toon/settings/faceLightingSettings.d.ts +32 -0
- package/types/toon/settings/furSettings.d.ts +23 -0
- package/types/toon/settings/glitterSettings.d.ts +43 -0
- package/types/toon/settings/hairHighlightSettings.d.ts +89 -0
- package/types/toon/settings/indirectLightSettings.d.ts +43 -0
- package/types/toon/settings/localLightSettings.d.ts +46 -0
- package/types/toon/settings/materialMapSettings.d.ts +86 -0
- package/types/toon/settings/outlineSettings.d.ts +125 -0
- package/types/toon/settings/perspectiveRemovalSettings.d.ts +14 -0
- package/types/toon/settings/rimLightSettings.d.ts +79 -0
- package/types/toon/settings/sceneShadowSettings.d.ts +32 -0
- package/types/toon/settings/selfShadowSettings.d.ts +44 -0
- package/types/toon/settings/shadowColorSettings.d.ts +77 -0
- package/types/toon/settings/skinToneSettings.d.ts +30 -0
- package/types/toon/settings/specularSettings.d.ts +96 -0
- package/types/toon/settings/stickerSettings.d.ts +40 -0
- package/types/toon/toonMaterialAdapter.d.ts +883 -0
- package/types/toon/toonSettings.d.ts +1182 -0
- package/types/vegetation/branchTree.d.ts +10 -0
- package/types/vegetation/callMeSenseiGrass.d.ts +8 -0
- package/types/vegetation/compiledTree.d.ts +75 -0
- package/types/vegetation/contactShadowField.d.ts +26 -0
- package/types/vegetation/flowerSpecies.d.ts +107 -0
- package/types/vegetation/grass.d.ts +4 -0
- package/types/vegetation/grassClump.d.ts +7 -0
- package/types/vegetation/grassPalettes.d.ts +29 -0
- package/types/vegetation/importedVegetationMaterial.d.ts +13 -0
- package/types/vegetation/index.d.ts +216 -0
- package/types/vegetation/legacyTreePresets.d.ts +22 -0
- package/types/vegetation/scatter.d.ts +12 -0
- package/types/vegetation/stylizedBush.d.ts +2 -0
- package/types/vegetation/stylizedFlower.d.ts +2 -0
- package/types/vegetation/stylizedFlowers.d.ts +8 -0
- package/types/vegetation/stylizedForest.d.ts +3 -0
- package/types/vegetation/stylizedGrass.d.ts +21 -0
- package/types/vegetation/stylizedTree.d.ts +19 -0
- package/types/vegetation/stylizedTreeFoliage.d.ts +18 -0
- package/types/vegetation/stylizedUnderstory.d.ts +50 -0
- package/types/vegetation/treeExport.d.ts +6 -0
- package/types/vegetation/treeSurfaceTextures.d.ts +72 -0
- package/types/vegetation/vegetationShaders.d.ts +74 -0
- package/types/version.d.ts +1 -0
- package/types/water/index.d.ts +1 -0
- package/types/water/sceneOverrideLayers.d.ts +16 -0
- package/types/water/water.d.ts +17 -0
- package/types/water/waterBreakerSystem.d.ts +46 -0
- package/types/water/waterCurrentField.d.ts +115 -0
- package/types/water/waterInteraction.d.ts +21 -0
- package/types/water/waterMaterial.d.ts +60 -0
- package/types/water/waterNearshorePhase.d.ts +5 -0
- package/types/water/waterRain.d.ts +17 -0
- package/types/water/waterRippleSimulation.d.ts +52 -0
- package/types/water/waterScenePasses.d.ts +70 -0
- package/types/water/waterSettings.d.ts +648 -0
- package/types/water/waterShoreMaterial.d.ts +3 -0
- package/types/water/waterShoreStateField.d.ts +2 -0
- package/types/water/waterSplashSystem.d.ts +2 -0
- package/types/water/waterStageSettings.d.ts +9 -0
- package/types/water/waterSurface.d.ts +2 -0
- package/types/water/waterUnderwaterAtmosphere.d.ts +103 -0
- package/types/water/waterVegetation.d.ts +16 -0
- package/types/worldCollision.d.ts +22 -0
- package/AGENTS.md +0 -254
- package/ATTRIBUTION.md +0 -78
- package/docs/characters.md +0 -144
- package/docs/debug-panel.md +0 -126
- package/docs/docs.css +0 -589
- package/docs/environment.md +0 -186
- package/docs/getting-started.md +0 -180
- package/docs/index.html +0 -14
- package/docs/lab-architecture.md +0 -100
- package/docs/lighting.md +0 -825
- package/docs/main.jsx +0 -739
- package/docs/mcp.md +0 -97
- package/docs/post-processing.md +0 -98
- package/docs/settings-reference.md +0 -1878
- package/docs/shader-constants.md +0 -77
- package/docs/sky.md +0 -182
- package/docs/style-labs.md +0 -309
- package/docs/texture-lab.md +0 -135
- package/docs/toon-shading.md +0 -183
- package/docs/tsl-conventions.md +0 -167
- package/docs/vegetation-sky.md +0 -275
- package/docs/water.md +0 -430
- package/docs/weather.md +0 -200
- package/docs/world-scale.md +0 -111
- package/mcp/style-lab-tools.mjs +0 -371
- package/src/ambientfx/INTEGRATION.md +0 -164
- package/src/ambientfx/ambientFxPresets.js +0 -83
- package/src/ambientfx/ambientFxSettings.js +0 -368
- package/src/ambientfx/emitters.js +0 -169
- package/src/ambientfx/index.js +0 -5
- package/src/ambientfx/particleBackbone.js +0 -493
- package/src/ambientfx/stylizedAmbientFx.js +0 -450
- package/src/biome/biomeGenerator.js +0 -385
- package/src/biome/biomeRuntime.js +0 -299
- package/src/biome/index.js +0 -2
- package/src/buildinggen/buildingAsset.js +0 -44
- package/src/buildinggen/buildingGrammar.js +0 -311
- package/src/buildinggen/buildingMesh.js +0 -451
- package/src/buildinggen/buildingPresets.js +0 -46
- package/src/buildinggen/buildingRecipe.js +0 -100
- package/src/buildinggen/buildingSettings.js +0 -238
- package/src/buildinggen/index.js +0 -6
- package/src/camera/cameraDirector.js +0 -157
- package/src/camera/cameraGenerator.js +0 -367
- package/src/camera/cameraRig.js +0 -570
- package/src/camera/cameraSettings.js +0 -236
- package/src/camera/index.js +0 -7
- package/src/catalog/builtinEntries.js +0 -245
- package/src/catalog/catalog.js +0 -210
- package/src/catalog/index.js +0 -3
- package/src/core/shaderBackend.js +0 -24
- package/src/debrisgen/debrisFields.js +0 -544
- package/src/debrisgen/debrisGenerator.js +0 -1929
- package/src/debrisgen/debrisPalettes.js +0 -71
- package/src/debrisgen/debrisPhysics.js +0 -198
- package/src/debrisgen/debrisPresets.js +0 -162
- package/src/debrisgen/debrisSettings.js +0 -333
- package/src/debrisgen/debrisTextures.js +0 -380
- package/src/debrisgen/index.js +0 -5
- package/src/debug/fieldValues.js +0 -95
- package/src/debug/index.js +0 -7
- package/src/debug/settingsPanel.js +0 -170
- package/src/fauna/INTEGRATION.md +0 -174
- package/src/fauna/boids.js +0 -861
- package/src/fauna/faunaBodies.js +0 -492
- package/src/fauna/faunaPresets.js +0 -52
- package/src/fauna/faunaSettings.js +0 -525
- package/src/fauna/index.js +0 -5
- package/src/fauna/stylizedFauna.js +0 -395
- package/src/game-feel/gameFeelGenerator.js +0 -402
- package/src/game-feel/gameFeelRuntime.js +0 -549
- package/src/game-feel/index.js +0 -2
- package/src/motion/index.js +0 -5
- package/src/motion/motionClip.js +0 -441
- package/src/motion/motionController.js +0 -628
- package/src/motion/motionDocuments.js +0 -225
- package/src/motion/motionGraph.js +0 -307
- package/src/motion/motionSettings.js +0 -222
- package/src/pathgen/index.js +0 -7
- package/src/pathgen/pathBridge.js +0 -232
- package/src/pathgen/pathPresets.js +0 -35
- package/src/pathgen/pathRibbon.js +0 -410
- package/src/pathgen/pathRouter.js +0 -380
- package/src/pathgen/pathSettings.js +0 -335
- package/src/pathgen/pathTextures.js +0 -123
- package/src/pathgen/stylizedPaths.js +0 -453
- package/src/propgen/generatorsWave1.js +0 -379
- package/src/propgen/generatorsWave2.js +0 -462
- package/src/propgen/index.js +0 -5
- package/src/propgen/propAsset.js +0 -323
- package/src/propgen/propParts.js +0 -170
- package/src/propgen/propPlacement.js +0 -459
- package/src/propgen/propPresets.js +0 -82
- package/src/propgen/propSettings.js +0 -395
- package/src/soundscape/index.js +0 -4
- package/src/soundscape/soundscapeGenerator.js +0 -179
- package/src/soundscape/soundscapeRuntime.js +0 -806
- package/src/soundscape/soundscapeSettings.js +0 -292
- package/src/stylizedTerrain.js +0 -631
- package/src/stylizedWorld.js +0 -903
- package/src/vegetation/treeRecipe.js +0 -647
- package/src/vfxgen/INTEGRATION.md +0 -145
- package/src/vfxgen/core/burstBackbone.js +0 -380
- package/src/vfxgen/core/projectileCore.js +0 -92
- package/src/vfxgen/core/spriteShapes.js +0 -98
- package/src/vfxgen/core/trailRibbon.js +0 -272
- package/src/vfxgen/core/vfxRandom.js +0 -29
- package/src/vfxgen/effects/emitHelpers.js +0 -37
- package/src/vfxgen/effects/magicEffects.js +0 -162
- package/src/vfxgen/effects/movementEffects.js +0 -87
- package/src/vfxgen/effects/weaponEffects.js +0 -118
- package/src/vfxgen/index.js +0 -18
- package/src/vfxgen/moves/moveController.js +0 -146
- package/src/vfxgen/moves/moveLibrary.js +0 -335
- package/src/vfxgen/vfxPresets.js +0 -98
- package/src/vfxgen/vfxSettings.js +0 -384
- package/src/vfxgen/vfxSystem.js +0 -449
- package/src/vfxgen/weapons/stylizedWeapons.js +0 -137
- package/src/villagegen/index.js +0 -4
- package/src/villagegen/stylizedVillage.js +0 -490
- package/src/villagegen/villageArchetypes.js +0 -160
- package/src/villagegen/villageNames.js +0 -40
- package/src/villagegen/villageSites.js +0 -105
- package/src/weather/index.js +0 -6
- package/src/weather/weatherPrecipitation.js +0 -221
- package/src/weather/weatherPresets.js +0 -258
- package/src/weather/weatherSettings.js +0 -269
- package/src/weather/weatherSystem.js +0 -871
- package/src/worldMinimap.js +0 -214
- package/src/worldPresets.js +0 -125
|
@@ -0,0 +1,1903 @@
|
|
|
1
|
+
// The volumetric cloud raymarcher.
|
|
2
|
+
//
|
|
3
|
+
// A screen-space pass: 128 primary steps along the view ray through a spherical
|
|
4
|
+
// shell, 6 light steps toward the sun at every non-empty sample. Both counts
|
|
5
|
+
// come from src/sky/skyQualityTiers.js and are fixed for every quality tier —
|
|
6
|
+
// tiers scale how many *rays* are marched (cloudHistoryDiv, see
|
|
7
|
+
// cloudReprojection.js), never the steps per ray, because changing the step
|
|
8
|
+
// count changes the transmittance integral and therefore the look.
|
|
9
|
+
//
|
|
10
|
+
// Written from the published literature summarized in docs/sky-cloud-parameters.md:
|
|
11
|
+
//
|
|
12
|
+
// Schneider & Vos, "The Real-Time Volumetric Cloudscapes of Horizon Zero
|
|
13
|
+
// Dawn" (SIGGRAPH 2015) — the shell, the weather-map/height-gradient/
|
|
14
|
+
// base-shape/erosion density recipe, the cone-spread light march.
|
|
15
|
+
// Hillaire, EGSR 2020 / SIGGRAPH 2015 — the energy-conserving segment
|
|
16
|
+
// integral and the analytic aerial-perspective solution.
|
|
17
|
+
// Bruneton & Neyret 2008 — the transmittance parameterisation this reuses
|
|
18
|
+
// through src/sky/atmosphereScattering.js.
|
|
19
|
+
//
|
|
20
|
+
// Geometry. Everything is world-space metres, but the shell is spherical, so
|
|
21
|
+
// altitudes have to survive a planet radius of 6360 km in float32. Two
|
|
22
|
+
// conditioned forms do that and are used everywhere instead of the direct
|
|
23
|
+
// expressions:
|
|
24
|
+
//
|
|
25
|
+
// altitude(camera + d) = (camAlt + d.y) + (d.x^2 + d.z^2) / (2R + camAlt + d.y)
|
|
26
|
+
// mu(after distance t) = (r*mu + t) / rAfter
|
|
27
|
+
//
|
|
28
|
+
// The first is `|p - centre| - R` rearranged so no term is ever the difference
|
|
29
|
+
// of two planet-scale numbers; at 42 km horizontal it reproduces the 139 m of
|
|
30
|
+
// earth curvature to within 1.5 mm (measured, not estimated). The direct form
|
|
31
|
+
// loses about a metre in float32, which is a third of a percent of a 2800 m
|
|
32
|
+
// shell — and it loses it at the horizon, where the melt window lives.
|
|
33
|
+
//
|
|
34
|
+
// The planet is re-centred under the camera every frame, at
|
|
35
|
+
// `(cameraX, groundLevel - R, cameraZ)`. That is what keeps the horizon at the
|
|
36
|
+
// right distance wherever the host places the camera; a centre fixed at
|
|
37
|
+
// `(0, -R, 0)` would leave a camera 100 km out from the world origin 780 m below
|
|
38
|
+
// its own local horizon. Two consequences to know about. Altitude is measured
|
|
39
|
+
// from the observer, so a distant cloud's height fraction drifts as the camera
|
|
40
|
+
// moves — 0.035 over 35 km at the default shell, absorbed entirely by the height
|
|
41
|
+
// gradient's plateau, so the density does not move with it. And the cloud *field*
|
|
42
|
+
// is still world-anchored: every noise and coverage lookup uses the absolute
|
|
43
|
+
// world position, so flying toward a cloud approaches it. Only the altitude and
|
|
44
|
+
// the horizon-bank distance are camera-relative, and both are camera-relative by
|
|
45
|
+
// definition. `cloudReprojection.js` re-centres identically from the same camera,
|
|
46
|
+
// which is what keeps the two passes agreeing within a frame.
|
|
47
|
+
//
|
|
48
|
+
// Output. `vec4(scatteredRadiance, transmittance)` in linear HDR, in the same
|
|
49
|
+
// unit as `sun.intensity`. The compositor's job is
|
|
50
|
+
// `sky * transmittance + scatteredRadiance` — no tonemap and no exposure here,
|
|
51
|
+
// exactly as the sky dome leaves them to the post chain.
|
|
52
|
+
|
|
53
|
+
import * as THREE from 'three';
|
|
54
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
55
|
+
import {
|
|
56
|
+
Break,
|
|
57
|
+
Fn,
|
|
58
|
+
If,
|
|
59
|
+
Loop,
|
|
60
|
+
abs,
|
|
61
|
+
clamp,
|
|
62
|
+
cross,
|
|
63
|
+
exp,
|
|
64
|
+
float,
|
|
65
|
+
length,
|
|
66
|
+
log2,
|
|
67
|
+
max,
|
|
68
|
+
min,
|
|
69
|
+
mix,
|
|
70
|
+
mrt,
|
|
71
|
+
normalize,
|
|
72
|
+
pow,
|
|
73
|
+
saturate,
|
|
74
|
+
screenUV,
|
|
75
|
+
select,
|
|
76
|
+
smoothstep,
|
|
77
|
+
sqrt,
|
|
78
|
+
step,
|
|
79
|
+
texture,
|
|
80
|
+
texture3D,
|
|
81
|
+
uniform,
|
|
82
|
+
property,
|
|
83
|
+
vec2,
|
|
84
|
+
vec3,
|
|
85
|
+
vec4,
|
|
86
|
+
} from 'three/tsl';
|
|
87
|
+
|
|
88
|
+
import {
|
|
89
|
+
ATMOSPHERE_MEDIUM,
|
|
90
|
+
atmosphereRaymarchNodes,
|
|
91
|
+
} from '../sky/atmosphereScattering.js';
|
|
92
|
+
import { applySkyColorNode } from '../sky/skyColor.js';
|
|
93
|
+
import {
|
|
94
|
+
CLOUD_LIGHT_MARCH_STEPS,
|
|
95
|
+
CLOUD_PRIMARY_MARCH_STEPS,
|
|
96
|
+
assertFixedMarchBudget,
|
|
97
|
+
resolveQuality,
|
|
98
|
+
} from '../sky/skyQualityTiers.js';
|
|
99
|
+
import {
|
|
100
|
+
applyCloudInnerPaintNode,
|
|
101
|
+
applyCloudLightBlendNode,
|
|
102
|
+
applyCloudTopLightNode,
|
|
103
|
+
applyCloudTimePaletteNode,
|
|
104
|
+
applyCloudWhiteTopNode,
|
|
105
|
+
createCloudLightingModel,
|
|
106
|
+
} from './cloudLighting.js';
|
|
107
|
+
import { AmbientSkyBaker } from './ambientSkyBaker.js';
|
|
108
|
+
import {
|
|
109
|
+
CLOUD_BASE_SHAPE_EROSION_WEIGHTS,
|
|
110
|
+
getCloudBaseShapeVolume,
|
|
111
|
+
} from './noise/baseShapeVolume.js';
|
|
112
|
+
import { getCloudCirrusMap } from './noise/cirrusMap.js';
|
|
113
|
+
import { getCloudErosionVolume } from './noise/erosionVolume.js';
|
|
114
|
+
import { getCurlNoiseVolume } from './noise/curlNoise.js';
|
|
115
|
+
import { getWeatherMap } from './noise/weatherMap.js';
|
|
116
|
+
import { uploadNoiseVolumeMipChain } from './noise/noiseVolume.js';
|
|
117
|
+
|
|
118
|
+
// The budget this module marches with is asserted at import time, so a tier
|
|
119
|
+
// table that grew a step-count field fails here rather than silently changing
|
|
120
|
+
// every rendered cloud.
|
|
121
|
+
assertFixedMarchBudget();
|
|
122
|
+
|
|
123
|
+
/** Planet radius in metres — the atmosphere module's bottom radius, in km. */
|
|
124
|
+
export const CLOUD_PLANET_RADIUS = ATMOSPHERE_MEDIUM.bottomRadius * 1000;
|
|
125
|
+
|
|
126
|
+
// The physical light march keeps the full optical depth. The white-top style
|
|
127
|
+
// descriptor uses a broader reach only for classifying sun-readable upper
|
|
128
|
+
// regions; it never feeds scattering, extinction, transmittance, or opacity.
|
|
129
|
+
export const CLOUD_WHITE_TOP_DEPTH_SCALE = 0.25;
|
|
130
|
+
export const CLOUD_WHITE_TOP_MIN_SUN_REACH = 0.55;
|
|
131
|
+
export const CLOUD_WHITE_TOP_HEIGHT_GAIN = 5;
|
|
132
|
+
/** Smallest accumulated alpha contribution accepted as the visible surface. */
|
|
133
|
+
export const CLOUD_SURFACE_LIGHT_MIN_WEIGHT = 0.002;
|
|
134
|
+
|
|
135
|
+
/** Metres sampled around the first visible point to recover a broad exterior normal. */
|
|
136
|
+
export const CLOUD_SURFACE_NORMAL_RADIUS = 100;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Transmittance at which the primary march stops.
|
|
140
|
+
*
|
|
141
|
+
* A 128-step march that never breaks early costs the same on a clear pixel as
|
|
142
|
+
* on an overcast one, and an overcast sky is where the frame budget is tightest.
|
|
143
|
+
* 0.004 is about eight stops below full brightness — below the point where a
|
|
144
|
+
* further sample can move the image — and on a `thunderstorm` sky it retires
|
|
145
|
+
* most rays in the first fifth of the shell.
|
|
146
|
+
*/
|
|
147
|
+
export const CLOUD_TRANSMITTANCE_EPSILON = 0.004;
|
|
148
|
+
|
|
149
|
+
/** Normalized density below which a sample contributes nothing and is skipped. */
|
|
150
|
+
export const CLOUD_DENSITY_EPSILON = 1e-4;
|
|
151
|
+
|
|
152
|
+
/** Fine primary-march step in world metres. */
|
|
153
|
+
export const CLOUD_BASE_STEP_SIZE = 25;
|
|
154
|
+
|
|
155
|
+
/** Empty space advances at four times the current cone-footprint step. */
|
|
156
|
+
export const CLOUD_COARSE_STEP_SCALE = 4;
|
|
157
|
+
|
|
158
|
+
/** Empty fine samples required before returning to coarse mode. */
|
|
159
|
+
export const CLOUD_FINE_EMPTY_LIMIT = 4;
|
|
160
|
+
|
|
161
|
+
/** Distance-based fine-step growth multiplier. */
|
|
162
|
+
export const CLOUD_STEP_CONE_FACTOR = 1.5;
|
|
163
|
+
|
|
164
|
+
/** Largest optical depth integrated by one visible-surface sample. */
|
|
165
|
+
export const CLOUD_MAX_OPTICAL_DEPTH_PER_STEP = 0.5;
|
|
166
|
+
|
|
167
|
+
/** Smallest density-adaptive core step as a fraction of the cone-footprint step. */
|
|
168
|
+
export const CLOUD_CORE_STEP_MIN_SCALE = 0.15;
|
|
169
|
+
|
|
170
|
+
/** Opaque cloud interiors advance faster once their contribution is hidden. */
|
|
171
|
+
export const CLOUD_INTERIOR_STEP_SCALE = 3;
|
|
172
|
+
export const CLOUD_INTERIOR_COARSEN_START = 1;
|
|
173
|
+
export const CLOUD_INTERIOR_COARSEN_FULL = 3;
|
|
174
|
+
|
|
175
|
+
/** Metres the cirrus/haze deck sits above the top of the volumetric shell. */
|
|
176
|
+
export const CLOUD_DECK_ALTITUDE_OFFSET = 2000;
|
|
177
|
+
|
|
178
|
+
/** Longest slant path, in deck thicknesses, a grazing view is allowed to accrue. */
|
|
179
|
+
export const CLOUD_DECK_MAX_SLANT = 6;
|
|
180
|
+
|
|
181
|
+
/** Floor on |cos| for the deck's slant path, so the horizon does not divide by zero. */
|
|
182
|
+
export const CLOUD_DECK_MIN_COS = 0.02;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Representative extinction of the deck, 1/m. Only the moon rim reads it — the
|
|
186
|
+
* deck's own opacity comes from its texture and coverage — and a thin deck has
|
|
187
|
+
* to read as an edge everywhere for the rim to land on it.
|
|
188
|
+
*/
|
|
189
|
+
export const CLOUD_DECK_EXTINCTION = 0.0004;
|
|
190
|
+
|
|
191
|
+
/** Self-shadowing optical depth the deck accrues at full opacity. */
|
|
192
|
+
export const CLOUD_DECK_LIGHT_DEPTH = 1.5;
|
|
193
|
+
|
|
194
|
+
/** Light-march length as a fraction of the shell thickness. */
|
|
195
|
+
export const CLOUD_LIGHT_MARCH_LENGTH_FRACTION = 1;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Geometric growth of the light-march step.
|
|
199
|
+
*
|
|
200
|
+
* Six steps cannot resolve a 2800 m shell evenly, so they are graded: the first
|
|
201
|
+
* two land inside the sample's own neighbourhood, where the self-shadow that
|
|
202
|
+
* shapes a billow lives, and the last reaches most of the way out of the cloud
|
|
203
|
+
* to catch a tower shadowing the deck below it. At 1.7 the last step is 12
|
|
204
|
+
* times the first.
|
|
205
|
+
*/
|
|
206
|
+
export const CLOUD_LIGHT_MARCH_GROWTH = 1.5;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Cone half-width of the light march, as a fraction of the distance marched.
|
|
210
|
+
*
|
|
211
|
+
* The light march is a cone, not a line: six samples along a single ray alias
|
|
212
|
+
* into hard-edged shadow bands, and spreading them decorrelates the bands. At
|
|
213
|
+
* 0.3 the cone's half-angle is 16.7 degrees, which is **not** the sun's angular
|
|
214
|
+
* radius (0.26 degrees) — it is the width over which multiple scattering has
|
|
215
|
+
* already smeared the shadow by the time it reaches the eye. Sizing the cone to
|
|
216
|
+
* the solar disc would leave the banding it exists to remove.
|
|
217
|
+
*/
|
|
218
|
+
export const CLOUD_LIGHT_CONE_SPREAD = 0.05;
|
|
219
|
+
|
|
220
|
+
/** Base light-cone step in world metres. */
|
|
221
|
+
export const CLOUD_LIGHT_STEP_SIZE = 25;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Unit offsets the light march spreads its samples over: a Vogel (golden-angle)
|
|
225
|
+
* disc, deterministic and better stratified for six points than any hand-picked
|
|
226
|
+
* set.
|
|
227
|
+
*
|
|
228
|
+
* Two dimensions, not three, because the offsets are applied on a basis built
|
|
229
|
+
* around the light direction at march time — see `createCloudLightMarch`. A
|
|
230
|
+
* fixed world-space lattice would displace the taps by a constant world
|
|
231
|
+
* direction regardless of where the sun is: the two heaviest taps of a sphere
|
|
232
|
+
* lattice sit 187 m and 550 m *below* the sample at the default 2800 m
|
|
233
|
+
* thickness, so a sample under a low sun is shadowed by cloud that is not
|
|
234
|
+
* between it and the sun at all.
|
|
235
|
+
*/
|
|
236
|
+
export const CLOUD_LIGHT_CONE_OFFSETS = Object.freeze(
|
|
237
|
+
Array.from({ length: CLOUD_LIGHT_MARCH_STEPS }, (unused, index) => {
|
|
238
|
+
const golden = Math.PI * (3 - Math.sqrt(5));
|
|
239
|
+
const radius = Math.sqrt((index + 0.5) / CLOUD_LIGHT_MARCH_STEPS);
|
|
240
|
+
const phi = index * golden;
|
|
241
|
+
return Object.freeze([radius * Math.cos(phi), radius * Math.sin(phi)]);
|
|
242
|
+
}),
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Nubis-style density-height profiles, expressed as
|
|
247
|
+
* `[bottomStart, bottomEnd, topStart, topEnd]` shell fractions.
|
|
248
|
+
*
|
|
249
|
+
* The 2017 density-model presentation defines the type axis as stratus at 0,
|
|
250
|
+
* stratocumulus at 0.5 and cumulus at 1. The four breakpoints below are the
|
|
251
|
+
* canonical public HZD implementation values used with that axis: a profile is
|
|
252
|
+
* `smoothstep(x, y, h) - smoothstep(z, w, h)`, and the three vec4s are blended
|
|
253
|
+
* with triangular weights before that profile is evaluated. Blending the
|
|
254
|
+
* breakpoints first is important: it moves the cloud floor and crown smoothly
|
|
255
|
+
* instead of cross-fading two already-shaped slabs.
|
|
256
|
+
*/
|
|
257
|
+
export const CLOUD_STRATUS_HEIGHT_GRADIENT = Object.freeze([0.02, 0.05, 0.09, 0.11]);
|
|
258
|
+
export const CLOUD_STRATOCUMULUS_HEIGHT_GRADIENT = Object.freeze([0.02, 0.2, 0.48, 0.625]);
|
|
259
|
+
export const CLOUD_CUMULUS_HEIGHT_GRADIENT = Object.freeze([0.01, 0.0625, 0.78, 1]);
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Couples the published 0-5 `erosionStrength*` range to the erosion field's own
|
|
263
|
+
* [0, 1] range.
|
|
264
|
+
*
|
|
265
|
+
* Detail times strength becomes the lower edge of a density remap. A remap,
|
|
266
|
+
* rather than a subtraction multiplied by `(1 - density)`, preserves a value
|
|
267
|
+
* of one in the core while allowing the high-frequency field to move the
|
|
268
|
+
* actual surface. Multiplying by `(1 - density)` made saturated macro bodies
|
|
269
|
+
* immune to erosion and left them as smooth extruded weather-map shapes.
|
|
270
|
+
*/
|
|
271
|
+
export const CLOUD_EROSION_CARVE_SCALE = 0.2;
|
|
272
|
+
|
|
273
|
+
/** Height scale of the wispy inversion, per the erosion volume's documented recipe. */
|
|
274
|
+
export const CLOUD_EROSION_WISP_HEIGHT = 10;
|
|
275
|
+
|
|
276
|
+
/** Smallest erosion tile, metres — keeps a zero multiplier from dividing by zero. */
|
|
277
|
+
export const CLOUD_EROSION_MIN_SCALE = 32;
|
|
278
|
+
|
|
279
|
+
/** Curl advection of the erosion sample, as a fraction of the erosion tile. */
|
|
280
|
+
export const CLOUD_CURL_STRENGTH_FRACTION = 0.12;
|
|
281
|
+
|
|
282
|
+
/** Per-channel top-dilation weights for the packed Worley volume. */
|
|
283
|
+
export const CLOUD_BASE_CHANNEL_STRENGTHS = Object.freeze([0.7, 0.41, 0.23]);
|
|
284
|
+
|
|
285
|
+
/** Per-channel erosion weights when that volume is sampled at a smaller scale. */
|
|
286
|
+
export const CLOUD_EROSION_CHANNEL_STRENGTHS = Object.freeze([0.113, 0.04, 0.02]);
|
|
287
|
+
|
|
288
|
+
/** Coverage-space width of the weather-map floor carve. */
|
|
289
|
+
export const CLOUD_WEATHER_CARVE_WIDTH = 0.1;
|
|
290
|
+
|
|
291
|
+
// Unique suffix for the laid-out GPU functions this module emits. A layout name
|
|
292
|
+
// is a GPU identifier, so two cloud materials compiled into one program would
|
|
293
|
+
// collide on it.
|
|
294
|
+
let volumeId = 0;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Scopes a laid-out TSL function to the build that consumes it.
|
|
298
|
+
*
|
|
299
|
+
* `Fn().setLayout()` emits one real GPU function instead of an inlined copy per
|
|
300
|
+
* call, which is the only way a 128-step march can afford this density field.
|
|
301
|
+
* But three caches that function's GENERATED TEXT in a map keyed by
|
|
302
|
+
* (backend, Fn) which outlives every build, and hands the cached text to any
|
|
303
|
+
* later build of the same Fn. The text does not travel. It reads its uniforms as
|
|
304
|
+
* `object.nodeUniformN` — N being the slot the generating build happened to
|
|
305
|
+
* allocate — and names its texture and sampler bindings the same way; and
|
|
306
|
+
* because a cached body is never regenerated, its bindings are never
|
|
307
|
+
* re-registered either. Handed to a build whose graph numbered the object group
|
|
308
|
+
* differently, `position - cameraPosition` becomes `vec3<f32> - vec2<f32>`
|
|
309
|
+
* (measured: WGSL "no matching overload for 'operator - (vec3<f32>,
|
|
310
|
+
* vec2<f32>)'", GLSL "wrong operand types"), and the three noise volumes'
|
|
311
|
+
* samplers are not declared in the program at all.
|
|
312
|
+
*
|
|
313
|
+
* That is not a corner case. `SkySystem.cloudShadow` puts this module's reduced
|
|
314
|
+
* density field into an arbitrary receiver material's graph, `cloudReprojection`
|
|
315
|
+
* marches into its own target, the env-map bake wants its own build with its own
|
|
316
|
+
* march settings, and any material-level change rebuilds the pass in place.
|
|
317
|
+
* Whichever program compiles second gets the first one's text.
|
|
318
|
+
*
|
|
319
|
+
* Explicit parameters are the fix for the uniforms and cannot be the fix for the
|
|
320
|
+
* volumes: WGSL and GLSL both need a texture and its sampler as bindings, and
|
|
321
|
+
* neither node builder maps a `texture`/`texture3D` layout input to a parameter
|
|
322
|
+
* type — there is no such parameter to pass. So the function is made to belong
|
|
323
|
+
* to its build instead. Every body then names the slots of the build it is
|
|
324
|
+
* emitted into, whatever else that build put in the object group and in whatever
|
|
325
|
+
* order, and a uniform or volume added to the field later is covered without
|
|
326
|
+
* anyone having to remember this.
|
|
327
|
+
*
|
|
328
|
+
* The key is `builder.globalCache`: one object per NodeBuilder, and — unlike
|
|
329
|
+
* `builder.cache`, which is swapped out and back around every sub-build — the
|
|
330
|
+
* same object for the whole of that build. Asserted rather than defaulted: a
|
|
331
|
+
* key that failed to identify the build would hand the same build two functions
|
|
332
|
+
* carrying one layout name, which is a duplicate GPU identifier and a far worse
|
|
333
|
+
* failure than the one this exists to prevent.
|
|
334
|
+
*/
|
|
335
|
+
function buildScoped(create) {
|
|
336
|
+
const perBuild = new WeakMap();
|
|
337
|
+
return (builder) => {
|
|
338
|
+
const scope = builder?.globalCache;
|
|
339
|
+
if (scope === null || typeof scope !== 'object') {
|
|
340
|
+
throw new TypeError(
|
|
341
|
+
'[cloudVolume] NodeBuilder has no globalCache to scope a laid-out function to; '
|
|
342
|
+
+ 'the three version this module was written against (r185) is the contract.',
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
let scoped = perBuild.get(scope);
|
|
346
|
+
if (scoped === undefined) {
|
|
347
|
+
scoped = create();
|
|
348
|
+
perBuild.set(scope, scoped);
|
|
349
|
+
}
|
|
350
|
+
return scoped;
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function vectorUniform(x = 0, y = 0, z = 0) {
|
|
355
|
+
return uniform(new THREE.Vector3(x, y, z));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Both roots of `t^2 + 2 b t + q = 0`, written so neither is the difference of
|
|
360
|
+
* two planet-scale numbers.
|
|
361
|
+
*
|
|
362
|
+
* The naive `-b ± sqrt(b^2 - q)` cancels catastrophically for whichever root
|
|
363
|
+
* has the same sign as `-b`: a vertical view from the ground computes the
|
|
364
|
+
* shell entry as 6.360000e6 minus 6.359999e6. Because `tNear * tFar = q`, the
|
|
365
|
+
* bad root is recovered from the good one by a division instead, and which root
|
|
366
|
+
* is which follows from the sign of `b`.
|
|
367
|
+
*/
|
|
368
|
+
function solveQuadratic(b, q) {
|
|
369
|
+
const discriminant = b.mul(b).sub(q).toVar();
|
|
370
|
+
const root = sqrt(max(discriminant, 0)).toVar();
|
|
371
|
+
const naiveNear = b.negate().sub(root).toVar();
|
|
372
|
+
const naiveFar = b.negate().add(root).toVar();
|
|
373
|
+
// The guards only matter for an exactly grazing ray, where both roots meet.
|
|
374
|
+
const stableFar = q.div(naiveNear.sub(1e-6)).toVar();
|
|
375
|
+
const stableNear = q.div(naiveFar.add(1e-6)).toVar();
|
|
376
|
+
const forward = step(0, b).toVar();
|
|
377
|
+
return {
|
|
378
|
+
discriminant,
|
|
379
|
+
far: mix(naiveFar, stableFar, forward).toVar(),
|
|
380
|
+
near: mix(stableNear, naiveNear, forward).toVar(),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Roots of the view ray against a sphere at `targetAltitude`, plus the two
|
|
386
|
+
* intersection flags the callers need. `frontHit` requires both a real
|
|
387
|
+
* discriminant and a positive near root: a negative discriminant leaves a
|
|
388
|
+
* meaningless positive root behind, so one test on its own is not enough.
|
|
389
|
+
*/
|
|
390
|
+
function intersectAltitude({ cameraAltitude, b, r, targetAltitude }) {
|
|
391
|
+
const target = float(targetAltitude);
|
|
392
|
+
const q = cameraAltitude.sub(target).mul(r.add(target).add(CLOUD_PLANET_RADIUS));
|
|
393
|
+
const roots = solveQuadratic(b, q);
|
|
394
|
+
return {
|
|
395
|
+
...roots,
|
|
396
|
+
frontHit: step(0, roots.discriminant).mul(step(0, roots.near)).toVar(),
|
|
397
|
+
hit: step(0, roots.discriminant).toVar(),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Distance at which the view ray crosses a single thin layer at
|
|
403
|
+
* `layerAltitude`, and whether it crosses it at all.
|
|
404
|
+
*
|
|
405
|
+
* Used for the cirrus/haze deck, which is a surface rather than a volume, so
|
|
406
|
+
* running it through `intersectCloudShell` with a one-metre shell would have made
|
|
407
|
+
* the hit test depend on the view angle: a vertical ray crosses one metre of it
|
|
408
|
+
* and a grazing ray several kilometres.
|
|
409
|
+
*
|
|
410
|
+
* A camera below the layer crosses it on the far root, one above it on the near
|
|
411
|
+
* root, and a ray that meets the planet first never reaches it.
|
|
412
|
+
*
|
|
413
|
+
* `above` is returned as well as consumed: it is the same 0/1 test that decides
|
|
414
|
+
* which root is the crossing, and it is therefore also the answer to "is this
|
|
415
|
+
* layer in front of everything below it along the ray", which the compositor
|
|
416
|
+
* needs.
|
|
417
|
+
*/
|
|
418
|
+
export function findCloudLayerCrossing({ cameraAltitude, viewDir, layerAltitude }) {
|
|
419
|
+
const altitude = max(float(cameraAltitude), 0.5).toVar();
|
|
420
|
+
const r = altitude.add(CLOUD_PLANET_RADIUS).toVar();
|
|
421
|
+
const b = r.mul(viewDir.y).toVar();
|
|
422
|
+
const layer = intersectAltitude({ b, cameraAltitude: altitude, r, targetAltitude: layerAltitude });
|
|
423
|
+
const ground = intersectAltitude({ b, cameraAltitude: altitude, r, targetAltitude: 0 });
|
|
424
|
+
const above = step(float(layerAltitude), altitude).toVar();
|
|
425
|
+
const distance = mix(layer.far, layer.near, above).toVar();
|
|
426
|
+
const blocked = ground.frontHit.mul(step(ground.near, distance)).toVar();
|
|
427
|
+
return {
|
|
428
|
+
above,
|
|
429
|
+
distance: max(distance, 1).toVar(),
|
|
430
|
+
hit: layer.hit.mul(step(1, distance)).mul(blocked.oneMinus()).toVar(),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Intersects the view ray with the cloud shell.
|
|
436
|
+
*
|
|
437
|
+
* Handles all three camera placements: below the deck (the common case, where
|
|
438
|
+
* the ray enters through the far side of the inner sphere), inside it (the
|
|
439
|
+
* march starts at the camera), and above it (a descending ray enters through
|
|
440
|
+
* the near side of the outer sphere). A ray that meets the planet first sees no
|
|
441
|
+
* cloud at all, and the march never runs past `maxDistance`.
|
|
442
|
+
*
|
|
443
|
+
* Emitted inline rather than wrapped in `Fn`, because the caller needs all
|
|
444
|
+
* three results and TSL functions return one value.
|
|
445
|
+
*/
|
|
446
|
+
export function intersectCloudShell({
|
|
447
|
+
cameraAltitude,
|
|
448
|
+
viewDir,
|
|
449
|
+
baseAltitude,
|
|
450
|
+
topAltitude,
|
|
451
|
+
maxDistance,
|
|
452
|
+
}) {
|
|
453
|
+
const altitude = max(float(cameraAltitude), 0.5).toVar();
|
|
454
|
+
const r = altitude.add(CLOUD_PLANET_RADIUS).toVar();
|
|
455
|
+
const b = r.mul(viewDir.y).toVar();
|
|
456
|
+
|
|
457
|
+
const intersectAt = (targetAltitude) => intersectAltitude({
|
|
458
|
+
b,
|
|
459
|
+
cameraAltitude: altitude,
|
|
460
|
+
r,
|
|
461
|
+
targetAltitude,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const inner = intersectAt(baseAltitude);
|
|
465
|
+
const outer = intersectAt(topAltitude);
|
|
466
|
+
const ground = intersectAt(0);
|
|
467
|
+
|
|
468
|
+
const tStart = float(0).toVar();
|
|
469
|
+
const tEnd = float(-1).toVar();
|
|
470
|
+
|
|
471
|
+
// Where the shell ends for a camera that is not below it: the inner sphere if
|
|
472
|
+
// the ray descends into it, the outer sphere otherwise. Branchless, because
|
|
473
|
+
// `frontHit` is already the 0/1 selector.
|
|
474
|
+
const exitAbove = mix(outer.far, inner.near, inner.frontHit).toVar();
|
|
475
|
+
|
|
476
|
+
If(altitude.lessThan(float(baseAltitude)), () => {
|
|
477
|
+
tStart.assign(inner.far);
|
|
478
|
+
tEnd.assign(outer.far);
|
|
479
|
+
}).ElseIf(altitude.greaterThan(float(topAltitude)), () => {
|
|
480
|
+
tStart.assign(max(outer.near, 0));
|
|
481
|
+
tEnd.assign(exitAbove);
|
|
482
|
+
// Looking away from the deck, or missing the outer sphere entirely.
|
|
483
|
+
If(outer.frontHit.lessThan(0.5), () => {
|
|
484
|
+
tEnd.assign(-1);
|
|
485
|
+
});
|
|
486
|
+
}).Else(() => {
|
|
487
|
+
tStart.assign(0);
|
|
488
|
+
tEnd.assign(exitAbove);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// The planet blocks the rest of the ray. A downward view from below the deck
|
|
492
|
+
// reaches the inner sphere only on the far side of the world, so this is what
|
|
493
|
+
// removes cloud from below the horizon rather than a separate test.
|
|
494
|
+
If(ground.frontHit.greaterThan(0.5), () => {
|
|
495
|
+
tEnd.assign(min(tEnd, ground.near));
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
tStart.assign(max(tStart, 0));
|
|
499
|
+
tEnd.assign(min(tEnd, max(float(maxDistance), 0)));
|
|
500
|
+
|
|
501
|
+
return {
|
|
502
|
+
tStart,
|
|
503
|
+
tEnd,
|
|
504
|
+
// A shell shorter than a metre is a grazing sliver, not a cloud.
|
|
505
|
+
hit: step(1, tEnd.sub(tStart)).toVar(),
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Conditioned altitude of a point offset from the camera by `delta`, in metres.
|
|
511
|
+
* See the module header for why the direct form is not used.
|
|
512
|
+
*
|
|
513
|
+
* The exact altitude is `sqrt(h2 + (R + a)^2) - R` for a flat height `a` and a
|
|
514
|
+
* squared horizontal distance `h2`, whose expansion is
|
|
515
|
+
* `a + h2 / (2 (R + a)) - h2^2 / (8 (R + a)^3) + ...`. This keeps the first two
|
|
516
|
+
* terms of the numerator exactly and drops the third, which at 42 km horizontal
|
|
517
|
+
* is 1.5 mm against 139 m of curvature. Writing the denominator as `2R + a`
|
|
518
|
+
* rather than `2R + 2a` looks equivalent at planet scale and is not: it costs a
|
|
519
|
+
* further 24 mm, sixteen times the whole remaining error, for no saving.
|
|
520
|
+
*/
|
|
521
|
+
function getAltitudeNode(cameraAltitude, delta) {
|
|
522
|
+
const flat = cameraAltitude.add(delta.y);
|
|
523
|
+
const horizontal = delta.x.mul(delta.x).add(delta.z.mul(delta.z));
|
|
524
|
+
return flat.add(horizontal.div(flat.mul(2).add(2 * CLOUD_PLANET_RADIUS)));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Builds the cloud-density samplers used by view, light, and shadow marches.
|
|
529
|
+
*
|
|
530
|
+
* `sampleDensityNode(worldPosition)` returns
|
|
531
|
+
* `vec3(normalizedDensity, heightFraction, occupancy)`:
|
|
532
|
+
*
|
|
533
|
+
* - `normalizedDensity` is the dimensionless [0, 1] field before
|
|
534
|
+
* `shape.density` turns it into an extinction coefficient.
|
|
535
|
+
* - `heightFraction` is the sample's place in the shell, which the lighting
|
|
536
|
+
* model needs anyway.
|
|
537
|
+
* - `occupancy` is the same field with the shell's height envelope left out —
|
|
538
|
+
* how much cloud surrounds the sample, independent of where in the shell it
|
|
539
|
+
* sits. `powderNode` keys on it; see `cloudLighting.js` for why the plain
|
|
540
|
+
* density is the wrong input for a term that darkens *edges*.
|
|
541
|
+
*
|
|
542
|
+
* One call, three results.
|
|
543
|
+
*
|
|
544
|
+
* `sampleCoarseDensityNode(worldPosition)` returns density alone from a reduced
|
|
545
|
+
* field: base shape and coverage, no erosion volume and no curl. That is the
|
|
546
|
+
* shape Nubis marches the light with, and the reason is cost — the light march
|
|
547
|
+
* evaluates a density six times per lit sample, so a full-detail field there
|
|
548
|
+
* costs 24 texture fetches against 12 for the reduced one. The high-frequency
|
|
549
|
+
* erosion carves edges finer than the light march's own 42 m first step can
|
|
550
|
+
* resolve, so what it buys in a shadow is noise rather than detail.
|
|
551
|
+
*
|
|
552
|
+
* GPU layouts prevent the 128 view samples and their light samples from
|
|
553
|
+
* inlining duplicate copies of the field. The returned `...Node` functions are
|
|
554
|
+
* small call shims that can safely be used by separate shader graphs.
|
|
555
|
+
*
|
|
556
|
+
* The recipe, in the order the two noise modules document it:
|
|
557
|
+
*
|
|
558
|
+
* heightGradient = bottomFade * topFade
|
|
559
|
+
* shape = remap(baseShape.r, -(1 - lowFreqFbm), 1, 0, 1) * heightGradient
|
|
560
|
+
* coverage = weather.r * (shape.coverage + horizonBank)
|
|
561
|
+
* density = remap(shape, 1 - coverage, 1, 0, 1) * coverage
|
|
562
|
+
* density -= baseWeatherCarve (thin bottoms)
|
|
563
|
+
* density -= erosionModifier * strength * (1 - density)
|
|
564
|
+
*
|
|
565
|
+
* Two coordinate frames are in play and mixing them up is not a subtle error.
|
|
566
|
+
* Every noise and coverage lookup uses the **absolute world position**, so the
|
|
567
|
+
* cloud field is anchored to the world and a camera that flies a kilometre
|
|
568
|
+
* actually approaches the cloud it was pointed at. Only three quantities are
|
|
569
|
+
* camera-relative, and each of them is camera-relative by definition: the
|
|
570
|
+
* conditioned altitude, which is expressed as an offset from the camera to stay
|
|
571
|
+
* out of planet-scale arithmetic; the horizontal distance the horizon bank
|
|
572
|
+
* builds over; and nothing else. Feeding `delta` to the noise instead pins the
|
|
573
|
+
* whole sky to the camera — the clouds slide along with it and the temporal
|
|
574
|
+
* reprojection, which projects a world position, disagrees with the marcher
|
|
575
|
+
* about where they are.
|
|
576
|
+
*/
|
|
577
|
+
export function createCloudDensityField({
|
|
578
|
+
shape,
|
|
579
|
+
wind,
|
|
580
|
+
weatherMap,
|
|
581
|
+
baseShapeVolume,
|
|
582
|
+
erosionVolume,
|
|
583
|
+
curlVolume = null,
|
|
584
|
+
cameraPosition,
|
|
585
|
+
cameraAltitude,
|
|
586
|
+
pixelConeAngle = float(0.001),
|
|
587
|
+
baseShapeResolution = float(64),
|
|
588
|
+
name = 'cloudDensity',
|
|
589
|
+
} = {}) {
|
|
590
|
+
if (!shape?.altitude || !shape?.thickness) {
|
|
591
|
+
throw new TypeError('createCloudDensityField needs a cloud shape param group.');
|
|
592
|
+
}
|
|
593
|
+
if (!wind?.direction || !wind?.offset) {
|
|
594
|
+
throw new TypeError('createCloudDensityField needs a cloud wind param group.');
|
|
595
|
+
}
|
|
596
|
+
if (!weatherMap?.isTexture) throw new TypeError('createCloudDensityField needs a weather map.');
|
|
597
|
+
if (!baseShapeVolume?.isTexture) {
|
|
598
|
+
throw new TypeError('createCloudDensityField needs a base-shape volume.');
|
|
599
|
+
}
|
|
600
|
+
if (!erosionVolume?.isTexture) {
|
|
601
|
+
throw new TypeError('createCloudDensityField needs an erosion volume.');
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const weatherNode = texture(weatherMap);
|
|
605
|
+
const baseShapeNode = texture3D(baseShapeVolume);
|
|
606
|
+
const erosionNode = texture3D(erosionVolume);
|
|
607
|
+
const curlNode = curlVolume?.isTexture ? texture3D(curlVolume) : null;
|
|
608
|
+
|
|
609
|
+
const [baseLow, baseMid, baseHigh] = CLOUD_BASE_CHANNEL_STRENGTHS;
|
|
610
|
+
const [detailLow, detailMid, detailHigh] = CLOUD_EROSION_CHANNEL_STRENGTHS;
|
|
611
|
+
|
|
612
|
+
volumeId += 1;
|
|
613
|
+
const functionName = `${name}${volumeId}`;
|
|
614
|
+
const coarseFunctionName = `${name}Coarse${volumeId}`;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Samples the shared cloud field. Named options make each call state why it
|
|
618
|
+
* differs from the normal camera-ray sample instead of relying on positional
|
|
619
|
+
* nulls and booleans.
|
|
620
|
+
*/
|
|
621
|
+
const sampleDensity = (position, {
|
|
622
|
+
detail = true,
|
|
623
|
+
viewDistance = null,
|
|
624
|
+
mipLevel = null,
|
|
625
|
+
coverage = null,
|
|
626
|
+
} = {}) => {
|
|
627
|
+
const delta = position.sub(cameraPosition).toVar();
|
|
628
|
+
const sampleDistance = length(delta).toVar();
|
|
629
|
+
// Primary samples derive their footprint and horizon lift from their own
|
|
630
|
+
// camera distance. Sun-cone taps receive the primary sample's distance so
|
|
631
|
+
// those values stay consistent across the light cone.
|
|
632
|
+
const fieldDistance = viewDistance ?? sampleDistance;
|
|
633
|
+
const altitude = getAltitudeNode(cameraAltitude, delta).toVar();
|
|
634
|
+
const thickness = max(shape.thickness, 1).toVar();
|
|
635
|
+
const heightFraction = altitude.sub(shape.altitude).div(thickness).toVar();
|
|
636
|
+
|
|
637
|
+
// --- wind -------------------------------------------------------------
|
|
638
|
+
// Drift moves the whole field, skew leans the sample upwind as height
|
|
639
|
+
// climbs so tops sit downwind of bases, and evolution walks only the 3D
|
|
640
|
+
// noise so shape churns without the weather system moving. All three are
|
|
641
|
+
// independent, which is the contract `wind.speed` / `wind.evolutionSpeed`
|
|
642
|
+
// publish.
|
|
643
|
+
//
|
|
644
|
+
// World position, not `delta` — see the frame note in the doc comment.
|
|
645
|
+
const drifted = position.sub(wind.offset).toVar();
|
|
646
|
+
const skewed = drifted.sub(
|
|
647
|
+
wind.direction.mul(wind.skew.mul(max(heightFraction, 0))),
|
|
648
|
+
).toVar();
|
|
649
|
+
const evolved = skewed.add(wind.evolutionOffset).toVar();
|
|
650
|
+
|
|
651
|
+
// --- density field ---------------------------------------------------
|
|
652
|
+
// The weather map's red channel is a column-height field. The one packed
|
|
653
|
+
// Worley volume is sampled at the broad base scale to dilate the column top,
|
|
654
|
+
// then sampled again at a smaller scale to erode both top and underside.
|
|
655
|
+
// Weather G is intentionally unused; this model does not blend separate
|
|
656
|
+
// cloud-type height profiles.
|
|
657
|
+
const weatherSample = weatherNode
|
|
658
|
+
.sample(position.xz.sub(wind.offset.xz).div(max(shape.weatherScale, 1)))
|
|
659
|
+
.toVar();
|
|
660
|
+
const weather = weatherSample.r.toVar();
|
|
661
|
+
const baseScale = max(shape.baseScale, 1).toVar();
|
|
662
|
+
const macroUv = evolved.div(baseScale).toVar();
|
|
663
|
+
const baseWorldTexel = baseScale.div(max(baseShapeResolution, 1)).toVar();
|
|
664
|
+
const baseLod = (mipLevel ?? max(
|
|
665
|
+
0,
|
|
666
|
+
log2(max(fieldDistance.mul(pixelConeAngle).div(baseWorldTexel), 1e-6)),
|
|
667
|
+
)).toVar();
|
|
668
|
+
const packed = baseShapeNode.sample(macroUv).level(baseLod).toVar();
|
|
669
|
+
let boundaryOffset = packed.r.mul(baseLow)
|
|
670
|
+
.add(packed.g.mul(baseMid))
|
|
671
|
+
.add(packed.b.mul(baseHigh))
|
|
672
|
+
.mul(max(shape.baseStrength, 0))
|
|
673
|
+
.toVar();
|
|
674
|
+
|
|
675
|
+
// The horizon coverage lift uses the full camera-to-sample
|
|
676
|
+
// distance. Reuse the same distance already computed for the cone-footprint
|
|
677
|
+
// LOD so the medium and its reference self-shadow stay in the same frame.
|
|
678
|
+
const bankRamp = smoothstep(
|
|
679
|
+
shape.horizonCoverageStart,
|
|
680
|
+
shape.horizonCoverageStart.add(max(shape.horizonCoverageRamp, 1)),
|
|
681
|
+
fieldDistance,
|
|
682
|
+
);
|
|
683
|
+
const effectiveCoverage = (coverage ?? shape.coverage
|
|
684
|
+
.add(shape.horizonCoverageAmount.mul(bankRamp)))
|
|
685
|
+
.toVar();
|
|
686
|
+
|
|
687
|
+
const expectedTop = weather
|
|
688
|
+
.add(effectiveCoverage.sub(1))
|
|
689
|
+
.add(boundaryOffset.mul(effectiveCoverage))
|
|
690
|
+
.toVar();
|
|
691
|
+
const localHeightFraction = clamp(
|
|
692
|
+
heightFraction.div(max(expectedTop, 1e-3)),
|
|
693
|
+
0,
|
|
694
|
+
1,
|
|
695
|
+
).toVar();
|
|
696
|
+
|
|
697
|
+
let erosionOffset = float(0).toVar();
|
|
698
|
+
if (detail) If(shape.erosionScaleBaseMultiplier.greaterThan(1e-4), () => {
|
|
699
|
+
const erosionScale = max(
|
|
700
|
+
shape.baseScale.mul(shape.erosionScaleBaseMultiplier),
|
|
701
|
+
CLOUD_EROSION_MIN_SCALE,
|
|
702
|
+
).toVar();
|
|
703
|
+
const erosionWorldTexel = erosionScale.div(max(baseShapeResolution, 1)).toVar();
|
|
704
|
+
const erosionLod = (mipLevel ?? max(
|
|
705
|
+
0,
|
|
706
|
+
log2(max(fieldDistance.mul(pixelConeAngle).div(erosionWorldTexel), 1e-6)),
|
|
707
|
+
)).toVar();
|
|
708
|
+
const erosionPacked = baseShapeNode
|
|
709
|
+
.sample(evolved.div(erosionScale))
|
|
710
|
+
.level(erosionLod)
|
|
711
|
+
.toVar();
|
|
712
|
+
const erosionField = mix(
|
|
713
|
+
erosionPacked.oneMinus(),
|
|
714
|
+
erosionPacked,
|
|
715
|
+
saturate(shape.erosionShape),
|
|
716
|
+
).toVar();
|
|
717
|
+
const erosionStrength = mix(
|
|
718
|
+
shape.erosionStrengthBase,
|
|
719
|
+
shape.erosionStrengthPeak,
|
|
720
|
+
localHeightFraction,
|
|
721
|
+
).toVar();
|
|
722
|
+
erosionOffset.assign(
|
|
723
|
+
erosionField.r.mul(detailLow)
|
|
724
|
+
.add(erosionField.g.mul(detailMid))
|
|
725
|
+
.add(erosionField.b.mul(detailHigh))
|
|
726
|
+
.negate()
|
|
727
|
+
.mul(erosionStrength),
|
|
728
|
+
);
|
|
729
|
+
boundaryOffset.addAssign(erosionOffset);
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
const coverageThreshold = weather
|
|
733
|
+
.add(effectiveCoverage.sub(1))
|
|
734
|
+
.add(boundaryOffset.mul(effectiveCoverage))
|
|
735
|
+
.toVar();
|
|
736
|
+
|
|
737
|
+
// `edgeSoftnessFalloff` is a per-kilometre divisor. At 1 the width stays
|
|
738
|
+
// constant; above 1 the top gets progressively crisper.
|
|
739
|
+
const heightKm = max(heightFraction, 0).mul(thickness).mul(0.001).toVar();
|
|
740
|
+
const edge = max(
|
|
741
|
+
shape.edgeSoftness.div(pow(max(shape.edgeSoftnessFalloff, 1e-3), heightKm)),
|
|
742
|
+
1e-4,
|
|
743
|
+
).toVar();
|
|
744
|
+
|
|
745
|
+
const topFalloff = smoothstep(
|
|
746
|
+
edge.negate(),
|
|
747
|
+
edge,
|
|
748
|
+
coverageThreshold.sub(heightFraction),
|
|
749
|
+
).toVar();
|
|
750
|
+
const baseThreshold = erosionOffset.negate().mul(effectiveCoverage).toVar();
|
|
751
|
+
const baseFalloff = smoothstep(
|
|
752
|
+
edge.negate(),
|
|
753
|
+
edge,
|
|
754
|
+
heightFraction.sub(baseThreshold),
|
|
755
|
+
).toVar();
|
|
756
|
+
|
|
757
|
+
const baseBandEnd = max(
|
|
758
|
+
shape.baseWeatherHeightEnd,
|
|
759
|
+
shape.baseWeatherHeightStart.add(1e-3),
|
|
760
|
+
);
|
|
761
|
+
const baseBand = smoothstep(
|
|
762
|
+
shape.baseWeatherHeightStart,
|
|
763
|
+
baseBandEnd,
|
|
764
|
+
heightFraction,
|
|
765
|
+
);
|
|
766
|
+
const requiredCoverage = baseBand.oneMinus()
|
|
767
|
+
.mul(shape.baseWeatherStrength)
|
|
768
|
+
.toVar();
|
|
769
|
+
const weatherBaseFalloff = smoothstep(
|
|
770
|
+
requiredCoverage.sub(CLOUD_WEATHER_CARVE_WIDTH),
|
|
771
|
+
requiredCoverage,
|
|
772
|
+
weather,
|
|
773
|
+
).toVar();
|
|
774
|
+
const density = topFalloff.mul(baseFalloff).mul(weatherBaseFalloff).toVar();
|
|
775
|
+
|
|
776
|
+
return {
|
|
777
|
+
density,
|
|
778
|
+
heightFraction: saturate(heightFraction),
|
|
779
|
+
occupancy: density,
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
// Keep every density variant in the same build scope so they share one set of
|
|
784
|
+
// uniforms and cannot drift onto different cloud state.
|
|
785
|
+
const laidOut = buildScoped(() => ({
|
|
786
|
+
sampleDensity: Fn(([position]) => {
|
|
787
|
+
const field = sampleDensity(position);
|
|
788
|
+
return vec3(field.density, field.heightFraction, field.occupancy);
|
|
789
|
+
}).setLayout({
|
|
790
|
+
name: functionName,
|
|
791
|
+
type: 'vec3',
|
|
792
|
+
inputs: [{ name: 'position', type: 'vec3' }],
|
|
793
|
+
}),
|
|
794
|
+
sampleCoarseDensity: Fn(([position]) => (
|
|
795
|
+
sampleDensity(position, { detail: false }).density
|
|
796
|
+
)).setLayout({
|
|
797
|
+
name: coarseFunctionName,
|
|
798
|
+
type: 'float',
|
|
799
|
+
inputs: [{ name: 'position', type: 'vec3' }],
|
|
800
|
+
}),
|
|
801
|
+
sampleLightDensity: Fn(([position, viewDistance]) => (
|
|
802
|
+
sampleDensity(position, { viewDistance }).density
|
|
803
|
+
)).setLayout({
|
|
804
|
+
name: `${functionName}ForLight`,
|
|
805
|
+
type: 'float',
|
|
806
|
+
inputs: [
|
|
807
|
+
{ name: 'position', type: 'vec3' },
|
|
808
|
+
{ name: 'viewDistance', type: 'float' },
|
|
809
|
+
],
|
|
810
|
+
}),
|
|
811
|
+
sampleCoarseLightDensity: Fn(([position, viewDistance]) => (
|
|
812
|
+
sampleDensity(position, { detail: false, viewDistance }).density
|
|
813
|
+
)).setLayout({
|
|
814
|
+
name: `${coarseFunctionName}ForLight`,
|
|
815
|
+
type: 'float',
|
|
816
|
+
inputs: [
|
|
817
|
+
{ name: 'position', type: 'vec3' },
|
|
818
|
+
{ name: 'viewDistance', type: 'float' },
|
|
819
|
+
],
|
|
820
|
+
}),
|
|
821
|
+
sampleShadowDensity: Fn(([position, mipLevel]) => (
|
|
822
|
+
sampleDensity(position, { coverage: shape.coverage, mipLevel }).density
|
|
823
|
+
)).setLayout({
|
|
824
|
+
name: `${functionName}Shadow`,
|
|
825
|
+
type: 'float',
|
|
826
|
+
inputs: [
|
|
827
|
+
{ name: 'position', type: 'vec3' },
|
|
828
|
+
{ name: 'mipLevel', type: 'float' },
|
|
829
|
+
],
|
|
830
|
+
}),
|
|
831
|
+
}));
|
|
832
|
+
|
|
833
|
+
// What callers hold: an inline shim whose entire body is one call to the
|
|
834
|
+
// laid-out function, so the per-build lookup happens where the builder is in
|
|
835
|
+
// scope and the field is still emitted once per build rather than inlined per
|
|
836
|
+
// march step. The shim itself carries no state, so it is safe to hand to any
|
|
837
|
+
// number of foreign graphs — which `SkySystem.cloudShadow` does.
|
|
838
|
+
const sampleDensityNode = Fn(
|
|
839
|
+
([position], builder) => laidOut(builder).sampleDensity(position),
|
|
840
|
+
'vec3',
|
|
841
|
+
);
|
|
842
|
+
const sampleCoarseDensityNode = Fn(
|
|
843
|
+
([position], builder) => laidOut(builder).sampleCoarseDensity(position),
|
|
844
|
+
'float',
|
|
845
|
+
);
|
|
846
|
+
const sampleLightDensityNode = Fn(
|
|
847
|
+
([position, viewDistance], builder) => (
|
|
848
|
+
laidOut(builder).sampleLightDensity(position, viewDistance)
|
|
849
|
+
),
|
|
850
|
+
'float',
|
|
851
|
+
);
|
|
852
|
+
const sampleCoarseLightDensityNode = Fn(
|
|
853
|
+
([position, viewDistance], builder) => (
|
|
854
|
+
laidOut(builder).sampleCoarseLightDensity(position, viewDistance)
|
|
855
|
+
),
|
|
856
|
+
'float',
|
|
857
|
+
);
|
|
858
|
+
const sampleShadowDensityNode = Fn(
|
|
859
|
+
([position, mipLevel], builder) => (
|
|
860
|
+
laidOut(builder).sampleShadowDensity(position, mipLevel)
|
|
861
|
+
),
|
|
862
|
+
'float',
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
return {
|
|
866
|
+
baseShapeNode,
|
|
867
|
+
curlNode,
|
|
868
|
+
erosionNode,
|
|
869
|
+
functionName,
|
|
870
|
+
coarseFunctionName,
|
|
871
|
+
sampleCoarseDensityNode,
|
|
872
|
+
sampleCoarseLightDensityNode,
|
|
873
|
+
sampleDensityNode,
|
|
874
|
+
sampleLightDensityNode,
|
|
875
|
+
sampleShadowDensityNode,
|
|
876
|
+
weatherNode,
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Builds the light march as one laid-out TSL function.
|
|
882
|
+
*
|
|
883
|
+
* Returns the optical depth from a sample toward `lightDirection`: six graded
|
|
884
|
+
* steps over one shell thickness, spread into a cone oriented on the light,
|
|
885
|
+
* already multiplied by `shape.density` so the caller has a dimensionless depth.
|
|
886
|
+
*
|
|
887
|
+
* Surface samples march the full field. Only after the
|
|
888
|
+
* accumulated view alpha passes 0.7 do the hidden interior samples switch to
|
|
889
|
+
* the cheaper base-only upper bound. The first cone tap reuses the primary
|
|
890
|
+
* density rather than fetching the field again.
|
|
891
|
+
*/
|
|
892
|
+
function createCloudLightMarch({
|
|
893
|
+
shape,
|
|
894
|
+
sampleDensityNode,
|
|
895
|
+
sampleCoarseDensityNode,
|
|
896
|
+
name = 'cloudLightDepth',
|
|
897
|
+
}) {
|
|
898
|
+
const weights = Array.from(
|
|
899
|
+
{ length: CLOUD_LIGHT_MARCH_STEPS },
|
|
900
|
+
(unused, index) => CLOUD_LIGHT_MARCH_GROWTH ** index,
|
|
901
|
+
);
|
|
902
|
+
|
|
903
|
+
volumeId += 1;
|
|
904
|
+
const functionName = `${name}${volumeId}`;
|
|
905
|
+
|
|
906
|
+
// Per build, for the reason `buildScoped` gives: this body reads
|
|
907
|
+
// `shape.thickness` and `shape.density` off the object group by generated name,
|
|
908
|
+
// and it inlines the reduced density field's own bindings through the call it
|
|
909
|
+
// makes.
|
|
910
|
+
const laidOutLightDepth = buildScoped(() => Fn(([
|
|
911
|
+
position,
|
|
912
|
+
lightDirection,
|
|
913
|
+
useCheapDensity,
|
|
914
|
+
originDensity,
|
|
915
|
+
viewDistance,
|
|
916
|
+
]) => {
|
|
917
|
+
// Basis for the cone. The reference axis is whichever of world up and world
|
|
918
|
+
// right the light is least aligned with, chosen by a `step` rather than a
|
|
919
|
+
// branch, so the cross product never degenerates at any sun elevation.
|
|
920
|
+
const reference = mix(vec3(0, 1, 0), vec3(1, 0, 0), step(0.9, lightDirection.y.abs()));
|
|
921
|
+
const tangent = normalize(cross(lightDirection, reference)).toVar();
|
|
922
|
+
const bitangent = cross(lightDirection, tangent).toVar();
|
|
923
|
+
const depth = float(0).toVar();
|
|
924
|
+
for (let index = 0; index < CLOUD_LIGHT_MARCH_STEPS; index += 1) {
|
|
925
|
+
const stepCoef = weights[index];
|
|
926
|
+
const stepLength = CLOUD_LIGHT_STEP_SIZE * stepCoef;
|
|
927
|
+
if (index === 0) {
|
|
928
|
+
depth.addAssign(originDensity.mul(stepLength));
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
const startCoef = (stepCoef - 1) / (CLOUD_LIGHT_MARCH_GROWTH - 1);
|
|
932
|
+
const mid = CLOUD_LIGHT_STEP_SIZE * (startCoef + stepCoef * 0.5);
|
|
933
|
+
const offset = CLOUD_LIGHT_CONE_OFFSETS[index];
|
|
934
|
+
const spread = float(mid).mul(CLOUD_LIGHT_CONE_SPREAD);
|
|
935
|
+
const samplePosition = position
|
|
936
|
+
.add(lightDirection.mul(mid))
|
|
937
|
+
.add(tangent.mul(offset[0]).add(bitangent.mul(offset[1])).mul(spread));
|
|
938
|
+
const lightDensity = float(0).toVar();
|
|
939
|
+
If(useCheapDensity.greaterThan(0.5), () => {
|
|
940
|
+
lightDensity.assign(sampleCoarseDensityNode(samplePosition, viewDistance));
|
|
941
|
+
}).Else(() => {
|
|
942
|
+
lightDensity.assign(sampleDensityNode(samplePosition, viewDistance));
|
|
943
|
+
});
|
|
944
|
+
depth.addAssign(lightDensity.mul(stepLength));
|
|
945
|
+
}
|
|
946
|
+
return depth.mul(max(shape.density, 0));
|
|
947
|
+
}).setLayout({
|
|
948
|
+
name: functionName,
|
|
949
|
+
type: 'float',
|
|
950
|
+
inputs: [
|
|
951
|
+
{ name: 'position', type: 'vec3' },
|
|
952
|
+
{ name: 'lightDirection', type: 'vec3' },
|
|
953
|
+
{ name: 'useCheapDensity', type: 'float' },
|
|
954
|
+
{ name: 'originDensity', type: 'float' },
|
|
955
|
+
{ name: 'viewDistance', type: 'float' },
|
|
956
|
+
],
|
|
957
|
+
}));
|
|
958
|
+
|
|
959
|
+
const lightDepthNode = Fn(
|
|
960
|
+
([position, lightDirection, useCheapDensity, originDensity, viewDistance], builder) => (
|
|
961
|
+
laidOutLightDepth(builder)(
|
|
962
|
+
position,
|
|
963
|
+
lightDirection,
|
|
964
|
+
useCheapDensity,
|
|
965
|
+
originDensity,
|
|
966
|
+
viewDistance,
|
|
967
|
+
)
|
|
968
|
+
),
|
|
969
|
+
'float',
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
return { functionName, lightDepthNode, stepWeights: Object.freeze(weights) };
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* The primary march. Emitted inline rather than wrapped in `Fn` because the
|
|
977
|
+
* caller needs the radiance, the transmittance and the mean cloud distance, and
|
|
978
|
+
* a TSL function returns one value.
|
|
979
|
+
*
|
|
980
|
+
* The segment integral is Hillaire's energy-conserving form: for a constant
|
|
981
|
+
* medium over a step, `integral(T * S) = albedo * L_in * (1 - exp(-sigma dt))`,
|
|
982
|
+
* which is exact rather than the midpoint approximation and does not fall apart
|
|
983
|
+
* when `sigma dt` is large — which it is, at 0.048 1/m over a 300 m step.
|
|
984
|
+
*/
|
|
985
|
+
export function marchCloud({
|
|
986
|
+
shell,
|
|
987
|
+
cameraPosition,
|
|
988
|
+
viewDir,
|
|
989
|
+
densityNode,
|
|
990
|
+
coarseDensityNode = null,
|
|
991
|
+
lightDepthNode,
|
|
992
|
+
inScatterNode,
|
|
993
|
+
shape,
|
|
994
|
+
sunDirection,
|
|
995
|
+
moonDirection,
|
|
996
|
+
nightFactor,
|
|
997
|
+
cosSun,
|
|
998
|
+
cosMoon,
|
|
999
|
+
sunRadiance,
|
|
1000
|
+
zenithRadiance,
|
|
1001
|
+
horizonRadiance,
|
|
1002
|
+
groundBounceRadiance,
|
|
1003
|
+
moonRadiance,
|
|
1004
|
+
jitter,
|
|
1005
|
+
stepConeAngle = float(0.003),
|
|
1006
|
+
steps = CLOUD_PRIMARY_MARCH_STEPS,
|
|
1007
|
+
}) {
|
|
1008
|
+
const scattered = vec3(0).toVar();
|
|
1009
|
+
const weightedPhysicalLight = float(0).toVar();
|
|
1010
|
+
const transmittance = float(1).toVar();
|
|
1011
|
+
const weightedDistance = float(0).toVar();
|
|
1012
|
+
const weightedSunlight = float(0).toVar();
|
|
1013
|
+
const weightedSunlitHeight = float(0).toVar();
|
|
1014
|
+
const surfacePhysicalLight = float(0).toVar();
|
|
1015
|
+
const surfaceSunlight = float(0).toVar();
|
|
1016
|
+
const surfaceSunlitHeight = float(0).toVar();
|
|
1017
|
+
const surfaceSunFacing = float(0.5).toVar();
|
|
1018
|
+
const surfaceLightSet = float(0).toVar();
|
|
1019
|
+
const weightSum = float(0).toVar();
|
|
1020
|
+
const hitDistance = float(1e6).toVar();
|
|
1021
|
+
|
|
1022
|
+
const recordSurfaceLight = ({
|
|
1023
|
+
heightFraction,
|
|
1024
|
+
inScatterSample,
|
|
1025
|
+
lightOpticalDepth,
|
|
1026
|
+
position,
|
|
1027
|
+
weight,
|
|
1028
|
+
}) => {
|
|
1029
|
+
If(
|
|
1030
|
+
surfaceLightSet.lessThan(0.5).and(weight.greaterThan(CLOUD_SURFACE_LIGHT_MIN_WEIGHT)),
|
|
1031
|
+
() => {
|
|
1032
|
+
const radius = CLOUD_SURFACE_NORMAL_RADIUS;
|
|
1033
|
+
// Use the broad envelope for the lighting normal. Including the full
|
|
1034
|
+
// erosion field here turns sub-pixel wisps into glittering normal
|
|
1035
|
+
// changes; opacity already retains that detail at the physical edge.
|
|
1036
|
+
const sampleSurfaceDensity = coarseDensityNode
|
|
1037
|
+
? (samplePosition) => coarseDensityNode(samplePosition)
|
|
1038
|
+
: (samplePosition) => densityNode(samplePosition).x;
|
|
1039
|
+
const gradient = vec3(
|
|
1040
|
+
sampleSurfaceDensity(position.add(vec3(radius, 0, 0)))
|
|
1041
|
+
.sub(sampleSurfaceDensity(position.sub(vec3(radius, 0, 0)))),
|
|
1042
|
+
sampleSurfaceDensity(position.add(vec3(0, radius, 0)))
|
|
1043
|
+
.sub(sampleSurfaceDensity(position.sub(vec3(0, radius, 0)))),
|
|
1044
|
+
sampleSurfaceDensity(position.add(vec3(0, 0, radius)))
|
|
1045
|
+
.sub(sampleSurfaceDensity(position.sub(vec3(0, 0, radius)))),
|
|
1046
|
+
).toVar();
|
|
1047
|
+
const outwardNormal = normalize(mix(
|
|
1048
|
+
vec3(0, 1, 0),
|
|
1049
|
+
gradient.negate(),
|
|
1050
|
+
step(1e-5, length(gradient)),
|
|
1051
|
+
)).toVar();
|
|
1052
|
+
const sunlight = exp(lightOpticalDepth.negate()).toVar();
|
|
1053
|
+
surfacePhysicalLight.assign(inScatterSample.a);
|
|
1054
|
+
surfaceSunlight.assign(sunlight);
|
|
1055
|
+
surfaceSunFacing.assign(smoothstep(-0.15, 0.85, outwardNormal.dot(sunDirection)));
|
|
1056
|
+
surfaceSunlitHeight.assign(
|
|
1057
|
+
heightFraction.mul(mix(
|
|
1058
|
+
CLOUD_WHITE_TOP_MIN_SUN_REACH,
|
|
1059
|
+
1,
|
|
1060
|
+
exp(lightOpticalDepth.mul(CLOUD_WHITE_TOP_DEPTH_SCALE).negate()),
|
|
1061
|
+
)),
|
|
1062
|
+
);
|
|
1063
|
+
surfaceLightSet.assign(1);
|
|
1064
|
+
},
|
|
1065
|
+
);
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
If(shell.hit.greaterThan(0.5), () => {
|
|
1069
|
+
const thickness = max(shape.thickness, 1).toVar();
|
|
1070
|
+
// These are fixed world-space steps, not a shell-span subdivision.
|
|
1071
|
+
// The fine stride follows the pixel footprint with distance but never drops
|
|
1072
|
+
// below 25 m. Empty regions use a 4x stride; occupied surfaces then adapt
|
|
1073
|
+
// the integration step so no sample contributes more than tau=0.5.
|
|
1074
|
+
const getStepSizeNode = (distance) => max(
|
|
1075
|
+
float(CLOUD_BASE_STEP_SIZE),
|
|
1076
|
+
float(CLOUD_STEP_CONE_FACTOR).mul(stepConeAngle).mul(distance),
|
|
1077
|
+
);
|
|
1078
|
+
const t = shell.tStart.add(getStepSizeNode(shell.tStart).mul(jitter)).toVar();
|
|
1079
|
+
const stepSize = float(CLOUD_BASE_STEP_SIZE * CLOUD_COARSE_STEP_SCALE).toVar();
|
|
1080
|
+
const coarseMode = float(coarseDensityNode ? 1 : 0).toVar();
|
|
1081
|
+
const emptyFineSamples = float(0).toVar();
|
|
1082
|
+
const opticalDepthAccum = float(0).toVar();
|
|
1083
|
+
|
|
1084
|
+
Loop(steps, () => {
|
|
1085
|
+
// Early out. Without it an overcast sky costs the same as a clear one,
|
|
1086
|
+
// and 128 steps is not a budget that survives being spent twice.
|
|
1087
|
+
If(transmittance.lessThan(CLOUD_TRANSMITTANCE_EPSILON), () => {
|
|
1088
|
+
// Once the interior is opaque, the remaining samples cannot affect
|
|
1089
|
+
// sub-threshold transmission is discarded before exiting the loop.
|
|
1090
|
+
transmittance.assign(0);
|
|
1091
|
+
Break();
|
|
1092
|
+
});
|
|
1093
|
+
If(t.greaterThanEqual(shell.tEnd), () => {
|
|
1094
|
+
Break();
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
const position = cameraPosition.add(viewDir.mul(t)).toVar();
|
|
1098
|
+
const effectiveBaseStep = getStepSizeNode(t).toVar();
|
|
1099
|
+
const effectiveLargeStep = effectiveBaseStep.mul(CLOUD_COARSE_STEP_SCALE).toVar();
|
|
1100
|
+
if (coarseDensityNode) {
|
|
1101
|
+
If(coarseMode.greaterThan(0.5), () => {
|
|
1102
|
+
const coarseDensity = coarseDensityNode(position).toVar();
|
|
1103
|
+
If(coarseDensity.greaterThan(CLOUD_DENSITY_EPSILON), () => {
|
|
1104
|
+
// The cheap density is an upper bound because the detail field only
|
|
1105
|
+
// erodes it. Confirm the full field before paying for fine steps.
|
|
1106
|
+
const confirmed = densityNode(position).x.toVar();
|
|
1107
|
+
If(confirmed.greaterThan(CLOUD_DENSITY_EPSILON), () => {
|
|
1108
|
+
t.assign(max(shell.tStart, t.sub(effectiveLargeStep)));
|
|
1109
|
+
coarseMode.assign(0);
|
|
1110
|
+
emptyFineSamples.assign(0);
|
|
1111
|
+
stepSize.assign(effectiveBaseStep);
|
|
1112
|
+
}).Else(() => {
|
|
1113
|
+
stepSize.assign(effectiveLargeStep);
|
|
1114
|
+
});
|
|
1115
|
+
}).Else(() => {
|
|
1116
|
+
stepSize.assign(effectiveLargeStep);
|
|
1117
|
+
});
|
|
1118
|
+
}).Else(() => {
|
|
1119
|
+
const sample = densityNode(position).toVar();
|
|
1120
|
+
const normalizedDensity = sample.x.toVar();
|
|
1121
|
+
|
|
1122
|
+
If(normalizedDensity.greaterThan(CLOUD_DENSITY_EPSILON), () => {
|
|
1123
|
+
emptyFineSamples.assign(0);
|
|
1124
|
+
If(hitDistance.greaterThanEqual(1e6), () => {
|
|
1125
|
+
hitDistance.assign(t);
|
|
1126
|
+
});
|
|
1127
|
+
const heightFraction = sample.y.toVar();
|
|
1128
|
+
const extinction = normalizedDensity.mul(max(shape.density, 0)).toVar();
|
|
1129
|
+
const surfaceCoreStep = clamp(
|
|
1130
|
+
float(CLOUD_MAX_OPTICAL_DEPTH_PER_STEP).div(max(extinction, 1e-6)),
|
|
1131
|
+
effectiveBaseStep.mul(CLOUD_CORE_STEP_MIN_SCALE),
|
|
1132
|
+
effectiveBaseStep,
|
|
1133
|
+
).toVar();
|
|
1134
|
+
const interiorOpenness = smoothstep(
|
|
1135
|
+
CLOUD_INTERIOR_COARSEN_START,
|
|
1136
|
+
CLOUD_INTERIOR_COARSEN_FULL,
|
|
1137
|
+
opticalDepthAccum,
|
|
1138
|
+
).toVar();
|
|
1139
|
+
const coreStep = mix(
|
|
1140
|
+
surfaceCoreStep,
|
|
1141
|
+
effectiveBaseStep.mul(CLOUD_INTERIOR_STEP_SCALE),
|
|
1142
|
+
interiorOpenness,
|
|
1143
|
+
).toVar();
|
|
1144
|
+
stepSize.assign(coreStep);
|
|
1145
|
+
const cheapLight = step(0.3, transmittance).oneMinus().toVar();
|
|
1146
|
+
const lightOpticalDepth = lightDepthNode(
|
|
1147
|
+
position,
|
|
1148
|
+
sunDirection,
|
|
1149
|
+
cheapLight,
|
|
1150
|
+
normalizedDensity,
|
|
1151
|
+
t,
|
|
1152
|
+
).toVar();
|
|
1153
|
+
const moonLightOpticalDepth = float(0).toVar();
|
|
1154
|
+
If(float(nightFactor).greaterThan(1e-4), () => {
|
|
1155
|
+
moonLightOpticalDepth.assign(lightDepthNode(
|
|
1156
|
+
position,
|
|
1157
|
+
moonDirection,
|
|
1158
|
+
cheapLight,
|
|
1159
|
+
normalizedDensity,
|
|
1160
|
+
t,
|
|
1161
|
+
));
|
|
1162
|
+
});
|
|
1163
|
+
const inScatterSample = inScatterNode(
|
|
1164
|
+
heightFraction,
|
|
1165
|
+
sample.z,
|
|
1166
|
+
extinction,
|
|
1167
|
+
lightOpticalDepth,
|
|
1168
|
+
moonLightOpticalDepth,
|
|
1169
|
+
thickness.mul(heightFraction.oneMinus()),
|
|
1170
|
+
thickness.mul(heightFraction),
|
|
1171
|
+
cosSun,
|
|
1172
|
+
cosMoon,
|
|
1173
|
+
sunRadiance,
|
|
1174
|
+
zenithRadiance,
|
|
1175
|
+
horizonRadiance,
|
|
1176
|
+
groundBounceRadiance,
|
|
1177
|
+
moonRadiance,
|
|
1178
|
+
).toVar();
|
|
1179
|
+
const inScatter = inScatterSample.rgb.toVar();
|
|
1180
|
+
|
|
1181
|
+
const sampleTransmittance = exp(extinction.mul(coreStep).negate()).toVar();
|
|
1182
|
+
const weight = transmittance.mul(sampleTransmittance.oneMinus()).toVar();
|
|
1183
|
+
recordSurfaceLight({
|
|
1184
|
+
heightFraction,
|
|
1185
|
+
inScatterSample,
|
|
1186
|
+
lightOpticalDepth,
|
|
1187
|
+
position,
|
|
1188
|
+
weight,
|
|
1189
|
+
});
|
|
1190
|
+
scattered.addAssign(inScatter.mul(weight));
|
|
1191
|
+
weightedPhysicalLight.addAssign(inScatterSample.a.mul(weight));
|
|
1192
|
+
weightedDistance.addAssign(t.mul(weight));
|
|
1193
|
+
weightedSunlight.addAssign(exp(lightOpticalDepth.negate()).mul(weight));
|
|
1194
|
+
weightedSunlitHeight.addAssign(
|
|
1195
|
+
heightFraction
|
|
1196
|
+
.mul(mix(
|
|
1197
|
+
CLOUD_WHITE_TOP_MIN_SUN_REACH,
|
|
1198
|
+
1,
|
|
1199
|
+
exp(lightOpticalDepth.mul(CLOUD_WHITE_TOP_DEPTH_SCALE).negate()),
|
|
1200
|
+
))
|
|
1201
|
+
.mul(weight),
|
|
1202
|
+
);
|
|
1203
|
+
weightSum.addAssign(weight);
|
|
1204
|
+
transmittance.mulAssign(sampleTransmittance);
|
|
1205
|
+
opticalDepthAccum.addAssign(extinction.mul(coreStep));
|
|
1206
|
+
}).Else(() => {
|
|
1207
|
+
emptyFineSamples.addAssign(1);
|
|
1208
|
+
stepSize.assign(effectiveBaseStep);
|
|
1209
|
+
If(emptyFineSamples.greaterThanEqual(CLOUD_FINE_EMPTY_LIMIT), () => {
|
|
1210
|
+
coarseMode.assign(1);
|
|
1211
|
+
stepSize.assign(effectiveLargeStep);
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
} else {
|
|
1216
|
+
const sample = densityNode(position).toVar();
|
|
1217
|
+
const normalizedDensity = sample.x.toVar();
|
|
1218
|
+
If(normalizedDensity.greaterThan(CLOUD_DENSITY_EPSILON), () => {
|
|
1219
|
+
If(hitDistance.greaterThanEqual(1e6), () => {
|
|
1220
|
+
hitDistance.assign(t);
|
|
1221
|
+
});
|
|
1222
|
+
const heightFraction = sample.y.toVar();
|
|
1223
|
+
const extinction = normalizedDensity.mul(max(shape.density, 0)).toVar();
|
|
1224
|
+
const surfaceCoreStep = clamp(
|
|
1225
|
+
float(CLOUD_MAX_OPTICAL_DEPTH_PER_STEP).div(max(extinction, 1e-6)),
|
|
1226
|
+
effectiveBaseStep.mul(CLOUD_CORE_STEP_MIN_SCALE),
|
|
1227
|
+
effectiveBaseStep,
|
|
1228
|
+
).toVar();
|
|
1229
|
+
const interiorOpenness = smoothstep(
|
|
1230
|
+
CLOUD_INTERIOR_COARSEN_START,
|
|
1231
|
+
CLOUD_INTERIOR_COARSEN_FULL,
|
|
1232
|
+
opticalDepthAccum,
|
|
1233
|
+
).toVar();
|
|
1234
|
+
const coreStep = mix(
|
|
1235
|
+
surfaceCoreStep,
|
|
1236
|
+
effectiveBaseStep.mul(CLOUD_INTERIOR_STEP_SCALE),
|
|
1237
|
+
interiorOpenness,
|
|
1238
|
+
).toVar();
|
|
1239
|
+
stepSize.assign(coreStep);
|
|
1240
|
+
const cheapLight = step(0.3, transmittance).oneMinus().toVar();
|
|
1241
|
+
const lightOpticalDepth = lightDepthNode(
|
|
1242
|
+
position,
|
|
1243
|
+
sunDirection,
|
|
1244
|
+
cheapLight,
|
|
1245
|
+
normalizedDensity,
|
|
1246
|
+
t,
|
|
1247
|
+
).toVar();
|
|
1248
|
+
const moonLightOpticalDepth = float(0).toVar();
|
|
1249
|
+
If(float(nightFactor).greaterThan(1e-4), () => {
|
|
1250
|
+
moonLightOpticalDepth.assign(lightDepthNode(
|
|
1251
|
+
position,
|
|
1252
|
+
moonDirection,
|
|
1253
|
+
cheapLight,
|
|
1254
|
+
normalizedDensity,
|
|
1255
|
+
t,
|
|
1256
|
+
));
|
|
1257
|
+
});
|
|
1258
|
+
const inScatterSample = inScatterNode(
|
|
1259
|
+
heightFraction,
|
|
1260
|
+
sample.z,
|
|
1261
|
+
extinction,
|
|
1262
|
+
lightOpticalDepth,
|
|
1263
|
+
moonLightOpticalDepth,
|
|
1264
|
+
thickness.mul(heightFraction.oneMinus()),
|
|
1265
|
+
thickness.mul(heightFraction),
|
|
1266
|
+
cosSun,
|
|
1267
|
+
cosMoon,
|
|
1268
|
+
sunRadiance,
|
|
1269
|
+
zenithRadiance,
|
|
1270
|
+
horizonRadiance,
|
|
1271
|
+
groundBounceRadiance,
|
|
1272
|
+
moonRadiance,
|
|
1273
|
+
).toVar();
|
|
1274
|
+
const inScatter = inScatterSample.rgb.toVar();
|
|
1275
|
+
const sampleTransmittance = exp(extinction.mul(coreStep).negate()).toVar();
|
|
1276
|
+
const weight = transmittance.mul(sampleTransmittance.oneMinus()).toVar();
|
|
1277
|
+
recordSurfaceLight({
|
|
1278
|
+
heightFraction,
|
|
1279
|
+
inScatterSample,
|
|
1280
|
+
lightOpticalDepth,
|
|
1281
|
+
position,
|
|
1282
|
+
weight,
|
|
1283
|
+
});
|
|
1284
|
+
scattered.addAssign(inScatter.mul(weight));
|
|
1285
|
+
weightedPhysicalLight.addAssign(inScatterSample.a.mul(weight));
|
|
1286
|
+
weightedDistance.addAssign(t.mul(weight));
|
|
1287
|
+
weightedSunlight.addAssign(exp(lightOpticalDepth.negate()).mul(weight));
|
|
1288
|
+
weightedSunlitHeight.addAssign(
|
|
1289
|
+
heightFraction
|
|
1290
|
+
.mul(mix(
|
|
1291
|
+
CLOUD_WHITE_TOP_MIN_SUN_REACH,
|
|
1292
|
+
1,
|
|
1293
|
+
exp(lightOpticalDepth.mul(CLOUD_WHITE_TOP_DEPTH_SCALE).negate()),
|
|
1294
|
+
))
|
|
1295
|
+
.mul(weight),
|
|
1296
|
+
);
|
|
1297
|
+
weightSum.addAssign(weight);
|
|
1298
|
+
transmittance.mulAssign(sampleTransmittance);
|
|
1299
|
+
opticalDepthAccum.addAssign(extinction.mul(coreStep));
|
|
1300
|
+
}).Else(() => {
|
|
1301
|
+
stepSize.assign(effectiveBaseStep);
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
t.addAssign(stepSize);
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
// Fallback distance when nothing was accumulated. `shell.tEnd` is deliberately
|
|
1309
|
+
// left negative on a miss and `tStart` is then an unused root that can be
|
|
1310
|
+
// planet-scale, so the fallback is clamped into the shell rather than trusted:
|
|
1311
|
+
// it feeds the aerial perspective, and an unclamped 6e6 there would ask the
|
|
1312
|
+
// transmittance table for a point outside the atmosphere.
|
|
1313
|
+
const midShell = shell.tStart.add(shell.tEnd).mul(0.5);
|
|
1314
|
+
const fallback = mix(midShell, weightedDistance.div(max(weightSum, 1e-6)), step(1e-6, weightSum));
|
|
1315
|
+
const physicalLight = weightedPhysicalLight.div(max(weightSum, 1e-6)).toVar();
|
|
1316
|
+
const sunlight = weightedSunlight.div(max(weightSum, 1e-6)).toVar();
|
|
1317
|
+
const sunlitHeight = weightedSunlitHeight.div(max(weightSum, 1e-6)).toVar();
|
|
1318
|
+
return {
|
|
1319
|
+
alpha: transmittance.oneMinus().toVar(),
|
|
1320
|
+
hitDistance,
|
|
1321
|
+
meanDistance: clamp(fallback, 1, max(shell.tEnd, 1)).toVar(),
|
|
1322
|
+
physicalLight,
|
|
1323
|
+
scattered,
|
|
1324
|
+
sunlight,
|
|
1325
|
+
sunlitHeight: sunlitHeight.mul(CLOUD_WHITE_TOP_HEIGHT_GAIN).toVar(),
|
|
1326
|
+
surfacePhysicalLight: mix(physicalLight, surfacePhysicalLight, surfaceLightSet).toVar(),
|
|
1327
|
+
surfaceSunlight: mix(sunlight, surfaceSunlight, surfaceLightSet).toVar(),
|
|
1328
|
+
surfaceSunFacing: mix(float(0.5), surfaceSunFacing, surfaceLightSet).toVar(),
|
|
1329
|
+
surfaceSunlitHeight: mix(sunlitHeight, surfaceSunlitHeight, surfaceLightSet)
|
|
1330
|
+
.mul(CLOUD_WHITE_TOP_HEIGHT_GAIN)
|
|
1331
|
+
.toVar(),
|
|
1332
|
+
transmittance,
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function resolveVolumes({ quality, seed, volumes }) {
|
|
1337
|
+
const resolved = resolveQuality(quality);
|
|
1338
|
+
return {
|
|
1339
|
+
baseShape: volumes?.baseShape ?? getCloudBaseShapeVolume({ dims: resolved.baseShapeDims, seed }),
|
|
1340
|
+
cirrus: volumes?.cirrus ?? getCloudCirrusMap({ seed }),
|
|
1341
|
+
curl: volumes?.curl ?? getCurlNoiseVolume({ seed }),
|
|
1342
|
+
erosion: volumes?.erosion ?? getCloudErosionVolume({ seed }),
|
|
1343
|
+
quality: resolved,
|
|
1344
|
+
weather: volumes?.weather ?? getWeatherMap({ resolution: resolved.weatherMapResolution, seed }),
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Builds the cloud raymarcher as a fullscreen-pass node material.
|
|
1350
|
+
*
|
|
1351
|
+
* A `NodeMaterial` with a `fragmentNode`, not a lit material with a `colorNode`:
|
|
1352
|
+
* the pass writes linear HDR radiance in RGB and view transmittance in A, and
|
|
1353
|
+
* neither may be touched by tone mapping or an output colour transform on its
|
|
1354
|
+
* way into the reconstruction buffer.
|
|
1355
|
+
*
|
|
1356
|
+
* The view ray is built from an explicit `rayBasis` uniform rather than from
|
|
1357
|
+
* TSL's `cameraPosition` / `cameraProjectionMatrixInverse`, for two reasons.
|
|
1358
|
+
* The pass is drawn with a fullscreen quad, whose own camera is what those
|
|
1359
|
+
* built-ins would report. And an inverse-projection unprojection needs an NDC z
|
|
1360
|
+
* whose range differs between WebGPU (0..1) and WebGL2 (-1..1), which is exactly
|
|
1361
|
+
* the kind of backend split this project cannot ship. Call `update(camera)`
|
|
1362
|
+
* once a frame to refresh it.
|
|
1363
|
+
*/
|
|
1364
|
+
export function createCloudVolumeMaterial({
|
|
1365
|
+
params,
|
|
1366
|
+
style = null,
|
|
1367
|
+
skyColor = null,
|
|
1368
|
+
atmosphere,
|
|
1369
|
+
scattering,
|
|
1370
|
+
sun,
|
|
1371
|
+
timeOfDay = null,
|
|
1372
|
+
quality = undefined,
|
|
1373
|
+
seed = 1,
|
|
1374
|
+
volumes = null,
|
|
1375
|
+
groundLevel = 0,
|
|
1376
|
+
name = 'ToonLabCloudVolume',
|
|
1377
|
+
} = {}) {
|
|
1378
|
+
if (!params?.shape?.altitude || !params?.lighting || !params?.wind || !params?.fade) {
|
|
1379
|
+
throw new TypeError('createCloudVolumeMaterial needs a CloudParams instance.');
|
|
1380
|
+
}
|
|
1381
|
+
if (!atmosphere?.multipleScattering) {
|
|
1382
|
+
throw new TypeError('createCloudVolumeMaterial needs an atmosphere param group.');
|
|
1383
|
+
}
|
|
1384
|
+
if (!scattering?.transmittanceNode) {
|
|
1385
|
+
throw new TypeError('createCloudVolumeMaterial needs a scattering bake.');
|
|
1386
|
+
}
|
|
1387
|
+
if (!sun?.direction) {
|
|
1388
|
+
throw new TypeError('createCloudVolumeMaterial needs a sun.');
|
|
1389
|
+
}
|
|
1390
|
+
const budget = assertFixedMarchBudget();
|
|
1391
|
+
|
|
1392
|
+
const { shape, lighting, wind, cirrus, haze, fade } = params;
|
|
1393
|
+
const resolved = resolveVolumes({ quality, seed, volumes });
|
|
1394
|
+
|
|
1395
|
+
// Owned uniforms. The camera-derived three are written by `update(camera)`;
|
|
1396
|
+
// the two jitters are written by the reconstruction pass.
|
|
1397
|
+
const cameraPositionUniform = vectorUniform();
|
|
1398
|
+
const rayBasis = uniform(new THREE.Matrix3());
|
|
1399
|
+
const groundLevelUniform = uniform(groundLevel);
|
|
1400
|
+
const pixelJitter = uniform(new THREE.Vector2());
|
|
1401
|
+
const marchJitter = uniform(0.5);
|
|
1402
|
+
const pixelConeAngle = uniform(0.001);
|
|
1403
|
+
const stepConeAngle = uniform(0.003);
|
|
1404
|
+
const baseShapeResolution = uniform(resolved.baseShape?.image?.width ?? 64);
|
|
1405
|
+
const rayHitDistance = property('float', 'toonlabCloudRayHitDistance');
|
|
1406
|
+
// A generated cirrus mask ships with the field; the 1x1 stand-in keeps the
|
|
1407
|
+
// graph stable when a host explicitly clears it. `cirrusEnabled` is the gate,
|
|
1408
|
+
// so setCirrusTexture(null) still removes the deck exactly.
|
|
1409
|
+
//
|
|
1410
|
+
// The filters are set explicitly because `DataTexture` defaults to
|
|
1411
|
+
// NearestFilter, which the node builders classify as unfilterable: the tap then
|
|
1412
|
+
// compiles to a `textureLoad` with a hand-rolled repeat wrap and no sampler
|
|
1413
|
+
// binding at all. `setCirrusTexture` only writes `TextureNode.value`, and a
|
|
1414
|
+
// TextureNode carries no `customCacheKey`, so swapping a filtered map in
|
|
1415
|
+
// afterwards does not invalidate the compiled program — the deck would stay
|
|
1416
|
+
// point-sampled for the life of the material. Both textures are filterable, so
|
|
1417
|
+
// the graph compiles to a `textureSample` once and the swap is a pure uniform
|
|
1418
|
+
// change.
|
|
1419
|
+
const cirrusFallback = new THREE.DataTexture(
|
|
1420
|
+
new Uint8Array([255, 255, 255, 255]),
|
|
1421
|
+
1,
|
|
1422
|
+
1,
|
|
1423
|
+
THREE.RGBAFormat,
|
|
1424
|
+
THREE.UnsignedByteType,
|
|
1425
|
+
);
|
|
1426
|
+
cirrusFallback.name = `${name}CirrusFallback`;
|
|
1427
|
+
cirrusFallback.colorSpace = THREE.NoColorSpace;
|
|
1428
|
+
cirrusFallback.wrapS = THREE.RepeatWrapping;
|
|
1429
|
+
cirrusFallback.wrapT = THREE.RepeatWrapping;
|
|
1430
|
+
cirrusFallback.minFilter = THREE.LinearFilter;
|
|
1431
|
+
cirrusFallback.magFilter = THREE.LinearFilter;
|
|
1432
|
+
cirrusFallback.generateMipmaps = false;
|
|
1433
|
+
cirrusFallback.needsUpdate = true;
|
|
1434
|
+
const cirrusEnabled = uniform(resolved.cirrus?.isTexture ? 1 : 0);
|
|
1435
|
+
const cirrusNode = texture(resolved.cirrus?.isTexture ? resolved.cirrus : cirrusFallback);
|
|
1436
|
+
|
|
1437
|
+
const moonDirection = timeOfDay?.moonDirection ?? vectorUniform(0, -1, 0);
|
|
1438
|
+
const moonColor = timeOfDay?.moonColor ?? uniform(new THREE.Color(0, 0, 0));
|
|
1439
|
+
const moonIntensity = timeOfDay?.moonIntensity ?? uniform(0);
|
|
1440
|
+
|
|
1441
|
+
const field = createCloudDensityField({
|
|
1442
|
+
baseShapeVolume: resolved.baseShape,
|
|
1443
|
+
baseShapeResolution,
|
|
1444
|
+
cameraAltitude: max(cameraPositionUniform.y.sub(groundLevelUniform), 0.5),
|
|
1445
|
+
cameraPosition: cameraPositionUniform,
|
|
1446
|
+
curlVolume: resolved.curl,
|
|
1447
|
+
erosionVolume: resolved.erosion,
|
|
1448
|
+
pixelConeAngle,
|
|
1449
|
+
shape,
|
|
1450
|
+
weatherMap: resolved.weather,
|
|
1451
|
+
wind,
|
|
1452
|
+
});
|
|
1453
|
+
const light = createCloudLightMarch({
|
|
1454
|
+
sampleCoarseDensityNode: field.sampleCoarseLightDensityNode,
|
|
1455
|
+
sampleDensityNode: field.sampleLightDensityNode,
|
|
1456
|
+
shape,
|
|
1457
|
+
});
|
|
1458
|
+
const model = createCloudLightingModel({ atmosphere, lighting, style, timeOfDay });
|
|
1459
|
+
const ambientSky = new AmbientSkyBaker();
|
|
1460
|
+
ambientSky.update(atmosphere, sun, lighting);
|
|
1461
|
+
// `createCloudLightingModel`'s in-scatter function is laid out too, and its
|
|
1462
|
+
// layout is not this module's to widen, so the model is re-created per build
|
|
1463
|
+
// and the graph below scatters through THAT one — same reason as `buildScoped`,
|
|
1464
|
+
// whose comment has the mechanism. The eagerly built model stays on the api
|
|
1465
|
+
// because what consumers take from it (`sunTransmittanceNode`, `keyLightNode`)
|
|
1466
|
+
// are inline node factories with no laid-out body to go stale.
|
|
1467
|
+
const scopedModel = buildScoped(
|
|
1468
|
+
() => createCloudLightingModel({ atmosphere, lighting, style, timeOfDay }),
|
|
1469
|
+
);
|
|
1470
|
+
const inScatterNode = Fn(
|
|
1471
|
+
(inputs, builder) => scopedModel(builder).inScatterNode(...inputs),
|
|
1472
|
+
'vec4',
|
|
1473
|
+
);
|
|
1474
|
+
|
|
1475
|
+
const uniforms = {
|
|
1476
|
+
baseShapeResolution,
|
|
1477
|
+
cameraPosition: cameraPositionUniform,
|
|
1478
|
+
cirrusEnabled,
|
|
1479
|
+
groundLevel: groundLevelUniform,
|
|
1480
|
+
marchJitter,
|
|
1481
|
+
pixelConeAngle,
|
|
1482
|
+
pixelJitter,
|
|
1483
|
+
rayBasis,
|
|
1484
|
+
stepConeAngle,
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
const material = new NodeMaterial();
|
|
1488
|
+
material.name = name;
|
|
1489
|
+
material.depthTest = false;
|
|
1490
|
+
material.depthWrite = false;
|
|
1491
|
+
material.transparent = false;
|
|
1492
|
+
material.toneMapped = false;
|
|
1493
|
+
material.blending = THREE.NoBlending;
|
|
1494
|
+
material.fog = false;
|
|
1495
|
+
material.uniforms = uniforms;
|
|
1496
|
+
|
|
1497
|
+
const cloudColorNode = Fn(() => {
|
|
1498
|
+
// screenUV is top-left origin on both backends (three flips the WebGL frag
|
|
1499
|
+
// coord to the WebGPU convention), so NDC y is 1 - 2v.
|
|
1500
|
+
const ndc = vec2(
|
|
1501
|
+
screenUV.x.mul(2).sub(1),
|
|
1502
|
+
screenUV.y.mul(-2).add(1),
|
|
1503
|
+
).add(pixelJitter).toVar();
|
|
1504
|
+
const viewDir = normalize(rayBasis.mul(vec3(ndc, 1))).toVar();
|
|
1505
|
+
const cameraAltitude = max(cameraPositionUniform.y.sub(groundLevelUniform), 0.5).toVar();
|
|
1506
|
+
|
|
1507
|
+
const baseAltitude = max(shape.altitude, 0).toVar();
|
|
1508
|
+
const topAltitude = baseAltitude.add(max(shape.thickness, 1)).toVar();
|
|
1509
|
+
const shell = intersectCloudShell({
|
|
1510
|
+
baseAltitude,
|
|
1511
|
+
cameraAltitude,
|
|
1512
|
+
maxDistance: fade.maxMarchDist,
|
|
1513
|
+
topAltitude,
|
|
1514
|
+
viewDir,
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
// --- light setup, once per pixel --------------------------------------
|
|
1518
|
+
const sunDirection = normalize(sun.direction).toVar();
|
|
1519
|
+
const cosSun = clamp(viewDir.dot(sunDirection), -1, 1).toVar();
|
|
1520
|
+
const moonLightDirection = normalize(moonDirection).toVar();
|
|
1521
|
+
const cosMoon = clamp(viewDir.dot(moonLightDirection), -1, 1).toVar();
|
|
1522
|
+
const sunIrradiance = sun.color.mul(sun.intensity).toVar();
|
|
1523
|
+
|
|
1524
|
+
const deckAltitude = topAltitude.add(CLOUD_DECK_ALTITUDE_OFFSET).toVar();
|
|
1525
|
+
const sunRadiance = sunIrradiance.mul(ambientSky.sunTransmittance).toVar();
|
|
1526
|
+
const zenithRadiance = ambientSky.zenithRadiance.toVar();
|
|
1527
|
+
const horizonRadiance = ambientSky.horizonRadiance.toVar();
|
|
1528
|
+
const groundBounceRadiance = ambientSky.groundBounceRadiance.toVar();
|
|
1529
|
+
const moonRadiance = moonColor.mul(moonIntensity).toVar();
|
|
1530
|
+
|
|
1531
|
+
// --- the volumetric march ---------------------------------------------
|
|
1532
|
+
const march = marchCloud({
|
|
1533
|
+
cameraPosition: cameraPositionUniform,
|
|
1534
|
+
coarseDensityNode: field.sampleCoarseDensityNode,
|
|
1535
|
+
cosMoon,
|
|
1536
|
+
cosSun,
|
|
1537
|
+
densityNode: field.sampleDensityNode,
|
|
1538
|
+
groundBounceRadiance,
|
|
1539
|
+
horizonRadiance,
|
|
1540
|
+
inScatterNode,
|
|
1541
|
+
jitter: marchJitter,
|
|
1542
|
+
lightDepthNode: light.lightDepthNode,
|
|
1543
|
+
moonDirection: moonLightDirection,
|
|
1544
|
+
moonRadiance,
|
|
1545
|
+
nightFactor: timeOfDay?.skyDarkness ?? float(0),
|
|
1546
|
+
shape,
|
|
1547
|
+
shell,
|
|
1548
|
+
stepConeAngle,
|
|
1549
|
+
zenithRadiance,
|
|
1550
|
+
sunDirection,
|
|
1551
|
+
sunRadiance,
|
|
1552
|
+
viewDir,
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
const scattered = march.scattered.toVar();
|
|
1556
|
+
const transmittance = march.transmittance.toVar();
|
|
1557
|
+
const volumeAlpha = transmittance.oneMinus().toVar();
|
|
1558
|
+
const surfaceLightAmount = style?.surfaceLight
|
|
1559
|
+
? saturate(
|
|
1560
|
+
style.enabled
|
|
1561
|
+
.mul(style.amount)
|
|
1562
|
+
.mul(style.surfaceLight.enabled)
|
|
1563
|
+
.mul(style.surfaceLight.amount),
|
|
1564
|
+
).toVar()
|
|
1565
|
+
: float(0);
|
|
1566
|
+
const whiteTopHeight = mix(
|
|
1567
|
+
march.sunlitHeight,
|
|
1568
|
+
march.surfaceSunlitHeight,
|
|
1569
|
+
surfaceLightAmount,
|
|
1570
|
+
).toVar();
|
|
1571
|
+
const whiteTopPhysicalLight = mix(
|
|
1572
|
+
march.physicalLight,
|
|
1573
|
+
march.surfacePhysicalLight,
|
|
1574
|
+
surfaceLightAmount,
|
|
1575
|
+
).toVar();
|
|
1576
|
+
const surfaceDirectionalSunlight = saturate(
|
|
1577
|
+
march.surfaceSunlight.mul(mix(
|
|
1578
|
+
0.15,
|
|
1579
|
+
1.35,
|
|
1580
|
+
pow(march.surfaceSunFacing, 1.2),
|
|
1581
|
+
)),
|
|
1582
|
+
).toVar();
|
|
1583
|
+
const whiteTopSunlight = mix(
|
|
1584
|
+
march.sunlight,
|
|
1585
|
+
surfaceDirectionalSunlight,
|
|
1586
|
+
surfaceLightAmount,
|
|
1587
|
+
).toVar();
|
|
1588
|
+
|
|
1589
|
+
// Final-pixel paint. Tone and blue hue are per-sample lighting stages;
|
|
1590
|
+
// the shadow wash, white top, light blend, and time palette use resolved
|
|
1591
|
+
// opacity only as a colour mask, so density, transmittance and the physical
|
|
1592
|
+
// silhouette remain unchanged.
|
|
1593
|
+
const whiteTopDaylight = smoothstep(
|
|
1594
|
+
0.01,
|
|
1595
|
+
0.2,
|
|
1596
|
+
max(sunRadiance.dot(vec3(0.2126, 0.7152, 0.0722)), 0),
|
|
1597
|
+
).toVar();
|
|
1598
|
+
scattered.assign(applyCloudInnerPaintNode(
|
|
1599
|
+
scattered,
|
|
1600
|
+
volumeAlpha,
|
|
1601
|
+
style,
|
|
1602
|
+
whiteTopDaylight,
|
|
1603
|
+
));
|
|
1604
|
+
scattered.assign(applyCloudWhiteTopNode(
|
|
1605
|
+
scattered,
|
|
1606
|
+
volumeAlpha,
|
|
1607
|
+
whiteTopHeight.mul(whiteTopDaylight),
|
|
1608
|
+
style,
|
|
1609
|
+
));
|
|
1610
|
+
scattered.assign(applyCloudTopLightNode(
|
|
1611
|
+
scattered,
|
|
1612
|
+
whiteTopPhysicalLight,
|
|
1613
|
+
whiteTopSunlight,
|
|
1614
|
+
volumeAlpha,
|
|
1615
|
+
whiteTopHeight,
|
|
1616
|
+
whiteTopDaylight,
|
|
1617
|
+
surfaceLightAmount,
|
|
1618
|
+
march.surfaceSunFacing,
|
|
1619
|
+
style,
|
|
1620
|
+
));
|
|
1621
|
+
scattered.assign(applyCloudLightBlendNode(
|
|
1622
|
+
scattered,
|
|
1623
|
+
volumeAlpha,
|
|
1624
|
+
march.sunlitHeight,
|
|
1625
|
+
whiteTopDaylight,
|
|
1626
|
+
style,
|
|
1627
|
+
));
|
|
1628
|
+
scattered.assign(applyCloudTimePaletteNode(
|
|
1629
|
+
scattered,
|
|
1630
|
+
volumeAlpha,
|
|
1631
|
+
march.sunlitHeight,
|
|
1632
|
+
timeOfDay?.morningLight ?? float(0),
|
|
1633
|
+
timeOfDay?.eveningLight ?? float(0),
|
|
1634
|
+
timeOfDay?.skyDarkness ?? float(0),
|
|
1635
|
+
style,
|
|
1636
|
+
));
|
|
1637
|
+
|
|
1638
|
+
// Apply aerial perspective to the cumulus result before adding
|
|
1639
|
+
// the high deck. Both the air transmittance and the in-scattered light come
|
|
1640
|
+
// from the same 12-step LUT-assisted atmosphere path as CloudMaterial.ts.
|
|
1641
|
+
If(march.hitDistance.lessThan(1e6), () => {
|
|
1642
|
+
const aerial = atmosphereRaymarchNodes({
|
|
1643
|
+
densityScale: fade.hazeDensityScale,
|
|
1644
|
+
maxDistanceKm: march.meanDistance.mul(0.001),
|
|
1645
|
+
mieDirectionalG: atmosphere.mieDirectionalG,
|
|
1646
|
+
mieScatteringStrength: atmosphere.mieScatteringStrength,
|
|
1647
|
+
scattering,
|
|
1648
|
+
skyMultipleScattering: atmosphere.skyMultipleScattering,
|
|
1649
|
+
sunDir: sunDirection,
|
|
1650
|
+
sunIrradiance: vec3(sun.intensity),
|
|
1651
|
+
viewDir,
|
|
1652
|
+
});
|
|
1653
|
+
scattered.assign(
|
|
1654
|
+
scattered.mul(aerial.transmittance).add(aerial.luminance.mul(volumeAlpha)),
|
|
1655
|
+
);
|
|
1656
|
+
|
|
1657
|
+
// The melt converges cloud colour to the sky along the same view ray. It
|
|
1658
|
+
// does not reduce alpha: an opaque distant cloud still occludes the sun.
|
|
1659
|
+
const skyAlongRay = applySkyColorNode(atmosphereRaymarchNodes({
|
|
1660
|
+
mieDirectionalG: atmosphere.mieDirectionalG,
|
|
1661
|
+
mieScatteringStrength: atmosphere.mieScatteringStrength,
|
|
1662
|
+
scattering,
|
|
1663
|
+
skyMultipleScattering: atmosphere.skyMultipleScattering,
|
|
1664
|
+
sunDir: sunDirection,
|
|
1665
|
+
sunIrradiance: vec3(sun.intensity),
|
|
1666
|
+
viewDir,
|
|
1667
|
+
}).luminance, viewDir, skyColor, timeOfDay);
|
|
1668
|
+
const melt = smoothstep(
|
|
1669
|
+
fade.horizonMeltStart,
|
|
1670
|
+
max(fade.horizonMeltEnd, fade.horizonMeltStart.add(1)),
|
|
1671
|
+
march.meanDistance,
|
|
1672
|
+
);
|
|
1673
|
+
scattered.assign(mix(scattered, skyAlongRay.mul(volumeAlpha), melt));
|
|
1674
|
+
});
|
|
1675
|
+
|
|
1676
|
+
// --- cirrus + haze deck ------------------------------------------------
|
|
1677
|
+
const deck = findCloudLayerCrossing({
|
|
1678
|
+
cameraAltitude,
|
|
1679
|
+
layerAltitude: deckAltitude,
|
|
1680
|
+
viewDir,
|
|
1681
|
+
});
|
|
1682
|
+
const deckDistance = deck.distance.toVar();
|
|
1683
|
+
const deckPosition = cameraPositionUniform
|
|
1684
|
+
.add(viewDir.mul(deckDistance))
|
|
1685
|
+
.sub(wind.offset)
|
|
1686
|
+
.toVar();
|
|
1687
|
+
// Slant path through a thin slab: a grazing view crosses more of it, which
|
|
1688
|
+
// is why a cirrus deck thickens toward the horizon on its own.
|
|
1689
|
+
const slant = min(
|
|
1690
|
+
float(1).div(max(viewDir.y.abs(), CLOUD_DECK_MIN_COS)),
|
|
1691
|
+
CLOUD_DECK_MAX_SLANT,
|
|
1692
|
+
).rgb.toVar();
|
|
1693
|
+
const cirrusSample = cirrusNode
|
|
1694
|
+
.sample(deckPosition.xz.div(max(cirrus.scale, 1)))
|
|
1695
|
+
.r
|
|
1696
|
+
.mul(cirrusEnabled)
|
|
1697
|
+
.toVar();
|
|
1698
|
+
// Both decks saturate toward opaque rather than clipping, which is what
|
|
1699
|
+
// "high values saturate to fully opaque" has to mean for the 0-8 range
|
|
1700
|
+
// `haze.density` publishes.
|
|
1701
|
+
const cirrusOpacity = exp(
|
|
1702
|
+
cirrusSample.mul(max(cirrus.strength, 0)).mul(slant).negate(),
|
|
1703
|
+
).oneMinus().toVar();
|
|
1704
|
+
// Haze is driven by coverage rather than a texture, so it thickens wherever
|
|
1705
|
+
// the cumulus below it do — on its own scale, not `shape.weatherScale`.
|
|
1706
|
+
const hazeCoverage = field.weatherNode
|
|
1707
|
+
.sample(deckPosition.xz.div(max(haze.scale, 1)))
|
|
1708
|
+
.r
|
|
1709
|
+
.mul(saturate(shape.coverage))
|
|
1710
|
+
.toVar();
|
|
1711
|
+
const hazeOpacity = exp(
|
|
1712
|
+
hazeCoverage.mul(max(haze.density, 0)).mul(slant).negate(),
|
|
1713
|
+
).oneMinus().toVar();
|
|
1714
|
+
const deckOpacity = saturate(
|
|
1715
|
+
cirrusOpacity.oneMinus().mul(hazeOpacity.oneMinus()).oneMinus(),
|
|
1716
|
+
).mul(step(0.5, deck.hit)).toVar();
|
|
1717
|
+
|
|
1718
|
+
// The deck reuses the volumetric lighting model with a thin synthetic
|
|
1719
|
+
// sample: height fraction 1 (no base darkening on a cirrus deck), no slab
|
|
1720
|
+
// above or below (ambient and bounce arrive unattenuated), and a
|
|
1721
|
+
// self-shadow that grows with its own opacity. Its own opacity stands in for
|
|
1722
|
+
// the occupancy the powder term keys on, so a wisp of cirrus darkens the way
|
|
1723
|
+
// a wisp of cumulus does and a saturated storm haze is left alone.
|
|
1724
|
+
const deckRadiance = inScatterNode(
|
|
1725
|
+
float(1),
|
|
1726
|
+
deckOpacity,
|
|
1727
|
+
float(CLOUD_DECK_EXTINCTION),
|
|
1728
|
+
deckOpacity.mul(CLOUD_DECK_LIGHT_DEPTH),
|
|
1729
|
+
deckOpacity.mul(CLOUD_DECK_LIGHT_DEPTH),
|
|
1730
|
+
float(0),
|
|
1731
|
+
float(0),
|
|
1732
|
+
cosSun,
|
|
1733
|
+
cosMoon,
|
|
1734
|
+
sunRadiance,
|
|
1735
|
+
zenithRadiance,
|
|
1736
|
+
horizonRadiance,
|
|
1737
|
+
groundBounceRadiance,
|
|
1738
|
+
moonRadiance,
|
|
1739
|
+
).rgb.toVar();
|
|
1740
|
+
|
|
1741
|
+
// Composite the cirrus/haze deck behind the volumetric layer.
|
|
1742
|
+
const deckTerm = deckRadiance.mul(deckOpacity).toVar();
|
|
1743
|
+
scattered.addAssign(deckTerm.mul(transmittance));
|
|
1744
|
+
transmittance.mulAssign(deckOpacity.oneMinus());
|
|
1745
|
+
|
|
1746
|
+
rayHitDistance.assign(select(
|
|
1747
|
+
march.hitDistance.lessThan(1e6),
|
|
1748
|
+
min(march.hitDistance, float(60000)),
|
|
1749
|
+
float(65000),
|
|
1750
|
+
));
|
|
1751
|
+
return vec4(max(scattered, vec3(0)), saturate(transmittance));
|
|
1752
|
+
})();
|
|
1753
|
+
// Carry first-hit distance beside cloud color. The attachment names
|
|
1754
|
+
// are matched by cloudReprojection's MRT render target.
|
|
1755
|
+
material.fragmentNode = mrt({
|
|
1756
|
+
output: cloudColorNode,
|
|
1757
|
+
rayHitDist: vec4(rayHitDistance, 0, 0, 1),
|
|
1758
|
+
});
|
|
1759
|
+
|
|
1760
|
+
const rightScratch = new THREE.Vector3();
|
|
1761
|
+
const upScratch = new THREE.Vector3();
|
|
1762
|
+
const forwardScratch = new THREE.Vector3();
|
|
1763
|
+
|
|
1764
|
+
const api = {
|
|
1765
|
+
material,
|
|
1766
|
+
uniforms,
|
|
1767
|
+
marchBudget: budget,
|
|
1768
|
+
lighting: model,
|
|
1769
|
+
densityField: field,
|
|
1770
|
+
ambientSky,
|
|
1771
|
+
lightMarch: light,
|
|
1772
|
+
volumes: resolved,
|
|
1773
|
+
|
|
1774
|
+
/**
|
|
1775
|
+
* Refreshes the camera-derived uniforms. Call once a frame, before the pass.
|
|
1776
|
+
*
|
|
1777
|
+
* `tanX`/`tanY` come from the projection matrix rather than from
|
|
1778
|
+
* `camera.fov`, so an authored or asymmetric projection still produces the
|
|
1779
|
+
* right rays, and a resize needs no extra call.
|
|
1780
|
+
*/
|
|
1781
|
+
update(camera) {
|
|
1782
|
+
if (!camera?.isCamera) return null;
|
|
1783
|
+
camera.updateMatrixWorld();
|
|
1784
|
+
const world = camera.matrixWorld.elements;
|
|
1785
|
+
const projection = camera.projectionMatrix.elements;
|
|
1786
|
+
const tanX = projection[0] !== 0 ? 1 / projection[0] : 1;
|
|
1787
|
+
const tanY = projection[5] !== 0 ? 1 / projection[5] : 1;
|
|
1788
|
+
rightScratch.set(world[0], world[1], world[2]).normalize().multiplyScalar(tanX);
|
|
1789
|
+
upScratch.set(world[4], world[5], world[6]).normalize().multiplyScalar(tanY);
|
|
1790
|
+
forwardScratch.set(-world[8], -world[9], -world[10]).normalize();
|
|
1791
|
+
rayBasis.value.set(
|
|
1792
|
+
rightScratch.x, upScratch.x, forwardScratch.x,
|
|
1793
|
+
rightScratch.y, upScratch.y, forwardScratch.y,
|
|
1794
|
+
rightScratch.z, upScratch.z, forwardScratch.z,
|
|
1795
|
+
);
|
|
1796
|
+
cameraPositionUniform.value.setFromMatrixPosition(camera.matrixWorld);
|
|
1797
|
+
scattering.bakeIfNeeded();
|
|
1798
|
+
ambientSky.update(atmosphere, sun, lighting);
|
|
1799
|
+
return uniforms;
|
|
1800
|
+
},
|
|
1801
|
+
|
|
1802
|
+
/** World Y treated as ground, metres. Shifts the whole shell with it. */
|
|
1803
|
+
get groundLevel() {
|
|
1804
|
+
return groundLevelUniform.value;
|
|
1805
|
+
},
|
|
1806
|
+
set groundLevel(value) {
|
|
1807
|
+
const next = Number(value);
|
|
1808
|
+
if (!Number.isFinite(next)) return;
|
|
1809
|
+
groundLevelUniform.value = next;
|
|
1810
|
+
},
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Host-supplied cirrus texture, or null to hide the deck.
|
|
1814
|
+
*
|
|
1815
|
+
* Two properties are forced, and both are stated out loud rather than
|
|
1816
|
+
* silently, since they mutate the host's texture.
|
|
1817
|
+
*
|
|
1818
|
+
* The colour space, because `texture()` decodes an sRGB map to linear on
|
|
1819
|
+
* sample and this reads the red channel as an opacity mask: a decode would
|
|
1820
|
+
* bend the mask's midtones and quietly thin the deck.
|
|
1821
|
+
*
|
|
1822
|
+
* The filters, because the fragment graph was compiled against a filterable
|
|
1823
|
+
* texture. A NearestFilter map is classified as unfilterable by the node
|
|
1824
|
+
* builders, and a swap only writes `TextureNode.value` — it does not change
|
|
1825
|
+
* the graph's cache key, so the compiled `textureSample` would stay in place
|
|
1826
|
+
* and read an unfilterable binding. Point-sampling a cirrus deck also aliases
|
|
1827
|
+
* badly under `cirrus.scale`.
|
|
1828
|
+
*/
|
|
1829
|
+
setCirrusTexture(map) {
|
|
1830
|
+
if (map?.isTexture) {
|
|
1831
|
+
if (map.colorSpace !== THREE.NoColorSpace) {
|
|
1832
|
+
console.warn(
|
|
1833
|
+
`[cloudVolume] Cirrus texture "${map.name || 'unnamed'}" colorSpace `
|
|
1834
|
+
+ `"${map.colorSpace}" was set to NoColorSpace; the deck reads it as an opacity mask.`,
|
|
1835
|
+
);
|
|
1836
|
+
map.colorSpace = THREE.NoColorSpace;
|
|
1837
|
+
map.needsUpdate = true;
|
|
1838
|
+
}
|
|
1839
|
+
if (map.magFilter === THREE.NearestFilter || map.minFilter === THREE.NearestFilter) {
|
|
1840
|
+
console.warn(
|
|
1841
|
+
`[cloudVolume] Cirrus texture "${map.name || 'unnamed'}" was point-sampled; `
|
|
1842
|
+
+ 'filters were set to LinearFilter so the deck matches the compiled shader.',
|
|
1843
|
+
);
|
|
1844
|
+
map.magFilter = THREE.LinearFilter;
|
|
1845
|
+
if (map.minFilter === THREE.NearestFilter) map.minFilter = THREE.LinearFilter;
|
|
1846
|
+
map.needsUpdate = true;
|
|
1847
|
+
}
|
|
1848
|
+
cirrusNode.value = map;
|
|
1849
|
+
cirrusEnabled.value = 1;
|
|
1850
|
+
} else {
|
|
1851
|
+
cirrusNode.value = cirrusFallback;
|
|
1852
|
+
cirrusEnabled.value = 0;
|
|
1853
|
+
}
|
|
1854
|
+
return api;
|
|
1855
|
+
},
|
|
1856
|
+
|
|
1857
|
+
/**
|
|
1858
|
+
* Swaps a regenerated weather map or noise volume in place.
|
|
1859
|
+
*
|
|
1860
|
+
* Assigning the texture node's value rather than rebuilding the graph: a
|
|
1861
|
+
* rebuild would recompile the shader, and the sky-cloud lab regenerates the
|
|
1862
|
+
* weather map on every drag of a profile slider.
|
|
1863
|
+
*/
|
|
1864
|
+
setVolumes({ baseShape, cirrus, curl, erosion, weather } = {}) {
|
|
1865
|
+
if (weather?.isTexture) {
|
|
1866
|
+
resolved.weather = weather;
|
|
1867
|
+
field.weatherNode.value = weather;
|
|
1868
|
+
}
|
|
1869
|
+
if (baseShape?.isTexture) {
|
|
1870
|
+
resolved.baseShape = baseShape;
|
|
1871
|
+
field.baseShapeNode.value = baseShape;
|
|
1872
|
+
baseShapeResolution.value = baseShape.image?.width ?? baseShapeResolution.value;
|
|
1873
|
+
}
|
|
1874
|
+
if (erosion?.isTexture) {
|
|
1875
|
+
resolved.erosion = erosion;
|
|
1876
|
+
field.erosionNode.value = erosion;
|
|
1877
|
+
}
|
|
1878
|
+
if (curl?.isTexture && field.curlNode) {
|
|
1879
|
+
resolved.curl = curl;
|
|
1880
|
+
field.curlNode.value = curl;
|
|
1881
|
+
}
|
|
1882
|
+
if (cirrus?.isTexture) {
|
|
1883
|
+
resolved.cirrus = cirrus;
|
|
1884
|
+
cirrusNode.value = cirrus;
|
|
1885
|
+
cirrusEnabled.value = 1;
|
|
1886
|
+
}
|
|
1887
|
+
return api;
|
|
1888
|
+
},
|
|
1889
|
+
|
|
1890
|
+
/** Uploads the authored 3D mip pyramid once the WebGPU renderer exists. */
|
|
1891
|
+
prepareNoiseMipmaps(renderer) {
|
|
1892
|
+
return uploadNoiseVolumeMipChain(renderer, resolved.baseShape);
|
|
1893
|
+
},
|
|
1894
|
+
|
|
1895
|
+
dispose() {
|
|
1896
|
+
cirrusFallback.dispose();
|
|
1897
|
+
material.dispose();
|
|
1898
|
+
},
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
material.userData.toonlabCloudVolume = api;
|
|
1902
|
+
return api;
|
|
1903
|
+
}
|