@egret/engine 0.0.0-stage → 7.0.1-rc.3
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +464 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +42 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +69 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +52 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +15 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +43 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +233 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +29 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +109 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +25 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +411 -0
- package/dist/cameraTypes.d.ts +114 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +33 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +42 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +34 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +31 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +50 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +134 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +119 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +20 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +81 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +64 -0
- package/dist/internal/uiFactoryState.js +157 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +12 -0
- package/dist/keyboardInput.js +578 -0
- package/dist/keyboardInputTypes.d.ts +81 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +14 -0
- package/dist/kit.js +9 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +16 -0
- package/dist/manifestResourceState.js +57 -0
- package/dist/manifestResourceTypes.d.ts +25 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +37 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +292 -0
- package/dist/particleTypes.d.ts +107 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +167 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +623 -0
- package/dist/pointerInput.d.ts +11 -0
- package/dist/pointerInput.js +299 -0
- package/dist/pointerInputTypes.d.ts +38 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +29 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +331 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +88 -0
- package/dist/rendering/prepareSharedDraws2D.js +652 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +18 -0
- package/dist/rendering/sharedColor2D.js +68 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +118 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +95 -0
- package/dist/rendering/world3d/Animation3D.js +380 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +157 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +601 -0
- package/dist/rendering/world3d/Batch3D.d.ts +71 -0
- package/dist/rendering/world3d/Batch3D.js +329 -0
- package/dist/rendering/world3d/Camera3D.d.ts +57 -0
- package/dist/rendering/world3d/Camera3D.js +129 -0
- package/dist/rendering/world3d/Character3D.d.ts +123 -0
- package/dist/rendering/world3d/Character3D.js +303 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +115 -0
- package/dist/rendering/world3d/Cloth3D.js +498 -0
- package/dist/rendering/world3d/Compression3D.d.ts +21 -0
- package/dist/rendering/world3d/Compression3D.js +702 -0
- package/dist/rendering/world3d/Curves3D.d.ts +111 -0
- package/dist/rendering/world3d/Curves3D.js +455 -0
- package/dist/rendering/world3d/Decal3D.d.ts +41 -0
- package/dist/rendering/world3d/Decal3D.js +241 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +85 -0
- package/dist/rendering/world3d/Geometry3D.js +326 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +51 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +75 -0
- package/dist/rendering/world3d/Gizmo3D.js +512 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +67 -0
- package/dist/rendering/world3d/Gltf3D.js +976 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +107 -0
- package/dist/rendering/world3d/GpuParticles3D.js +400 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +33 -0
- package/dist/rendering/world3d/Hdr3D.js +190 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +75 -0
- package/dist/rendering/world3d/Jelly3D.js +266 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +27 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +75 -0
- package/dist/rendering/world3d/Light3D.js +93 -0
- package/dist/rendering/world3d/Material3D.d.ts +243 -0
- package/dist/rendering/world3d/Material3D.js +267 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +108 -0
- package/dist/rendering/world3d/Mesh3D.js +323 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +12 -0
- package/dist/rendering/world3d/Meshopt3D.js +275 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +173 -0
- package/dist/rendering/world3d/Navigation3D.js +971 -0
- package/dist/rendering/world3d/Object3D.d.ts +107 -0
- package/dist/rendering/world3d/Object3D.js +305 -0
- package/dist/rendering/world3d/Particles3D.d.ts +85 -0
- package/dist/rendering/world3d/Particles3D.js +274 -0
- package/dist/rendering/world3d/Physics3D.d.ts +416 -0
- package/dist/rendering/world3d/Physics3D.js +2835 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +35 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +227 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +39 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +338 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +174 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +534 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +69 -0
- package/dist/rendering/world3d/Ragdoll3D.js +200 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +37 -0
- package/dist/rendering/world3d/Raycast3D.js +246 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +88 -0
- package/dist/rendering/world3d/RenderList3D.js +490 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +20 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +49 -0
- package/dist/rendering/world3d/Serialize3D.js +607 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +78 -0
- package/dist/rendering/world3d/StateMachine3D.js +277 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +227 -0
- package/dist/rendering/world3d/Terrain3D.js +803 -0
- package/dist/rendering/world3d/Text3D.d.ts +90 -0
- package/dist/rendering/world3d/Text3D.js +558 -0
- package/dist/rendering/world3d/Texture3D.d.ts +133 -0
- package/dist/rendering/world3d/Texture3D.js +252 -0
- package/dist/rendering/world3d/Trail3D.d.ts +59 -0
- package/dist/rendering/world3d/Trail3D.js +193 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +97 -0
- package/dist/rendering/world3d/Vehicle3D.js +226 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +55 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +229 -0
- package/dist/rendering/world3d/Water3D.d.ts +163 -0
- package/dist/rendering/world3d/Water3D.js +606 -0
- package/dist/rendering/world3d/core3D.d.ts +34 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +64 -0
- package/dist/rendering/world3d/debug3D.js +257 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +99 -0
- package/dist/rendering/world3d/geometries3D.js +605 -0
- package/dist/rendering/world3d/helpers3D.d.ts +65 -0
- package/dist/rendering/world3d/helpers3D.js +177 -0
- package/dist/rendering/world3d/index.d.ts +91 -0
- package/dist/rendering/world3d/index.js +56 -0
- package/dist/rendering/world3d/math3D.d.ts +78 -0
- package/dist/rendering/world3d/math3D.js +640 -0
- package/dist/rendering/world3d/primitives3D.d.ts +60 -0
- package/dist/rendering/world3d/primitives3D.js +196 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +56 -0
- package/dist/saveStore.js +163 -0
- package/dist/semanticList.d.ts +122 -0
- package/dist/semanticList.js +174 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +532 -0
- package/dist/semanticTypes.d.ts +167 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +21 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +23 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +169 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +27 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +109 -0
- package/dist/ui/controlKeys.js +249 -0
- package/dist/ui/controls.d.ts +52 -0
- package/dist/ui/controls.js +288 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +91 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +50 -0
- package/dist/ui/rangeControl.js +167 -0
- package/dist/ui/scrollControl.d.ts +72 -0
- package/dist/ui/scrollControl.js +218 -0
- package/dist/ui/stateControls.d.ts +82 -0
- package/dist/ui/stateControls.js +328 -0
- package/dist/ui/textEditor.d.ts +53 -0
- package/dist/ui/textEditor.js +370 -0
- package/dist/ui/textEditorTypes.d.ts +78 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +96 -0
- package/dist/ui/textFieldControl.js +259 -0
- package/dist/ui/theme.d.ts +59 -0
- package/dist/ui/theme.js +165 -0
- package/dist/ui/types.d.ts +265 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1497 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +112 -0
- package/dist/ui/uiRootModel.js +60 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +74 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +39 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +41 -0
- package/dist/web/BrowserAudio.js +473 -0
- package/dist/web/BrowserFrameLoop.d.ts +65 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +112 -0
- package/dist/web/BrowserGame.js +352 -0
- package/dist/web/BrowserGamepadInput.d.ts +35 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +24 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +66 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +53 -0
- package/dist/web/BrowserInputActions.js +342 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +289 -0
- package/dist/web/BrowserPlay.js +1301 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserSemantics.d.ts +34 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +46 -0
- package/dist/web/BrowserStatsPanel.js +137 -0
- package/dist/web/BrowserStorage.d.ts +33 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +49 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +83 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +52 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +28 -0
- package/dist/web/BrowserVideo.js +211 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +29 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +169 -0
- package/dist/web/CanvasKitParagraphProvider.js +691 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +147 -0
- package/dist/web/ManifestByteSource.js +974 -0
- package/dist/web/ManifestFontContentLoader.d.ts +12 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2672 -0
- package/dist/web/WebGPUHost.d.ts +87 -0
- package/dist/web/WebGPUHost.js +3349 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +50 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +14 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +10 -0
- package/dist/web/kit.js +7 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +5 -0
- package/dist/web/play.js +6 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +57 -0
- package/dist/web/resources.d.ts +27 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +9 -0
- package/dist/web/sharedEffectShaders.js +165 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +30 -0
- package/dist/web/sharedWebGL2Options.js +96 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +20 -0
- package/dist/web/sharedWebGL2Shaders.js +314 -0
- package/dist/web/sharedWebGPUOptions.d.ts +37 -0
- package/dist/web/sharedWebGPUOptions.js +126 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +70 -0
- package/dist/web/webgl2Native.js +568 -0
- package/dist/web/webgl2Types.d.ts +132 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +53 -0
- package/dist/web/webgpuImageResidency.js +61 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +84 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +211 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +29 -0
- package/dist/web/world3d/Audio3D.d.ts +68 -0
- package/dist/web/world3d/Audio3D.js +212 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +182 -0
- package/dist/web/world3d/BrowserPlay3D.js +851 -0
- package/dist/web/world3d/FlyControls3D.d.ts +55 -0
- package/dist/web/world3d/FlyControls3D.js +160 -0
- package/dist/web/world3d/FollowControls3D.d.ts +28 -0
- package/dist/web/world3d/FollowControls3D.js +117 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +55 -0
- package/dist/web/world3d/OrbitControls3D.js +187 -0
- package/dist/web/world3d/TransformControls3D.d.ts +34 -0
- package/dist/web/world3d/TransformControls3D.js +125 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +133 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1173 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +110 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1915 -0
- package/dist/web/world3d/World3DView.d.ts +51 -0
- package/dist/web/world3d/World3DView.js +77 -0
- package/dist/web/world3d/app3D.d.ts +136 -0
- package/dist/web/world3d/app3D.js +304 -0
- package/dist/web/world3d/assets3D.d.ts +38 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +47 -0
- package/dist/web/world3d/atmosphere3D.js +178 -0
- package/dist/web/world3d/frame3D.d.ts +142 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +23 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +38 -0
- package/dist/web/world3d/index.js +23 -0
- package/dist/web/world3d/loaders3D.d.ts +26 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +49 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +28 -0
- package/dist/web/world3d/overlay3D.js +170 -0
- package/dist/web/world3d/post3D.d.ts +112 -0
- package/dist/web/world3d/post3D.js +459 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +14 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +31 -0
- package/dist/web/world3d/stats3D.js +80 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +66 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +35 -0
- package/dist/web/world3d/webgpu.js +22 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,1173 @@
|
|
|
1
|
+
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
2
|
+
import { linearToSrgb, mat3NormalFromMat4, mat4Invert } from '../../rendering/world3d/math3D.js';
|
|
3
|
+
import { SkinnedInstancedMesh3D } from '../../rendering/world3d/AnimationTexture3D.js';
|
|
4
|
+
import { GpuParticles3D } from '../../rendering/world3d/GpuParticles3D.js';
|
|
5
|
+
import { RenderList3D } from '../../rendering/world3d/RenderList3D.js';
|
|
6
|
+
import { CubeTexture3D, RenderTarget3D } from '../../rendering/world3d/Texture3D.js';
|
|
7
|
+
import { FRAME_BLOCK_FLOATS_3D, FRAME_OFFSETS_3D, outputToneMapping3D, planShadows3D, TILED_LIGHTS_3D, writeFrameBlock3D, writeTiledLights3D } from './frame3D.js';
|
|
8
|
+
import { createPostProcessSettings3D, outlineActive3D, postViewFromCamera3D } from './post3D.js';
|
|
9
|
+
import { PostChainWebGL23D } from './postWebGL23D.js';
|
|
10
|
+
import { WebGL2FrameMetrics3D } from './webGL2FrameMetrics3D.js';
|
|
11
|
+
import { GpuResources3D } from './gpuResources3D.js';
|
|
12
|
+
import { applyMaterialWebGL23D, buildMaterialDefinesWebGL23D, MATERIAL_VARIANT_WEBGL2_3D as V } from './materialWebGL23D.js';
|
|
13
|
+
import { MAX_MORPH_INFLUENCES_3D, SKYBOX_SHADER_3D, TEXTURE_UNITS_3D, buildMaterialShader3D } from './shaders3D.js';
|
|
14
|
+
function includesReflectionMesh(mesh, reflection, shadow) {
|
|
15
|
+
if (!shadow && (mesh.layers & reflection.layerMask) === 0)
|
|
16
|
+
return false;
|
|
17
|
+
for (let node = mesh; node; node = node.parent)
|
|
18
|
+
if (reflection.hidden.includes(node))
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const IDENTITY4 = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
23
|
+
function colorProgramFlags(fog, toneMapping, environment, linear) {
|
|
24
|
+
return ((fog ? V.fog : 0) |
|
|
25
|
+
(toneMapping !== 'none' ? V.toneMapped : 0) |
|
|
26
|
+
(environment ? V.environment : 0) |
|
|
27
|
+
(linear ? V.linearOutput : 0));
|
|
28
|
+
}
|
|
29
|
+
export class WebGL2Renderer3D {
|
|
30
|
+
canvas;
|
|
31
|
+
toneMapping;
|
|
32
|
+
exposure;
|
|
33
|
+
shadowsEnabled;
|
|
34
|
+
/** Bloom, color grading and FXAA; set `enabled` to turn the chain on. */
|
|
35
|
+
postProcess = createPostProcessSettings3D();
|
|
36
|
+
viewport;
|
|
37
|
+
autoClear = true;
|
|
38
|
+
#post;
|
|
39
|
+
#frameMetrics;
|
|
40
|
+
#viewKind = 'main';
|
|
41
|
+
#reflectionTarget;
|
|
42
|
+
#validReflections = new WeakSet();
|
|
43
|
+
#viewIndex = -1;
|
|
44
|
+
#frameToneMapping = 'none';
|
|
45
|
+
info = {
|
|
46
|
+
frame: 0,
|
|
47
|
+
drawCalls: 0,
|
|
48
|
+
triangles: 0,
|
|
49
|
+
visited: 0,
|
|
50
|
+
culled: 0,
|
|
51
|
+
lightsDropped: 0,
|
|
52
|
+
lightsTiled: 0,
|
|
53
|
+
shadowMaps: 0,
|
|
54
|
+
programs: 0,
|
|
55
|
+
geometries: 0,
|
|
56
|
+
textures: 0
|
|
57
|
+
};
|
|
58
|
+
#gl;
|
|
59
|
+
#alpha;
|
|
60
|
+
#options;
|
|
61
|
+
#list = new RenderList3D();
|
|
62
|
+
#frameData = new Float32Array(FRAME_BLOCK_FLOATS_3D);
|
|
63
|
+
#materialPrograms = new Map();
|
|
64
|
+
#resources;
|
|
65
|
+
#frameBuffer = null;
|
|
66
|
+
#emptyVao = null;
|
|
67
|
+
#shadowAtlas;
|
|
68
|
+
#shadowFallback;
|
|
69
|
+
#sceneDepth;
|
|
70
|
+
#sceneDepthReady = false;
|
|
71
|
+
#shadowAtlasSize;
|
|
72
|
+
#shadowCount = 0;
|
|
73
|
+
#lost = false;
|
|
74
|
+
#disposed = false;
|
|
75
|
+
// Cached pipeline state avoids redundant driver calls.
|
|
76
|
+
#program;
|
|
77
|
+
#cull = '';
|
|
78
|
+
#blend = '';
|
|
79
|
+
#depthTest;
|
|
80
|
+
#depthWrite;
|
|
81
|
+
#frontCw = false;
|
|
82
|
+
#offset;
|
|
83
|
+
#scratch16 = new Float32Array(16);
|
|
84
|
+
#scratch9 = new Float32Array(9);
|
|
85
|
+
#lightMatrix = new Float32Array(16);
|
|
86
|
+
#morphIndices = new Int32Array(MAX_MORPH_INFLUENCES_3D);
|
|
87
|
+
#morphWeights = new Float32Array(MAX_MORPH_INFLUENCES_3D);
|
|
88
|
+
#onLost;
|
|
89
|
+
#onRestored;
|
|
90
|
+
constructor(options) {
|
|
91
|
+
const canvas = options?.canvas;
|
|
92
|
+
if (!canvas || typeof canvas.getContext !== 'function')
|
|
93
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'canvas');
|
|
94
|
+
this.#options = options;
|
|
95
|
+
this.#alpha = options.alpha ?? false;
|
|
96
|
+
const gl = canvas.getContext('webgl2', {
|
|
97
|
+
alpha: this.#alpha,
|
|
98
|
+
antialias: options.antialias ?? true,
|
|
99
|
+
depth: true,
|
|
100
|
+
stencil: false,
|
|
101
|
+
premultipliedAlpha: true,
|
|
102
|
+
powerPreference: options.powerPreference ?? 'high-performance',
|
|
103
|
+
preserveDrawingBuffer: options.preserveDrawingBuffer ?? false
|
|
104
|
+
});
|
|
105
|
+
if (!gl)
|
|
106
|
+
throw new World3DError('WORLD3D_CONTEXT_UNAVAILABLE', 'webgl2');
|
|
107
|
+
this.canvas = canvas;
|
|
108
|
+
this.#gl = gl;
|
|
109
|
+
this.#frameMetrics = new WebGL2FrameMetrics3D(gl);
|
|
110
|
+
this.toneMapping = options.toneMapping ?? 'aces';
|
|
111
|
+
this.exposure = options.exposure ?? 1;
|
|
112
|
+
this.shadowsEnabled = options.shadows ?? true;
|
|
113
|
+
this.#shadowAtlasSize = Math.min(options.shadowAtlasSize ?? 2048, gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
|
114
|
+
this.#resources = new GpuResources3D(gl);
|
|
115
|
+
this.#onLost = (event) => {
|
|
116
|
+
// Without preventDefault the browser never restores the context.
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
this.#lost = true;
|
|
119
|
+
this.#resources.reset();
|
|
120
|
+
this.#frameMetrics.reset(true);
|
|
121
|
+
this.#validReflections = new WeakSet();
|
|
122
|
+
options.onContextLost?.();
|
|
123
|
+
};
|
|
124
|
+
this.#onRestored = () => {
|
|
125
|
+
this.#resources.reset();
|
|
126
|
+
this.#resources = new GpuResources3D(gl);
|
|
127
|
+
this.#post?.dispose(true);
|
|
128
|
+
this.#post = undefined;
|
|
129
|
+
this.clearMaterialPrograms();
|
|
130
|
+
this.#frameBuffer = this.#emptyVao = null;
|
|
131
|
+
this.#tiledTexture = null;
|
|
132
|
+
this.#shadowAtlas = this.#shadowFallback = undefined;
|
|
133
|
+
this.#sceneDepth = undefined;
|
|
134
|
+
this.#sceneDepthReady = false;
|
|
135
|
+
this.#grab = undefined;
|
|
136
|
+
this.resetState();
|
|
137
|
+
this.#lost = false;
|
|
138
|
+
options.onContextRestored?.();
|
|
139
|
+
};
|
|
140
|
+
canvas.addEventListener('webglcontextlost', this.#onLost);
|
|
141
|
+
canvas.addEventListener('webglcontextrestored', this.#onRestored);
|
|
142
|
+
}
|
|
143
|
+
get isContextLost() {
|
|
144
|
+
return this.#lost || this.#gl.isContextLost();
|
|
145
|
+
}
|
|
146
|
+
/** Link and initialize the specified draw variants without submitting any draws. */
|
|
147
|
+
async preparePrograms(requests) {
|
|
148
|
+
if (this.#disposed)
|
|
149
|
+
throw new World3DError('WORLD3D_DISPOSED', 'renderer');
|
|
150
|
+
if (this.isContextLost)
|
|
151
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'program preparation');
|
|
152
|
+
const programs = [];
|
|
153
|
+
for (const request of requests) {
|
|
154
|
+
const { mesh, material, reflection } = request;
|
|
155
|
+
const target = reflection?.target ?? request.target;
|
|
156
|
+
if (reflection && request.target && reflection.target !== request.target)
|
|
157
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'reflection program target');
|
|
158
|
+
const geometry = mesh.geometry;
|
|
159
|
+
if (geometry.isDisposed || material.isDisposed || target?.isDisposed)
|
|
160
|
+
throw new World3DError('WORLD3D_DISPOSED', 'program preparation input');
|
|
161
|
+
const pass = request.pass ?? 'color';
|
|
162
|
+
if (pass !== 'color' && pass !== 'shadow' && pass !== 'depth-prepass')
|
|
163
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'program preparation pass');
|
|
164
|
+
const shadows = this.shadowsEnabled && (reflection?.shadows ?? true);
|
|
165
|
+
if (reflection &&
|
|
166
|
+
((pass === 'shadow' && !shadows) || !includesReflectionMesh(mesh, reflection, pass === 'shadow')))
|
|
167
|
+
continue;
|
|
168
|
+
// The main post chain draws into a linear HDR scene target. The mirror uses its own output.
|
|
169
|
+
const post = !reflection && this.postProcess.enabled;
|
|
170
|
+
const toneMapping = post ? 'none' : outputToneMapping3D(reflection?.toneMapping ?? this.toneMapping, target);
|
|
171
|
+
const flags = pass === 'color'
|
|
172
|
+
? colorProgramFlags(request.fog === true, toneMapping, request.environment === true, post || Boolean(target)) |
|
|
173
|
+
(request.receiveShadows && (!reflection || shadows) ? V.receiveShadow : 0) |
|
|
174
|
+
(request.softDepth ? V.softDepth : 0) |
|
|
175
|
+
(request.transmission ? V.transmission : 0)
|
|
176
|
+
: V.depthOnly;
|
|
177
|
+
const morphs = geometry.morphTargets;
|
|
178
|
+
const morphAttributes = !morphs.length ? 0 : morphs.some(morph => morph.normal) ? 2 : 1;
|
|
179
|
+
programs.push(this.programRequest(material, this.meshProgramVariant(mesh, geometry, material, flags, morphAttributes)));
|
|
180
|
+
}
|
|
181
|
+
await this.#resources.preparePrograms(programs);
|
|
182
|
+
}
|
|
183
|
+
/** The underlying context, for advanced interop. Restore any state you change. */
|
|
184
|
+
get context() {
|
|
185
|
+
return this.#gl;
|
|
186
|
+
}
|
|
187
|
+
/** Resize the drawing buffer; `pixelRatio` multiplies the logical size. */
|
|
188
|
+
setSize(width, height, pixelRatio = 1) {
|
|
189
|
+
const w = Math.max(1, Math.floor(width * pixelRatio)), h = Math.max(1, Math.floor(height * pixelRatio));
|
|
190
|
+
if (!Number.isFinite(w) || !Number.isFinite(h))
|
|
191
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'size');
|
|
192
|
+
if (this.canvas.width !== w)
|
|
193
|
+
this.canvas.width = w;
|
|
194
|
+
if (this.canvas.height !== h)
|
|
195
|
+
this.canvas.height = h;
|
|
196
|
+
}
|
|
197
|
+
/** Match the drawing buffer to the canvas's CSS size. Returns true when it changed. */
|
|
198
|
+
resizeToDisplaySize(pixelRatio = 1) {
|
|
199
|
+
const element = this.canvas;
|
|
200
|
+
if (typeof element.clientWidth !== 'number')
|
|
201
|
+
return false;
|
|
202
|
+
const w = Math.max(1, Math.floor(element.clientWidth * pixelRatio)), h = Math.max(1, Math.floor(element.clientHeight * pixelRatio));
|
|
203
|
+
if (element.width === w && element.height === h)
|
|
204
|
+
return false;
|
|
205
|
+
element.width = w;
|
|
206
|
+
element.height = h;
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
// ---- frame ---------------------------------------------------------------
|
|
210
|
+
/**
|
|
211
|
+
* Draw one frame to the canvas, or into `target` when given. Returns false
|
|
212
|
+
* when the context is lost and nothing was drawn.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* Draw runs of plain meshes that share a geometry and a material as one
|
|
216
|
+
* instanced draw each, in the main view and in shadow maps. On by default;
|
|
217
|
+
* the meshes themselves are untouched.
|
|
218
|
+
*/
|
|
219
|
+
get autoInstancing() {
|
|
220
|
+
return this.#list.autoInstanceThreshold > 1;
|
|
221
|
+
}
|
|
222
|
+
set autoInstancing(value) {
|
|
223
|
+
this.#list.autoInstanceThreshold = value ? 8 : 0;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Light point lights past the eight a frame lights directly through a tiled list: each pixel visits only the
|
|
227
|
+
* lights whose range reaches its screen tile, up to 32 a tile and 256 in all. On by default.
|
|
228
|
+
*/
|
|
229
|
+
get tiledLights() {
|
|
230
|
+
return this.#list.tiledLights;
|
|
231
|
+
}
|
|
232
|
+
set tiledLights(value) {
|
|
233
|
+
this.#list.tiledLights = Boolean(value);
|
|
234
|
+
}
|
|
235
|
+
#tiledTable = new Float32Array(TILED_LIGHTS_3D.width * TILED_LIGHTS_3D.rows * 4);
|
|
236
|
+
#tiledTexture = null;
|
|
237
|
+
/** Writes the tiled lights for this view and binds their table; an empty table when there are none. */
|
|
238
|
+
bindTiledLights(camera, width, height, x, y) {
|
|
239
|
+
const gl = this.#gl;
|
|
240
|
+
const count = writeTiledLights3D(this.#frameData, this.#tiledTable, this.#list.tiledPointLights, camera.viewProjectionMatrix, width, height, false, x, y);
|
|
241
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.tiledLights);
|
|
242
|
+
if (!this.#tiledTexture) {
|
|
243
|
+
this.#tiledTexture = gl.createTexture();
|
|
244
|
+
gl.bindTexture(gl.TEXTURE_2D, this.#tiledTexture);
|
|
245
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
246
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
247
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
248
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
249
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, TILED_LIGHTS_3D.width, TILED_LIGHTS_3D.rows, 0, gl.RGBA, gl.FLOAT, this.#tiledTable);
|
|
250
|
+
}
|
|
251
|
+
else
|
|
252
|
+
gl.bindTexture(gl.TEXTURE_2D, this.#tiledTexture);
|
|
253
|
+
if (count > 0)
|
|
254
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, TILED_LIGHTS_3D.width, TILED_LIGHTS_3D.rows, gl.RGBA, gl.FLOAT, this.#tiledTable);
|
|
255
|
+
this.info.lightsTiled = count;
|
|
256
|
+
}
|
|
257
|
+
/** Measure the WebGL2 renderer calls made synchronously by one application frame. */
|
|
258
|
+
measureFrame(draw, options) {
|
|
259
|
+
if (this.#disposed)
|
|
260
|
+
throw new World3DError('WORLD3D_DISPOSED', 'renderer');
|
|
261
|
+
return this.#frameMetrics.capture(draw, options?.gpuTiming === true);
|
|
262
|
+
}
|
|
263
|
+
/** Resolve ready GPU samples without waiting. Call from a later browser turn. */
|
|
264
|
+
pollFrameTimings() {
|
|
265
|
+
this.#frameMetrics.poll();
|
|
266
|
+
}
|
|
267
|
+
render(scene, camera, target) {
|
|
268
|
+
return this.renderMeasuredView(scene, camera, target, target !== undefined && this.#reflectionTarget === target ? 'reflection' : target ? 'offscreen' : 'main');
|
|
269
|
+
}
|
|
270
|
+
/** Draw the view prepared by PlanarReflection3D and identify it in frame metrics. */
|
|
271
|
+
renderReflection(scene, camera, target) {
|
|
272
|
+
const saved = this.#reflectionTarget;
|
|
273
|
+
this.#reflectionTarget = target;
|
|
274
|
+
try {
|
|
275
|
+
return this.recordReflection(target, this.render(scene, camera, target));
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.#reflectionTarget = saved;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** Draw the mirror directly with its own output, shadows and object selection. */
|
|
282
|
+
renderReflectionPass(scene, camera, pass) {
|
|
283
|
+
return this.recordReflection(pass.target, this.renderMeasuredView(scene, camera, pass.target, 'reflection', pass));
|
|
284
|
+
}
|
|
285
|
+
recordReflection(target, rendered) {
|
|
286
|
+
if (rendered) {
|
|
287
|
+
this.#validReflections.add(target);
|
|
288
|
+
this.#frameMetrics.recordReflection('rendered');
|
|
289
|
+
}
|
|
290
|
+
return rendered;
|
|
291
|
+
}
|
|
292
|
+
/** The retained mirror image must still belong to the live WebGL2 context. */
|
|
293
|
+
reuseReflection(target) {
|
|
294
|
+
if (this.#disposed || this.isContextLost || !this.#validReflections.has(target))
|
|
295
|
+
return false;
|
|
296
|
+
this.#frameMetrics.recordReflection('reused');
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
renderMeasuredView(scene, camera, target, kind, reflection) {
|
|
300
|
+
if (this.#disposed)
|
|
301
|
+
throw new World3DError('WORLD3D_DISPOSED', 'renderer');
|
|
302
|
+
if (this.isContextLost)
|
|
303
|
+
return false;
|
|
304
|
+
const viewIndex = this.#frameMetrics.beginView();
|
|
305
|
+
const post = !reflection && this.postProcess.enabled;
|
|
306
|
+
if (viewIndex < 0)
|
|
307
|
+
return post
|
|
308
|
+
? this.renderPost(scene, camera, target)
|
|
309
|
+
: this.renderView(scene, camera, target, 'color', reflection);
|
|
310
|
+
const start = performance.now(), oldIndex = this.#viewIndex, oldKind = this.#viewKind;
|
|
311
|
+
this.#viewIndex = viewIndex;
|
|
312
|
+
this.#viewKind = kind;
|
|
313
|
+
try {
|
|
314
|
+
return post
|
|
315
|
+
? this.renderPost(scene, camera, target)
|
|
316
|
+
: this.renderView(scene, camera, target, 'color', reflection);
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
this.#viewIndex = oldIndex;
|
|
320
|
+
this.#viewKind = oldKind;
|
|
321
|
+
this.#frameMetrics.endView(start);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
renderView(scene, camera, target, passKind = 'color', reflection) {
|
|
325
|
+
if (target?.isDisposed)
|
|
326
|
+
throw new World3DError('WORLD3D_DISPOSED', 'render target');
|
|
327
|
+
const gl = this.#gl, list = this.#list, info = this.info;
|
|
328
|
+
const toneMapping = (this.#frameToneMapping = outputToneMapping3D(reflection?.toneMapping ?? this.toneMapping, target));
|
|
329
|
+
list.build(scene, camera, reflection);
|
|
330
|
+
info.frame = list.frame;
|
|
331
|
+
info.drawCalls = info.triangles = 0;
|
|
332
|
+
info.visited = list.stats.visited;
|
|
333
|
+
info.culled = list.stats.culled;
|
|
334
|
+
info.lightsDropped = list.stats.lightsDropped;
|
|
335
|
+
this.resetState();
|
|
336
|
+
this.bindFrameBlock();
|
|
337
|
+
this.renderShadows(camera, this.shadowsEnabled && (reflection?.shadows ?? true));
|
|
338
|
+
// Surfaces that fade near solid geometry read its depth, drawn once up front.
|
|
339
|
+
this.#sceneDepthReady =
|
|
340
|
+
list.transparent.some(item => item.material.softness > 0) && this.renderSceneDepth(camera, target);
|
|
341
|
+
const view = this.viewport, width = target?.width ?? gl.drawingBufferWidth, height = target?.height ?? gl.drawingBufferHeight;
|
|
342
|
+
const viewWidth = view ? Math.max(Math.round(view[2] * width), 1) : width;
|
|
343
|
+
const viewHeight = view ? Math.max(Math.round(view[3] * height), 1) : height;
|
|
344
|
+
const pass = this.#frameMetrics.begin(this.#viewKind, this.#viewIndex, passKind, width, height);
|
|
345
|
+
try {
|
|
346
|
+
if (target) {
|
|
347
|
+
const entry = this.#resources.target(target);
|
|
348
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, entry.framebuffer);
|
|
349
|
+
gl.viewport(0, 0, target.width, target.height);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
353
|
+
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
354
|
+
}
|
|
355
|
+
this.#linearOutput = target !== undefined;
|
|
356
|
+
const background = scene.background;
|
|
357
|
+
gl.depthMask(true);
|
|
358
|
+
this.#depthWrite = true;
|
|
359
|
+
// sRGB targets encode on write, so they are cleared with linear values.
|
|
360
|
+
const encode = target ? (value) => value : linearToSrgb;
|
|
361
|
+
if (Array.isArray(background))
|
|
362
|
+
gl.clearColor(encode(background[0]), encode(background[1]), encode(background[2]), 1);
|
|
363
|
+
else
|
|
364
|
+
gl.clearColor(0, 0, 0, (target || this.#alpha) && !background ? 0 : 1);
|
|
365
|
+
gl.clear(this.autoClear ? gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT : gl.DEPTH_BUFFER_BIT);
|
|
366
|
+
if (view) {
|
|
367
|
+
const x = Math.round(view[0] * width), y = Math.round(view[1] * height);
|
|
368
|
+
gl.viewport(x, y, viewWidth, viewHeight);
|
|
369
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
370
|
+
gl.scissor(x, y, viewWidth, viewHeight);
|
|
371
|
+
}
|
|
372
|
+
let environmentMaxMip = 0;
|
|
373
|
+
this.#lastEnvironment = scene.environment;
|
|
374
|
+
if (scene.environment)
|
|
375
|
+
environmentMaxMip = this.#resources.bindCube(TEXTURE_UNITS_3D.environment, scene.environment);
|
|
376
|
+
writeFrameBlock3D(this.#frameData, scene, camera, list, this.#shadowSlots, {
|
|
377
|
+
exposure: this.exposure,
|
|
378
|
+
toneMapping,
|
|
379
|
+
environmentMaxMip
|
|
380
|
+
});
|
|
381
|
+
this.#frameData[FRAME_OFFSETS_3D.clipInfo + 2] = view ? view[2] : 1;
|
|
382
|
+
this.#frameData[FRAME_OFFSETS_3D.clipInfo + 3] = view ? view[3] : 1;
|
|
383
|
+
this.bindTiledLights(camera, viewWidth, viewHeight, view ? Math.round(view[0] * width) : 0, view ? Math.round(view[1] * height) : 0);
|
|
384
|
+
this.uploadFrameBlock();
|
|
385
|
+
const flags = colorProgramFlags(Boolean(scene.fog), toneMapping, Boolean(scene.environment), Boolean(target));
|
|
386
|
+
for (const item of list.opaque)
|
|
387
|
+
this.draw(item, flags);
|
|
388
|
+
if (background instanceof CubeTexture3D)
|
|
389
|
+
this.drawSkybox(background, scene.backgroundIntensity, camera);
|
|
390
|
+
// See-through surfaces read a copy of everything drawn so far.
|
|
391
|
+
this.#grabbed = false;
|
|
392
|
+
for (const item of list.transparent)
|
|
393
|
+
if (item.material.transmission > 0 && item.material.shading === 'standard') {
|
|
394
|
+
this.#grabbed = this.grabScene(target);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
for (const item of list.transparent)
|
|
398
|
+
this.draw(item, flags);
|
|
399
|
+
this.#grabbed = false;
|
|
400
|
+
gl.bindVertexArray(null);
|
|
401
|
+
if (view)
|
|
402
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
403
|
+
if (target)
|
|
404
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
this.#frameMetrics.end(pass);
|
|
408
|
+
}
|
|
409
|
+
this.#resources.prune(list.frame);
|
|
410
|
+
const counts = this.#resources.counts;
|
|
411
|
+
info.programs = counts.programs;
|
|
412
|
+
info.geometries = counts.geometries;
|
|
413
|
+
info.textures = counts.textures;
|
|
414
|
+
info.shadowMaps = this.#shadowCount;
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
/** Draw the scene into the half-float chain target, then post-process into the output. */
|
|
418
|
+
renderPost(scene, camera, target) {
|
|
419
|
+
const gl = this.#gl;
|
|
420
|
+
if (target?.isDisposed)
|
|
421
|
+
throw new World3DError('WORLD3D_DISPOSED', 'render target');
|
|
422
|
+
const width = target ? target.width : gl.drawingBufferWidth, height = target ? target.height : gl.drawingBufferHeight;
|
|
423
|
+
const post = (this.#post ??= new PostChainWebGL23D(gl, this.#resources));
|
|
424
|
+
post.scene.setSize(Math.max(width, 1), Math.max(height, 1));
|
|
425
|
+
if (this.isContextLost || !this.renderView(scene, camera, post.scene))
|
|
426
|
+
return false;
|
|
427
|
+
const output = target ? this.#resources.target(target).framebuffer : null;
|
|
428
|
+
// 8-bit targets encode sRGB on write and half-float targets store linear light; only the canvas needs encoded values.
|
|
429
|
+
// Outlined objects are drawn once more, flat white, into a mask the composite traces.
|
|
430
|
+
let maskTexture;
|
|
431
|
+
if (outlineActive3D(this.postProcess)) {
|
|
432
|
+
post.mask.setSize(Math.max(width, 1), Math.max(height, 1));
|
|
433
|
+
const saved = {
|
|
434
|
+
layerMask: camera.layerMask,
|
|
435
|
+
override: scene.overrideMaterial,
|
|
436
|
+
background: scene.background,
|
|
437
|
+
shadows: this.shadowsEnabled,
|
|
438
|
+
planes: scene.clippingPlanes
|
|
439
|
+
};
|
|
440
|
+
camera.layerMask = this.postProcess.outlineLayers;
|
|
441
|
+
scene.overrideMaterial = post.maskMaterial;
|
|
442
|
+
scene.background = [0, 0, 0];
|
|
443
|
+
this.shadowsEnabled = false;
|
|
444
|
+
// Legacy scene counters exclude the helper pass, which frame metrics include.
|
|
445
|
+
const counted = { ...this.info };
|
|
446
|
+
try {
|
|
447
|
+
if (!this.isContextLost && this.renderView(scene, camera, post.mask, 'outline-mask'))
|
|
448
|
+
maskTexture = this.#resources.target(post.mask).color;
|
|
449
|
+
}
|
|
450
|
+
finally {
|
|
451
|
+
camera.layerMask = saved.layerMask;
|
|
452
|
+
scene.overrideMaterial = saved.override;
|
|
453
|
+
scene.background = saved.background;
|
|
454
|
+
this.shadowsEnabled = saved.shadows;
|
|
455
|
+
Object.assign(this.info, counted);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const sceneEntry = this.#resources.target(post.scene);
|
|
459
|
+
const postPass = this.#frameMetrics.begin(this.#viewKind, this.#viewIndex, 'postprocess', width, height);
|
|
460
|
+
try {
|
|
461
|
+
const draws = post.run(sceneEntry.color, sceneEntry.depthTexture, maskTexture, postViewFromCamera3D(camera), width, height, output, target !== undefined, this.postProcess, target?.format === 'rgba16f' ? 'none' : this.toneMapping, (this.#emptyVao ??= gl.createVertexArray()));
|
|
462
|
+
this.info.drawCalls += draws;
|
|
463
|
+
this.#frameMetrics.record(draws, draws);
|
|
464
|
+
}
|
|
465
|
+
finally {
|
|
466
|
+
this.#frameMetrics.end(postPass);
|
|
467
|
+
}
|
|
468
|
+
this.resetState();
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
/** Copy the output drawn so far into a texture on the scene-color unit. */
|
|
472
|
+
grabScene(target) {
|
|
473
|
+
const gl = this.#gl, source = target ? this.#resources.target(target).framebuffer : null;
|
|
474
|
+
const width = target ? target.width : gl.drawingBufferWidth, height = target ? target.height : gl.drawingBufferHeight;
|
|
475
|
+
const format = target
|
|
476
|
+
? target.format === 'rgba16f' && this.#resources.floatTargets
|
|
477
|
+
? gl.RGBA16F
|
|
478
|
+
: gl.SRGB8_ALPHA8
|
|
479
|
+
: this.#alpha
|
|
480
|
+
? gl.RGBA8
|
|
481
|
+
: gl.RGB8;
|
|
482
|
+
let grab = this.#grab;
|
|
483
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.sceneColor);
|
|
484
|
+
if (!grab) {
|
|
485
|
+
const texture = gl.createTexture(), framebuffer = gl.createFramebuffer();
|
|
486
|
+
if (!texture || !framebuffer) {
|
|
487
|
+
if (texture)
|
|
488
|
+
gl.deleteTexture(texture);
|
|
489
|
+
if (framebuffer)
|
|
490
|
+
gl.deleteFramebuffer(framebuffer);
|
|
491
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
grab = this.#grab = { texture, framebuffer, width: 0, height: 0, format: 0 };
|
|
495
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
496
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
497
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
498
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
499
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
500
|
+
}
|
|
501
|
+
else
|
|
502
|
+
gl.bindTexture(gl.TEXTURE_2D, grab.texture);
|
|
503
|
+
if (grab.width !== width || grab.height !== height || grab.format !== format) {
|
|
504
|
+
if (format === gl.RGBA16F)
|
|
505
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, gl.RGBA, gl.HALF_FLOAT, null);
|
|
506
|
+
else if (format === gl.RGB8)
|
|
507
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
|
|
508
|
+
else
|
|
509
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
510
|
+
grab.width = width;
|
|
511
|
+
grab.height = height;
|
|
512
|
+
grab.format = format;
|
|
513
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, grab.framebuffer);
|
|
514
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, grab.texture, 0);
|
|
515
|
+
}
|
|
516
|
+
if (target) {
|
|
517
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, source);
|
|
518
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, grab.framebuffer);
|
|
519
|
+
gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
|
|
520
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, source);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
// The canvas may be antialiased; a texture copy reads its resolved image.
|
|
524
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
525
|
+
gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
|
|
526
|
+
}
|
|
527
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
#grab;
|
|
531
|
+
#grabbed = false;
|
|
532
|
+
/** Stands for every plain opaque material while drawing depth only. */
|
|
533
|
+
#plainDepth = {};
|
|
534
|
+
resetState() {
|
|
535
|
+
const gl = this.#gl;
|
|
536
|
+
this.#appliedProgram = undefined;
|
|
537
|
+
this.#appliedMaterial = undefined;
|
|
538
|
+
this.#program = undefined;
|
|
539
|
+
this.#cull = '';
|
|
540
|
+
this.#blend = '';
|
|
541
|
+
this.#depthTest = undefined;
|
|
542
|
+
this.#depthWrite = undefined;
|
|
543
|
+
this.#offset = undefined;
|
|
544
|
+
this.#frontCw = false;
|
|
545
|
+
if (this.#gl.isContextLost())
|
|
546
|
+
return;
|
|
547
|
+
gl.frontFace(gl.CCW);
|
|
548
|
+
gl.depthFunc(gl.LEQUAL);
|
|
549
|
+
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
550
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
551
|
+
gl.colorMask(true, true, true, true);
|
|
552
|
+
}
|
|
553
|
+
/** std140 blocks stay active even when unused, so the buffer must be bound before the shadow pass. */
|
|
554
|
+
bindFrameBlock() {
|
|
555
|
+
const gl = this.#gl;
|
|
556
|
+
if (!this.#frameBuffer) {
|
|
557
|
+
this.#frameBuffer = gl.createBuffer();
|
|
558
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, this.#frameBuffer);
|
|
559
|
+
gl.bufferData(gl.UNIFORM_BUFFER, this.#frameData.byteLength, gl.DYNAMIC_DRAW);
|
|
560
|
+
}
|
|
561
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, this.#frameBuffer);
|
|
562
|
+
}
|
|
563
|
+
uploadFrameBlock() {
|
|
564
|
+
const gl = this.#gl;
|
|
565
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, this.#frameBuffer);
|
|
566
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, this.#frameData);
|
|
567
|
+
}
|
|
568
|
+
// ---- shadows -------------------------------------------------------------
|
|
569
|
+
#shadowSlots = new Map();
|
|
570
|
+
createShadowAtlas(size) {
|
|
571
|
+
const gl = this.#gl;
|
|
572
|
+
const texture = gl.createTexture(), framebuffer = gl.createFramebuffer();
|
|
573
|
+
if (!texture || !framebuffer) {
|
|
574
|
+
if (texture)
|
|
575
|
+
gl.deleteTexture(texture);
|
|
576
|
+
if (framebuffer)
|
|
577
|
+
gl.deleteFramebuffer(framebuffer);
|
|
578
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'shadow atlas');
|
|
579
|
+
}
|
|
580
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.shadow);
|
|
581
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
582
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.DEPTH_COMPONENT24, size, size);
|
|
583
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
584
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
585
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
586
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
587
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
|
|
588
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, gl.LEQUAL);
|
|
589
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
590
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, texture, 0);
|
|
591
|
+
gl.drawBuffers([gl.NONE]);
|
|
592
|
+
gl.readBuffer(gl.NONE);
|
|
593
|
+
gl.clearDepth(1);
|
|
594
|
+
gl.depthMask(true);
|
|
595
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
596
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
597
|
+
return { texture, framebuffer, size };
|
|
598
|
+
}
|
|
599
|
+
renderShadows(camera, enabled) {
|
|
600
|
+
const gl = this.#gl;
|
|
601
|
+
// A shadow-free reflection can run before the main view. Keep its comparison sampler complete
|
|
602
|
+
// without replacing the full atlas needed by the next pass.
|
|
603
|
+
const atlas = enabled
|
|
604
|
+
? (this.#shadowAtlas ??= this.createShadowAtlas(this.#shadowAtlasSize))
|
|
605
|
+
: (this.#shadowFallback ??= this.createShadowAtlas(1));
|
|
606
|
+
this.#shadowCount = 0;
|
|
607
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.shadow);
|
|
608
|
+
gl.bindTexture(gl.TEXTURE_2D, atlas.texture);
|
|
609
|
+
const plans = planShadows3D(this.#frameData, this.#list, atlas.size, enabled, false, this.#shadowSlots, camera);
|
|
610
|
+
if (plans.length === 0)
|
|
611
|
+
return;
|
|
612
|
+
const pass = this.#viewIndex < 0
|
|
613
|
+
? undefined
|
|
614
|
+
: this.#frameMetrics.begin(this.#viewKind, this.#viewIndex, 'shadow', atlas.size, atlas.size, plans.map(plan => plan.tile));
|
|
615
|
+
try {
|
|
616
|
+
// Unbind the atlas while rendering into it to avoid a feedback loop.
|
|
617
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
618
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, atlas.framebuffer);
|
|
619
|
+
gl.viewport(0, 0, atlas.size, atlas.size);
|
|
620
|
+
gl.depthMask(true);
|
|
621
|
+
this.#depthWrite = true;
|
|
622
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
623
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
624
|
+
gl.enable(gl.POLYGON_OFFSET_FILL);
|
|
625
|
+
gl.polygonOffset(1.5, 4);
|
|
626
|
+
gl.colorMask(false, false, false, false);
|
|
627
|
+
for (const plan of plans) {
|
|
628
|
+
gl.viewport(plan.x, plan.y, plan.tile, plan.tile);
|
|
629
|
+
gl.scissor(plan.x, plan.y, plan.tile, plan.tile);
|
|
630
|
+
this.#lightMatrix = plan.matrix;
|
|
631
|
+
for (const mesh of plan.casters)
|
|
632
|
+
this.drawDepth(mesh);
|
|
633
|
+
}
|
|
634
|
+
gl.colorMask(true, true, true, true);
|
|
635
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
636
|
+
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
637
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
638
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.shadow);
|
|
639
|
+
gl.bindTexture(gl.TEXTURE_2D, atlas.texture);
|
|
640
|
+
this.#shadowCount = plans.length;
|
|
641
|
+
this.#program = undefined;
|
|
642
|
+
this.#appliedProgram = undefined;
|
|
643
|
+
}
|
|
644
|
+
finally {
|
|
645
|
+
this.#frameMetrics.end(pass);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/** Draw the depth of the opaque scene, as the camera sees it, into a texture of the output's size. */
|
|
649
|
+
renderSceneDepth(camera, target) {
|
|
650
|
+
const gl = this.#gl, width = target ? target.width : gl.drawingBufferWidth, height = target ? target.height : gl.drawingBufferHeight;
|
|
651
|
+
const view = this.viewport;
|
|
652
|
+
const viewWidth = view ? Math.max(Math.round(view[2] * width), 1) : width;
|
|
653
|
+
const viewHeight = view ? Math.max(Math.round(view[3] * height), 1) : height;
|
|
654
|
+
const pass = this.#frameMetrics.begin(this.#viewKind, this.#viewIndex, 'depth-prepass', width, height);
|
|
655
|
+
try {
|
|
656
|
+
let entry = this.#sceneDepth;
|
|
657
|
+
if (!entry || entry.width !== width || entry.height !== height) {
|
|
658
|
+
if (entry) {
|
|
659
|
+
gl.deleteTexture(entry.texture);
|
|
660
|
+
gl.deleteFramebuffer(entry.framebuffer);
|
|
661
|
+
this.#sceneDepth = undefined;
|
|
662
|
+
}
|
|
663
|
+
const texture = gl.createTexture(), framebuffer = gl.createFramebuffer();
|
|
664
|
+
if (!texture || !framebuffer) {
|
|
665
|
+
if (texture)
|
|
666
|
+
gl.deleteTexture(texture);
|
|
667
|
+
if (framebuffer)
|
|
668
|
+
gl.deleteFramebuffer(framebuffer);
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.sceneDepth);
|
|
672
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
673
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.DEPTH_COMPONENT24, width, height);
|
|
674
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
675
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
676
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
677
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
678
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
679
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, texture, 0);
|
|
680
|
+
gl.drawBuffers([gl.NONE]);
|
|
681
|
+
gl.readBuffer(gl.NONE);
|
|
682
|
+
entry = this.#sceneDepth = { texture, framebuffer, width, height };
|
|
683
|
+
}
|
|
684
|
+
// The texture must not be bound for reading while it is drawn into.
|
|
685
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.sceneDepth);
|
|
686
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
687
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, entry.framebuffer);
|
|
688
|
+
if (view)
|
|
689
|
+
gl.viewport(Math.round(view[0] * width), Math.round(view[1] * height), viewWidth, viewHeight);
|
|
690
|
+
else
|
|
691
|
+
gl.viewport(0, 0, width, height);
|
|
692
|
+
gl.depthMask(true);
|
|
693
|
+
this.#depthWrite = true;
|
|
694
|
+
gl.clearDepth(1);
|
|
695
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
696
|
+
this.#lightMatrix = camera.viewProjectionMatrix;
|
|
697
|
+
// Keep the camera view's face culling and material offset.
|
|
698
|
+
for (const item of this.#list.opaque) {
|
|
699
|
+
if (item.geometry.topology === 'triangles' &&
|
|
700
|
+
item.material.depthWrite &&
|
|
701
|
+
!item.material.billboard &&
|
|
702
|
+
!item.material.screenSpace)
|
|
703
|
+
this.draw(item, 0, 'scene');
|
|
704
|
+
}
|
|
705
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
706
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.sceneDepth);
|
|
707
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.texture);
|
|
708
|
+
this.#program = undefined;
|
|
709
|
+
this.#appliedProgram = undefined;
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
finally {
|
|
713
|
+
this.#frameMetrics.end(pass);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
depthItem = {
|
|
717
|
+
mesh: undefined,
|
|
718
|
+
geometry: undefined,
|
|
719
|
+
material: undefined,
|
|
720
|
+
start: 0,
|
|
721
|
+
count: 0,
|
|
722
|
+
depth: 0
|
|
723
|
+
};
|
|
724
|
+
drawDepth(mesh) {
|
|
725
|
+
const geometry = mesh.geometry, item = this.depthItem, groups = geometry.groups;
|
|
726
|
+
if (geometry.topology !== 'triangles')
|
|
727
|
+
return;
|
|
728
|
+
item.mesh = mesh;
|
|
729
|
+
item.geometry = geometry;
|
|
730
|
+
if (Array.isArray(mesh.material) && groups.length > 0) {
|
|
731
|
+
for (const group of groups) {
|
|
732
|
+
item.material = mesh.materialAt(group.materialIndex);
|
|
733
|
+
item.start = group.start;
|
|
734
|
+
item.count = group.count;
|
|
735
|
+
if (item.material.visible && !item.material.isDisposed && !item.material.billboard)
|
|
736
|
+
this.draw(item, 0, 'shadow');
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
item.material = mesh.materialAt(0);
|
|
741
|
+
item.start = 0;
|
|
742
|
+
item.count = geometry.drawCount;
|
|
743
|
+
if (item.material.visible && !item.material.isDisposed && !item.material.billboard)
|
|
744
|
+
this.draw(item, 0, 'shadow');
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
// ---- programs --------------------------------------------------------------
|
|
748
|
+
selectProgram(material, variant) {
|
|
749
|
+
let cache = this.#materialPrograms.get(material.id);
|
|
750
|
+
if (!cache) {
|
|
751
|
+
const unsubscribe = material.onDispose(() => {
|
|
752
|
+
this.#materialPrograms.delete(material.id);
|
|
753
|
+
});
|
|
754
|
+
cache = { version: material.version, variants: new Map(), unsubscribe };
|
|
755
|
+
this.#materialPrograms.set(material.id, cache);
|
|
756
|
+
}
|
|
757
|
+
else if (cache.version !== material.version) {
|
|
758
|
+
cache.version = material.version;
|
|
759
|
+
cache.variants.clear();
|
|
760
|
+
}
|
|
761
|
+
let program = cache.variants.get(variant);
|
|
762
|
+
if (program)
|
|
763
|
+
return program;
|
|
764
|
+
const { key, sources } = this.programRequest(material, variant);
|
|
765
|
+
program = this.#resources.program(key, sources);
|
|
766
|
+
cache.variants.set(variant, program);
|
|
767
|
+
return program;
|
|
768
|
+
}
|
|
769
|
+
programRequest(material, variant) {
|
|
770
|
+
const depthOnly = (variant & V.depthOnly) !== 0;
|
|
771
|
+
const defines = buildMaterialDefinesWebGL23D(material, variant, depthOnly);
|
|
772
|
+
const custom = depthOnly ? undefined : material.shader?.glsl, customVertex = material.shader?.glslVertex;
|
|
773
|
+
const customNormal = depthOnly || material.shading === 'unlit' || material.shading === 'matcap'
|
|
774
|
+
? undefined
|
|
775
|
+
: material.shader?.glslNormal;
|
|
776
|
+
if (custom !== undefined)
|
|
777
|
+
defines.push('CUSTOM_FRAGMENT');
|
|
778
|
+
if (customVertex !== undefined)
|
|
779
|
+
defines.push('CUSTOM_VERTEX');
|
|
780
|
+
if (customNormal !== undefined)
|
|
781
|
+
defines.push('CUSTOM_NORMAL');
|
|
782
|
+
return {
|
|
783
|
+
key: defines.join(' ') +
|
|
784
|
+
(custom === undefined && customVertex === undefined && customNormal === undefined
|
|
785
|
+
? ''
|
|
786
|
+
: '|' + material.shader.key),
|
|
787
|
+
sources: () => buildMaterialShader3D(defines, custom, customVertex, customNormal)
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
applyMaterial(program, material, depthOnly) {
|
|
791
|
+
applyMaterialWebGL23D(this.#gl, program.uniforms, this.#resources, this.#scratch9, material, depthOnly);
|
|
792
|
+
}
|
|
793
|
+
applyState(material, shadow, mirrored) {
|
|
794
|
+
const gl = this.#gl;
|
|
795
|
+
// Shadow maps draw both faces: closed and open meshes then cast alike.
|
|
796
|
+
const cull = shadow || material.side === 'double' || material.billboard ? 'none' : material.side;
|
|
797
|
+
if (cull !== this.#cull) {
|
|
798
|
+
if (cull === 'none')
|
|
799
|
+
gl.disable(gl.CULL_FACE);
|
|
800
|
+
else {
|
|
801
|
+
gl.enable(gl.CULL_FACE);
|
|
802
|
+
gl.cullFace(cull === 'back' ? gl.FRONT : gl.BACK);
|
|
803
|
+
}
|
|
804
|
+
this.#cull = cull;
|
|
805
|
+
}
|
|
806
|
+
if (mirrored !== this.#frontCw) {
|
|
807
|
+
gl.frontFace(mirrored ? gl.CW : gl.CCW);
|
|
808
|
+
this.#frontCw = mirrored;
|
|
809
|
+
}
|
|
810
|
+
const depthTest = material.depthTest, depthWrite = shadow || material.depthWrite;
|
|
811
|
+
if (depthTest !== this.#depthTest) {
|
|
812
|
+
if (depthTest)
|
|
813
|
+
gl.enable(gl.DEPTH_TEST);
|
|
814
|
+
else
|
|
815
|
+
gl.disable(gl.DEPTH_TEST);
|
|
816
|
+
this.#depthTest = depthTest;
|
|
817
|
+
}
|
|
818
|
+
if (depthWrite !== this.#depthWrite) {
|
|
819
|
+
gl.depthMask(depthWrite);
|
|
820
|
+
this.#depthWrite = depthWrite;
|
|
821
|
+
}
|
|
822
|
+
if (shadow)
|
|
823
|
+
return;
|
|
824
|
+
const blend = material.alphaMode === 'blend' ? material.blending : 'off';
|
|
825
|
+
if (blend !== this.#blend) {
|
|
826
|
+
if (blend === 'off')
|
|
827
|
+
gl.disable(gl.BLEND);
|
|
828
|
+
else {
|
|
829
|
+
gl.enable(gl.BLEND);
|
|
830
|
+
if (blend === 'additive')
|
|
831
|
+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE, gl.ZERO, gl.ONE);
|
|
832
|
+
else if (blend === 'multiply')
|
|
833
|
+
gl.blendFuncSeparate(gl.DST_COLOR, gl.ZERO, gl.ZERO, gl.ONE);
|
|
834
|
+
else if (blend === 'premultiplied')
|
|
835
|
+
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
836
|
+
else
|
|
837
|
+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
838
|
+
}
|
|
839
|
+
this.#blend = blend;
|
|
840
|
+
}
|
|
841
|
+
const offset = material.polygonOffset;
|
|
842
|
+
if (offset !== this.#offset) {
|
|
843
|
+
if (offset) {
|
|
844
|
+
gl.enable(gl.POLYGON_OFFSET_FILL);
|
|
845
|
+
gl.polygonOffset(offset[0], offset[1]);
|
|
846
|
+
}
|
|
847
|
+
else
|
|
848
|
+
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
849
|
+
this.#offset = offset;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
// ---- drawing -----------------------------------------------------------------
|
|
853
|
+
meshProgramVariant(mesh, geometry, material, variant, morphAttributes) {
|
|
854
|
+
const depthOnly = (variant & V.depthOnly) !== 0;
|
|
855
|
+
const instanced = mesh.isInstanced, skinned = mesh.skeleton !== undefined &&
|
|
856
|
+
geometry.getAttribute('joints') !== undefined &&
|
|
857
|
+
geometry.getAttribute('weights') !== undefined;
|
|
858
|
+
if (geometry.getAttribute('normal'))
|
|
859
|
+
variant |= V.normal;
|
|
860
|
+
// Baked instances already fill the vertex inputs both backends can count on; they do without tangents, vertex colors and second coordinates.
|
|
861
|
+
const baked = mesh instanceof SkinnedInstancedMesh3D && mesh.skeleton === undefined;
|
|
862
|
+
if (geometry.getAttribute('tangent') && !baked)
|
|
863
|
+
variant |= V.tangent;
|
|
864
|
+
if (geometry.getAttribute('uv1') && !baked) {
|
|
865
|
+
variant |= V.uv1;
|
|
866
|
+
// A texture's coordinate set can change without changing the material version.
|
|
867
|
+
if (!depthOnly && material.occlusionMap?.channel === 1)
|
|
868
|
+
variant |= V.occlusionSecond;
|
|
869
|
+
if (!depthOnly && material.emissiveMap?.channel === 1)
|
|
870
|
+
variant |= V.emissiveSecond;
|
|
871
|
+
if (!depthOnly && material.lightMap?.channel === 1)
|
|
872
|
+
variant |= V.lightSecond;
|
|
873
|
+
}
|
|
874
|
+
if (geometry.getAttribute('uv')) {
|
|
875
|
+
variant |= V.uv;
|
|
876
|
+
// A texture can change its source without changing the material version.
|
|
877
|
+
if (!depthOnly && material.map?.source instanceof RenderTarget3D)
|
|
878
|
+
variant |= V.mapFromTarget;
|
|
879
|
+
}
|
|
880
|
+
if (material.vertexColors && geometry.getAttribute('color') && !baked)
|
|
881
|
+
variant |= V.color;
|
|
882
|
+
if (skinned)
|
|
883
|
+
variant |= V.skin;
|
|
884
|
+
if (morphAttributes > 0)
|
|
885
|
+
variant |= V.morph | (morphAttributes === 2 ? V.morphNormals : 0);
|
|
886
|
+
if (instanced)
|
|
887
|
+
variant |= V.instancing | (mesh.instanceColors ? V.instanceColor : 0);
|
|
888
|
+
if (!skinned &&
|
|
889
|
+
mesh instanceof SkinnedInstancedMesh3D &&
|
|
890
|
+
geometry.getAttribute('joints') !== undefined &&
|
|
891
|
+
geometry.getAttribute('weights') !== undefined)
|
|
892
|
+
variant |= V.skinInstancing;
|
|
893
|
+
if (instanced && mesh instanceof GpuParticles3D)
|
|
894
|
+
variant |= V.gpuParticles;
|
|
895
|
+
if (geometry.topology === 'points')
|
|
896
|
+
variant |= V.points;
|
|
897
|
+
if (!depthOnly) {
|
|
898
|
+
if (!(material.softness > 0))
|
|
899
|
+
variant &= ~V.softDepth;
|
|
900
|
+
if (!mesh.receiveShadow)
|
|
901
|
+
variant &= ~V.receiveShadow;
|
|
902
|
+
if (!(material.transmission > 0))
|
|
903
|
+
variant &= ~V.transmission;
|
|
904
|
+
}
|
|
905
|
+
return variant;
|
|
906
|
+
}
|
|
907
|
+
draw(item, frameFlags, depthPass) {
|
|
908
|
+
const depthOnly = depthPass !== undefined, shadow = depthPass === 'shadow';
|
|
909
|
+
const gl = this.#gl, { mesh, geometry, material } = item, resources = this.#resources;
|
|
910
|
+
const gpu = resources.geometry(geometry);
|
|
911
|
+
const flags = depthOnly
|
|
912
|
+
? V.depthOnly
|
|
913
|
+
: frameFlags |
|
|
914
|
+
(this.#sceneDepthReady ? V.softDepth : 0) |
|
|
915
|
+
(this.#shadowCount > 0 ? V.receiveShadow : 0) |
|
|
916
|
+
(this.#grabbed ? V.transmission : 0);
|
|
917
|
+
const variant = this.meshProgramVariant(mesh, geometry, material, flags, gpu.morph?.attributes ?? 0);
|
|
918
|
+
const instanced = (variant & V.instancing) !== 0, skinned = (variant & V.skin) !== 0;
|
|
919
|
+
const crowd = (variant & V.skinInstancing) !== 0 ? mesh : undefined;
|
|
920
|
+
const program = this.selectProgram(material, variant), u = program.uniforms, frame = this.#list.frame;
|
|
921
|
+
if (program !== this.#program) {
|
|
922
|
+
gl.useProgram(program.program);
|
|
923
|
+
this.#program = program;
|
|
924
|
+
}
|
|
925
|
+
// Texture units are shared by all programs, so material state is reapplied
|
|
926
|
+
// whenever either the program or the material differs from the previous draw.
|
|
927
|
+
// In a shadow pass an opaque material without a vertex hook contributes nothing but its
|
|
928
|
+
// program, so casters that share the program need no per-material work.
|
|
929
|
+
const applied = depthOnly && material.alphaMode === 'opaque' && material.shader === undefined ? this.#plainDepth : material;
|
|
930
|
+
if (program !== this.#appliedProgram || applied !== this.#appliedMaterial) {
|
|
931
|
+
this.applyMaterial(program, material, depthOnly);
|
|
932
|
+
this.#appliedProgram = program;
|
|
933
|
+
this.#appliedMaterial = applied;
|
|
934
|
+
}
|
|
935
|
+
if (depthOnly && u['uDepthViewProjection'])
|
|
936
|
+
gl.uniformMatrix4fv(u['uDepthViewProjection'], false, this.#lightMatrix);
|
|
937
|
+
const world = mesh.matrixWorld;
|
|
938
|
+
const determinant = world[0] * (world[5] * world[10] - world[6] * world[9]) -
|
|
939
|
+
world[4] * (world[1] * world[10] - world[2] * world[9]) +
|
|
940
|
+
world[8] * (world[1] * world[6] - world[2] * world[5]);
|
|
941
|
+
this.applyState(material, shadow, determinant < 0 && !skinned);
|
|
942
|
+
if (skinned) {
|
|
943
|
+
const bones = resources.bones(mesh.skeleton, frame);
|
|
944
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.bones);
|
|
945
|
+
gl.bindTexture(gl.TEXTURE_2D, bones);
|
|
946
|
+
if (u['uBindMatrix'])
|
|
947
|
+
gl.uniformMatrix4fv(u['uBindMatrix'], false, mesh.bindMatrix);
|
|
948
|
+
if (u['uModel'])
|
|
949
|
+
gl.uniformMatrix4fv(u['uModel'], false, IDENTITY4);
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
if (crowd) {
|
|
953
|
+
// Creating the table binds another unit, so fetch it before selecting this one.
|
|
954
|
+
const table = resources.animations(crowd.animations);
|
|
955
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.bones);
|
|
956
|
+
gl.bindTexture(gl.TEXTURE_2D, table);
|
|
957
|
+
}
|
|
958
|
+
if (u['uModel'])
|
|
959
|
+
gl.uniformMatrix4fv(u['uModel'], false, world);
|
|
960
|
+
if (u['uNormalMatrix'])
|
|
961
|
+
gl.uniformMatrix3fv(u['uNormalMatrix'], false, mat3NormalFromMat4(this.#scratch9, world));
|
|
962
|
+
}
|
|
963
|
+
if (gpu.morph)
|
|
964
|
+
this.applyMorph(program, mesh, gpu);
|
|
965
|
+
// Baked instances take their morph weights from the table; the shader only needs to know how many targets to read.
|
|
966
|
+
if (gpu.morph && crowd && u['uMorphCount'])
|
|
967
|
+
gl.uniform1i(u['uMorphCount'], Math.min(MAX_MORPH_INFLUENCES_3D, crowd.animations.morphCount, geometry.morphTargets.length));
|
|
968
|
+
const wire = material.wireframe && !shadow && geometry.topology === 'triangles' ? resources.wireframe(geometry) : undefined;
|
|
969
|
+
gl.bindVertexArray(wire ? wire.vao : instanced ? resources.instances(mesh, frame) : gpu.vao);
|
|
970
|
+
const topology = geometry.topology;
|
|
971
|
+
const mode = wire
|
|
972
|
+
? gl.LINES
|
|
973
|
+
: topology === 'triangles'
|
|
974
|
+
? gl.TRIANGLES
|
|
975
|
+
: topology === 'lines'
|
|
976
|
+
? gl.LINES
|
|
977
|
+
: topology === 'line-strip'
|
|
978
|
+
? gl.LINE_STRIP
|
|
979
|
+
: gl.POINTS;
|
|
980
|
+
const instances = mesh instanceof SkinnedInstancedMesh3D ? mesh.drawCount : instanced ? mesh.count : 1;
|
|
981
|
+
if (instances <= 0)
|
|
982
|
+
return;
|
|
983
|
+
if (wire) {
|
|
984
|
+
// Wireframe draws the whole geometry: its edge list is not split by groups.
|
|
985
|
+
if (instanced)
|
|
986
|
+
gl.drawElementsInstanced(mode, wire.count, wire.type, 0, instances);
|
|
987
|
+
else
|
|
988
|
+
gl.drawElements(mode, wire.count, wire.type, 0);
|
|
989
|
+
}
|
|
990
|
+
else if (gpu.indexed) {
|
|
991
|
+
const bytes = gpu.indexType === gl.UNSIGNED_INT ? 4 : gpu.indexType === gl.UNSIGNED_SHORT ? 2 : 1;
|
|
992
|
+
if (instanced)
|
|
993
|
+
gl.drawElementsInstanced(mode, item.count, gpu.indexType, item.start * bytes, instances);
|
|
994
|
+
else
|
|
995
|
+
gl.drawElements(mode, item.count, gpu.indexType, item.start * bytes);
|
|
996
|
+
}
|
|
997
|
+
else if (instanced)
|
|
998
|
+
gl.drawArraysInstanced(mode, item.start, item.count, instances);
|
|
999
|
+
else
|
|
1000
|
+
gl.drawArrays(mode, item.start, item.count);
|
|
1001
|
+
if (this.#viewIndex >= 0)
|
|
1002
|
+
this.#frameMetrics.record(1, mode === gl.TRIANGLES ? Math.floor(item.count / 3) * instances : 0);
|
|
1003
|
+
if (!depthOnly) {
|
|
1004
|
+
this.info.drawCalls++;
|
|
1005
|
+
if (mode === gl.TRIANGLES)
|
|
1006
|
+
this.info.triangles += (item.count / 3) * instances;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
/** Upload the strongest morph influences; the shader blends at most a fixed number. */
|
|
1010
|
+
applyMorph(program, mesh, gpu) {
|
|
1011
|
+
const gl = this.#gl, u = program.uniforms, morph = gpu.morph, weights = mesh.morphWeights;
|
|
1012
|
+
const indices = this.#morphIndices, values = this.#morphWeights;
|
|
1013
|
+
let count = 0;
|
|
1014
|
+
for (let i = 0; i < weights.length; i++) {
|
|
1015
|
+
const weight = weights[i];
|
|
1016
|
+
if (weight === 0)
|
|
1017
|
+
continue;
|
|
1018
|
+
if (count < MAX_MORPH_INFLUENCES_3D) {
|
|
1019
|
+
indices[count] = i;
|
|
1020
|
+
values[count] = weight;
|
|
1021
|
+
count++;
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
// Replace the weakest selected influence when this one is stronger.
|
|
1025
|
+
let weakest = 0;
|
|
1026
|
+
for (let k = 1; k < count; k++)
|
|
1027
|
+
if (Math.abs(values[k]) < Math.abs(values[weakest]))
|
|
1028
|
+
weakest = k;
|
|
1029
|
+
if (Math.abs(weight) > Math.abs(values[weakest])) {
|
|
1030
|
+
indices[weakest] = i;
|
|
1031
|
+
values[weakest] = weight;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.morph);
|
|
1035
|
+
gl.bindTexture(gl.TEXTURE_2D, morph.texture);
|
|
1036
|
+
if (u['uMorphLayout'])
|
|
1037
|
+
gl.uniform3i(u['uMorphLayout'], morph.vertexCount, morph.width, morph.attributes);
|
|
1038
|
+
if (u['uMorphCount'])
|
|
1039
|
+
gl.uniform1i(u['uMorphCount'], count);
|
|
1040
|
+
if (u['uMorphIndices'])
|
|
1041
|
+
gl.uniform1iv(u['uMorphIndices'], indices);
|
|
1042
|
+
if (u['uMorphWeights'])
|
|
1043
|
+
gl.uniform1fv(u['uMorphWeights'], values);
|
|
1044
|
+
}
|
|
1045
|
+
drawSkybox(texture, intensity, camera) {
|
|
1046
|
+
const gl = this.#gl, program = this.#resources.program('skybox', () => SKYBOX_SHADER_3D), u = program.uniforms;
|
|
1047
|
+
gl.useProgram(program.program);
|
|
1048
|
+
this.#program = program;
|
|
1049
|
+
this.#appliedProgram = undefined;
|
|
1050
|
+
this.#resources.bindCube(TEXTURE_UNITS_3D.environment, texture);
|
|
1051
|
+
if (!mat4Invert(this.#scratch16, camera.viewProjectionMatrix))
|
|
1052
|
+
return;
|
|
1053
|
+
if (u['uInverseViewProjection'])
|
|
1054
|
+
gl.uniformMatrix4fv(u['uInverseViewProjection'], false, this.#scratch16);
|
|
1055
|
+
if (u['uOutput'])
|
|
1056
|
+
gl.uniform4f(u['uOutput'], intensity, this.#linearOutput ? 1 : 0, this.exposure, this.#frameToneMapping === 'aces' ? 2 : this.#frameToneMapping === 'reinhard' ? 1 : 0);
|
|
1057
|
+
gl.disable(gl.CULL_FACE);
|
|
1058
|
+
this.#cull = 'none';
|
|
1059
|
+
gl.disable(gl.BLEND);
|
|
1060
|
+
this.#blend = 'off';
|
|
1061
|
+
gl.enable(gl.DEPTH_TEST);
|
|
1062
|
+
this.#depthTest = true;
|
|
1063
|
+
gl.depthMask(false);
|
|
1064
|
+
this.#depthWrite = false;
|
|
1065
|
+
gl.bindVertexArray((this.#emptyVao ??= gl.createVertexArray()));
|
|
1066
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
1067
|
+
if (this.#viewIndex >= 0)
|
|
1068
|
+
this.#frameMetrics.record(1, 1);
|
|
1069
|
+
this.info.drawCalls++;
|
|
1070
|
+
// Restore the scene environment binding the skybox may have replaced.
|
|
1071
|
+
const environment = this.#lastEnvironment;
|
|
1072
|
+
if (environment && environment !== texture)
|
|
1073
|
+
this.#resources.bindCube(TEXTURE_UNITS_3D.environment, environment);
|
|
1074
|
+
}
|
|
1075
|
+
#lastEnvironment;
|
|
1076
|
+
#linearOutput = false;
|
|
1077
|
+
#appliedProgram;
|
|
1078
|
+
#appliedMaterial;
|
|
1079
|
+
assertReadbackAvailable() {
|
|
1080
|
+
if (this.#disposed)
|
|
1081
|
+
throw new World3DError('WORLD3D_DISPOSED', 'renderer');
|
|
1082
|
+
if (this.isContextLost)
|
|
1083
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'readback');
|
|
1084
|
+
}
|
|
1085
|
+
readFramebuffer(framebuffer, x, y, width, height) {
|
|
1086
|
+
const gl = this.#gl, out = new Uint8Array(width * height * 4);
|
|
1087
|
+
const previousRead = gl.getParameter(gl.READ_FRAMEBUFFER_BINDING);
|
|
1088
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, framebuffer);
|
|
1089
|
+
try {
|
|
1090
|
+
gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, out);
|
|
1091
|
+
}
|
|
1092
|
+
finally {
|
|
1093
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, previousRead);
|
|
1094
|
+
}
|
|
1095
|
+
return out;
|
|
1096
|
+
}
|
|
1097
|
+
/** Read back RGBA8 pixels of the last frame; requires preserveDrawingBuffer or a call right after render(). */
|
|
1098
|
+
readPixels(x = 0, y = 0, width = this.#gl.drawingBufferWidth, height = this.#gl.drawingBufferHeight) {
|
|
1099
|
+
this.assertReadbackAvailable();
|
|
1100
|
+
return this.readFramebuffer(null, x, y, width, height);
|
|
1101
|
+
}
|
|
1102
|
+
/** RGBA8 pixels of a render target, top row first. Resolves immediately on WebGL2. */
|
|
1103
|
+
async readRenderTargetPixels(target) {
|
|
1104
|
+
this.assertReadbackAvailable();
|
|
1105
|
+
const width = target.width, height = target.height;
|
|
1106
|
+
if (target.format === 'rgba16f')
|
|
1107
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'half-float targets cannot be read back as bytes');
|
|
1108
|
+
const rows = this.readFramebuffer(this.#resources.target(target).framebuffer, 0, 0, width, height);
|
|
1109
|
+
const out = new Uint8Array(rows.length);
|
|
1110
|
+
// WebGL returns the bottom row first; flip to the shared top-first order.
|
|
1111
|
+
for (let y = 0; y < height; y++)
|
|
1112
|
+
out.set(rows.subarray((height - 1 - y) * width * 4, (height - y) * width * 4), y * width * 4);
|
|
1113
|
+
return out;
|
|
1114
|
+
}
|
|
1115
|
+
clearMaterialPrograms() {
|
|
1116
|
+
for (const entry of this.#materialPrograms.values())
|
|
1117
|
+
entry.unsubscribe();
|
|
1118
|
+
this.#materialPrograms.clear();
|
|
1119
|
+
}
|
|
1120
|
+
/** True when textures in this compressed format can be used on this device. */
|
|
1121
|
+
supportsCompressedFormat(format) {
|
|
1122
|
+
return this.#resources.compressedFormat(format, false) !== undefined;
|
|
1123
|
+
}
|
|
1124
|
+
/** Release every GPU object and detach from the canvas. Idempotent. */
|
|
1125
|
+
dispose() {
|
|
1126
|
+
if (this.#disposed)
|
|
1127
|
+
return;
|
|
1128
|
+
this.#disposed = true;
|
|
1129
|
+
this.#frameMetrics.reset(this.isContextLost);
|
|
1130
|
+
const gl = this.#gl;
|
|
1131
|
+
this.canvas.removeEventListener('webglcontextlost', this.#onLost);
|
|
1132
|
+
this.canvas.removeEventListener('webglcontextrestored', this.#onRestored);
|
|
1133
|
+
this.#list.clear();
|
|
1134
|
+
this.clearMaterialPrograms();
|
|
1135
|
+
if (this.isContextLost) {
|
|
1136
|
+
this.#post?.dispose(true);
|
|
1137
|
+
this.#post = undefined;
|
|
1138
|
+
this.#resources.reset();
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
this.#post?.dispose();
|
|
1142
|
+
this.#post = undefined;
|
|
1143
|
+
this.#resources.dispose();
|
|
1144
|
+
if (this.#frameBuffer)
|
|
1145
|
+
gl.deleteBuffer(this.#frameBuffer);
|
|
1146
|
+
if (this.#tiledTexture)
|
|
1147
|
+
gl.deleteTexture(this.#tiledTexture);
|
|
1148
|
+
this.#tiledTexture = null;
|
|
1149
|
+
if (this.#emptyVao)
|
|
1150
|
+
gl.deleteVertexArray(this.#emptyVao);
|
|
1151
|
+
for (const atlas of [this.#shadowAtlas, this.#shadowFallback]) {
|
|
1152
|
+
if (!atlas)
|
|
1153
|
+
continue;
|
|
1154
|
+
gl.deleteTexture(atlas.texture);
|
|
1155
|
+
gl.deleteFramebuffer(atlas.framebuffer);
|
|
1156
|
+
}
|
|
1157
|
+
this.#shadowAtlas = this.#shadowFallback = undefined;
|
|
1158
|
+
if (this.#grab) {
|
|
1159
|
+
gl.deleteTexture(this.#grab.texture);
|
|
1160
|
+
gl.deleteFramebuffer(this.#grab.framebuffer);
|
|
1161
|
+
this.#grab = undefined;
|
|
1162
|
+
}
|
|
1163
|
+
if (this.#sceneDepth) {
|
|
1164
|
+
gl.deleteTexture(this.#sceneDepth.texture);
|
|
1165
|
+
gl.deleteFramebuffer(this.#sceneDepth.framebuffer);
|
|
1166
|
+
this.#sceneDepth = undefined;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
export function createWebGL2Renderer3D(options) {
|
|
1171
|
+
return new WebGL2Renderer3D(options);
|
|
1172
|
+
}
|
|
1173
|
+
//# sourceMappingURL=WebGL2Renderer3D.js.map
|