zhuda-laya-engine 0.0.0-stage → 2.1.0
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/AGENTS.md +236 -0
- package/CHANGELOG.md +431 -0
- package/LICENSE +41 -0
- package/README.md +247 -2
- package/assets/branding/layaair-tribute-mark.svg +5 -0
- package/assets/branding/zhuda-layaair-mark.svg +34 -0
- package/assets/prefabs/CoinFountainVfx.lh +197 -0
- package/assets/prefabs/ConfirmActionButton.lh +87 -0
- package/assets/prefabs/LevelUpAuraVfx.lh +136 -0
- package/assets/prefabs/MineExplosionParticle.lh +352 -0
- package/assets/prefabs/NineSliceDialogFrame.lh +171 -0
- package/assets/prefabs/SwordSlashTrailVfx.lh +117 -0
- package/assets/prefabs/TacticalHudBar.lh +134 -0
- package/assets/prefabs/TelemetryDashboard.lh +87 -0
- package/assets/prefabs/UnityCrystalGuardian.lh +144 -0
- package/assets/prefabs/ZhudaSpine42Mascot.lh +183 -0
- package/assets/scenes/MinesweeperStage.ls +1180 -0
- package/dist/asset-calibration-report.json +969 -0
- package/dist/build-manifest.json +254 -0
- package/dist/sdk/zhuda-laya-csg.cjs +710 -0
- package/dist/sdk/zhuda-laya-csg.esm.js +683 -0
- package/dist/sdk/zhuda-laya-csg.min.cjs +7 -0
- package/dist/sdk/zhuda-laya-csg.min.esm.js +7 -0
- package/dist/sdk/zhuda-laya-demo.cjs +5990 -0
- package/dist/sdk/zhuda-laya-demo.esm.js +5956 -0
- package/dist/sdk/zhuda-laya-demo.min.cjs +12 -0
- package/dist/sdk/zhuda-laya-demo.min.esm.js +12 -0
- package/dist/sdk/zhuda-laya-engine.cjs +52628 -0
- package/dist/sdk/zhuda-laya-engine.esm.js +51848 -0
- package/dist/sdk/zhuda-laya-engine.min.cjs +2710 -0
- package/dist/sdk/zhuda-laya-engine.min.esm.js +2710 -0
- package/docs/3d-acceptance.md +47 -0
- package/docs/3d-integration.md +190 -0
- package/docs/README.md +112 -0
- package/docs/SUPPORT.md +21 -0
- package/docs/agent-development.md +219 -0
- package/docs/animation-control.md +213 -0
- package/docs/asset-loading.md +97 -0
- package/docs/assets/reference-games.jpg +0 -0
- package/docs/assets/solana-qr.png +0 -0
- package/docs/assets/sponsor-pass.svg +32 -0
- package/docs/audio.md +319 -0
- package/docs/backend-delivery.md +218 -0
- package/docs/basis-textures.md +94 -0
- package/docs/browser-sdk-releases.json +204 -0
- package/docs/browser-sdk.md +187 -0
- package/docs/cinematics.md +267 -0
- package/docs/cloth.md +280 -0
- package/docs/combat-runtime.md +82 -0
- package/docs/consumer-route.md +169 -0
- package/docs/consumer-tooling.md +518 -0
- package/docs/crowd-runtime.md +195 -0
- package/docs/developer-tooling.md +191 -0
- package/docs/film-scenes.md +1504 -0
- package/docs/filmic-rendering.md +743 -0
- package/docs/flythrough.md +89 -0
- package/docs/gpu-depth.md +207 -0
- package/docs/grass.md +127 -0
- package/docs/hdr-environment.md +76 -0
- package/docs/instanced-meshes.md +137 -0
- package/docs/layout-and-media.md +37 -0
- package/docs/layout-wireframe.md +80 -0
- package/docs/lighting-depth.md +185 -0
- package/docs/minigame-packaging.md +79 -0
- package/docs/model-editor.md +66 -0
- package/docs/model-lod.md +122 -0
- package/docs/model-pipeline.md +74 -0
- package/docs/model-showcase.md +365 -0
- package/docs/overview.md +183 -0
- package/docs/plans/README.md +133 -0
- package/docs/plans/TASK-TEMPLATE.md +64 -0
- package/docs/plans/TASK-spine38-isolated-topology-20261106.md +89 -0
- package/docs/plans/TEMPLATE.md +44 -0
- package/docs/plans/VERIFICATION-TEMPLATE.md +45 -0
- package/docs/plans/asset-packaging.md +140 -0
- package/docs/plans/cinematic-production/task.md +97 -0
- package/docs/plans/cinematic-production/verification.md +49 -0
- package/docs/plans/consumer-delivery-followups.md +129 -0
- package/docs/plans/desktop-and-agent-gates/hardening-task.md +85 -0
- package/docs/plans/desktop-and-agent-gates/hardening-verification.md +109 -0
- package/docs/plans/desktop-and-agent-gates/task.md +94 -0
- package/docs/plans/desktop-and-agent-gates/verification.md +60 -0
- package/docs/plans/prefab-toolchain.md +73 -0
- package/docs/plans/preview-runtime-hardening.md +68 -0
- package/docs/platform-adapters.md +113 -0
- package/docs/post-quality.md +242 -0
- package/docs/prefab-editor.md +194 -0
- package/docs/prefab-library.md +94 -0
- package/docs/prefab-workflow.md +75 -0
- package/docs/procedural-assets.md +463 -0
- package/docs/procedural-prefabs.md +133 -0
- package/docs/quality-route.md +386 -0
- package/docs/release-policy.md +79 -0
- package/docs/routes/README.md +180 -0
- package/docs/routes/TEMPLATE.md +54 -0
- package/docs/routes/action-adventure-3d-minigame.md +238 -0
- package/docs/routes/apocalypse-survival-3d.md +219 -0
- package/docs/routes/aqua-freeze-2d-minigame.md +183 -0
- package/docs/routes/astral-minimal-film-look.md +141 -0
- package/docs/routes/cascade-slot.md +93 -0
- package/docs/routes/clip-free-garments.md +229 -0
- package/docs/routes/drop-merge-2d-minigame.md +200 -0
- package/docs/routes/dungeon-line-slot.md +87 -0
- package/docs/routes/film-as-data.md +131 -0
- package/docs/routes/film-fight-that-lands.md +198 -0
- package/docs/routes/film-ink-lines.md +120 -0
- package/docs/routes/floating-island.md +229 -0
- package/docs/routes/game-2d.md +168 -0
- package/docs/routes/game-rules-first.md +89 -0
- package/docs/routes/game-to-prefabs.md +249 -0
- package/docs/routes/go-game-server.md +95 -0
- package/docs/routes/good-looking-3d-scene.md +99 -0
- package/docs/routes/high-quality-character.md +263 -0
- package/docs/routes/humanoid-from-shapes.md +97 -0
- package/docs/routes/hunting-action-3d.md +76 -0
- package/docs/routes/idle-gacha-2d.md +67 -0
- package/docs/routes/interactive-film-viewer.md +141 -0
- package/docs/routes/isometric-mystery-2d.md +217 -0
- package/docs/routes/key-art-to-animated-title.md +132 -0
- package/docs/routes/laya-ide-project-cli-web.md +125 -0
- package/docs/routes/layered-cloth-on-body.md +240 -0
- package/docs/routes/low-poly-character-from-shapes.md +475 -0
- package/docs/routes/match-three-2d.md +64 -0
- package/docs/routes/merge-2d.md +59 -0
- package/docs/routes/mini-game-build.md +80 -0
- package/docs/routes/mobile-always-landscape.md +149 -0
- package/docs/routes/mobile-web-fullscreen.md +255 -0
- package/docs/routes/model-from-dcc.md +106 -0
- package/docs/routes/new-game-project.md +100 -0
- package/docs/routes/onboarding-tutorial-2d.md +54 -0
- package/docs/routes/online-lockstep-match.md +473 -0
- package/docs/routes/outdoor-landscape.md +134 -0
- package/docs/routes/outfit-swap-3d.md +144 -0
- package/docs/routes/papercraft-diorama.md +186 -0
- package/docs/routes/platform-fighter-2d.md +235 -0
- package/docs/routes/platformer-2d.md +69 -0
- package/docs/routes/pole-rescue-arcade-3d.md +198 -0
- package/docs/routes/pose-atlas-motion.md +188 -0
- package/docs/routes/prototype-to-center.md +162 -0
- package/docs/routes/raft-brawl-3d-minigame.md +205 -0
- package/docs/routes/rhythm-2d.md +82 -0
- package/docs/routes/rigged-phone-character.md +120 -0
- package/docs/routes/screen-fit-game-box.md +127 -0
- package/docs/routes/shared-islands.md +195 -0
- package/docs/routes/side-view-duel.md +266 -0
- package/docs/routes/single-html-page.md +83 -0
- package/docs/routes/smooth-character-motion.md +162 -0
- package/docs/routes/spine-character.md +175 -0
- package/docs/routes/story-counting-2d.md +219 -0
- package/docs/routes/survivors-2d.md +60 -0
- package/docs/routes/third-person-town-3d.md +240 -0
- package/docs/routes/tower-defence-3d.md +67 -0
- package/docs/routes/ui-test-by-probe.md +219 -0
- package/docs/routes/underwater.md +138 -0
- package/docs/routes/visual-content-prefab.md +101 -0
- package/docs/runtime-hardening.md +108 -0
- package/docs/shader-warm-up.md +125 -0
- package/docs/spring-bones.md +79 -0
- package/docs/stylized-shading.md +171 -0
- package/docs/terrain-shader.md +130 -0
- package/docs/vrm.md +128 -0
- package/docs/walking.md +97 -0
- package/docs/webgpu.md +225 -0
- package/docs/white-label-themes.md +212 -0
- package/docs/zh-CN/README.md +130 -0
- package/examples/browser-sdk/2d-webgpu.html +46 -0
- package/examples/browser-sdk/2d.html +46 -0
- package/examples/browser-sdk/3d-gltf-webgpu.html +50 -0
- package/examples/browser-sdk/3d-gltf.html +50 -0
- package/examples/browser-sdk/3d-webgpu.html +46 -0
- package/examples/browser-sdk/3d.html +46 -0
- package/examples/cinematic-capture/Main.ts +294 -0
- package/examples/cinematic-capture/README.md +27 -0
- package/examples/model-inspector/README.md +15 -0
- package/examples/model-inspector/asset.gltf +158 -0
- package/examples/windows-webgpu/README.md +57 -0
- package/examples/windows-webgpu/bundle.mjs +122 -0
- package/examples/windows-webgpu/main.mjs +302 -0
- package/examples/windows-webgpu/package-lock.json +2353 -0
- package/examples/windows-webgpu/package.json +40 -0
- package/examples/windows-webgpu/squirrel.mjs +66 -0
- package/package.json +259 -4
- package/packages/ci-gate/export-film.mjs +347 -0
- package/packages/ci-gate/verify-sequence.mjs +285 -0
- package/packages/compiler/agent-contract.mjs +545 -0
- package/packages/compiler/ast-scanner.mjs +254 -0
- package/packages/compiler/backend-loader.mjs +62 -0
- package/packages/compiler/branding-assets.mjs +32 -0
- package/packages/compiler/branding.mjs +324 -0
- package/packages/compiler/browser-auto-example.mjs +31 -0
- package/packages/compiler/browser-model-example.mjs +53 -0
- package/packages/compiler/browser-process.mjs +344 -0
- package/packages/compiler/browser-sdk-example.mjs +50 -0
- package/packages/compiler/browser-sdk.mjs +342 -0
- package/packages/compiler/chrome-host.mjs +196 -0
- package/packages/compiler/cli.mjs +22 -0
- package/packages/compiler/compiler-runtime.mjs +41 -0
- package/packages/compiler/consumer-accept.mjs +89 -0
- package/packages/compiler/consumer-build.mjs +641 -0
- package/packages/compiler/consumer-guards.mjs +422 -0
- package/packages/compiler/consumer-publication.mjs +56 -0
- package/packages/compiler/consumer-scripts.mjs +134 -0
- package/packages/compiler/consumer-starter-2d.mjs +54 -0
- package/packages/compiler/consumer-starter-minigame.mjs +30 -0
- package/packages/compiler/editor-http.mjs +210 -0
- package/packages/compiler/editor-request.ts +12 -0
- package/packages/compiler/film-host-client.ts +249 -0
- package/packages/compiler/flythrough-file.mjs +144 -0
- package/packages/compiler/json-locate.mjs +85 -0
- package/packages/compiler/layout-contract.mjs +472 -0
- package/packages/compiler/minigame-bootstrap.mjs +24 -0
- package/packages/compiler/minigame-bridge.mjs +66 -0
- package/packages/compiler/minigame-guards.mjs +107 -0
- package/packages/compiler/minigame-toolchain.mjs +241 -0
- package/packages/compiler/model-crown.mjs +173 -0
- package/packages/compiler/model-editor-client.ts +809 -0
- package/packages/compiler/model-editor.mjs +242 -0
- package/packages/compiler/model-lod.mjs +547 -0
- package/packages/compiler/prefab-check.mjs +288 -0
- package/packages/compiler/prefab-checks.mjs +74 -0
- package/packages/compiler/prefab-dependencies.mjs +102 -0
- package/packages/compiler/prefab-editor-client.ts +950 -0
- package/packages/compiler/prefab-editor-preview.ts +89 -0
- package/packages/compiler/prefab-editor-server.mjs +585 -0
- package/packages/compiler/prefab-editor.mjs +43 -0
- package/packages/compiler/prefab-environment.mjs +107 -0
- package/packages/compiler/prefab-lifecycle.mjs +60 -0
- package/packages/compiler/prefab-preview.mjs +159 -0
- package/packages/compiler/prefab-watch.mjs +459 -0
- package/packages/compiler/runtime3d-types.mjs +91 -0
- package/packages/compiler/stage-probe.mjs +557 -0
- package/packages/compiler/visual-asset-audit.mjs +609 -0
- package/packages/compiler/visual-contract-audit.mjs +173 -0
- package/packages/compiler/webgpu-loader.mjs +153 -0
- package/packages/compiler/zhuda-build.mjs +714 -0
- package/packages/compiler/zhuda-doctor.mjs +186 -0
- package/packages/compiler/zhuda-init.mjs +353 -0
- package/packages/compiler/zhuda-layout.mjs +163 -0
- package/packages/compiler/zhuda-minigame.mjs +636 -0
- package/packages/core/BenchmarkEngine.ts +2 -0
- package/packages/core/BitmapFontContract.ts +159 -0
- package/packages/core/DeclarativeSDK.ts +686 -0
- package/packages/core/IframeSoundAdapter.ts +1824 -0
- package/packages/core/NoSleepAdapter.ts +302 -0
- package/packages/core/PixelCalibrationEngine.ts +602 -0
- package/packages/core/Prefab.ts +314 -0
- package/packages/core/RealmGuards.ts +111 -0
- package/packages/core/ResponsiveLayout.ts +149 -0
- package/packages/core/RuntimeGuards.ts +261 -0
- package/packages/core/SpineCharacter.ts +243 -0
- package/packages/core/SpineVisualContract.ts +238 -0
- package/packages/core/SplashSignal.ts +72 -0
- package/packages/core/StaticAssetPipeline.ts +3 -0
- package/packages/core/TopologyGraph.ts +693 -0
- package/packages/core/UnityBridgePipeline.ts +2 -0
- package/packages/core/VideoSurface.ts +75 -0
- package/packages/core/ViewportMatrixEngine.ts +237 -0
- package/packages/core/VisualFocusContract.ts +76 -0
- package/packages/core/VisualMigrationPipeline.ts +245 -0
- package/packages/core/WebViewSurface.ts +116 -0
- package/packages/core/audio/OfflineMix.ts +186 -0
- package/packages/core/audio/Spatial.ts +312 -0
- package/packages/core/audio/StreamVoice.ts +161 -0
- package/packages/core/csg/Bsp.ts +310 -0
- package/packages/core/csg/index.ts +589 -0
- package/packages/core/effects/Effect2D.ts +286 -0
- package/packages/core/effects/Effect3D.ts +213 -0
- package/packages/core/effects/EffectBudget.ts +695 -0
- package/packages/core/effects/EffectDirector.ts +254 -0
- package/packages/core/effects/EffectPresets.ts +843 -0
- package/packages/core/effects/EffectPresets2D.ts +1011 -0
- package/packages/core/effects/EffectSprites.ts +143 -0
- package/packages/core/effects/ParticleEventLink.ts +53 -0
- package/packages/core/effects/README.md +108 -0
- package/packages/core/effects/VfxMaterial.ts +253 -0
- package/packages/core/film/BakeKey.ts +21 -0
- package/packages/core/film/ColorValues.ts +44 -0
- package/packages/core/film/FilmLint.ts +353 -0
- package/packages/core/film/FilmPrefab.ts +82 -0
- package/packages/core/film/FilmReview.ts +84 -0
- package/packages/core/film/FilmScene.ts +3442 -0
- package/packages/core/film/FilmStage.ts +2148 -0
- package/packages/core/film/Flythrough.ts +169 -0
- package/packages/core/film/FlythroughReport.ts +326 -0
- package/packages/core/film/FrameMetrics.ts +167 -0
- package/packages/core/film/LiveLook.ts +242 -0
- package/packages/core/film/LookQuality.ts +94 -0
- package/packages/core/film/Projection.ts +74 -0
- package/packages/core/film/SceneLook.ts +363 -0
- package/packages/core/film/index.ts +12 -0
- package/packages/core/index.ts +48 -0
- package/packages/core/particles/EffectEnvelope.ts +52 -0
- package/packages/core/particles/LayaParticleRenderer.ts +182 -0
- package/packages/core/particles/LayaParticleRenderer3D.ts +218 -0
- package/packages/core/particles/ParticleExtras.ts +163 -0
- package/packages/core/particles/ParticleMesh3D.ts +156 -0
- package/packages/core/particles/ParticleSystem.ts +324 -0
- package/packages/core/particles/ParticleSystem3D.ts +411 -0
- package/packages/core/particles/ParticleTypes.ts +230 -0
- package/packages/core/particles/ParticleTypes3D.ts +115 -0
- package/packages/core/particles/README.md +181 -0
- package/packages/core/particles/RibbonPath3D.ts +234 -0
- package/packages/core/particles/RibbonTrail.ts +145 -0
- package/packages/core/particles/RibbonTrail3D.ts +166 -0
- package/packages/core/particles/index.ts +12 -0
- package/packages/core/prefabs/PrefabLibrary.ts +692 -0
- package/packages/core/prefabs/PrefabTree3D.ts +291 -0
- package/packages/core/prefabs/index.ts +10 -0
- package/packages/core/procedural/Geometry.ts +1871 -0
- package/packages/core/procedural/Hand.ts +1510 -0
- package/packages/core/procedural/Isosurface.ts +1035 -0
- package/packages/core/procedural/ModuleHarness.ts +180 -0
- package/packages/core/procedural/Noise.ts +123 -0
- package/packages/core/procedural/PhotoMaterial.ts +283 -0
- package/packages/core/procedural/ProceduralAssetProvider.ts +105 -0
- package/packages/core/procedural/ProceduralMaterial.ts +184 -0
- package/packages/core/procedural/PropFactory.ts +307 -0
- package/packages/core/procedural/Random.ts +70 -0
- package/packages/core/procedural/SynthAudio.ts +221 -0
- package/packages/core/procedural/TerrainMesh.ts +207 -0
- package/packages/core/procedural/TextureRecipe.ts +464 -0
- package/packages/core/procedural/TriplanarMaterial.ts +169 -0
- package/packages/core/procedural/Variation.ts +94 -0
- package/packages/core/procedural/index.ts +15 -0
- package/packages/core/runtime3d/ActionFrames.ts +245 -0
- package/packages/core/runtime3d/AnimationBlend.ts +282 -0
- package/packages/core/runtime3d/AnimationBlendMath.ts +98 -0
- package/packages/core/runtime3d/AssetProvider.ts +775 -0
- package/packages/core/runtime3d/AssetShowcase.ts +190 -0
- package/packages/core/runtime3d/Assets.ts +801 -0
- package/packages/core/runtime3d/AsyncDeadline.ts +53 -0
- package/packages/core/runtime3d/AsyncOperation.ts +39 -0
- package/packages/core/runtime3d/BackendChoice.ts +359 -0
- package/packages/core/runtime3d/BakedCrowd.ts +575 -0
- package/packages/core/runtime3d/BasisTexture.ts +657 -0
- package/packages/core/runtime3d/CameraCollision.ts +69 -0
- package/packages/core/runtime3d/CameraEffects.ts +752 -0
- package/packages/core/runtime3d/CameraRig.ts +70 -0
- package/packages/core/runtime3d/CharacterController.ts +272 -0
- package/packages/core/runtime3d/CinematicCapture.ts +457 -0
- package/packages/core/runtime3d/Clocks.ts +724 -0
- package/packages/core/runtime3d/Cloth.ts +183 -0
- package/packages/core/runtime3d/Clouds.ts +462 -0
- package/packages/core/runtime3d/ColorLut.ts +351 -0
- package/packages/core/runtime3d/CombatQueries.ts +240 -0
- package/packages/core/runtime3d/ComputePass.ts +582 -0
- package/packages/core/runtime3d/CrowdPresentation.ts +368 -0
- package/packages/core/runtime3d/DebugDraw.ts +567 -0
- package/packages/core/runtime3d/DebugStats.ts +35 -0
- package/packages/core/runtime3d/Decals.ts +309 -0
- package/packages/core/runtime3d/DensityVolume.ts +238 -0
- package/packages/core/runtime3d/DistanceBricks.ts +349 -0
- package/packages/core/runtime3d/Dither.ts +199 -0
- package/packages/core/runtime3d/DrawWarmUp.ts +217 -0
- package/packages/core/runtime3d/EdgeSmoothing.ts +108 -0
- package/packages/core/runtime3d/EnvironmentProbe.ts +656 -0
- package/packages/core/runtime3d/Filmic.ts +973 -0
- package/packages/core/runtime3d/Foliage.ts +367 -0
- package/packages/core/runtime3d/GltfIntake.ts +914 -0
- package/packages/core/runtime3d/GltfSecondUv.ts +153 -0
- package/packages/core/runtime3d/GraphicsGuard.ts +171 -0
- package/packages/core/runtime3d/Grass.ts +1080 -0
- package/packages/core/runtime3d/GroundTruthAO.ts +360 -0
- package/packages/core/runtime3d/HalfFloat.ts +44 -0
- package/packages/core/runtime3d/HdrEnvironment.ts +588 -0
- package/packages/core/runtime3d/Ik.ts +392 -0
- package/packages/core/runtime3d/InputBuffer.ts +165 -0
- package/packages/core/runtime3d/InstancedMesh.ts +460 -0
- package/packages/core/runtime3d/Laya342Adapters.ts +1095 -0
- package/packages/core/runtime3d/Laya342GltfAdapter.ts +751 -0
- package/packages/core/runtime3d/LensFinish.ts +153 -0
- package/packages/core/runtime3d/LensFlare.ts +490 -0
- package/packages/core/runtime3d/LightFog.ts +1008 -0
- package/packages/core/runtime3d/LightingDepth.ts +544 -0
- package/packages/core/runtime3d/Lightmap.ts +238 -0
- package/packages/core/runtime3d/Math3D.ts +84 -0
- package/packages/core/runtime3d/MeshQuery.ts +547 -0
- package/packages/core/runtime3d/MeshoptModelDecoder.ts +354 -0
- package/packages/core/runtime3d/MiniGameSplash.ts +70 -0
- package/packages/core/runtime3d/ModelAnimationSampler.ts +97 -0
- package/packages/core/runtime3d/ModelCompatibility.ts +890 -0
- package/packages/core/runtime3d/ModelDecoder.ts +294 -0
- package/packages/core/runtime3d/ModelInspector.ts +226 -0
- package/packages/core/runtime3d/ModelLod.ts +163 -0
- package/packages/core/runtime3d/ModelPlacements.ts +426 -0
- package/packages/core/runtime3d/ObjectMotion.ts +217 -0
- package/packages/core/runtime3d/PhysicalCamera.ts +190 -0
- package/packages/core/runtime3d/PointShadow.ts +500 -0
- package/packages/core/runtime3d/PointShadowSchedule.ts +201 -0
- package/packages/core/runtime3d/Pool.ts +120 -0
- package/packages/core/runtime3d/ProbeVolume.ts +695 -0
- package/packages/core/runtime3d/QualityGovernor.ts +385 -0
- package/packages/core/runtime3d/QualityMemory.ts +200 -0
- package/packages/core/runtime3d/RenderScale.ts +356 -0
- package/packages/core/runtime3d/RenderSpaces.ts +105 -0
- package/packages/core/runtime3d/Renderer.ts +377 -0
- package/packages/core/runtime3d/ResultPlayback.ts +239 -0
- package/packages/core/runtime3d/Runtime.ts +507 -0
- package/packages/core/runtime3d/RuntimeDriver.ts +127 -0
- package/packages/core/runtime3d/SceneLifecycle.ts +211 -0
- package/packages/core/runtime3d/SceneMutation.ts +107 -0
- package/packages/core/runtime3d/SceneQueries.ts +191 -0
- package/packages/core/runtime3d/ScreenReflections.ts +595 -0
- package/packages/core/runtime3d/SelectionOutline.ts +389 -0
- package/packages/core/runtime3d/ShaderErrors.ts +104 -0
- package/packages/core/runtime3d/ShaderRegistry.ts +34 -0
- package/packages/core/runtime3d/ShaderWarmUp.ts +473 -0
- package/packages/core/runtime3d/ShadowUpdates.ts +287 -0
- package/packages/core/runtime3d/SkinBinding.ts +235 -0
- package/packages/core/runtime3d/Smaa.ts +386 -0
- package/packages/core/runtime3d/SmaaTables.ts +244 -0
- package/packages/core/runtime3d/SpringBones.ts +184 -0
- package/packages/core/runtime3d/SurfaceBuffer.ts +76 -0
- package/packages/core/runtime3d/Surfaces.ts +1105 -0
- package/packages/core/runtime3d/Themes.ts +344 -0
- package/packages/core/runtime3d/Timeline.ts +362 -0
- package/packages/core/runtime3d/ToneCurves.ts +292 -0
- package/packages/core/runtime3d/TransformGizmo.ts +539 -0
- package/packages/core/runtime3d/TriangleMask.ts +250 -0
- package/packages/core/runtime3d/Underwater.ts +778 -0
- package/packages/core/runtime3d/Utf8.ts +87 -0
- package/packages/core/runtime3d/Vrm.ts +773 -0
- package/packages/core/runtime3d/VrmDocument.ts +1830 -0
- package/packages/core/runtime3d/WalkGrid.ts +471 -0
- package/packages/core/runtime3d/WebGPU342Adapters.ts +280 -0
- package/packages/core/runtime3d/index.ts +147 -0
- package/packages/core/shaders/Laya342ShaderTemplates.ts +6 -0
- package/packages/core/shaders/LitSurfaceMaterial.ts +1076 -0
- package/packages/core/shaders/LitSurfaceTemplates.ts +13 -0
- package/packages/core/shaders/ReflectiveSurface.ts +285 -0
- package/packages/core/shaders/ShaderMaterials.ts +387 -0
- package/packages/core/shaders/ToonMaterial.ts +559 -0
- package/packages/core/shaders/WaterRipples.ts +170 -0
- package/packages/core/shaders/WaterSurface.ts +480 -0
- package/packages/core/shaders/ZhudaCommon.ts +109 -0
- package/packages/core/shaders/index.ts +6 -0
- package/packages/core/simulation/Cloth.ts +1541 -0
- package/packages/core/simulation/ParticleCore.ts +498 -0
- package/packages/core/simulation/SpringBones.ts +553 -0
- package/packages/core/simulation/index.ts +3 -0
- package/packages/core/terrain/Heightfield.ts +385 -0
- package/packages/core/terrain/Terrain2D.ts +324 -0
- package/packages/core/terrain/Terrain3D.ts +452 -0
- package/packages/core/terrain/TerrainShell.ts +94 -0
- package/packages/core/terrain/index.ts +3 -0
- package/packages/demo/BenchmarkEngine.ts +184 -0
- package/packages/demo/PixelCalibrationEngine.ts +36 -0
- package/packages/demo/ProceduralStarter.ts +312 -0
- package/packages/demo/StaticAssetPipeline.ts +1631 -0
- package/packages/demo/UnityBridgePipeline.ts +485 -0
- package/packages/demo/index.ts +6 -0
- package/packages/mcp-server/arguments.mjs +81 -0
- package/packages/mcp-server/corpus.mjs +627 -0
- package/packages/mcp-server/film-host.mjs +627 -0
- package/packages/mcp-server/film-session.mjs +95 -0
- package/packages/mcp-server/film-tools.mjs +460 -0
- package/packages/mcp-server/index.mjs +931 -0
- package/packages/mcp-server/quality-route.mjs +332 -0
- package/packages/mcp-server/roots.mjs +72 -0
- package/packages/mcp-server/runtime.mjs +81 -0
- package/packages/types/BitmapFontContract.d.ts +19 -0
- package/packages/types/DeclarativeSDK.d.ts +137 -0
- package/packages/types/IframeSoundAdapter.d.ts +173 -0
- package/packages/types/NoSleepAdapter.d.ts +50 -0
- package/packages/types/PixelCalibrationEngine.d.ts +83 -0
- package/packages/types/Prefab.d.ts +11 -0
- package/packages/types/RealmGuards.d.ts +26 -0
- package/packages/types/ResponsiveLayout.d.ts +10 -0
- package/packages/types/RuntimeGuards.d.ts +55 -0
- package/packages/types/SpineCharacter.d.ts +94 -0
- package/packages/types/SpineVisualContract.d.ts +50 -0
- package/packages/types/SplashSignal.d.ts +27 -0
- package/packages/types/TopologyGraph.d.ts +76 -0
- package/packages/types/VideoSurface.d.ts +21 -0
- package/packages/types/ViewportMatrixEngine.d.ts +27 -0
- package/packages/types/VisualFocusContract.d.ts +32 -0
- package/packages/types/VisualMigrationPipeline.d.ts +53 -0
- package/packages/types/WebViewSurface.d.ts +26 -0
- package/packages/types/audio/OfflineMix.d.ts +10 -0
- package/packages/types/audio/Spatial.d.ts +63 -0
- package/packages/types/audio/StreamVoice.d.ts +31 -0
- package/packages/types/browser.d.ts +44 -0
- package/packages/types/csg/Bsp.d.ts +85 -0
- package/packages/types/csg/index.d.ts +81 -0
- package/packages/types/demo/BenchmarkEngine.d.ts +61 -0
- package/packages/types/demo/PixelCalibrationEngine.d.ts +13 -0
- package/packages/types/demo/ProceduralStarter.d.ts +11 -0
- package/packages/types/demo/StaticAssetPipeline.d.ts +87 -0
- package/packages/types/demo/UnityBridgePipeline.d.ts +49 -0
- package/packages/types/demo/index.d.ts +7 -0
- package/packages/types/editor-preview.d.ts +27 -0
- package/packages/types/effects/Effect2D.d.ts +65 -0
- package/packages/types/effects/Effect3D.d.ts +42 -0
- package/packages/types/effects/EffectBudget.d.ts +179 -0
- package/packages/types/effects/EffectDirector.d.ts +68 -0
- package/packages/types/effects/EffectPresets.d.ts +27 -0
- package/packages/types/effects/EffectPresets2D.d.ts +32 -0
- package/packages/types/effects/EffectSprites.d.ts +23 -0
- package/packages/types/effects/ParticleEventLink.d.ts +16 -0
- package/packages/types/effects/VfxMaterial.d.ts +52 -0
- package/packages/types/film/BakeKey.d.ts +9 -0
- package/packages/types/film/ColorValues.d.ts +25 -0
- package/packages/types/film/FilmLint.d.ts +40 -0
- package/packages/types/film/FilmPrefab.d.ts +22 -0
- package/packages/types/film/FilmReview.d.ts +27 -0
- package/packages/types/film/FilmScene.d.ts +1214 -0
- package/packages/types/film/FilmStage.d.ts +237 -0
- package/packages/types/film/Flythrough.d.ts +44 -0
- package/packages/types/film/FlythroughReport.d.ts +132 -0
- package/packages/types/film/FrameMetrics.d.ts +49 -0
- package/packages/types/film/LiveLook.d.ts +60 -0
- package/packages/types/film/LookQuality.d.ts +24 -0
- package/packages/types/film/Projection.d.ts +20 -0
- package/packages/types/film/SceneLook.d.ts +122 -0
- package/packages/types/film/index.d.ts +13 -0
- package/packages/types/index.d.ts +49 -0
- package/packages/types/particles/EffectEnvelope.d.ts +18 -0
- package/packages/types/particles/LayaParticleRenderer.d.ts +30 -0
- package/packages/types/particles/LayaParticleRenderer3D.d.ts +29 -0
- package/packages/types/particles/ParticleExtras.d.ts +50 -0
- package/packages/types/particles/ParticleMesh3D.d.ts +24 -0
- package/packages/types/particles/ParticleSystem.d.ts +52 -0
- package/packages/types/particles/ParticleSystem3D.d.ts +69 -0
- package/packages/types/particles/ParticleTypes.d.ts +89 -0
- package/packages/types/particles/ParticleTypes3D.d.ts +56 -0
- package/packages/types/particles/RibbonPath3D.d.ts +32 -0
- package/packages/types/particles/RibbonTrail.d.ts +38 -0
- package/packages/types/particles/RibbonTrail3D.d.ts +22 -0
- package/packages/types/particles/index.d.ts +13 -0
- package/packages/types/prefabs/PrefabLibrary.d.ts +176 -0
- package/packages/types/prefabs/PrefabTree3D.d.ts +59 -0
- package/packages/types/prefabs/index.d.ts +4 -0
- package/packages/types/procedural/Geometry.d.ts +252 -0
- package/packages/types/procedural/Hand.d.ts +150 -0
- package/packages/types/procedural/Isosurface.d.ts +181 -0
- package/packages/types/procedural/ModuleHarness.d.ts +90 -0
- package/packages/types/procedural/Noise.d.ts +15 -0
- package/packages/types/procedural/PhotoMaterial.d.ts +49 -0
- package/packages/types/procedural/ProceduralAssetProvider.d.ts +31 -0
- package/packages/types/procedural/ProceduralMaterial.d.ts +63 -0
- package/packages/types/procedural/PropFactory.d.ts +94 -0
- package/packages/types/procedural/Random.d.ts +26 -0
- package/packages/types/procedural/SynthAudio.d.ts +49 -0
- package/packages/types/procedural/TerrainMesh.d.ts +55 -0
- package/packages/types/procedural/TextureRecipe.d.ts +125 -0
- package/packages/types/procedural/TriplanarMaterial.d.ts +27 -0
- package/packages/types/procedural/Variation.d.ts +23 -0
- package/packages/types/procedural/index.d.ts +16 -0
- package/packages/types/runtime3d/ActionFrames.d.ts +62 -0
- package/packages/types/runtime3d/AnimationBlend.d.ts +57 -0
- package/packages/types/runtime3d/AnimationBlendMath.d.ts +27 -0
- package/packages/types/runtime3d/AssetProvider.d.ts +167 -0
- package/packages/types/runtime3d/AssetShowcase.d.ts +44 -0
- package/packages/types/runtime3d/Assets.d.ts +166 -0
- package/packages/types/runtime3d/AsyncDeadline.d.ts +6 -0
- package/packages/types/runtime3d/AsyncOperation.d.ts +3 -0
- package/packages/types/runtime3d/BackendChoice.d.ts +130 -0
- package/packages/types/runtime3d/BakedCrowd.d.ts +156 -0
- package/packages/types/runtime3d/BasisTexture.d.ts +169 -0
- package/packages/types/runtime3d/CameraCollision.d.ts +20 -0
- package/packages/types/runtime3d/CameraEffects.d.ts +134 -0
- package/packages/types/runtime3d/CameraRig.d.ts +27 -0
- package/packages/types/runtime3d/CharacterController.d.ts +71 -0
- package/packages/types/runtime3d/CinematicCapture.d.ts +103 -0
- package/packages/types/runtime3d/Clocks.d.ts +200 -0
- package/packages/types/runtime3d/Cloth.d.ts +57 -0
- package/packages/types/runtime3d/Clouds.d.ts +69 -0
- package/packages/types/runtime3d/ColorLut.d.ts +73 -0
- package/packages/types/runtime3d/CombatQueries.d.ts +50 -0
- package/packages/types/runtime3d/ComputePass.d.ts +134 -0
- package/packages/types/runtime3d/CrowdPresentation.d.ts +104 -0
- package/packages/types/runtime3d/DebugDraw.d.ts +161 -0
- package/packages/types/runtime3d/DebugStats.d.ts +24 -0
- package/packages/types/runtime3d/Decals.d.ts +65 -0
- package/packages/types/runtime3d/DensityVolume.d.ts +39 -0
- package/packages/types/runtime3d/DistanceBricks.d.ts +97 -0
- package/packages/types/runtime3d/Dither.d.ts +78 -0
- package/packages/types/runtime3d/DrawWarmUp.d.ts +93 -0
- package/packages/types/runtime3d/EdgeSmoothing.d.ts +10 -0
- package/packages/types/runtime3d/EnvironmentProbe.d.ts +139 -0
- package/packages/types/runtime3d/Filmic.d.ts +243 -0
- package/packages/types/runtime3d/Foliage.d.ts +95 -0
- package/packages/types/runtime3d/GltfIntake.d.ts +236 -0
- package/packages/types/runtime3d/GltfSecondUv.d.ts +54 -0
- package/packages/types/runtime3d/GraphicsGuard.d.ts +18 -0
- package/packages/types/runtime3d/Grass.d.ts +226 -0
- package/packages/types/runtime3d/GroundTruthAO.d.ts +64 -0
- package/packages/types/runtime3d/HalfFloat.d.ts +13 -0
- package/packages/types/runtime3d/HdrEnvironment.d.ts +144 -0
- package/packages/types/runtime3d/Ik.d.ts +123 -0
- package/packages/types/runtime3d/InputBuffer.d.ts +49 -0
- package/packages/types/runtime3d/InstancedMesh.d.ts +116 -0
- package/packages/types/runtime3d/Laya342Adapters.d.ts +306 -0
- package/packages/types/runtime3d/Laya342GltfAdapter.d.ts +105 -0
- package/packages/types/runtime3d/LensFinish.d.ts +38 -0
- package/packages/types/runtime3d/LensFlare.d.ts +114 -0
- package/packages/types/runtime3d/LightFog.d.ts +190 -0
- package/packages/types/runtime3d/LightingDepth.d.ts +128 -0
- package/packages/types/runtime3d/Lightmap.d.ts +55 -0
- package/packages/types/runtime3d/Math3D.d.ts +19 -0
- package/packages/types/runtime3d/MeshQuery.d.ts +107 -0
- package/packages/types/runtime3d/MeshoptModelDecoder.d.ts +34 -0
- package/packages/types/runtime3d/MiniGameSplash.d.ts +4 -0
- package/packages/types/runtime3d/ModelAnimationSampler.d.ts +26 -0
- package/packages/types/runtime3d/ModelCompatibility.d.ts +169 -0
- package/packages/types/runtime3d/ModelDecoder.d.ts +66 -0
- package/packages/types/runtime3d/ModelInspector.d.ts +77 -0
- package/packages/types/runtime3d/ModelLod.d.ts +61 -0
- package/packages/types/runtime3d/ModelPlacements.d.ts +77 -0
- package/packages/types/runtime3d/ObjectMotion.d.ts +43 -0
- package/packages/types/runtime3d/PhysicalCamera.d.ts +51 -0
- package/packages/types/runtime3d/PointShadow.d.ts +71 -0
- package/packages/types/runtime3d/PointShadowSchedule.d.ts +74 -0
- package/packages/types/runtime3d/Pool.d.ts +33 -0
- package/packages/types/runtime3d/ProbeVolume.d.ts +123 -0
- package/packages/types/runtime3d/QualityGovernor.d.ts +201 -0
- package/packages/types/runtime3d/QualityMemory.d.ts +83 -0
- package/packages/types/runtime3d/RenderScale.d.ts +69 -0
- package/packages/types/runtime3d/RenderSpaces.d.ts +44 -0
- package/packages/types/runtime3d/Renderer.d.ts +62 -0
- package/packages/types/runtime3d/ResultPlayback.d.ts +70 -0
- package/packages/types/runtime3d/Runtime.d.ts +136 -0
- package/packages/types/runtime3d/RuntimeDriver.d.ts +42 -0
- package/packages/types/runtime3d/SceneLifecycle.d.ts +84 -0
- package/packages/types/runtime3d/SceneMutation.d.ts +34 -0
- package/packages/types/runtime3d/SceneQueries.d.ts +71 -0
- package/packages/types/runtime3d/ScreenReflections.d.ts +78 -0
- package/packages/types/runtime3d/SelectionOutline.d.ts +68 -0
- package/packages/types/runtime3d/ShaderErrors.d.ts +27 -0
- package/packages/types/runtime3d/ShaderRegistry.d.ts +10 -0
- package/packages/types/runtime3d/ShaderWarmUp.d.ts +162 -0
- package/packages/types/runtime3d/ShadowUpdates.d.ts +125 -0
- package/packages/types/runtime3d/SkinBinding.d.ts +53 -0
- package/packages/types/runtime3d/Smaa.d.ts +60 -0
- package/packages/types/runtime3d/SmaaTables.d.ts +12 -0
- package/packages/types/runtime3d/SpringBones.d.ts +69 -0
- package/packages/types/runtime3d/SurfaceBuffer.d.ts +28 -0
- package/packages/types/runtime3d/Surfaces.d.ts +326 -0
- package/packages/types/runtime3d/Themes.d.ts +70 -0
- package/packages/types/runtime3d/Timeline.d.ts +88 -0
- package/packages/types/runtime3d/ToneCurves.d.ts +59 -0
- package/packages/types/runtime3d/TransformGizmo.d.ts +139 -0
- package/packages/types/runtime3d/TriangleMask.d.ts +84 -0
- package/packages/types/runtime3d/Underwater.d.ts +120 -0
- package/packages/types/runtime3d/Utf8.d.ts +12 -0
- package/packages/types/runtime3d/Vrm.d.ts +120 -0
- package/packages/types/runtime3d/VrmDocument.d.ts +381 -0
- package/packages/types/runtime3d/WalkGrid.d.ts +94 -0
- package/packages/types/runtime3d/WebGPU342Adapters.d.ts +27 -0
- package/packages/types/runtime3d/index.d.ts +102 -0
- package/packages/types/shaders/Laya342ShaderTemplates.d.ts +3 -0
- package/packages/types/shaders/LitSurfaceMaterial.d.ts +257 -0
- package/packages/types/shaders/LitSurfaceTemplates.d.ts +7 -0
- package/packages/types/shaders/ReflectiveSurface.d.ts +58 -0
- package/packages/types/shaders/ShaderMaterials.d.ts +60 -0
- package/packages/types/shaders/ToonMaterial.d.ts +176 -0
- package/packages/types/shaders/WaterRipples.d.ts +48 -0
- package/packages/types/shaders/WaterSurface.d.ts +110 -0
- package/packages/types/shaders/ZhudaCommon.d.ts +31 -0
- package/packages/types/shaders/index.d.ts +7 -0
- package/packages/types/simulation/Cloth.d.ts +381 -0
- package/packages/types/simulation/ParticleCore.d.ts +125 -0
- package/packages/types/simulation/SpringBones.d.ts +107 -0
- package/packages/types/simulation/index.d.ts +4 -0
- package/packages/types/terrain/Heightfield.d.ts +67 -0
- package/packages/types/terrain/Terrain2D.d.ts +81 -0
- package/packages/types/terrain/Terrain3D.d.ts +80 -0
- package/packages/types/terrain/TerrainShell.d.ts +8 -0
- package/packages/types/terrain/index.d.ts +4 -0
- package/packages/types/vendor/LayaAir.runtime.d.ts +97440 -0
- package/packages/types/vendor/REPAIRS.md +30 -0
- package/packages/types/vendor/restored-3.4.2.json +142 -0
- package/packages/types/vendor/spine.runtime.d.ts +1507 -0
- package/packages/types/vendor/wechat-media.d.ts +877 -0
- package/packages/types/zhuda-2d-ui.d.ts +244 -0
- package/packages/types/zhuda-3d-physics.d.ts +34 -0
- package/packages/types/zhuda-audio.d.ts +128 -0
- package/packages/types/zhuda-bootstrap.d.ts +100 -0
- package/packages/types/zhuda-branding.d.ts +6 -0
- package/packages/types/zhuda-core.d.ts +46 -0
- package/packages/types/zhuda-declarative.d.ts +81 -0
- package/packages/types/zhuda-effects.d.ts +302 -0
- package/packages/types/zhuda-layout.d.ts +96 -0
- package/packages/types/zhuda-particles.d.ts +477 -0
- package/packages/types/zhuda-spine42.d.ts +23 -0
- package/packages/types/zhuda-static-assets.d.ts +389 -0
- package/packages/types/zhuda-video.d.ts +24 -0
- package/packages/types/zhuda-visual-contract.d.ts +52 -0
- package/packages/types/zhuda-webview.d.ts +43 -0
- package/vendor/basis/LICENSE.txt +55 -0
- package/vendor/basis/README.md +25 -0
- package/vendor/basis/basis_transcoder.js +19 -0
- package/vendor/basis/basis_transcoder.wasm +0 -0
- package/vendor/laya-3.4.2/WEBGPU-LICENSES.txt +1259 -0
- package/vendor/laya-3.4.2/libs/laya.ani.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.box2D.js +1209 -0
- package/vendor/laya-3.4.2/libs/laya.bridge.js +2273 -0
- package/vendor/laya-3.4.2/libs/laya.bullet.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.core.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.d3.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.device.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.gltf.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ik.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.light2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.line2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.native-spine42.js +7672 -0
- package/vendor/laya-3.4.2/libs/laya.navMesh2d.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.navMesh3d.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.navMeshCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particle.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particle3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particleCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.physics2D.js +3774 -0
- package/vendor/laya-3.4.2/libs/laya.physics3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.postProcess.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.spine.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.spine3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.tilemap.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trail2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trail3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trailCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ui.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ui2.js +9904 -0
- package/vendor/laya-3.4.2/libs/laya.vfx.js +6754 -0
- package/vendor/laya-3.4.2/libs/laya.webgl_2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.webgl_3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.webgpu_2D.js +18576 -0
- package/vendor/laya-3.4.2/libs/laya.webgpu_3D.js +6729 -0
- package/vendor/laya-3.4.2/libs/nagabind.js +395 -0
- package/vendor/laya-3.4.2/libs/nagabind_bg.wasm +0 -0
- package/vendor/laya-3.4.2/libs/shader_compiler_web.js +22 -0
- package/vendor/laya-3.4.2/libs/shader_compiler_web.wasm +0 -0
- package/vendor/laya-3.4.2/libs/spine-core-3.8.js +1 -0
- package/vendor/laya-3.4.2/libs/spine-core-4.2.js +10216 -0
- package/vendor/laya-3.4.2/webgpu-provenance.json +41 -0
- package/vendor/meshoptimizer/LICENSE.txt +21 -0
- package/vendor/meshoptimizer/README.md +13 -0
- package/vendor/threejs-post/LICENSE.txt +53 -0
- package/vendor/threejs-post/README.md +54 -0
- package/zhuda.config.json +22 -0
|
@@ -0,0 +1,973 @@
|
|
|
1
|
+
import { prepareLaya342ManualDraw } from './Laya342Adapters.ts';
|
|
2
|
+
import { zhudaShadowBorrower } from './ShadowUpdates.ts';
|
|
3
|
+
import type { CinematicLinearChain } from './CinematicCapture.ts';
|
|
4
|
+
import { zhudaShaderRegistrar } from './ShaderRegistry.ts';
|
|
5
|
+
import { zhudaToHalfFloats, zhudaToRgbd } from './HalfFloat.ts';
|
|
6
|
+
import { ZhudaGroundTruthAO, validateZhudaGroundTruthAO } from './GroundTruthAO.ts';
|
|
7
|
+
import {
|
|
8
|
+
applyZhudaToneCurve,
|
|
9
|
+
releaseZhudaToneCurve,
|
|
10
|
+
ZHUDA_TONE_MAPPINGS,
|
|
11
|
+
type ZhudaToneMapping,
|
|
12
|
+
} from './ToneCurves.ts';
|
|
13
|
+
|
|
14
|
+
const SOURCE_VERTEX =
|
|
15
|
+
'#define SHADER_NAME ZhudaLinearSourceVS\nvarying vec2 v_Texcoord0;void main(){gl_Position=vec4(a_PositionTexcoord.xy,0.0,1.0);v_Texcoord0=a_PositionTexcoord.zw;}';
|
|
16
|
+
// u_ZhudaAverageUse.x: 0 passes the scene through, 1 replaces it with the picture.
|
|
17
|
+
const SOURCE_FRAGMENT = `#define SHADER_NAME ZhudaLinearSourceFS
|
|
18
|
+
#include "Color.glsl";
|
|
19
|
+
varying vec2 v_Texcoord0;
|
|
20
|
+
void main(){
|
|
21
|
+
vec4 source=texture2D(u_MainTex,v_Texcoord0);
|
|
22
|
+
#ifdef Gamma_u_MainTex
|
|
23
|
+
source=gammaToLinear(source);
|
|
24
|
+
#endif
|
|
25
|
+
// The picture is stored top row first; a render target is sampled bottom row first.
|
|
26
|
+
vec4 average=texture2D(u_ZhudaAverage,vec2(v_Texcoord0.x,1.0-v_Texcoord0.y));
|
|
27
|
+
gl_FragColor=mix(source,vec4(average.rgb,source.a),u_ZhudaAverageUse.x);
|
|
28
|
+
}`;
|
|
29
|
+
/**
|
|
30
|
+
* The brightest scene value, after exposure, that the lookup table of
|
|
31
|
+
* LayaAir's `ColorGradEffect` holds: its log encoding ends at 58.85. A value
|
|
32
|
+
* above it is looked up outside the table and comes out dark or in the wrong
|
|
33
|
+
* colour (a red lamp turned grey-green, then lost its red altogether).
|
|
34
|
+
*/
|
|
35
|
+
export const ZHUDA_GRADE_TABLE_MAX = 56;
|
|
36
|
+
// Scales a colour whose brightest channel is above the table's end down to it:
|
|
37
|
+
// the hue is kept, and the table turns that brightness into near-white.
|
|
38
|
+
const RANGE_FRAGMENT = `#define SHADER_NAME ZhudaGradeRangeFS
|
|
39
|
+
#include "Color.glsl";
|
|
40
|
+
varying vec2 v_Texcoord0;
|
|
41
|
+
void main(){
|
|
42
|
+
vec4 source=texture2D(u_MainTex,v_Texcoord0);
|
|
43
|
+
#ifdef Gamma_u_MainTex
|
|
44
|
+
source=gammaToLinear(source);
|
|
45
|
+
#endif
|
|
46
|
+
float peak=max(source.r,max(source.g,source.b));
|
|
47
|
+
gl_FragColor=vec4(source.rgb*min(1.0,u_ZhudaGradeRange.x/max(peak,0.0001)),source.a);
|
|
48
|
+
}`;
|
|
49
|
+
const rangeRegistered = new WeakSet<object>();
|
|
50
|
+
function registerGradeRange(l: any) {
|
|
51
|
+
if (rangeRegistered.has(l.Shader3D)) return;
|
|
52
|
+
const shader = l.Shader3D.add('ZhudaGradeRange');
|
|
53
|
+
shader.shaderType = l.ShaderFeatureType.PostProcess;
|
|
54
|
+
const sub = new l.SubShader(
|
|
55
|
+
{ a_PositionTexcoord: [l.VertexMesh.MESH_POSITION0, l.ShaderDataType.Vector4] },
|
|
56
|
+
{ u_MainTex: l.ShaderDataType.Texture2D, u_ZhudaGradeRange: l.ShaderDataType.Vector4 },
|
|
57
|
+
);
|
|
58
|
+
shader.addSubShader(sub);
|
|
59
|
+
const pass = sub.addShaderPass(SOURCE_VERTEX, RANGE_FRAGMENT);
|
|
60
|
+
pass.statefirst = true;
|
|
61
|
+
pass.renderState.cull = l.RenderState.CULL_NONE;
|
|
62
|
+
rangeRegistered.add(l.Shader3D);
|
|
63
|
+
}
|
|
64
|
+
zhudaShaderRegistrar(registerGradeRange);
|
|
65
|
+
const sourceRegistered = new WeakSet<object>();
|
|
66
|
+
function registerLinearSource(l: any) {
|
|
67
|
+
if (sourceRegistered.has(l.Shader3D)) return;
|
|
68
|
+
const shader = l.Shader3D.add('ZhudaLinearSource');
|
|
69
|
+
shader.shaderType = l.ShaderFeatureType.PostProcess;
|
|
70
|
+
const sub = new l.SubShader(
|
|
71
|
+
{ a_PositionTexcoord: [l.VertexMesh.MESH_POSITION0, l.ShaderDataType.Vector4] },
|
|
72
|
+
{
|
|
73
|
+
u_MainTex: l.ShaderDataType.Texture2D,
|
|
74
|
+
u_ZhudaAverage: l.ShaderDataType.Texture2D,
|
|
75
|
+
u_ZhudaAverageUse: l.ShaderDataType.Vector4,
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
shader.addSubShader(sub);
|
|
79
|
+
const pass = sub.addShaderPass(SOURCE_VERTEX, SOURCE_FRAGMENT);
|
|
80
|
+
pass.statefirst = true;
|
|
81
|
+
pass.renderState.cull = l.RenderState.CULL_NONE;
|
|
82
|
+
sourceRegistered.add(l.Shader3D);
|
|
83
|
+
}
|
|
84
|
+
zhudaShaderRegistrar(registerLinearSource);
|
|
85
|
+
|
|
86
|
+
export interface PrefilteredEnvironmentSpec {
|
|
87
|
+
size: number;
|
|
88
|
+
levels: { size: number; offset: number; elements: number }[];
|
|
89
|
+
ambientSH: number[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Switches a camera's multisampling and frees the HDR target of the other
|
|
93
|
+
* kind. LayaAir hands a camera its target from a pool every frame and puts it
|
|
94
|
+
* back afterwards; a target with the other sample count is never asked for
|
|
95
|
+
* again and would stay in the pool, a full frame of memory, for as long as
|
|
96
|
+
* the page lives. Between frames that target is in the pool: it is destroyed
|
|
97
|
+
* here. Only HDR targets with a depth buffer are touched (what a camera with
|
|
98
|
+
* `enableHDR` draws into); another camera that still wants one gets a new one.
|
|
99
|
+
*/
|
|
100
|
+
function setCameraMultisampling(l: any, camera: any, msaa: boolean) {
|
|
101
|
+
if (camera.msaa === msaa) return;
|
|
102
|
+
camera.msaa = msaa;
|
|
103
|
+
const type = l.RenderTexture;
|
|
104
|
+
const pool: any[] | undefined = type?._pool;
|
|
105
|
+
if (!Array.isArray(pool)) return;
|
|
106
|
+
for (let i = pool.length - 1; i >= 0; i--) {
|
|
107
|
+
const target = pool[i];
|
|
108
|
+
if (
|
|
109
|
+
!target ||
|
|
110
|
+
target.destroyed ||
|
|
111
|
+
target.isMRT ||
|
|
112
|
+
target.colorFormat !== l.RenderTargetFormat.R16G16B16A16 ||
|
|
113
|
+
target.depthStencilFormat === l.RenderTargetFormat.None ||
|
|
114
|
+
target.multiSamples > 1 === msaa
|
|
115
|
+
)
|
|
116
|
+
continue;
|
|
117
|
+
pool.splice(i, 1);
|
|
118
|
+
if (typeof type._poolMemory === 'number')
|
|
119
|
+
type._poolMemory -= (target._renderTarget?.gpuMemory ?? 0) / 1024 / 1024;
|
|
120
|
+
target._inPool = false;
|
|
121
|
+
target.destroy();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function requireCapabilities(l: any, names: string[]) {
|
|
125
|
+
for (const name of names)
|
|
126
|
+
if (!l.LayaGL.renderEngine.getCapable(l.RenderCapable[name]))
|
|
127
|
+
throw Error('Filmic rendering requires ' + name);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* How an environment is stored on the graphics card: 32-bit floats, 16-bit
|
|
131
|
+
* floats (half the memory, values to 65504, which every WebGL 2 device
|
|
132
|
+
* filters), or 8 bits a channel with a divisor in alpha (LayaAir's RGBD: a
|
|
133
|
+
* quarter of the memory of `half`, values to 255, coarse above 1).
|
|
134
|
+
*/
|
|
135
|
+
export type ZhudaEnvironmentFormat = 'float' | 'half' | 'rgbd';
|
|
136
|
+
|
|
137
|
+
/** The formats this device can filter, best first. `rgbd` is always there. */
|
|
138
|
+
export function zhudaEnvironmentFormats(
|
|
139
|
+
runtime: any = (globalThis as any).Laya,
|
|
140
|
+
): ZhudaEnvironmentFormat[] {
|
|
141
|
+
const engine = runtime?.LayaGL?.renderEngine,
|
|
142
|
+
capable = runtime?.RenderCapable ?? {};
|
|
143
|
+
const has = (name: string) =>
|
|
144
|
+
typeof engine?.getCapable === 'function' && engine.getCapable(capable[name]) === true;
|
|
145
|
+
return [
|
|
146
|
+
...(has('TextureFormat_R32G32B32A32') && has('Texture_FloatLinearFiltering')
|
|
147
|
+
? (['float'] as const)
|
|
148
|
+
: []),
|
|
149
|
+
...(has('TextureFormat_R16G16B16A16') && has('Texture_HalfFloatLinearFiltering')
|
|
150
|
+
? (['half'] as const)
|
|
151
|
+
: []),
|
|
152
|
+
'rgbd',
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Upload an offline convolved GGX mip chain. Offsets are float32 elements, not bytes.
|
|
157
|
+
* Data is scene-linear RGBA in WebGL cube face order +X,-X,+Y,-Y,+Z,-Z.
|
|
158
|
+
* Mip roughness follows Laya's r*(2-r) lookup. Stored in the best format the
|
|
159
|
+
* device filters (`zhudaEnvironmentFormats`), or in `format` when given: a
|
|
160
|
+
* format the device does not have is refused, never replaced. */
|
|
161
|
+
export function createPrefilteredEnvironment(
|
|
162
|
+
spec: PrefilteredEnvironmentSpec,
|
|
163
|
+
pixels: Float32Array,
|
|
164
|
+
format?: ZhudaEnvironmentFormat,
|
|
165
|
+
) {
|
|
166
|
+
if (
|
|
167
|
+
!Number.isInteger(spec.size) ||
|
|
168
|
+
spec.size < 1 ||
|
|
169
|
+
spec.size & (spec.size - 1) ||
|
|
170
|
+
spec.ambientSH.length !== 27 ||
|
|
171
|
+
!spec.ambientSH.every(Number.isFinite)
|
|
172
|
+
)
|
|
173
|
+
throw Error('Invalid environment descriptor');
|
|
174
|
+
if (spec.levels.length !== Math.log2(spec.size) + 1) throw Error('Incomplete GGX mip chain');
|
|
175
|
+
let offset = 0;
|
|
176
|
+
for (const [i, level] of spec.levels.entries()) {
|
|
177
|
+
const size = Math.max(1, spec.size >> i),
|
|
178
|
+
elements = size * size * 4 * 6;
|
|
179
|
+
if (level.size !== size || level.offset !== offset || level.elements !== elements)
|
|
180
|
+
throw Error('Invalid environment mip layout');
|
|
181
|
+
offset += elements;
|
|
182
|
+
}
|
|
183
|
+
if (offset !== pixels.length || !pixels.every((v) => Number.isFinite(v) && v >= 0))
|
|
184
|
+
throw Error('Invalid environment pixels');
|
|
185
|
+
const l = (globalThis as any).Laya;
|
|
186
|
+
const available = zhudaEnvironmentFormats(l);
|
|
187
|
+
const stored = format ?? available[0];
|
|
188
|
+
if (!available.includes(stored))
|
|
189
|
+
throw Error(
|
|
190
|
+
`Environment format ${String(format)} is not available here (this device filters ${available.join(', ')})`,
|
|
191
|
+
);
|
|
192
|
+
const texture = new l.TextureCube(
|
|
193
|
+
spec.size,
|
|
194
|
+
stored === 'float'
|
|
195
|
+
? l.TextureFormat.R32G32B32A32
|
|
196
|
+
: stored === 'half'
|
|
197
|
+
? l.TextureFormat.R16G16B16A16
|
|
198
|
+
: l.TextureFormat.R8G8B8A8,
|
|
199
|
+
true,
|
|
200
|
+
false,
|
|
201
|
+
);
|
|
202
|
+
texture.filterMode = l.FilterMode.Trilinear;
|
|
203
|
+
// The pixels as the format holds them; the layout (elements, four a texel) stays.
|
|
204
|
+
const encode = (data: Float32Array): Float32Array | Uint16Array | Uint8Array =>
|
|
205
|
+
stored === 'float' ? data : stored === 'half' ? zhudaToHalfFloats(data) : zhudaToRgbd(data);
|
|
206
|
+
// Laya's pixel upload order is +Z,-Z,+X,-X,+Y,-Y, unlike WebGL/DDS.
|
|
207
|
+
const faces = (
|
|
208
|
+
level: { size: number; offset: number },
|
|
209
|
+
pixels: Float32Array | Uint16Array | Uint8Array,
|
|
210
|
+
) =>
|
|
211
|
+
[4, 5, 0, 1, 2, 3].map((i) =>
|
|
212
|
+
pixels.subarray(
|
|
213
|
+
level.offset + i * level.size * level.size * 4,
|
|
214
|
+
level.offset + (i + 1) * level.size * level.size * 4,
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
// The first upload allocates the texture; later ones replace its texels.
|
|
218
|
+
// A second `setPixelsData` asks WebGL to allocate the immutable texture
|
|
219
|
+
// again: an INVALID_OPERATION on every update of a look that changes.
|
|
220
|
+
const upload = (floats: Float32Array, allocate: boolean) => {
|
|
221
|
+
const data = encode(floats);
|
|
222
|
+
if (allocate) texture.setPixelsData(faces(spec.levels[0], data), false, false);
|
|
223
|
+
for (let i = allocate ? 1 : 0; i < spec.levels.length; i++) {
|
|
224
|
+
const level = spec.levels[i];
|
|
225
|
+
texture.updateSubPixelsData(
|
|
226
|
+
faces(level, data),
|
|
227
|
+
0,
|
|
228
|
+
0,
|
|
229
|
+
level.size,
|
|
230
|
+
level.size,
|
|
231
|
+
i,
|
|
232
|
+
false,
|
|
233
|
+
false,
|
|
234
|
+
false,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
upload(pixels, true);
|
|
239
|
+
let ambientSH = spec.ambientSH;
|
|
240
|
+
return {
|
|
241
|
+
texture,
|
|
242
|
+
/** How the light is stored on this device. */
|
|
243
|
+
format: stored,
|
|
244
|
+
apply(scene: any) {
|
|
245
|
+
scene.iblTex = texture;
|
|
246
|
+
scene.iblTexRGBD = stored === 'rgbd';
|
|
247
|
+
scene.ambientMode = l.AmbientMode.SphericalHarmonics;
|
|
248
|
+
scene.ambientSH = new Float32Array(ambientSH);
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Replaces the pixels and ambient colours in the same texture, for an
|
|
252
|
+
* environment of the same size. Scenes it was applied to see the new
|
|
253
|
+
* reflections at once; call `apply` again for the new ambient colours.
|
|
254
|
+
*/
|
|
255
|
+
update(next: Float32Array, nextSH: readonly number[]) {
|
|
256
|
+
if (texture.destroyed) throw Error('Disposed environment');
|
|
257
|
+
if (
|
|
258
|
+
next.length !== pixels.length ||
|
|
259
|
+
nextSH.length !== 27 ||
|
|
260
|
+
!nextSH.every(Number.isFinite) ||
|
|
261
|
+
!next.every((v) => Number.isFinite(v) && v >= 0)
|
|
262
|
+
)
|
|
263
|
+
throw Error('Invalid environment update');
|
|
264
|
+
upload(next, false);
|
|
265
|
+
ambientSH = [...nextSH];
|
|
266
|
+
},
|
|
267
|
+
dispose() {
|
|
268
|
+
texture.destroy();
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The values of the chain that can be set while it runs (`setGrade`). */
|
|
274
|
+
export interface ZhudaFilmicGrade {
|
|
275
|
+
exposure?: number;
|
|
276
|
+
contrast?: number;
|
|
277
|
+
saturation?: number;
|
|
278
|
+
bloomIntensity?: number;
|
|
279
|
+
aoIntensity?: number;
|
|
280
|
+
aoRadius?: number;
|
|
281
|
+
/** The curve from scene light to screen colour (default `aces`): see `ZhudaToneMapping`. */
|
|
282
|
+
toneMapping?: ZhudaToneMapping;
|
|
283
|
+
/**
|
|
284
|
+
* White balance, each -100..100 (default 0). `temperature`: above 0 warmer
|
|
285
|
+
* (toward orange), below 0 cooler (toward blue). `tint`: above 0 toward
|
|
286
|
+
* magenta, below 0 toward green.
|
|
287
|
+
*/
|
|
288
|
+
temperature?: number;
|
|
289
|
+
tint?: number;
|
|
290
|
+
/**
|
|
291
|
+
* Three numbers each, for red, green and blue, applied to the scene's
|
|
292
|
+
* light before the curve as `(colour * gain + lift) ^ gamma`: `lift`
|
|
293
|
+
* (-1..1, default 0) moves the shadows, `gain` (0..16, default 1) the
|
|
294
|
+
* highlights, and `gamma` (0.1..10, default 1) bends the middle: above 1
|
|
295
|
+
* it darkens.
|
|
296
|
+
*/
|
|
297
|
+
lift?: readonly number[];
|
|
298
|
+
gamma?: readonly number[];
|
|
299
|
+
gain?: readonly number[];
|
|
300
|
+
/**
|
|
301
|
+
* Where bloom begins, as a display value (default 1.2: a little above
|
|
302
|
+
* white; LayaAir turns it into light with the screen's curve).
|
|
303
|
+
*/
|
|
304
|
+
bloomThreshold?: number;
|
|
305
|
+
/** How gradually bloom sets in below the threshold, 0..1 (default 0.5); 0 is a hard start. */
|
|
306
|
+
bloomSoftKnee?: number;
|
|
307
|
+
/** -1..1 (default 0): above 0 the bloom is stretched sideways, below 0 upright, as a lens with an oval opening does. */
|
|
308
|
+
bloomAnamorphic?: number;
|
|
309
|
+
/**
|
|
310
|
+
* How far the bloom spreads, 1..10 (default 4): each step more doubles
|
|
311
|
+
* its reach. The reach is a share of the picture, whatever its size.
|
|
312
|
+
*/
|
|
313
|
+
bloomDiffusion?: number;
|
|
314
|
+
/** How strongly the bloom lights up the dirt picture (default 1 with a picture, else 0). */
|
|
315
|
+
bloomDirt?: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const GRADE_RANGES: Record<string, readonly [number, number]> = {
|
|
319
|
+
exposure: [0, 1048576],
|
|
320
|
+
contrast: [0, 1048576],
|
|
321
|
+
saturation: [0, 1048576],
|
|
322
|
+
bloomIntensity: [0, 1048576],
|
|
323
|
+
aoIntensity: [0, 1048576],
|
|
324
|
+
aoRadius: [0, 1048576],
|
|
325
|
+
temperature: [-100, 100],
|
|
326
|
+
tint: [-100, 100],
|
|
327
|
+
bloomThreshold: [0, 1048576],
|
|
328
|
+
bloomSoftKnee: [0, 1],
|
|
329
|
+
bloomAnamorphic: [-1, 1],
|
|
330
|
+
bloomDiffusion: [1, 10],
|
|
331
|
+
bloomDirt: [0, 1048576],
|
|
332
|
+
};
|
|
333
|
+
const GRADE_TRIPLES: Record<string, readonly [number, number]> = {
|
|
334
|
+
lift: [-1, 1],
|
|
335
|
+
gamma: [0.1, 10],
|
|
336
|
+
gain: [0, 16],
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
/** Lists what is wrong with the values of a grade, each as `name: rule`; empty when they are valid. */
|
|
340
|
+
export function validateZhudaFilmicGrade(values: ZhudaFilmicGrade): string[] {
|
|
341
|
+
const issues: string[] = [];
|
|
342
|
+
const v = (values ?? {}) as Record<string, unknown>;
|
|
343
|
+
for (const [key, [low, high]] of Object.entries(GRADE_RANGES)) {
|
|
344
|
+
const value = v[key];
|
|
345
|
+
if (value === undefined) continue;
|
|
346
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < low || value > high)
|
|
347
|
+
issues.push(`${key}: use ${low}..${high}`);
|
|
348
|
+
}
|
|
349
|
+
for (const [key, [low, high]] of Object.entries(GRADE_TRIPLES)) {
|
|
350
|
+
const value = v[key];
|
|
351
|
+
if (value === undefined) continue;
|
|
352
|
+
if (
|
|
353
|
+
!Array.isArray(value) ||
|
|
354
|
+
value.length !== 3 ||
|
|
355
|
+
!value.every((n) => typeof n === 'number' && Number.isFinite(n) && n >= low && n <= high)
|
|
356
|
+
)
|
|
357
|
+
issues.push(`${key}: three numbers ${low}..${high}`);
|
|
358
|
+
}
|
|
359
|
+
if (
|
|
360
|
+
v.toneMapping !== undefined &&
|
|
361
|
+
!ZHUDA_TONE_MAPPINGS.includes(v.toneMapping as ZhudaToneMapping)
|
|
362
|
+
)
|
|
363
|
+
issues.push(`toneMapping: use ${ZHUDA_TONE_MAPPINGS.join(', ')}`);
|
|
364
|
+
return issues;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface FilmicOptions extends ZhudaFilmicGrade {
|
|
368
|
+
ao?: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* How ambient occlusion is worked out (default `sao`, LayaAir's own).
|
|
371
|
+
* `gtao`: by horizons in the depth picture (`ZhudaGroundTruthAO`): open
|
|
372
|
+
* ground is left as it is, and the scene is not drawn once more for
|
|
373
|
+
* normals. Its strength is a power, 0..4, where 1 is what the geometry
|
|
374
|
+
* hides; `aoIntensity` defaults to 1 with it.
|
|
375
|
+
*/
|
|
376
|
+
aoMethod?: 'sao' | 'gtao';
|
|
377
|
+
/** With `gtao`: work the occlusion out at half size (default false). */
|
|
378
|
+
aoHalfSize?: boolean;
|
|
379
|
+
bloom?: boolean;
|
|
380
|
+
/**
|
|
381
|
+
* A picture of the marks on a lens (dust, smears): where the bloom falls
|
|
382
|
+
* on it, it lights up. Borrowed: the caller destroys it after the pipeline.
|
|
383
|
+
*/
|
|
384
|
+
bloomDirtTexture?: any;
|
|
385
|
+
temporalAA?: boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Multisample the camera's HDR target (4x where the device allows it):
|
|
388
|
+
* geometry edges come out smooth in a frame drawn once, as a game draws it.
|
|
389
|
+
* Omitted, the camera keeps its own setting; disposal restores it either way.
|
|
390
|
+
*/
|
|
391
|
+
msaa?: boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Borrowed effects inserted after ambient occlusion and before bloom, in
|
|
394
|
+
* linear HDR: for example `ZhudaLightFog.effect`. They read the camera depth
|
|
395
|
+
* texture, which the pipeline switches on. The caller disposes them after
|
|
396
|
+
* the pipeline.
|
|
397
|
+
*/
|
|
398
|
+
sceneEffects?: readonly any[];
|
|
399
|
+
/**
|
|
400
|
+
* Borrowed effects added last, after tone mapping, in display space: for
|
|
401
|
+
* example `ZhudaLensFinish.effect`. The caller disposes them after the
|
|
402
|
+
* pipeline.
|
|
403
|
+
*/
|
|
404
|
+
finishEffects?: readonly any[];
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* LayaAir 3.4.2 keeps its colour grade last in a chain: an effect added
|
|
408
|
+
* after the grade is put before it. This adds one after it, where the
|
|
409
|
+
* finishing effects belong: on the picture the grade has made.
|
|
410
|
+
*/
|
|
411
|
+
function addAfterGrade(post: any, effect: any) {
|
|
412
|
+
const keepsLast = post._enableColorGrad;
|
|
413
|
+
post._enableColorGrad = false;
|
|
414
|
+
try {
|
|
415
|
+
post.addEffect(effect);
|
|
416
|
+
} finally {
|
|
417
|
+
post._enableColorGrad = keepsLast;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** Owns the camera's HDR, AO, restrained bloom and ACES chain. Caller chooses quality. */
|
|
421
|
+
export class ZhudaFilmicPipeline {
|
|
422
|
+
readonly post: any;
|
|
423
|
+
readonly grade: any;
|
|
424
|
+
/**
|
|
425
|
+
* LayaAir's occlusion effect. With `ao: false` it is not in the chain (it
|
|
426
|
+
* would cost a pass of the whole scene for its normals): making it active
|
|
427
|
+
* afterwards does nothing; build the pipeline with `ao` on instead.
|
|
428
|
+
*/
|
|
429
|
+
readonly ao: any;
|
|
430
|
+
/** The occlusion by horizons, with `aoMethod: 'gtao'`; `ao` is then idle. */
|
|
431
|
+
readonly groundAO: ZhudaGroundTruthAO | undefined;
|
|
432
|
+
readonly bloom: any;
|
|
433
|
+
/** Whether an occlusion effect is in the chain: not with `ao: false`. */
|
|
434
|
+
private readonly occludes: boolean;
|
|
435
|
+
/** The effect that darkens creases: LayaAir's, or the one by horizons. */
|
|
436
|
+
private readonly occlusion: any;
|
|
437
|
+
private previous: any;
|
|
438
|
+
private previousHDR: boolean;
|
|
439
|
+
private disposed = false;
|
|
440
|
+
private camera: any;
|
|
441
|
+
private ownsTAA = false;
|
|
442
|
+
private previousMSAA: boolean;
|
|
443
|
+
private previousDepth: number;
|
|
444
|
+
private readonly sceneEffects: readonly any[];
|
|
445
|
+
private readonly finishEffects: readonly any[];
|
|
446
|
+
/** Keeps what reaches the grade inside its lookup table; absent without the material effect class. */
|
|
447
|
+
private readonly range: { effect: any; material: any } | undefined;
|
|
448
|
+
private linear: { chain: CinematicLinearChain; dispose: () => void } | undefined;
|
|
449
|
+
constructor(camera: any, options: FilmicOptions = {}) {
|
|
450
|
+
this.camera = camera;
|
|
451
|
+
const l = (globalThis as any).Laya;
|
|
452
|
+
const issues = validateZhudaFilmicGrade(options);
|
|
453
|
+
if (options.aoMethod !== undefined && options.aoMethod !== 'sao' && options.aoMethod !== 'gtao')
|
|
454
|
+
issues.push('aoMethod: use sao or gtao');
|
|
455
|
+
// Refused before anything is made: by horizons the strength is a power, 0..4.
|
|
456
|
+
if (options.aoMethod === 'gtao' && options.ao !== false)
|
|
457
|
+
for (const issue of validateZhudaGroundTruthAO({
|
|
458
|
+
...(options.aoIntensity !== undefined ? { intensity: options.aoIntensity } : {}),
|
|
459
|
+
...(options.aoRadius !== undefined ? { radius: options.aoRadius } : {}),
|
|
460
|
+
}))
|
|
461
|
+
issues.push('ao' + issue[0].toUpperCase() + issue.slice(1));
|
|
462
|
+
if (issues.length) throw Error('Invalid filmic option ' + issues.join('; '));
|
|
463
|
+
if (camera.postProcess) throw Error('Camera already owns a postprocess chain');
|
|
464
|
+
requireCapabilities(l, ['RenderTextureFormat_R16G16B16A16']);
|
|
465
|
+
this.previous = camera.postProcess;
|
|
466
|
+
this.previousHDR = camera.enableHDR;
|
|
467
|
+
this.previousMSAA = camera.msaa;
|
|
468
|
+
this.previousDepth = camera.depthTextureMode;
|
|
469
|
+
const post = (this.post = new l.PostProcess());
|
|
470
|
+
this.ao = new l.ScalableAO();
|
|
471
|
+
// LayaAir 3.4.2 never writes the occlusion colour. Unset, the shader reads
|
|
472
|
+
// what the last owner of that uniform block left there: after a scene is
|
|
473
|
+
// mounted again every crease glows in some stale colour. Black is plain
|
|
474
|
+
// occlusion.
|
|
475
|
+
this.ao.aoColor = new l.Color(0, 0, 0, 1);
|
|
476
|
+
this.ao.intensity = options.aoIntensity ?? 0.65;
|
|
477
|
+
this.ao.radius = options.aoRadius ?? 0.7;
|
|
478
|
+
this.ao.aoQuality = l.AOQUALITY.High;
|
|
479
|
+
this.ao.active = options.ao !== false;
|
|
480
|
+
if (options.aoMethod === 'gtao' && options.ao !== false) {
|
|
481
|
+
this.groundAO = new ZhudaGroundTruthAO({
|
|
482
|
+
intensity: options.aoIntensity ?? 1,
|
|
483
|
+
radius: options.aoRadius ?? 0.5,
|
|
484
|
+
halfSize: options.aoHalfSize ?? false,
|
|
485
|
+
});
|
|
486
|
+
this.ao.active = false;
|
|
487
|
+
}
|
|
488
|
+
this.occlusion = this.groundAO ? this.groundAO.effect : this.ao;
|
|
489
|
+
// LayaAir asks every effect of a chain what the camera must draw for it,
|
|
490
|
+
// whether the effect is active or not, and its occlusion asks for the
|
|
491
|
+
// normals: an idle occlusion in the chain had the whole scene drawn once
|
|
492
|
+
// more every frame. It joins the chain only when it darkens something.
|
|
493
|
+
this.occludes = Boolean(this.groundAO) || this.ao.active;
|
|
494
|
+
this.bloom = new l.BloomEffect();
|
|
495
|
+
this.bloom.intensity = options.bloomIntensity ?? 0.12;
|
|
496
|
+
this.bloom.threshold = 1.2;
|
|
497
|
+
this.bloom.diffusion = 4;
|
|
498
|
+
this.bloom.active = options.bloom !== false;
|
|
499
|
+
// LayaAir 3.4.2 works out how the dirt picture covers the frame only when
|
|
500
|
+
// their shapes differ; a picture shaped like the frame keeps the cover
|
|
501
|
+
// of whatever was there before (at first, of no picture at all). This
|
|
502
|
+
// is the cover for equal shapes, set before each frame's bloom.
|
|
503
|
+
const bloom = this.bloom;
|
|
504
|
+
if (bloom._dirtTileOffset && typeof bloom.render === 'function') {
|
|
505
|
+
const render = bloom.render;
|
|
506
|
+
bloom.render = function (context: any) {
|
|
507
|
+
const dirt = bloom._dirtTexture,
|
|
508
|
+
viewport = context?.camera?.viewport;
|
|
509
|
+
if (dirt && viewport && dirt.width * viewport.height === dirt.height * viewport.width)
|
|
510
|
+
bloom._dirtTileOffset.setValue(1, 1, 0, 0);
|
|
511
|
+
return render.call(bloom, context);
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
this.grade = new l.ColorGradEffect();
|
|
515
|
+
this.grade.toneMapping = l.ToneMappingType.ACES;
|
|
516
|
+
this.grade.enableColorAdjust = true;
|
|
517
|
+
this.grade.postExposure = options.exposure ?? 1;
|
|
518
|
+
this.grade.contrast = options.contrast ?? 1.04;
|
|
519
|
+
this.grade.saturation = options.saturation ?? 0.96;
|
|
520
|
+
this.sceneEffects = [...(options.sceneEffects ?? [])];
|
|
521
|
+
this.finishEffects = [...(options.finishEffects ?? [])];
|
|
522
|
+
if (this.occludes) post.addEffect(this.occlusion);
|
|
523
|
+
for (const effect of this.sceneEffects) post.addEffect(effect);
|
|
524
|
+
if (this.sceneEffects.length) camera.depthTextureMode |= l.DepthTextureMode.Depth;
|
|
525
|
+
post.addEffect(this.bloom);
|
|
526
|
+
if (l.MaterialPostProcessEffect && l.Material && l.Shader3D?.add) {
|
|
527
|
+
registerGradeRange(l);
|
|
528
|
+
const material = new l.Material();
|
|
529
|
+
material.setShaderName('ZhudaGradeRange');
|
|
530
|
+
const effect = new l.MaterialPostProcessEffect();
|
|
531
|
+
effect.material = material;
|
|
532
|
+
this.range = { effect, material };
|
|
533
|
+
this.limit();
|
|
534
|
+
post.addEffect(effect);
|
|
535
|
+
}
|
|
536
|
+
post.addEffect(this.grade);
|
|
537
|
+
for (const effect of this.finishEffects) addAfterGrade(post, effect);
|
|
538
|
+
const { bloomDirtTexture, ...grade } = options;
|
|
539
|
+
if (bloomDirtTexture) this.setBloomDirt(bloomDirtTexture, options.bloomDirt ?? 1);
|
|
540
|
+
this.applyGrade(grade, true);
|
|
541
|
+
camera.enableHDR = true;
|
|
542
|
+
camera.postProcess = post;
|
|
543
|
+
if (options.msaa !== undefined) setCameraMultisampling(l, camera, !!options.msaa);
|
|
544
|
+
if (options.temporalAA) {
|
|
545
|
+
this.ownsTAA = true;
|
|
546
|
+
camera.taa = true;
|
|
547
|
+
camera.taaSettings.quality = l.TemporalAAQuality.High;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/** The table's end is in values after exposure: the limit before it moves with the exposure. */
|
|
551
|
+
private limit() {
|
|
552
|
+
if (!this.range) return;
|
|
553
|
+
const l = (globalThis as any).Laya;
|
|
554
|
+
this.range.material.setVector4(
|
|
555
|
+
'u_ZhudaGradeRange',
|
|
556
|
+
new l.Vector4(ZHUDA_GRADE_TABLE_MAX / Math.max(this.grade.postExposure, 1e-6), 0, 0, 0),
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
/** Update the existing ACES grading exposure multiplier. */
|
|
560
|
+
setExposure(value: number) {
|
|
561
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
562
|
+
if (!Number.isFinite(value) || value < 0 || value > 1048576)
|
|
563
|
+
throw Error('Invalid filmic exposure');
|
|
564
|
+
this.grade.postExposure = value;
|
|
565
|
+
this.limit();
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Sets values of the chain in place: exposure, contrast, saturation, the
|
|
569
|
+
* curve, white balance, lift, gamma and gain, bloom strength, threshold,
|
|
570
|
+
* knee, shape and spread, and ambient occlusion strength and radius. Whether bloom
|
|
571
|
+
* or ambient occlusion run at all is fixed at construction.
|
|
572
|
+
*/
|
|
573
|
+
setGrade(values: ZhudaFilmicGrade) {
|
|
574
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
575
|
+
const issues = validateZhudaFilmicGrade(values);
|
|
576
|
+
if (issues.length) throw Error('Invalid filmic value ' + issues.join('; '));
|
|
577
|
+
this.applyGrade(values, false);
|
|
578
|
+
}
|
|
579
|
+
private tone: ZhudaToneMapping = 'aces';
|
|
580
|
+
/** The curve in use. */
|
|
581
|
+
get toneMapping(): ZhudaToneMapping {
|
|
582
|
+
return this.tone;
|
|
583
|
+
}
|
|
584
|
+
private applyGrade(values: ZhudaFilmicGrade, first: boolean) {
|
|
585
|
+
const l = (globalThis as any).Laya;
|
|
586
|
+
if (!first && values.exposure !== undefined) {
|
|
587
|
+
this.grade.postExposure = values.exposure;
|
|
588
|
+
this.limit();
|
|
589
|
+
}
|
|
590
|
+
if (!first && values.contrast !== undefined) this.grade.contrast = values.contrast;
|
|
591
|
+
if (!first && values.saturation !== undefined) this.grade.saturation = values.saturation;
|
|
592
|
+
if (!first && values.bloomIntensity !== undefined) this.bloom.intensity = values.bloomIntensity;
|
|
593
|
+
if (!first && this.groundAO)
|
|
594
|
+
this.groundAO.set({
|
|
595
|
+
...(values.aoIntensity !== undefined ? { intensity: values.aoIntensity } : {}),
|
|
596
|
+
...(values.aoRadius !== undefined ? { radius: values.aoRadius } : {}),
|
|
597
|
+
});
|
|
598
|
+
else {
|
|
599
|
+
if (!first && values.aoIntensity !== undefined) this.ao.intensity = values.aoIntensity;
|
|
600
|
+
if (!first && values.aoRadius !== undefined) this.ao.radius = values.aoRadius;
|
|
601
|
+
}
|
|
602
|
+
if (values.temperature !== undefined) this.grade.temperature = values.temperature;
|
|
603
|
+
if (values.tint !== undefined) this.grade.tint = values.tint;
|
|
604
|
+
if (values.temperature !== undefined || values.tint !== undefined)
|
|
605
|
+
this.grade.enableBalance = this.grade.temperature !== 0 || this.grade.tint !== 0;
|
|
606
|
+
for (const key of ['lift', 'gamma', 'gain'] as const) {
|
|
607
|
+
const value = values[key];
|
|
608
|
+
if (value !== undefined) this.grade[key] = new l.Vector3(value[0], value[1], value[2]);
|
|
609
|
+
}
|
|
610
|
+
if (values.lift !== undefined || values.gamma !== undefined || values.gain !== undefined) {
|
|
611
|
+
const is = (v: any, n: number) => v.x === n && v.y === n && v.z === n;
|
|
612
|
+
this.grade.enableLiftGammaGain = !(
|
|
613
|
+
is(this.grade.lift, 0) &&
|
|
614
|
+
is(this.grade.gamma, 1) &&
|
|
615
|
+
is(this.grade.gain, 1)
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
if (values.bloomThreshold !== undefined) this.bloom.threshold = values.bloomThreshold;
|
|
619
|
+
if (values.bloomSoftKnee !== undefined) this.bloom.softKnee = values.bloomSoftKnee;
|
|
620
|
+
if (values.bloomAnamorphic !== undefined) this.bloom.anamorphicRatio = values.bloomAnamorphic;
|
|
621
|
+
if (values.bloomDiffusion !== undefined) this.bloom.diffusion = values.bloomDiffusion;
|
|
622
|
+
if (values.bloomDirt !== undefined) this.bloom.dirtIntensity = values.bloomDirt;
|
|
623
|
+
if (values.toneMapping !== undefined && values.toneMapping !== this.tone) {
|
|
624
|
+
applyZhudaToneCurve(l, this.grade, values.toneMapping);
|
|
625
|
+
this.tone = values.toneMapping;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* The picture of the marks on the lens that bloom lights up, and how
|
|
630
|
+
* strongly; `null` takes it away. Borrowed: the caller destroys the
|
|
631
|
+
* picture after the pipeline, or after handing over another.
|
|
632
|
+
*/
|
|
633
|
+
setBloomDirt(texture: any | null, intensity = 1) {
|
|
634
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
635
|
+
if (!Number.isFinite(intensity) || intensity < 0 || intensity > 1048576)
|
|
636
|
+
throw Error('Invalid filmic value bloomDirt: use 0..1048576');
|
|
637
|
+
this.bloom.dirtTexture = texture;
|
|
638
|
+
this.bloom.dirtIntensity = texture ? intensity : 0;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* The chain's handle for a capture that averages its samples in scene-linear
|
|
642
|
+
* light (see `CinematicLinearChain`): samples are drawn without tone mapping
|
|
643
|
+
* and lens finish, and their average is then drawn through both once. The
|
|
644
|
+
* first call puts one pass at the head of the chain; it is idle outside a
|
|
645
|
+
* capture.
|
|
646
|
+
*/
|
|
647
|
+
linearChain(): CinematicLinearChain {
|
|
648
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
649
|
+
if (this.linear) return this.linear.chain;
|
|
650
|
+
const l = (globalThis as any).Laya;
|
|
651
|
+
requireCapabilities(l, ['TextureFormat_R32G32B32A32']);
|
|
652
|
+
registerLinearSource(l);
|
|
653
|
+
const pictureOf = (width: number, height: number, data: Float32Array) => {
|
|
654
|
+
const texture = new l.Texture2D(
|
|
655
|
+
width,
|
|
656
|
+
height,
|
|
657
|
+
l.TextureFormat.R32G32B32A32,
|
|
658
|
+
false,
|
|
659
|
+
false,
|
|
660
|
+
false,
|
|
661
|
+
);
|
|
662
|
+
texture.filterMode = l.FilterMode.Point;
|
|
663
|
+
texture.wrapModeU = texture.wrapModeV = l.WrapMode.Clamp;
|
|
664
|
+
texture.setPixelsData(data, false, false);
|
|
665
|
+
return texture;
|
|
666
|
+
};
|
|
667
|
+
const material = new l.Material();
|
|
668
|
+
material.setShaderName('ZhudaLinearSource');
|
|
669
|
+
// Every declared uniform is written: an unset one reads stale bytes.
|
|
670
|
+
let picture = pictureOf(1, 1, new Float32Array(4));
|
|
671
|
+
material.setTexture('u_ZhudaAverage', picture);
|
|
672
|
+
const use = (on: number) =>
|
|
673
|
+
material.setVector4('u_ZhudaAverageUse', new l.Vector4(on, 0, 0, 0));
|
|
674
|
+
use(0);
|
|
675
|
+
const source = new l.MaterialPostProcessEffect();
|
|
676
|
+
source.material = material;
|
|
677
|
+
source.active = false;
|
|
678
|
+
const linearPart = [
|
|
679
|
+
...(this.occludes ? [this.occlusion] : []),
|
|
680
|
+
...this.sceneEffects,
|
|
681
|
+
this.bloom,
|
|
682
|
+
],
|
|
683
|
+
displayPart = [...(this.range ? [this.range.effect] : []), this.grade, ...this.finishEffects],
|
|
684
|
+
all = [...linearPart, ...displayPart];
|
|
685
|
+
// LayaAir sets its own passes up when the grade joins a chain: it leaves and joins as LayaAir made it.
|
|
686
|
+
if (this.tone !== 'aces') applyZhudaToneCurve(l, this.grade, 'aces');
|
|
687
|
+
// The source goes first; the rest keeps the order it was built in.
|
|
688
|
+
this.post.clearEffect();
|
|
689
|
+
for (const effect of [source, ...all])
|
|
690
|
+
if (this.finishEffects.includes(effect)) addAfterGrade(this.post, effect);
|
|
691
|
+
else this.post.addEffect(effect);
|
|
692
|
+
if (this.tone !== 'aces') applyZhudaToneCurve(l, this.grade, this.tone);
|
|
693
|
+
let saved: boolean[] | undefined;
|
|
694
|
+
const chain: CinematicLinearChain = {
|
|
695
|
+
beginSamples: () => {
|
|
696
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
697
|
+
saved ??= all.map((effect) => effect.active);
|
|
698
|
+
linearPart.forEach((effect, i) => (effect.active = saved![i]));
|
|
699
|
+
for (const effect of displayPart) effect.active = false;
|
|
700
|
+
use(0);
|
|
701
|
+
// Passing the scene through keeps one effect active whatever the look switched off.
|
|
702
|
+
source.active = true;
|
|
703
|
+
},
|
|
704
|
+
beginResolve: (average, width, height) => {
|
|
705
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
706
|
+
if (!saved) throw Error('The resolve follows the samples');
|
|
707
|
+
if (average.length !== width * height * 4) throw Error('Invalid accumulated picture');
|
|
708
|
+
if (picture.width !== width || picture.height !== height) {
|
|
709
|
+
picture.destroy();
|
|
710
|
+
picture = pictureOf(width, height, average);
|
|
711
|
+
material.setTexture('u_ZhudaAverage', picture);
|
|
712
|
+
} else picture.setSubPixelsData(0, 0, width, height, average, 0, false, false, false);
|
|
713
|
+
for (const effect of linearPart) effect.active = false;
|
|
714
|
+
displayPart.forEach((effect, i) => (effect.active = saved![linearPart.length + i]));
|
|
715
|
+
use(1);
|
|
716
|
+
source.active = true;
|
|
717
|
+
},
|
|
718
|
+
end: () => {
|
|
719
|
+
if (!saved) return;
|
|
720
|
+
all.forEach((effect, i) => (effect.active = saved![i]));
|
|
721
|
+
saved = undefined;
|
|
722
|
+
use(0);
|
|
723
|
+
source.active = false;
|
|
724
|
+
},
|
|
725
|
+
};
|
|
726
|
+
this.linear = {
|
|
727
|
+
chain,
|
|
728
|
+
dispose: () => {
|
|
729
|
+
material.destroy();
|
|
730
|
+
picture.destroy();
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
return chain;
|
|
734
|
+
}
|
|
735
|
+
/** Switches multisampling of the camera's HDR target on or off, in place. */
|
|
736
|
+
setAntialias(msaa: boolean) {
|
|
737
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
738
|
+
setCameraMultisampling((globalThis as any).Laya, this.camera, !!msaa);
|
|
739
|
+
}
|
|
740
|
+
/** Call on camera cuts, teleports and timeline seeks, not on ordinary movement. */
|
|
741
|
+
resetHistory() {
|
|
742
|
+
if (this.disposed) throw Error('Disposed filmic pipeline');
|
|
743
|
+
if (this.ownsTAA) this.camera.taaSettings.resetHistory();
|
|
744
|
+
}
|
|
745
|
+
dispose() {
|
|
746
|
+
if (this.disposed) return;
|
|
747
|
+
this.disposed = true;
|
|
748
|
+
if (this.ownsTAA) this.camera.taa = false;
|
|
749
|
+
if (this.camera.postProcess === this.post) {
|
|
750
|
+
this.camera.postProcess = this.previous;
|
|
751
|
+
this.camera.enableHDR = this.previousHDR;
|
|
752
|
+
setCameraMultisampling((globalThis as any).Laya, this.camera, !!this.previousMSAA);
|
|
753
|
+
this.camera.depthTextureMode = this.previousDepth;
|
|
754
|
+
}
|
|
755
|
+
releaseZhudaToneCurve((globalThis as any).Laya, this.grade);
|
|
756
|
+
this.post.clearEffect();
|
|
757
|
+
// The dirt picture is the caller's: the bloom only lets go of it.
|
|
758
|
+
if (this.bloom.dirtTexture) this.bloom.dirtTexture = null;
|
|
759
|
+
this.linear?.dispose();
|
|
760
|
+
this.linear = undefined;
|
|
761
|
+
this.groundAO?.dispose();
|
|
762
|
+
this.range?.material.destroy();
|
|
763
|
+
// LayaAir 3.4.2 release() detaches effects but does not free their LUT,
|
|
764
|
+
// materials or shader data. This version-pinned adapter owns those objects.
|
|
765
|
+
this.post._context.command.clear();
|
|
766
|
+
const owned = new Set([
|
|
767
|
+
this.grade._lutBuilderMat,
|
|
768
|
+
this.grade._lutTex,
|
|
769
|
+
this.grade._lutShaderData,
|
|
770
|
+
this.ao._shaderData,
|
|
771
|
+
this.bloom._shaderData,
|
|
772
|
+
this.bloom._compositeShaderData,
|
|
773
|
+
this.post._compositeShaderData,
|
|
774
|
+
]);
|
|
775
|
+
for (const resource of owned)
|
|
776
|
+
if (resource && !resource.destroyed) {
|
|
777
|
+
if ('lock' in resource) resource.lock = false;
|
|
778
|
+
resource.destroy();
|
|
779
|
+
}
|
|
780
|
+
this.post._context.camera = null;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/** A real mirrored scene camera for a horizontal surface. Objects on excludedLayer
|
|
785
|
+
* must include the reflecting surface to prevent feedback. The scene should not
|
|
786
|
+
* contain visible geometry below the plane: arbitrary oblique clipping is not provided. */
|
|
787
|
+
export class ZhudaPlanarReflection {
|
|
788
|
+
readonly camera: any;
|
|
789
|
+
readonly texture: any;
|
|
790
|
+
constructor(
|
|
791
|
+
scene: any,
|
|
792
|
+
options: {
|
|
793
|
+
width: number;
|
|
794
|
+
height: number;
|
|
795
|
+
planeY?: number;
|
|
796
|
+
excludedLayer: number;
|
|
797
|
+
near?: number;
|
|
798
|
+
far?: number;
|
|
799
|
+
/**
|
|
800
|
+
* Draw only what lies above the plane (an oblique near plane). Water
|
|
801
|
+
* needs it: its bed and the sunk part of stones are below the mirror
|
|
802
|
+
* and would otherwise cover the mirrored view.
|
|
803
|
+
*/
|
|
804
|
+
clipBelowPlane?: boolean;
|
|
805
|
+
/**
|
|
806
|
+
* Leave the mirrored camera out of the engine's frame loop: the owner
|
|
807
|
+
* draws it with `draw()` when it wants (default false: the loop draws it).
|
|
808
|
+
*/
|
|
809
|
+
manual?: boolean;
|
|
810
|
+
/**
|
|
811
|
+
* Whether the mirrored view draws shadow maps of its own. Left out, it
|
|
812
|
+
* does, except while the scene's shadows are not drawn every frame
|
|
813
|
+
* (`ZhudaShadowUpdates`, a look's `shadows.update`): there it reads
|
|
814
|
+
* the maps kept for the main view, since maps of its own would replace
|
|
815
|
+
* those and the main view would have to draw them again every frame.
|
|
816
|
+
* `true`: always, also under such a rule, which then saves nothing.
|
|
817
|
+
* `false`: never, in `draw()`, which saves a full shadow pass per
|
|
818
|
+
* frame; the mirrored view is then drawn without the sun's shadows.
|
|
819
|
+
*/
|
|
820
|
+
shadows?: boolean;
|
|
821
|
+
},
|
|
822
|
+
) {
|
|
823
|
+
const l = (globalThis as any).Laya;
|
|
824
|
+
if (
|
|
825
|
+
![options.width, options.height].every((v) => Number.isInteger(v) && v > 0 && v <= 8192) ||
|
|
826
|
+
!Number.isInteger(options.excludedLayer) ||
|
|
827
|
+
options.excludedLayer < 0 ||
|
|
828
|
+
options.excludedLayer > 30 ||
|
|
829
|
+
!Number.isFinite(options.planeY ?? 0)
|
|
830
|
+
)
|
|
831
|
+
throw Error('Invalid planar reflection options');
|
|
832
|
+
const near = options.near ?? 0.08,
|
|
833
|
+
far = options.far ?? 1500;
|
|
834
|
+
if (!Number.isFinite(near) || !Number.isFinite(far) || near <= 0 || far <= near)
|
|
835
|
+
throw Error('Invalid reflection clipping range');
|
|
836
|
+
requireCapabilities(l, ['RenderTextureFormat_R16G16B16A16']);
|
|
837
|
+
this.planeY = options.planeY ?? 0;
|
|
838
|
+
this.clip = options.clipBelowPlane ? { near, far } : undefined;
|
|
839
|
+
this.texture = new l.RenderTexture(
|
|
840
|
+
options.width,
|
|
841
|
+
options.height,
|
|
842
|
+
l.RenderTargetFormat.R16G16B16A16,
|
|
843
|
+
l.RenderTargetFormat.DEPTH_16,
|
|
844
|
+
false,
|
|
845
|
+
1,
|
|
846
|
+
);
|
|
847
|
+
this.camera = new l.Camera(options.width / options.height, near, far);
|
|
848
|
+
this.camera.name = 'zhuda-planar-reflection';
|
|
849
|
+
this.camera.enableHDR = true;
|
|
850
|
+
this.camera.renderTarget = this.texture;
|
|
851
|
+
this.camera.renderingOrder = -100;
|
|
852
|
+
this.camera.cullingMask = ~(1 << options.excludedLayer);
|
|
853
|
+
if (options.manual) this.camera.enableRender = false;
|
|
854
|
+
this.shadows = options.shadows;
|
|
855
|
+
if (this.shadows === undefined) zhudaShadowBorrower(this.camera);
|
|
856
|
+
this.scene = scene;
|
|
857
|
+
scene.addChild(this.camera);
|
|
858
|
+
}
|
|
859
|
+
private planeY: number;
|
|
860
|
+
private readonly shadows: boolean | undefined;
|
|
861
|
+
private readonly scene: any;
|
|
862
|
+
private clip?: { near: number; far: number };
|
|
863
|
+
private disposed = false;
|
|
864
|
+
update(eye: readonly number[], target: readonly number[], fieldOfView: number, aspect?: number) {
|
|
865
|
+
if (this.disposed) throw Error('Disposed reflection');
|
|
866
|
+
if (
|
|
867
|
+
eye.length !== 3 ||
|
|
868
|
+
target.length !== 3 ||
|
|
869
|
+
![...eye, ...target, fieldOfView].every(Number.isFinite) ||
|
|
870
|
+
fieldOfView <= 0 ||
|
|
871
|
+
fieldOfView >= 179
|
|
872
|
+
)
|
|
873
|
+
throw Error('Invalid reflection pose');
|
|
874
|
+
if (Math.hypot(...eye.map((v, i) => v - target[i])) < 1e-9)
|
|
875
|
+
throw Error('Reflection eye and target must differ');
|
|
876
|
+
const l = (globalThis as any).Laya;
|
|
877
|
+
if (aspect !== undefined) {
|
|
878
|
+
if (!Number.isFinite(aspect) || aspect <= 0) throw Error('Invalid reflection aspect');
|
|
879
|
+
this.camera.aspectRatio = aspect;
|
|
880
|
+
}
|
|
881
|
+
this.camera.fieldOfView = fieldOfView;
|
|
882
|
+
this.camera.transform.position = new l.Vector3(eye[0], 2 * this.planeY - eye[1], eye[2]);
|
|
883
|
+
const vertical = Math.hypot(eye[0] - target[0], eye[2] - target[2]) < 1e-9;
|
|
884
|
+
this.camera.transform.lookAt(
|
|
885
|
+
new l.Vector3(target[0], 2 * this.planeY - target[1], target[2]),
|
|
886
|
+
// A plain +Y up: with a flipped up Laya 3.4.2 draws no geometry from this
|
|
887
|
+
// camera. The returned matrix is this camera's own, so projected sampling
|
|
888
|
+
// stays exact either way.
|
|
889
|
+
vertical ? new l.Vector3(0, 0, 1) : new l.Vector3(0, 1, 0),
|
|
890
|
+
false,
|
|
891
|
+
);
|
|
892
|
+
if (this.clip) {
|
|
893
|
+
// Lengyel's oblique near plane: the frustum's near plane becomes the
|
|
894
|
+
// mirror plane, seen from the mirrored eye below it.
|
|
895
|
+
const sub = (a: readonly number[], b: readonly number[]) => a.map((v, i) => v - b[i]);
|
|
896
|
+
const dot = (a: readonly number[], b: readonly number[]) =>
|
|
897
|
+
a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
898
|
+
const cross = (a: readonly number[], b: readonly number[]) => [
|
|
899
|
+
a[1] * b[2] - a[2] * b[1],
|
|
900
|
+
a[2] * b[0] - a[0] * b[2],
|
|
901
|
+
a[0] * b[1] - a[1] * b[0],
|
|
902
|
+
];
|
|
903
|
+
const unit = (v: number[]) => v.map((n) => n / Math.hypot(v[0], v[1], v[2]));
|
|
904
|
+
const from = [eye[0], 2 * this.planeY - eye[1], eye[2]],
|
|
905
|
+
to = [target[0], 2 * this.planeY - target[1], target[2]];
|
|
906
|
+
const forward = unit(sub(to, from));
|
|
907
|
+
const side = unit(cross(forward, vertical ? [0, 0, 1] : [0, 1, 0])),
|
|
908
|
+
up = cross(side, forward);
|
|
909
|
+
// The plane in camera space (x right, y up, z toward the viewer), normal away from the camera.
|
|
910
|
+
const normal = [side[1], up[1], -forward[1]];
|
|
911
|
+
const offset = this.planeY - from[1] + 0.02;
|
|
912
|
+
const plane = [
|
|
913
|
+
...normal,
|
|
914
|
+
-dot(normal, [side[1] * offset, up[1] * offset, -forward[1] * offset]),
|
|
915
|
+
];
|
|
916
|
+
const projection = new l.Matrix4x4();
|
|
917
|
+
l.Matrix4x4.createPerspective(
|
|
918
|
+
(fieldOfView * Math.PI) / 180,
|
|
919
|
+
this.camera.aspectRatio,
|
|
920
|
+
this.clip.near,
|
|
921
|
+
this.clip.far,
|
|
922
|
+
projection,
|
|
923
|
+
);
|
|
924
|
+
const m = projection.elements;
|
|
925
|
+
const q = [
|
|
926
|
+
(Math.sign(plane[0]) + m[8]) / m[0],
|
|
927
|
+
(Math.sign(plane[1]) + m[9]) / m[5],
|
|
928
|
+
-1,
|
|
929
|
+
(1 + m[10]) / m[14],
|
|
930
|
+
];
|
|
931
|
+
// Laya's projection maps depth to 0..1, so the near plane is the third
|
|
932
|
+
// row itself: it becomes the mirror plane, scaled so that the far
|
|
933
|
+
// plane still passes through the far corner q of the frustum.
|
|
934
|
+
const scale = 1 / (plane[0] * q[0] + plane[1] * q[1] + plane[2] * q[2] + plane[3] * q[3]);
|
|
935
|
+
// Only when the camera really is below the plane; otherwise keep the plain frustum.
|
|
936
|
+
if (plane[3] < 0 && Number.isFinite(scale)) {
|
|
937
|
+
m[2] = plane[0] * scale;
|
|
938
|
+
m[6] = plane[1] * scale;
|
|
939
|
+
m[10] = plane[2] * scale;
|
|
940
|
+
m[14] = plane[3] * scale;
|
|
941
|
+
}
|
|
942
|
+
this.camera.projectionMatrix = projection;
|
|
943
|
+
}
|
|
944
|
+
const e = this.camera.projectionViewMatrix.elements;
|
|
945
|
+
return Array.from({ length: 4 }, (_, i) => [
|
|
946
|
+
e[i * 4],
|
|
947
|
+
e[i * 4 + 1],
|
|
948
|
+
e[i * 4 + 2],
|
|
949
|
+
e[i * 4 + 3],
|
|
950
|
+
]);
|
|
951
|
+
}
|
|
952
|
+
/** Draws the mirrored view now (captures, or a `manual` mirror in a game loop). */
|
|
953
|
+
draw(): void {
|
|
954
|
+
if (this.disposed) throw Error('Disposed reflection');
|
|
955
|
+
const l = (globalThis as any).Laya;
|
|
956
|
+
const before = l.Stat.enableShadow;
|
|
957
|
+
if (this.shadows === false) l.Stat.enableShadow = false;
|
|
958
|
+
try {
|
|
959
|
+
prepareLaya342ManualDraw(this.scene);
|
|
960
|
+
l.Camera.drawRenderTextureByScene(this.camera, this.scene, this.texture);
|
|
961
|
+
} finally {
|
|
962
|
+
l.Stat.enableShadow = before;
|
|
963
|
+
this.camera.renderTarget = this.texture;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
dispose() {
|
|
967
|
+
if (this.disposed) return;
|
|
968
|
+
this.disposed = true;
|
|
969
|
+
this.camera.renderTarget = null;
|
|
970
|
+
this.camera.destroy(true);
|
|
971
|
+
this.texture.destroy();
|
|
972
|
+
}
|
|
973
|
+
}
|