@egret/engine 0.0.0-stage → 7.0.2

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.
Files changed (601) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +101 -2
  4. package/README.zh-CN.md +102 -0
  5. package/dist/Engine.d.ts +77 -0
  6. package/dist/Engine.js +469 -0
  7. package/dist/animation/index.d.ts +6 -0
  8. package/dist/animation/index.js +5 -0
  9. package/dist/animation/sequenceController.d.ts +22 -0
  10. package/dist/animation/sequenceController.js +618 -0
  11. package/dist/animation/sequenceCoordinator.d.ts +26 -0
  12. package/dist/animation/sequenceCoordinator.js +161 -0
  13. package/dist/animation/sequenceInput.d.ts +25 -0
  14. package/dist/animation/sequenceInput.js +108 -0
  15. package/dist/animation/sequenceMath.d.ts +35 -0
  16. package/dist/animation/sequenceMath.js +164 -0
  17. package/dist/animation/sequenceResetSlot.d.ts +7 -0
  18. package/dist/animation/sequenceResetSlot.js +367 -0
  19. package/dist/animation/sequenceResetTypes.d.ts +48 -0
  20. package/dist/animation/sequenceResetTypes.js +2 -0
  21. package/dist/animation/types.d.ts +75 -0
  22. package/dist/animation/types.js +2 -0
  23. package/dist/assetBundle.d.ts +54 -0
  24. package/dist/assetBundle.js +173 -0
  25. package/dist/assetGroup.d.ts +17 -0
  26. package/dist/assetGroup.js +332 -0
  27. package/dist/assetGroupTypes.d.ts +17 -0
  28. package/dist/assetGroupTypes.js +2 -0
  29. package/dist/audio.d.ts +4 -0
  30. package/dist/audio.js +4 -0
  31. package/dist/audioCues.d.ts +47 -0
  32. package/dist/audioCues.js +127 -0
  33. package/dist/audioMixer.d.ts +7 -0
  34. package/dist/audioMixer.js +785 -0
  35. package/dist/audioTypes.d.ts +246 -0
  36. package/dist/audioTypes.js +3 -0
  37. package/dist/bitmapBindingTicket.d.ts +24 -0
  38. package/dist/bitmapBindingTicket.js +215 -0
  39. package/dist/bitmapButton.d.ts +4 -0
  40. package/dist/bitmapButton.js +407 -0
  41. package/dist/bitmapButtonTypes.d.ts +31 -0
  42. package/dist/bitmapButtonTypes.js +2 -0
  43. package/dist/bitmapFontParse.d.ts +10 -0
  44. package/dist/bitmapFontParse.js +246 -0
  45. package/dist/bitmapFontTypes.d.ts +112 -0
  46. package/dist/bitmapFontTypes.js +2 -0
  47. package/dist/bitmapResourceSlot.d.ts +26 -0
  48. package/dist/bitmapResourceSlot.js +340 -0
  49. package/dist/bitmapText.d.ts +6 -0
  50. package/dist/bitmapText.js +320 -0
  51. package/dist/bitmapfont.d.ts +5 -0
  52. package/dist/bitmapfont.js +5 -0
  53. package/dist/camera.d.ts +4 -0
  54. package/dist/camera.js +4 -0
  55. package/dist/camera2d.d.ts +7 -0
  56. package/dist/camera2d.js +419 -0
  57. package/dist/cameraTypes.d.ts +126 -0
  58. package/dist/cameraTypes.js +2 -0
  59. package/dist/closeHost.d.ts +4 -0
  60. package/dist/closeHost.js +66 -0
  61. package/dist/contentArtifacts.d.ts +12 -0
  62. package/dist/contentArtifacts.js +153 -0
  63. package/dist/contentAtlasPages.d.ts +13 -0
  64. package/dist/contentAtlasPages.js +117 -0
  65. package/dist/contentLoader.d.ts +6 -0
  66. package/dist/contentLoader.js +327 -0
  67. package/dist/contentTypes.d.ts +35 -0
  68. package/dist/contentTypes.js +2 -0
  69. package/dist/createEngine.d.ts +7 -0
  70. package/dist/createEngine.js +25 -0
  71. package/dist/createEngineForProfile.d.ts +5 -0
  72. package/dist/createEngineForProfile.js +45 -0
  73. package/dist/displaySubtreeTicket.d.ts +25 -0
  74. package/dist/displaySubtreeTicket.js +76 -0
  75. package/dist/fontContentLoader.d.ts +6 -0
  76. package/dist/fontContentLoader.js +298 -0
  77. package/dist/fontContentTypes.d.ts +39 -0
  78. package/dist/fontContentTypes.js +2 -0
  79. package/dist/gameClock.d.ts +24 -0
  80. package/dist/gameClock.js +246 -0
  81. package/dist/gameClockTypes.d.ts +37 -0
  82. package/dist/gameClockTypes.js +2 -0
  83. package/dist/gameRun.d.ts +53 -0
  84. package/dist/gameRun.js +97 -0
  85. package/dist/gamepad.d.ts +5 -0
  86. package/dist/gamepad.js +5 -0
  87. package/dist/gamepadInput.d.ts +4 -0
  88. package/dist/gamepadInput.js +281 -0
  89. package/dist/gamepadKeys.d.ts +4 -0
  90. package/dist/gamepadKeys.js +205 -0
  91. package/dist/gamepadTypes.d.ts +142 -0
  92. package/dist/gamepadTypes.js +3 -0
  93. package/dist/hover.d.ts +4 -0
  94. package/dist/hover.js +4 -0
  95. package/dist/hoverInput.d.ts +8 -0
  96. package/dist/hoverInput.js +503 -0
  97. package/dist/hoverInputTypes.d.ts +129 -0
  98. package/dist/hoverInputTypes.js +2 -0
  99. package/dist/index.d.ts +52 -0
  100. package/dist/index.js +21 -0
  101. package/dist/input.d.ts +6 -0
  102. package/dist/input.js +5 -0
  103. package/dist/inputActions.d.ts +86 -0
  104. package/dist/inputActions.js +330 -0
  105. package/dist/internal/contentFactoryState.d.ts +19 -0
  106. package/dist/internal/contentFactoryState.js +42 -0
  107. package/dist/internal/mouseInputFactoryState.d.ts +57 -0
  108. package/dist/internal/mouseInputFactoryState.js +125 -0
  109. package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
  110. package/dist/internal/sequenceControllerFactoryState.js +98 -0
  111. package/dist/internal/textFieldFactoryState.d.ts +11 -0
  112. package/dist/internal/textFieldFactoryState.js +32 -0
  113. package/dist/internal/texturedFrameState.d.ts +4 -0
  114. package/dist/internal/texturedFrameState.js +12 -0
  115. package/dist/internal/uiFactoryState.d.ts +68 -0
  116. package/dist/internal/uiFactoryState.js +173 -0
  117. package/dist/internal/uiRootState.d.ts +67 -0
  118. package/dist/internal/uiRootState.js +103 -0
  119. package/dist/keyboardInput.d.ts +13 -0
  120. package/dist/keyboardInput.js +579 -0
  121. package/dist/keyboardInputTypes.d.ts +93 -0
  122. package/dist/keyboardInputTypes.js +2 -0
  123. package/dist/kit.d.ts +16 -0
  124. package/dist/kit.js +10 -0
  125. package/dist/layout.d.ts +5 -0
  126. package/dist/layout.js +132 -0
  127. package/dist/layoutTypes.d.ts +28 -0
  128. package/dist/layoutTypes.js +2 -0
  129. package/dist/manifestAssetGroup.d.ts +10 -0
  130. package/dist/manifestAssetGroup.js +477 -0
  131. package/dist/manifestResourceState.d.ts +17 -0
  132. package/dist/manifestResourceState.js +58 -0
  133. package/dist/manifestResourceTypes.d.ts +26 -0
  134. package/dist/manifestResourceTypes.js +2 -0
  135. package/dist/motion.d.ts +35 -0
  136. package/dist/motion.js +206 -0
  137. package/dist/mouseInput.d.ts +102 -0
  138. package/dist/mouseInput.js +562 -0
  139. package/dist/mouseInputTypes.d.ts +41 -0
  140. package/dist/mouseInputTypes.js +2 -0
  141. package/dist/paragraph.d.ts +8 -0
  142. package/dist/paragraph.js +7 -0
  143. package/dist/particleEmitter.d.ts +4 -0
  144. package/dist/particleEmitter.js +300 -0
  145. package/dist/particleTypes.d.ts +115 -0
  146. package/dist/particleTypes.js +2 -0
  147. package/dist/particles.d.ts +4 -0
  148. package/dist/particles.js +4 -0
  149. package/dist/physics2d.d.ts +4 -0
  150. package/dist/physics2d.js +4 -0
  151. package/dist/physics2dGeometry.d.ts +39 -0
  152. package/dist/physics2dGeometry.js +230 -0
  153. package/dist/physics2dTypes.d.ts +221 -0
  154. package/dist/physics2dTypes.js +2 -0
  155. package/dist/physics2dWorld.d.ts +4 -0
  156. package/dist/physics2dWorld.js +823 -0
  157. package/dist/pointerInput.d.ts +12 -0
  158. package/dist/pointerInput.js +300 -0
  159. package/dist/pointerInputTypes.d.ts +41 -0
  160. package/dist/pointerInputTypes.js +2 -0
  161. package/dist/random.d.ts +30 -0
  162. package/dist/random.js +131 -0
  163. package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
  164. package/dist/rendering/ownedPreparationFailure2D.js +33 -0
  165. package/dist/rendering/packSharedDraws2D.d.ts +50 -0
  166. package/dist/rendering/packSharedDraws2D.js +379 -0
  167. package/dist/rendering/packedOrientation.d.ts +4 -0
  168. package/dist/rendering/packedOrientation.js +7 -0
  169. package/dist/rendering/prepareRectangles2D.d.ts +92 -0
  170. package/dist/rendering/prepareRectangles2D.js +481 -0
  171. package/dist/rendering/prepareSharedDraws2D.d.ts +90 -0
  172. package/dist/rendering/prepareSharedDraws2D.js +663 -0
  173. package/dist/rendering/preparedBatches2D.d.ts +17 -0
  174. package/dist/rendering/preparedBatches2D.js +30 -0
  175. package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
  176. package/dist/rendering/preparedSharedBatches2D.js +247 -0
  177. package/dist/rendering/sharedColor2D.d.ts +52 -0
  178. package/dist/rendering/sharedColor2D.js +191 -0
  179. package/dist/rendering/sharedEffects2D.d.ts +23 -0
  180. package/dist/rendering/sharedEffects2D.js +126 -0
  181. package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
  182. package/dist/rendering/sharedPreparationRetention2D.js +357 -0
  183. package/dist/rendering/srgbBytes.d.ts +3 -0
  184. package/dist/rendering/srgbBytes.js +64 -0
  185. package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
  186. package/dist/rendering/texturedPreparationBudget2D.js +81 -0
  187. package/dist/rendering/world3d/Animation3D.d.ts +104 -0
  188. package/dist/rendering/world3d/Animation3D.js +384 -0
  189. package/dist/rendering/world3d/AnimationTexture3D.d.ts +163 -0
  190. package/dist/rendering/world3d/AnimationTexture3D.js +603 -0
  191. package/dist/rendering/world3d/Batch3D.d.ts +75 -0
  192. package/dist/rendering/world3d/Batch3D.js +332 -0
  193. package/dist/rendering/world3d/Camera3D.d.ts +62 -0
  194. package/dist/rendering/world3d/Camera3D.js +132 -0
  195. package/dist/rendering/world3d/Character3D.d.ts +127 -0
  196. package/dist/rendering/world3d/Character3D.js +305 -0
  197. package/dist/rendering/world3d/Cloth3D.d.ts +130 -0
  198. package/dist/rendering/world3d/Cloth3D.js +503 -0
  199. package/dist/rendering/world3d/Compression3D.d.ts +22 -0
  200. package/dist/rendering/world3d/Compression3D.js +703 -0
  201. package/dist/rendering/world3d/Curves3D.d.ts +119 -0
  202. package/dist/rendering/world3d/Curves3D.js +460 -0
  203. package/dist/rendering/world3d/Decal3D.d.ts +43 -0
  204. package/dist/rendering/world3d/Decal3D.js +242 -0
  205. package/dist/rendering/world3d/Export3D.d.ts +13 -0
  206. package/dist/rendering/world3d/Export3D.js +263 -0
  207. package/dist/rendering/world3d/Geometry3D.d.ts +95 -0
  208. package/dist/rendering/world3d/Geometry3D.js +335 -0
  209. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +53 -0
  210. package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
  211. package/dist/rendering/world3d/Gizmo3D.d.ts +80 -0
  212. package/dist/rendering/world3d/Gizmo3D.js +514 -0
  213. package/dist/rendering/world3d/Gltf3D.d.ts +73 -0
  214. package/dist/rendering/world3d/Gltf3D.js +996 -0
  215. package/dist/rendering/world3d/GpuParticles3D.d.ts +109 -0
  216. package/dist/rendering/world3d/GpuParticles3D.js +401 -0
  217. package/dist/rendering/world3d/Hdr3D.d.ts +35 -0
  218. package/dist/rendering/world3d/Hdr3D.js +191 -0
  219. package/dist/rendering/world3d/Jelly3D.d.ts +77 -0
  220. package/dist/rendering/world3d/Jelly3D.js +267 -0
  221. package/dist/rendering/world3d/Ktx23D.d.ts +30 -0
  222. package/dist/rendering/world3d/Ktx23D.js +112 -0
  223. package/dist/rendering/world3d/Light3D.d.ts +84 -0
  224. package/dist/rendering/world3d/Light3D.js +97 -0
  225. package/dist/rendering/world3d/Material3D.d.ts +253 -0
  226. package/dist/rendering/world3d/Material3D.js +269 -0
  227. package/dist/rendering/world3d/Mesh3D.d.ts +112 -0
  228. package/dist/rendering/world3d/Mesh3D.js +337 -0
  229. package/dist/rendering/world3d/Meshopt3D.d.ts +15 -0
  230. package/dist/rendering/world3d/Meshopt3D.js +276 -0
  231. package/dist/rendering/world3d/Navigation3D.d.ts +213 -0
  232. package/dist/rendering/world3d/Navigation3D.js +1043 -0
  233. package/dist/rendering/world3d/Object3D.d.ts +118 -0
  234. package/dist/rendering/world3d/Object3D.js +315 -0
  235. package/dist/rendering/world3d/Particles3D.d.ts +90 -0
  236. package/dist/rendering/world3d/Particles3D.js +277 -0
  237. package/dist/rendering/world3d/Physics3D.d.ts +430 -0
  238. package/dist/rendering/world3d/Physics3D.js +2840 -0
  239. package/dist/rendering/world3d/PhysicsHull3D.d.ts +37 -0
  240. package/dist/rendering/world3d/PhysicsHull3D.js +229 -0
  241. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +41 -0
  242. package/dist/rendering/world3d/PhysicsMesh3D.js +340 -0
  243. package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
  244. package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
  245. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +179 -0
  246. package/dist/rendering/world3d/PhysicsRemote3D.js +536 -0
  247. package/dist/rendering/world3d/Ragdoll3D.d.ts +74 -0
  248. package/dist/rendering/world3d/Ragdoll3D.js +202 -0
  249. package/dist/rendering/world3d/Raycast3D.d.ts +40 -0
  250. package/dist/rendering/world3d/Raycast3D.js +247 -0
  251. package/dist/rendering/world3d/RenderList3D.d.ts +91 -0
  252. package/dist/rendering/world3d/RenderList3D.js +502 -0
  253. package/dist/rendering/world3d/Retarget3D.d.ts +21 -0
  254. package/dist/rendering/world3d/Retarget3D.js +185 -0
  255. package/dist/rendering/world3d/Rig3D.d.ts +57 -0
  256. package/dist/rendering/world3d/Rig3D.js +219 -0
  257. package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
  258. package/dist/rendering/world3d/Sdf3D.js +1136 -0
  259. package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
  260. package/dist/rendering/world3d/SdfLod3D.js +56 -0
  261. package/dist/rendering/world3d/Serialize3D.d.ts +66 -0
  262. package/dist/rendering/world3d/Serialize3D.js +629 -0
  263. package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
  264. package/dist/rendering/world3d/Simplify3D.js +426 -0
  265. package/dist/rendering/world3d/StateMachine3D.d.ts +87 -0
  266. package/dist/rendering/world3d/StateMachine3D.js +280 -0
  267. package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
  268. package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
  269. package/dist/rendering/world3d/Terrain3D.d.ts +248 -0
  270. package/dist/rendering/world3d/Terrain3D.js +827 -0
  271. package/dist/rendering/world3d/Text3D.d.ts +95 -0
  272. package/dist/rendering/world3d/Text3D.js +560 -0
  273. package/dist/rendering/world3d/Texture3D.d.ts +148 -0
  274. package/dist/rendering/world3d/Texture3D.js +270 -0
  275. package/dist/rendering/world3d/Trail3D.d.ts +62 -0
  276. package/dist/rendering/world3d/Trail3D.js +195 -0
  277. package/dist/rendering/world3d/Vehicle3D.d.ts +102 -0
  278. package/dist/rendering/world3d/Vehicle3D.js +228 -0
  279. package/dist/rendering/world3d/VolumetricFog3D.d.ts +57 -0
  280. package/dist/rendering/world3d/VolumetricFog3D.js +230 -0
  281. package/dist/rendering/world3d/Water3D.d.ts +165 -0
  282. package/dist/rendering/world3d/Water3D.js +607 -0
  283. package/dist/rendering/world3d/core3D.d.ts +36 -0
  284. package/dist/rendering/world3d/core3D.js +99 -0
  285. package/dist/rendering/world3d/debug3D.d.ts +69 -0
  286. package/dist/rendering/world3d/debug3D.js +262 -0
  287. package/dist/rendering/world3d/decoders3D.d.ts +42 -0
  288. package/dist/rendering/world3d/decoders3D.js +133 -0
  289. package/dist/rendering/world3d/geometries3D.d.ts +111 -0
  290. package/dist/rendering/world3d/geometries3D.js +610 -0
  291. package/dist/rendering/world3d/helpers3D.d.ts +67 -0
  292. package/dist/rendering/world3d/helpers3D.js +178 -0
  293. package/dist/rendering/world3d/index.d.ts +103 -0
  294. package/dist/rendering/world3d/index.js +62 -0
  295. package/dist/rendering/world3d/math3D.d.ts +114 -0
  296. package/dist/rendering/world3d/math3D.js +675 -0
  297. package/dist/rendering/world3d/primitives3D.d.ts +67 -0
  298. package/dist/rendering/world3d/primitives3D.js +197 -0
  299. package/dist/resources.d.ts +8 -0
  300. package/dist/resources.js +6 -0
  301. package/dist/saveStore.d.ts +71 -0
  302. package/dist/saveStore.js +182 -0
  303. package/dist/semanticList.d.ts +126 -0
  304. package/dist/semanticList.js +175 -0
  305. package/dist/semanticTree.d.ts +10 -0
  306. package/dist/semanticTree.js +539 -0
  307. package/dist/semanticTypes.d.ts +175 -0
  308. package/dist/semanticTypes.js +2 -0
  309. package/dist/semantics.d.ts +6 -0
  310. package/dist/semantics.js +5 -0
  311. package/dist/sequencePlayback.d.ts +19 -0
  312. package/dist/sequencePlayback.js +391 -0
  313. package/dist/sequencePlaybackTypes.d.ts +24 -0
  314. package/dist/sequencePlaybackTypes.js +2 -0
  315. package/dist/sequenceTargetClaims.d.ts +10 -0
  316. package/dist/sequenceTargetClaims.js +31 -0
  317. package/dist/srgbBytes.d.ts +3 -0
  318. package/dist/srgbBytes.js +64 -0
  319. package/dist/startEngine.d.ts +5 -0
  320. package/dist/startEngine.js +31 -0
  321. package/dist/surfaceOwnership.d.ts +3 -0
  322. package/dist/surfaceOwnership.js +15 -0
  323. package/dist/text.d.ts +24 -0
  324. package/dist/text.js +4 -0
  325. package/dist/textField.d.ts +6 -0
  326. package/dist/textField.js +6 -0
  327. package/dist/textTable.d.ts +41 -0
  328. package/dist/textTable.js +114 -0
  329. package/dist/tileMapDraw.d.ts +7 -0
  330. package/dist/tileMapDraw.js +310 -0
  331. package/dist/tiledImport.d.ts +9 -0
  332. package/dist/tiledImport.js +357 -0
  333. package/dist/tilemap.d.ts +5 -0
  334. package/dist/tilemap.js +5 -0
  335. package/dist/tilemapTypes.d.ts +182 -0
  336. package/dist/tilemapTypes.js +2 -0
  337. package/dist/timer.d.ts +34 -0
  338. package/dist/timer.js +119 -0
  339. package/dist/tween.d.ts +15 -0
  340. package/dist/tween.js +329 -0
  341. package/dist/tweenTypes.d.ts +31 -0
  342. package/dist/tweenTypes.js +2 -0
  343. package/dist/ui/controlKeys.d.ts +113 -0
  344. package/dist/ui/controlKeys.js +250 -0
  345. package/dist/ui/controls.d.ts +58 -0
  346. package/dist/ui/controls.js +290 -0
  347. package/dist/ui/editing.d.ts +3 -0
  348. package/dist/ui/editing.js +3 -0
  349. package/dist/ui/index.d.ts +19 -0
  350. package/dist/ui/index.js +11 -0
  351. package/dist/ui/keyboardFocus.d.ts +32 -0
  352. package/dist/ui/keyboardFocus.js +146 -0
  353. package/dist/ui/layerTypes.d.ts +98 -0
  354. package/dist/ui/layerTypes.js +2 -0
  355. package/dist/ui/layers.d.ts +4 -0
  356. package/dist/ui/layers.js +586 -0
  357. package/dist/ui/leafContent.d.ts +21 -0
  358. package/dist/ui/leafContent.js +136 -0
  359. package/dist/ui/rangeControl.d.ts +53 -0
  360. package/dist/ui/rangeControl.js +168 -0
  361. package/dist/ui/scrollControl.d.ts +84 -0
  362. package/dist/ui/scrollControl.js +222 -0
  363. package/dist/ui/stateControls.d.ts +90 -0
  364. package/dist/ui/stateControls.js +331 -0
  365. package/dist/ui/textEditor.d.ts +54 -0
  366. package/dist/ui/textEditor.js +371 -0
  367. package/dist/ui/textEditorTypes.d.ts +85 -0
  368. package/dist/ui/textEditorTypes.js +2 -0
  369. package/dist/ui/textFieldControl.d.ts +100 -0
  370. package/dist/ui/textFieldControl.js +260 -0
  371. package/dist/ui/theme.d.ts +64 -0
  372. package/dist/ui/theme.js +166 -0
  373. package/dist/ui/types.d.ts +285 -0
  374. package/dist/ui/types.js +2 -0
  375. package/dist/ui/uiRoot.d.ts +4 -0
  376. package/dist/ui/uiRoot.js +1526 -0
  377. package/dist/ui/uiRootDisplay.d.ts +46 -0
  378. package/dist/ui/uiRootDisplay.js +148 -0
  379. package/dist/ui/uiRootModel.d.ts +114 -0
  380. package/dist/ui/uiRootModel.js +66 -0
  381. package/dist/ui/virtualList.d.ts +20 -0
  382. package/dist/ui/virtualList.js +105 -0
  383. package/dist/video.d.ts +4 -0
  384. package/dist/video.js +4 -0
  385. package/dist/videoPlayer.d.ts +4 -0
  386. package/dist/videoPlayer.js +215 -0
  387. package/dist/videoTypes.d.ts +77 -0
  388. package/dist/videoTypes.js +2 -0
  389. package/dist/web/BrowserAssetBundle.d.ts +41 -0
  390. package/dist/web/BrowserAssetBundle.js +136 -0
  391. package/dist/web/BrowserAudio.d.ts +74 -0
  392. package/dist/web/BrowserAudio.js +503 -0
  393. package/dist/web/BrowserFrameLoop.d.ts +69 -0
  394. package/dist/web/BrowserFrameLoop.js +125 -0
  395. package/dist/web/BrowserGame.d.ts +174 -0
  396. package/dist/web/BrowserGame.js +473 -0
  397. package/dist/web/BrowserGamepadInput.d.ts +38 -0
  398. package/dist/web/BrowserGamepadInput.js +134 -0
  399. package/dist/web/BrowserHoverInput.d.ts +25 -0
  400. package/dist/web/BrowserHoverInput.js +266 -0
  401. package/dist/web/BrowserImageTextures.d.ts +72 -0
  402. package/dist/web/BrowserImageTextures.js +169 -0
  403. package/dist/web/BrowserInputActions.d.ts +63 -0
  404. package/dist/web/BrowserInputActions.js +345 -0
  405. package/dist/web/BrowserKeyboardInput.d.ts +4 -0
  406. package/dist/web/BrowserKeyboardInput.js +223 -0
  407. package/dist/web/BrowserPlay.d.ts +417 -0
  408. package/dist/web/BrowserPlay.js +1648 -0
  409. package/dist/web/BrowserPointerInput.d.ts +4 -0
  410. package/dist/web/BrowserPointerInput.js +511 -0
  411. package/dist/web/BrowserPreferences.d.ts +10 -0
  412. package/dist/web/BrowserPreferences.js +39 -0
  413. package/dist/web/BrowserSemantics.d.ts +36 -0
  414. package/dist/web/BrowserSemantics.js +418 -0
  415. package/dist/web/BrowserStatsPanel.d.ts +56 -0
  416. package/dist/web/BrowserStatsPanel.js +143 -0
  417. package/dist/web/BrowserStorage.d.ts +35 -0
  418. package/dist/web/BrowserStorage.js +132 -0
  419. package/dist/web/BrowserTextEditor.d.ts +52 -0
  420. package/dist/web/BrowserTextEditor.js +839 -0
  421. package/dist/web/BrowserTextInput.d.ts +89 -0
  422. package/dist/web/BrowserTextInput.js +524 -0
  423. package/dist/web/BrowserTextureProvider.d.ts +58 -0
  424. package/dist/web/BrowserTextureProvider.js +935 -0
  425. package/dist/web/BrowserVideo.d.ts +40 -0
  426. package/dist/web/BrowserVideo.js +237 -0
  427. package/dist/web/CanvasKitFontSetProvider.d.ts +32 -0
  428. package/dist/web/CanvasKitFontSetProvider.js +215 -0
  429. package/dist/web/CanvasKitParagraphProvider.d.ts +173 -0
  430. package/dist/web/CanvasKitParagraphProvider.js +692 -0
  431. package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
  432. package/dist/web/CanvasTextRasterProvider.js +312 -0
  433. package/dist/web/ManifestByteSource.d.ts +151 -0
  434. package/dist/web/ManifestByteSource.js +975 -0
  435. package/dist/web/ManifestFontContentLoader.d.ts +13 -0
  436. package/dist/web/ManifestFontContentLoader.js +30 -0
  437. package/dist/web/MouseInput.d.ts +4 -0
  438. package/dist/web/MouseInput.js +218 -0
  439. package/dist/web/WebGL2Host.d.ts +5 -0
  440. package/dist/web/WebGL2Host.js +2711 -0
  441. package/dist/web/WebGPUHost.d.ts +100 -0
  442. package/dist/web/WebGPUHost.js +3430 -0
  443. package/dist/web/audio.d.ts +3 -0
  444. package/dist/web/audio.js +4 -0
  445. package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
  446. package/dist/web/canvasKitParagraphGeometry.js +83 -0
  447. package/dist/web/editing.d.ts +5 -0
  448. package/dist/web/editing.js +4 -0
  449. package/dist/web/editorFonts.d.ts +54 -0
  450. package/dist/web/editorFonts.js +297 -0
  451. package/dist/web/game.d.ts +5 -0
  452. package/dist/web/game.js +6 -0
  453. package/dist/web/gamepad.d.ts +3 -0
  454. package/dist/web/gamepad.js +4 -0
  455. package/dist/web/hover.d.ts +3 -0
  456. package/dist/web/hover.js +4 -0
  457. package/dist/web/image.d.ts +4 -0
  458. package/dist/web/image.js +4 -0
  459. package/dist/web/imageProjections2D.d.ts +16 -0
  460. package/dist/web/imageProjections2D.js +2 -0
  461. package/dist/web/input.d.ts +6 -0
  462. package/dist/web/input.js +4 -0
  463. package/dist/web/keyboard.d.ts +3 -0
  464. package/dist/web/keyboard.js +3 -0
  465. package/dist/web/kit.d.ts +11 -0
  466. package/dist/web/kit.js +8 -0
  467. package/dist/web/loop.d.ts +3 -0
  468. package/dist/web/loop.js +4 -0
  469. package/dist/web/paragraph.d.ts +6 -0
  470. package/dist/web/paragraph.js +4 -0
  471. package/dist/web/play.d.ts +10 -0
  472. package/dist/web/play.js +9 -0
  473. package/dist/web/playMusic.d.ts +33 -0
  474. package/dist/web/playMusic.js +194 -0
  475. package/dist/web/playSfx.d.ts +36 -0
  476. package/dist/web/playSfx.js +112 -0
  477. package/dist/web/playTouch.d.ts +45 -0
  478. package/dist/web/playTouch.js +141 -0
  479. package/dist/web/playWidgets.d.ts +71 -0
  480. package/dist/web/playWidgets.js +431 -0
  481. package/dist/web/pointer.d.ts +3 -0
  482. package/dist/web/pointer.js +3 -0
  483. package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
  484. package/dist/web/prepareSharedSubmission2D.js +63 -0
  485. package/dist/web/resources.d.ts +29 -0
  486. package/dist/web/resources.js +96 -0
  487. package/dist/web/semantics.d.ts +3 -0
  488. package/dist/web/semantics.js +4 -0
  489. package/dist/web/sharedDeviceSession.d.ts +64 -0
  490. package/dist/web/sharedDeviceSession.js +2 -0
  491. package/dist/web/sharedEffectShaders.d.ts +13 -0
  492. package/dist/web/sharedEffectShaders.js +181 -0
  493. package/dist/web/sharedFrameUpload.d.ts +25 -0
  494. package/dist/web/sharedFrameUpload.js +2 -0
  495. package/dist/web/sharedHostDeferred.d.ts +7 -0
  496. package/dist/web/sharedHostDeferred.js +12 -0
  497. package/dist/web/sharedRetentionLedger.d.ts +85 -0
  498. package/dist/web/sharedRetentionLedger.js +391 -0
  499. package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
  500. package/dist/web/sharedSubmissionStorage2D.js +73 -0
  501. package/dist/web/sharedWebGL2Arena.d.ts +40 -0
  502. package/dist/web/sharedWebGL2Arena.js +77 -0
  503. package/dist/web/sharedWebGL2Options.d.ts +33 -0
  504. package/dist/web/sharedWebGL2Options.js +102 -0
  505. package/dist/web/sharedWebGL2Shaders.d.ts +33 -0
  506. package/dist/web/sharedWebGL2Shaders.js +408 -0
  507. package/dist/web/sharedWebGPUOptions.d.ts +41 -0
  508. package/dist/web/sharedWebGPUOptions.js +130 -0
  509. package/dist/web/text.d.ts +3 -0
  510. package/dist/web/text.js +3 -0
  511. package/dist/web/textInput.d.ts +3 -0
  512. package/dist/web/textInput.js +3 -0
  513. package/dist/web/video.d.ts +3 -0
  514. package/dist/web/video.js +4 -0
  515. package/dist/web/webgl2.d.ts +7 -0
  516. package/dist/web/webgl2.js +4 -0
  517. package/dist/web/webgl2LayerState.d.ts +50 -0
  518. package/dist/web/webgl2LayerState.js +102 -0
  519. package/dist/web/webgl2Native.d.ts +72 -0
  520. package/dist/web/webgl2Native.js +572 -0
  521. package/dist/web/webgl2Types.d.ts +150 -0
  522. package/dist/web/webgl2Types.js +2 -0
  523. package/dist/web/webgpu.d.ts +6 -0
  524. package/dist/web/webgpu.js +2 -0
  525. package/dist/web/webgpuBindingCache.d.ts +26 -0
  526. package/dist/web/webgpuBindingCache.js +223 -0
  527. package/dist/web/webgpuBufferPool.d.ts +51 -0
  528. package/dist/web/webgpuBufferPool.js +58 -0
  529. package/dist/web/webgpuImageResidency.d.ts +56 -0
  530. package/dist/web/webgpuImageResidency.js +65 -0
  531. package/dist/web/webgpuLifetime.d.ts +45 -0
  532. package/dist/web/webgpuLifetime.js +64 -0
  533. package/dist/web/webgpuRetentionPool.d.ts +66 -0
  534. package/dist/web/webgpuRetentionPool.js +85 -0
  535. package/dist/web/webgpuSharedPass.d.ts +7 -0
  536. package/dist/web/webgpuSharedPass.js +293 -0
  537. package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
  538. package/dist/web/webgpuSharedResolvePass.js +34 -0
  539. package/dist/web/world3d/Audio3D.d.ts +85 -0
  540. package/dist/web/world3d/Audio3D.js +271 -0
  541. package/dist/web/world3d/BrowserPlay3D.d.ts +295 -0
  542. package/dist/web/world3d/BrowserPlay3D.js +1256 -0
  543. package/dist/web/world3d/FlyControls3D.d.ts +59 -0
  544. package/dist/web/world3d/FlyControls3D.js +162 -0
  545. package/dist/web/world3d/FollowControls3D.d.ts +31 -0
  546. package/dist/web/world3d/FollowControls3D.js +119 -0
  547. package/dist/web/world3d/OrbitControls3D.d.ts +58 -0
  548. package/dist/web/world3d/OrbitControls3D.js +189 -0
  549. package/dist/web/world3d/TransformControls3D.d.ts +37 -0
  550. package/dist/web/world3d/TransformControls3D.js +128 -0
  551. package/dist/web/world3d/WebGL2Renderer3D.d.ts +136 -0
  552. package/dist/web/world3d/WebGL2Renderer3D.js +1175 -0
  553. package/dist/web/world3d/WebGPURenderer3D.d.ts +112 -0
  554. package/dist/web/world3d/WebGPURenderer3D.js +1916 -0
  555. package/dist/web/world3d/World3DView.d.ts +54 -0
  556. package/dist/web/world3d/World3DView.js +79 -0
  557. package/dist/web/world3d/app3D.d.ts +143 -0
  558. package/dist/web/world3d/app3D.js +305 -0
  559. package/dist/web/world3d/assets3D.d.ts +39 -0
  560. package/dist/web/world3d/assets3D.js +112 -0
  561. package/dist/web/world3d/atmosphere3D.d.ts +56 -0
  562. package/dist/web/world3d/atmosphere3D.js +193 -0
  563. package/dist/web/world3d/canvasFont3D.d.ts +21 -0
  564. package/dist/web/world3d/canvasFont3D.js +165 -0
  565. package/dist/web/world3d/frame3D.d.ts +144 -0
  566. package/dist/web/world3d/frame3D.js +388 -0
  567. package/dist/web/world3d/gpuResources3D.d.ts +98 -0
  568. package/dist/web/world3d/gpuResources3D.js +901 -0
  569. package/dist/web/world3d/host3D.d.ts +24 -0
  570. package/dist/web/world3d/host3D.js +61 -0
  571. package/dist/web/world3d/index.d.ts +40 -0
  572. package/dist/web/world3d/index.js +24 -0
  573. package/dist/web/world3d/loaders3D.d.ts +27 -0
  574. package/dist/web/world3d/loaders3D.js +138 -0
  575. package/dist/web/world3d/markers3D.d.ts +53 -0
  576. package/dist/web/world3d/markers3D.js +130 -0
  577. package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
  578. package/dist/web/world3d/materialWebGL23D.js +218 -0
  579. package/dist/web/world3d/overlay3D.d.ts +47 -0
  580. package/dist/web/world3d/overlay3D.js +187 -0
  581. package/dist/web/world3d/post3D.d.ts +116 -0
  582. package/dist/web/world3d/post3D.js +462 -0
  583. package/dist/web/world3d/postWebGL23D.d.ts +24 -0
  584. package/dist/web/world3d/postWebGL23D.js +237 -0
  585. package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
  586. package/dist/web/world3d/postWebGPU3D.js +255 -0
  587. package/dist/web/world3d/probe3D.d.ts +15 -0
  588. package/dist/web/world3d/probe3D.js +66 -0
  589. package/dist/web/world3d/shaders3D.d.ts +43 -0
  590. package/dist/web/world3d/shaders3D.js +851 -0
  591. package/dist/web/world3d/stats3D.d.ts +34 -0
  592. package/dist/web/world3d/stats3D.js +81 -0
  593. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +71 -0
  594. package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
  595. package/dist/web/world3d/webgpu.d.ts +37 -0
  596. package/dist/web/world3d/webgpu.js +23 -0
  597. package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
  598. package/dist/web/world3d/webgpuPacking3D.js +85 -0
  599. package/dist/web/world3d/wgsl3D.d.ts +68 -0
  600. package/dist/web/world3d/wgsl3D.js +781 -0
  601. package/package.json +220 -4
@@ -0,0 +1,851 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // First-party GLSL ES 3.00 shader library for the WebGL2 world3d renderer.
3
+ // One vertex and one fragment source are specialized through #define lists,
4
+ // so every material variant shares the same attribute and uniform contract.
5
+ /** Fixed vertex attribute locations shared by every program and vertex array. */
6
+ export const ATTRIBUTE_LOCATIONS_3D = Object.freeze({
7
+ position: 0,
8
+ normal: 1,
9
+ uv: 2,
10
+ tangent: 3,
11
+ color: 4,
12
+ joints: 5,
13
+ weights: 6,
14
+ uv1: 7,
15
+ instanceMatrix: 8,
16
+ instanceColor: 12,
17
+ instanceAnimation: 13,
18
+ instanceAnimation2: 14,
19
+ instanceLook: 15
20
+ });
21
+ /** Fixed texture units; samplers are assigned once when a program is linked. */
22
+ export const TEXTURE_UNITS_3D = Object.freeze({
23
+ map: 0,
24
+ normalMap: 1,
25
+ metallicRoughnessMap: 2,
26
+ occlusionMap: 3,
27
+ emissiveMap: 4,
28
+ environment: 5,
29
+ shadow: 6,
30
+ bones: 7,
31
+ morph: 8,
32
+ lightMap: 9,
33
+ sceneColor: 10,
34
+ reflectionMap: 11,
35
+ sceneDepth: 12,
36
+ tiledLights: 13
37
+ });
38
+ export const MAX_MORPH_INFLUENCES_3D = 8;
39
+ const FRAME_BLOCK = /* glsl */ `
40
+ layout(std140) uniform Frame {
41
+ mat4 uViewProjection;
42
+ mat4 uView;
43
+ vec4 uCameraPosition;
44
+ vec4 uFogColor;
45
+ vec4 uFogParams; // x: 0 none, 1 linear, 2 exponential; y: near or density; z: far
46
+ vec4 uAmbient;
47
+ vec4 uHemisphereSky;
48
+ vec4 uHemisphereGround;
49
+ vec4 uLightCounts; // directional, point, spot
50
+ vec4 uDirectionalDirection[4]; // xyz: travel direction; w: shadow slot or -1
51
+ vec4 uDirectionalColor[4];
52
+ vec4 uPointPosition[8]; // w: range, 0 = unbounded
53
+ vec4 uPointColor[8];
54
+ vec4 uSpotPosition[4]; // w: range
55
+ vec4 uSpotDirection[4]; // w: shadow slot or -1
56
+ vec4 uSpotColor[4];
57
+ vec4 uSpotCone[4]; // x: cos(outer), y: cos(inner)
58
+ mat4 uShadowMatrix[4];
59
+ vec4 uShadowRect[4]; // atlas uv offset (xy) and scale (zw)
60
+ vec4 uShadowParams[4]; // x: depth bias, y: normal bias, z: filter radius in atlas uv
61
+ vec4 uOutput; // x: environment intensity, y: environment max mip, z: exposure, w: tone mapping
62
+ vec4 uCascadeSplits; // view-space far distance of each cascade
63
+ vec4 uCascadeInfo; // x: cascaded directional light index or -1, y: cascade count, z: blend fraction
64
+ vec4 uPointShadow; // x: shadowed point light index or -1, y: first of its four slots
65
+ vec4 uClipPlanes[4]; // world-space planes; the negative side is discarded
66
+ vec4 uClipInfo; // x: plane count; zw: share of the output the view covers
67
+ vec4 uTileGrid; // tiles across, tiles down, tile edge in pixels, viewport origin x
68
+ vec4 uTileInfo; // x: tiled point lights (0 = none), y: header base, z: index base, w: viewport origin y
69
+ };
70
+ `;
71
+ const VERTEX_SOURCE = /* glsl */ `
72
+ layout(location = 0) in vec3 aPosition;
73
+ layout(location = 1) in vec3 aNormal;
74
+ layout(location = 2) in vec2 aUv;
75
+ layout(location = 3) in vec4 aTangent;
76
+ layout(location = 4) in vec4 aColor;
77
+ layout(location = 5) in uvec4 aJoints;
78
+ layout(location = 6) in vec4 aWeights;
79
+ layout(location = 7) in vec2 aUv1;
80
+ layout(location = 8) in mat4 aInstanceMatrix;
81
+ layout(location = 12) in vec4 aInstanceColor;
82
+ layout(location = 13) in vec4 aInstanceAnimation; // first frame, second frame, blend, shared numbers
83
+ layout(location = 14) in vec4 aInstanceAnimation2; // the same for a second clip, and its weight
84
+ layout(location = 15) in vec4 aInstanceLook; // rotation of the look bone
85
+ ${FRAME_BLOCK}
86
+ uniform mat4 uModel;
87
+ uniform mat3 uNormalMatrix;
88
+ uniform mat3 uUvTransform;
89
+ #ifdef DEPTH_ONLY
90
+ uniform mat4 uDepthViewProjection;
91
+ #endif
92
+ #ifdef USE_SKINNING
93
+ uniform highp sampler2D uBoneTexture;
94
+ uniform mat4 uBindMatrix;
95
+ #endif
96
+ #ifdef USE_SKIN_INSTANCING
97
+ uniform highp sampler2D uBoneTexture; // every frame of every clip: four texels per bone matrix, rows wrap
98
+ #endif
99
+ #ifdef USE_MORPH
100
+ uniform highp sampler2D uMorphTexture;
101
+ uniform ivec3 uMorphLayout; // vertex count, texture width, attributes per target
102
+ uniform int uMorphCount;
103
+ uniform int uMorphIndices[${MAX_MORPH_INFLUENCES_3D}];
104
+ uniform float uMorphWeights[${MAX_MORPH_INFLUENCES_3D}];
105
+ #endif
106
+ #ifdef BILLBOARD
107
+ uniform vec4 uSprite; // x: rotation, y: size attenuation flag
108
+ #endif
109
+ #ifdef POINTS
110
+ uniform vec2 uPointSize; // x: size in pixels, y: size attenuation flag
111
+ #endif
112
+ out vec3 vWorldPosition;
113
+ out vec3 vNormal;
114
+ out vec2 vUv;
115
+ out vec2 vUv1;
116
+ out vec4 vTangent;
117
+ out vec4 vColor;
118
+
119
+ #ifdef USE_SKINNING
120
+ mat4 boneMatrix(uint index) {
121
+ int row = int(index);
122
+ return mat4(texelFetch(uBoneTexture, ivec2(0, row), 0), texelFetch(uBoneTexture, ivec2(1, row), 0),
123
+ texelFetch(uBoneTexture, ivec2(2, row), 0), texelFetch(uBoneTexture, ivec2(3, row), 0));
124
+ }
125
+ #endif
126
+ #ifdef USE_SKIN_INSTANCING
127
+ // The fourth float carries what every instance shares: matrices per frame, and the bone that may turn.
128
+ int crowdStride() { return int(mod(aInstanceAnimation.w, 2048.0)); }
129
+ mat4 bakedBone(int joint, float frame) {
130
+ int texel = (int(frame) * crowdStride() + joint) * 4, width = textureSize(uBoneTexture, 0).x;
131
+ ivec2 at = ivec2(texel % width, texel / width);
132
+ return mat4(texelFetch(uBoneTexture, at, 0), texelFetch(uBoneTexture, at + ivec2(1, 0), 0),
133
+ texelFetch(uBoneTexture, at + ivec2(2, 0), 0), texelFetch(uBoneTexture, at + ivec2(3, 0), 0));
134
+ }
135
+ // One table entry for this instance: between two frames of its clip, and of a second clip when it has one.
136
+ mat4 bakedBlend(int joint) {
137
+ mat4 pose = bakedBone(joint, aInstanceAnimation.x) * (1.0 - aInstanceAnimation.z) + bakedBone(joint, aInstanceAnimation.y) * aInstanceAnimation.z;
138
+ if (aInstanceAnimation2.w > 0.0) {
139
+ pose = pose * (1.0 - aInstanceAnimation2.w)
140
+ + (bakedBone(joint, aInstanceAnimation2.x) * (1.0 - aInstanceAnimation2.z) + bakedBone(joint, aInstanceAnimation2.y) * aInstanceAnimation2.z) * aInstanceAnimation2.w;
141
+ }
142
+ return pose;
143
+ }
144
+ mat4 bakedJoint(uint joint) {
145
+ mat4 pose = bakedBlend(int(joint));
146
+ int look = int(aInstanceAnimation.w / 2048.0) - 1;
147
+ if (int(joint) == look) {
148
+ // Turn the bone about its joint, whose place in the bind pose is kept in frame 0.
149
+ vec3 pivot = bakedBone(look, 0.0)[3].xyz, v = aInstanceLook.xyz;
150
+ float w = aInstanceLook.w;
151
+ mat3 turn = mat3(1.0 - 2.0 * (v.y * v.y + v.z * v.z), 2.0 * (v.x * v.y + v.z * w), 2.0 * (v.x * v.z - v.y * w),
152
+ 2.0 * (v.x * v.y - v.z * w), 1.0 - 2.0 * (v.x * v.x + v.z * v.z), 2.0 * (v.y * v.z + v.x * w),
153
+ 2.0 * (v.x * v.z + v.y * w), 2.0 * (v.y * v.z - v.x * w), 1.0 - 2.0 * (v.x * v.x + v.y * v.y));
154
+ pose = pose * mat4(vec4(turn[0], 0.0), vec4(turn[1], 0.0), vec4(turn[2], 0.0), vec4(pivot - turn * pivot, 1.0));
155
+ }
156
+ return pose;
157
+ }
158
+ #endif
159
+ #ifdef USE_MORPH
160
+ vec3 morphDelta(int targetIndex, int channel) {
161
+ int texel = (targetIndex * uMorphLayout.z + channel) * uMorphLayout.x + gl_VertexID;
162
+ return texelFetch(uMorphTexture, ivec2(texel % uMorphLayout.y, texel / uMorphLayout.y), 0).xyz;
163
+ }
164
+ #endif
165
+
166
+ #if defined(CUSTOM_VERTEX) || defined(GPU_PARTICLES)
167
+ uniform vec4 uCustom[4];
168
+ #endif
169
+ #ifdef CUSTOM_VERTEX
170
+ /*CUSTOM_VERTEX*/
171
+ #endif
172
+ void main() {
173
+ vec3 position = aPosition;
174
+ #ifdef USE_NORMAL
175
+ vec3 normal = aNormal;
176
+ #else
177
+ vec3 normal = vec3(0.0, 0.0, 1.0);
178
+ #endif
179
+ #if defined(USE_MORPH) && defined(USE_SKIN_INSTANCING)
180
+ // Baked instances read their morph weights from the last entry of their frames.
181
+ mat4 bakedWeights = bakedBlend(crowdStride() - 1);
182
+ for (int i = 0; i < uMorphCount; i++) {
183
+ position += morphDelta(i, 0) * bakedWeights[i / 4][i % 4];
184
+ #ifdef USE_MORPH_NORMALS
185
+ normal += morphDelta(i, 1) * bakedWeights[i / 4][i % 4];
186
+ #endif
187
+ }
188
+ #elif defined(USE_MORPH)
189
+ for (int i = 0; i < uMorphCount; i++) {
190
+ position += morphDelta(uMorphIndices[i], 0) * uMorphWeights[i];
191
+ #ifdef USE_MORPH_NORMALS
192
+ normal += morphDelta(uMorphIndices[i], 1) * uMorphWeights[i];
193
+ #endif
194
+ }
195
+ #endif
196
+ mat4 model = uModel;
197
+ mat3 normalMatrix = uNormalMatrix;
198
+ #ifdef USE_SKINNING
199
+ mat4 skin = aWeights.x * boneMatrix(aJoints.x) + aWeights.y * boneMatrix(aJoints.y)
200
+ + aWeights.z * boneMatrix(aJoints.z) + aWeights.w * boneMatrix(aJoints.w);
201
+ model = skin * uBindMatrix;
202
+ normalMatrix = mat3(model);
203
+ #endif
204
+ float spriteTurn = 0.0;
205
+ #ifdef GPU_PARTICLES
206
+ // The instance slots carry a particle's start and birth, velocity and life, sizes and angles;
207
+ // where it is now follows from the time alone.
208
+ vec4 particleStart = aInstanceMatrix[0], particleMotion = aInstanceMatrix[1], particleLook = aInstanceMatrix[2];
209
+ float particleLife = max(particleMotion.w, 0.0001), particleTime = uCustom[0].x - particleStart.w;
210
+ bool particleAlive = true;
211
+ if (uCustom[0].y > 0.5) particleTime = mod(particleTime, particleLife);
212
+ else particleAlive = particleTime >= 0.0 && particleTime <= particleLife;
213
+ float particleAge = clamp(particleTime / particleLife, 0.0, 1.0);
214
+ float particleTravel = uCustom[1].w > 0.0001 ? (1.0 - exp(-uCustom[1].w * particleTime)) / uCustom[1].w : particleTime;
215
+ vec3 particleCenter = particleStart.xyz + particleMotion.xyz * particleTravel + uCustom[1].xyz * (0.5 * particleTime * particleTime);
216
+ if (uCustom[3].y > 0.5) {
217
+ // A floor: find when the particle comes down on it, then let it leave again slower, once. Drag is not applied on this path.
218
+ vec3 pull = uCustom[1].xyz, launch = particleMotion.xyz;
219
+ float a = 0.5 * pull.y, b = launch.y, c = particleStart.y - uCustom[3].z, hit = -1.0;
220
+ if (c == 0.0 && (b < 0.0 || (b == 0.0 && a < 0.0))) hit = 0.0;
221
+ else if (abs(a) > 0.000001) {
222
+ float discriminant = b * b - 4.0 * a * c;
223
+ if (discriminant > 0.0) {
224
+ float root = sqrt(discriminant);
225
+ hit = b < 0.0 ? 2.0 * c / (root - b) : (-b - root) / (2.0 * a);
226
+ }
227
+ } else if (b < 0.0) hit = -c / b;
228
+ particleCenter = particleStart.xyz + launch * particleTime + pull * (0.5 * particleTime * particleTime);
229
+ if (c >= 0.0 && hit >= 0.0 && particleTime >= hit) {
230
+ vec3 landed = particleStart.xyz + launch * hit + pull * (0.5 * hit * hit), away = (launch + pull * hit) * vec3(uCustom[3].w, -uCustom[3].w, uCustom[3].w);
231
+ float since = particleTime - hit;
232
+ particleCenter = landed + away * since + pull * (0.5 * since * since);
233
+ particleCenter.y = max(particleCenter.y, uCustom[3].z);
234
+ }
235
+ }
236
+ // Particles left behind in the world carry world positions and ignore the emitter's transform.
237
+ if (uCustom[3].x > 0.5) model = mat4(1.0);
238
+ float particleSize = mix(particleLook.x, particleLook.y, particleAge);
239
+ model = model * mat4(vec4(particleSize, 0.0, 0.0, 0.0), vec4(0.0, particleSize, 0.0, 0.0), vec4(0.0, 0.0, particleSize, 0.0), vec4(particleCenter, 1.0));
240
+ spriteTurn = particleLook.z + particleLook.w * particleTime;
241
+ #elif defined(USE_INSTANCING)
242
+ model = model * aInstanceMatrix;
243
+ normalMatrix = normalMatrix * mat3(aInstanceMatrix);
244
+ #endif
245
+ #ifdef USE_SKIN_INSTANCING
246
+ // Each instance is posed in its own space before its transform places it.
247
+ model = model * (aWeights.x * bakedJoint(aJoints.x) + aWeights.y * bakedJoint(aJoints.y) + aWeights.z * bakedJoint(aJoints.z) + aWeights.w * bakedJoint(aJoints.w));
248
+ normalMatrix = mat3(model);
249
+ #endif
250
+ vec4 world = model * vec4(position, 1.0);
251
+ #ifdef CUSTOM_VERTEX
252
+ #ifdef USE_VERTEX_COLOR
253
+ world.xyz = customVertex(world.xyz, position, normal, aUv, aColor);
254
+ #else
255
+ world.xyz = customVertex(world.xyz, position, normal, aUv, vec4(1.0));
256
+ #endif
257
+ #endif
258
+ #ifdef DEPTH_ONLY
259
+ mat4 viewProjection = uDepthViewProjection;
260
+ #else
261
+ mat4 viewProjection = uViewProjection;
262
+ #endif
263
+ #ifdef SCREEN_SPACE
264
+ // Positions are already in normalized device coordinates.
265
+ world = vec4(uCameraPosition.xyz, 1.0);
266
+ gl_Position = vec4(position.xy, 0.0, 1.0);
267
+ #elif defined(BILLBOARD)
268
+ // Expand the quad in view space around the transformed node origin.
269
+ vec4 center = uView * (model * vec4(0.0, 0.0, 0.0, 1.0));
270
+ vec2 scale = vec2(length(model[0].xyz), length(model[1].xyz));
271
+ if (uSprite.y < 0.5) scale *= -center.z;
272
+ float c = cos(uSprite.x + spriteTurn), s = sin(uSprite.x + spriteTurn);
273
+ vec2 corner = position.xy * scale;
274
+ center.xy += vec2(c * corner.x - s * corner.y, s * corner.x + c * corner.y);
275
+ world = inverse(uView) * center;
276
+ gl_Position = viewProjection * world;
277
+ normal = vec3(0.0, 0.0, 1.0);
278
+ normalMatrix = transpose(mat3(uView));
279
+ #else
280
+ gl_Position = viewProjection * world;
281
+ #endif
282
+ #ifdef POINTS
283
+ gl_PointSize = uPointSize.y > 0.5 ? uPointSize.x / max(gl_Position.w, 0.0001) : uPointSize.x;
284
+ #endif
285
+ vWorldPosition = world.xyz;
286
+ vNormal = normalMatrix * normal;
287
+ vUv = (uUvTransform * vec3(aUv, 1.0)).xy;
288
+ vUv1 = aUv1;
289
+ vTangent = vec4(mat3(model) * aTangent.xyz, aTangent.w);
290
+ vColor = vec4(1.0);
291
+ #ifdef USE_VERTEX_COLOR
292
+ vColor = aColor;
293
+ #endif
294
+ #ifdef USE_INSTANCE_COLOR
295
+ vColor *= aInstanceColor;
296
+ #endif
297
+ #ifdef GPU_PARTICLES
298
+ // From the instance's color to the shared end color over the particle's life, fading at both ends.
299
+ vColor = mix(aInstanceColor, uCustom[2], particleAge);
300
+ vColor.a *= smoothstep(0.0, max(uCustom[0].z, 0.0001), particleAge) * (1.0 - smoothstep(1.0 - max(uCustom[0].w, 0.0001), 1.0, particleAge));
301
+ if (!particleAlive) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
302
+ #endif
303
+ }
304
+ `;
305
+ const FRAGMENT_SOURCE = /* glsl */ `
306
+ ${FRAME_BLOCK}
307
+ uniform vec4 uColor; // linear rgb and opacity
308
+ uniform vec3 uEmissive;
309
+ uniform vec4 uSurface; // metallic, roughness, normal scale, occlusion strength
310
+ uniform vec4 uSpecular; // rgb and shininess
311
+ uniform float uAlphaCutoff;
312
+ uniform vec2 uClearcoat; // strength and roughness
313
+ uniform float uEnvironmentScale;
314
+ uniform sampler2D uMap;
315
+ uniform sampler2D uNormalMap;
316
+ uniform sampler2D uMetallicRoughnessMap;
317
+ uniform sampler2D uOcclusionMap;
318
+ uniform sampler2D uEmissiveMap;
319
+ uniform sampler2D uLightMap;
320
+ uniform vec4 uSheen; // color scaled by strength, roughness
321
+ uniform vec2 uExtra; // light map intensity, transmission
322
+ uniform highp sampler2D uTiledLights; // tiled point lights: lights, tile headers, light indices
323
+ vec4 tiledTexel(int i) {
324
+ return texelFetch(uTiledLights, ivec2(i % 512, i / 512), 0);
325
+ }
326
+ #ifdef USE_TRANSMISSION
327
+ uniform sampler2D uSceneColor; // what was drawn before the see-through surfaces
328
+ uniform vec4 uRefraction; // index of refraction, thickness, attenuation distance (0 = none)
329
+ uniform vec3 uAttenuation;
330
+ #endif
331
+ #ifdef USE_SOFT_DEPTH
332
+ uniform highp sampler2D uSceneDepth; // depth of the solid scene, drawn before the frame
333
+ uniform float uSoftness;
334
+ #endif
335
+ #ifdef USE_SPLAT
336
+ uniform sampler2D uSplatWeights;
337
+ uniform sampler2D uSplat0;
338
+ uniform sampler2D uSplat1;
339
+ uniform sampler2D uSplat2;
340
+ uniform sampler2D uSplat3;
341
+ uniform vec4 uSplatRepeat;
342
+ #endif
343
+ // Distance from the camera plane to the solid scene behind this pixel and to the surface itself;
344
+ // hooks may read them. Without a depth image the scene counts as far away.
345
+ float sceneDistance = 1.0e9;
346
+ float surfaceDistance = 0.0;
347
+ // This pixel's place on the output, counted from the top row when a depth image tells its height.
348
+ vec2 surfacePixel = vec2(0.0);
349
+ #ifdef USE_REFLECTION_MAP
350
+ uniform sampler2D uReflectionMap; // mirror image of the scene, read at the pixel's place on screen
351
+ uniform vec2 uReflection; // strength, distortion by the normal
352
+ #endif
353
+ uniform samplerCube uEnvironment;
354
+ uniform highp sampler2DShadow uShadowMap;
355
+ in vec3 vWorldPosition;
356
+ in vec3 vNormal;
357
+ in vec2 vUv;
358
+ in vec2 vUv1;
359
+ in vec4 vTangent;
360
+ in vec4 vColor;
361
+ out vec4 outColor;
362
+
363
+ const float PI = 3.141592653589793;
364
+
365
+ #ifndef DEPTH_ONLY
366
+ vec3 surfaceNormal() {
367
+ #if defined(FLAT_SHADED) || !defined(USE_NORMAL)
368
+ vec3 n = normalize(cross(dFdx(vWorldPosition), dFdy(vWorldPosition)));
369
+ #else
370
+ vec3 n = normalize(vNormal);
371
+ #ifdef DOUBLE_SIDED
372
+ if (!gl_FrontFacing) n = -n;
373
+ #endif
374
+ #endif
375
+ #ifdef USE_NORMAL_MAP
376
+ vec3 mapped = texture(uNormalMap, vUv).xyz * 2.0 - 1.0;
377
+ mapped.xy *= uSurface.z;
378
+ #ifdef USE_TANGENT
379
+ vec3 t = normalize(vTangent.xyz);
380
+ vec3 b = cross(n, t) * vTangent.w;
381
+ #else
382
+ // Derive a cotangent frame from screen-space derivatives.
383
+ vec3 dp1 = dFdx(vWorldPosition), dp2 = dFdy(vWorldPosition);
384
+ vec2 duv1 = dFdx(vUv), duv2 = dFdy(vUv);
385
+ vec3 dp2perp = cross(dp2, n), dp1perp = cross(n, dp1);
386
+ vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
387
+ vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;
388
+ float invmax = inversesqrt(max(dot(t, t), dot(b, b)));
389
+ t *= invmax; b *= invmax;
390
+ #endif
391
+ n = normalize(mat3(t, b, n) * mapped);
392
+ #endif
393
+ return n;
394
+ }
395
+
396
+ #ifdef RECEIVE_SHADOW
397
+ float shadowFactor(int slot, vec3 at, vec3 normal) {
398
+ vec4 params = uShadowParams[slot];
399
+ vec4 clip = uShadowMatrix[slot] * vec4(at + normal * params.y, 1.0);
400
+ vec3 ndc = clip.xyz / clip.w * 0.5 + 0.5;
401
+ if (clip.w <= 0.0 || any(lessThan(ndc, vec3(0.0))) || any(greaterThan(ndc, vec3(1.0)))) return 1.0;
402
+ vec4 rect = uShadowRect[slot];
403
+ float depth = ndc.z - params.x;
404
+ vec2 lower = rect.xy + params.z, upper = rect.xy + rect.zw - params.z;
405
+ float lit = 0.0;
406
+ // 3x3 taps on top of hardware 2x2 comparison filtering.
407
+ for (int y = -1; y <= 1; y++) {
408
+ for (int x = -1; x <= 1; x++) {
409
+ vec2 uv = clamp(rect.xy + ndc.xy * rect.zw + vec2(float(x), float(y)) * params.z, lower, upper);
410
+ lit += texture(uShadowMap, vec3(uv, depth));
411
+ }
412
+ }
413
+ return lit / 9.0;
414
+ }
415
+ // Read the four packed split distances through fixed components. Dynamic vector
416
+ // indexing here can fail ANGLE's D3D11 draw-time pixel shader compilation.
417
+ int selectCascade(float viewDepth, int count, out float edge) {
418
+ if (count > 3 && viewDepth > uCascadeSplits.z) { edge = uCascadeSplits.w; return 3; }
419
+ if (count > 2 && viewDepth > uCascadeSplits.y) { edge = uCascadeSplits.z; return 2; }
420
+ if (count > 1 && viewDepth > uCascadeSplits.x) { edge = uCascadeSplits.y; return 1; }
421
+ edge = uCascadeSplits.x;
422
+ return 0;
423
+ }
424
+ // One unfiltered lookup for a point in the air, as fog marching needs many; the flag picks the cascade for that depth.
425
+ float volumeShadow(int slot, vec3 at, bool cascaded) {
426
+ if (cascaded) {
427
+ float viewDepth = -(uView * vec4(at, 1.0)).z;
428
+ float edge;
429
+ int cascade = selectCascade(viewDepth, int(uCascadeInfo.y), edge);
430
+ if (viewDepth >= edge) return 1.0;
431
+ slot += cascade;
432
+ }
433
+ vec4 clip = uShadowMatrix[slot] * vec4(at, 1.0);
434
+ vec3 ndc = clip.xyz / clip.w * 0.5 + 0.5;
435
+ if (clip.w <= 0.0 || any(lessThan(ndc, vec3(0.0))) || any(greaterThan(ndc, vec3(1.0)))) return 1.0;
436
+ vec4 rect = uShadowRect[slot];
437
+ return texture(uShadowMap, vec3(rect.xy + ndc.xy * rect.zw, ndc.z - uShadowParams[slot].x));
438
+ }
439
+ float pointShadowFactor(int slot, vec3 fromLight, vec3 at, vec3 normal) {
440
+ // Faces of the tetrahedron the four maps were rendered through.
441
+ const float k = 0.5773502691896258;
442
+ float d0 = dot(fromLight, vec3(k, k, k)), d1 = dot(fromLight, vec3(-k, -k, k)), d2 = dot(fromLight, vec3(-k, k, -k)), d3 = dot(fromLight, vec3(k, -k, -k));
443
+ int face = 0; float best = d0;
444
+ if (d1 > best) { best = d1; face = 1; }
445
+ if (d2 > best) { best = d2; face = 2; }
446
+ if (d3 > best) face = 3;
447
+ return shadowFactor(slot + face, at, normal);
448
+ }
449
+ float cascadedShadowFactor(int slot, vec3 at, vec3 normal) {
450
+ float viewDepth = -(uView * vec4(at, 1.0)).z;
451
+ int count = int(uCascadeInfo.y);
452
+ float edge;
453
+ int cascade = selectCascade(viewDepth, count, edge);
454
+ if (viewDepth >= edge) return 1.0;
455
+ float visible = shadowFactor(slot + cascade, at, normal);
456
+ // Blend into the next cascade, or out to unshadowed past the last one.
457
+ float t = smoothstep(edge * (1.0 - uCascadeInfo.z), edge, viewDepth);
458
+ if (t > 0.0) visible = mix(visible, cascade < count - 1 ? shadowFactor(slot + cascade + 1, at, normal) : 1.0, t);
459
+ return visible;
460
+ }
461
+ #endif
462
+
463
+ float rangeFalloff(float dist, float range) {
464
+ float inverseSquare = 1.0 / max(dist * dist, 0.0001);
465
+ if (range <= 0.0) return inverseSquare;
466
+ float ratio = dist / range;
467
+ float window = clamp(1.0 - ratio * ratio * ratio * ratio, 0.0, 1.0);
468
+ return inverseSquare * window * window;
469
+ }
470
+
471
+ struct Surface {
472
+ vec3 albedo;
473
+ vec3 normal;
474
+ vec3 view;
475
+ vec3 f0;
476
+ float roughness;
477
+ float metallic;
478
+ };
479
+
480
+ // Radiance leaving the surface for one light of unit-normalized direction l.
481
+ vec3 shade(Surface s, vec3 l, vec3 radiance) {
482
+ float nl = max(dot(s.normal, l), 0.0);
483
+ if (nl <= 0.0) return vec3(0.0);
484
+ #if defined(SHADING_LAMBERT)
485
+ return s.albedo * radiance * nl;
486
+ #elif defined(SHADING_TOON)
487
+ // uSpecular.w carries the band count for toon shading.
488
+ return s.albedo * radiance * (ceil(nl * uSpecular.w - 0.001) / max(uSpecular.w, 1.0));
489
+ #elif defined(SHADING_PHONG)
490
+ vec3 h = normalize(l + s.view);
491
+ float specular = pow(max(dot(s.normal, h), 0.0), max(uSpecular.w, 1.0));
492
+ return (s.albedo + uSpecular.rgb * specular) * radiance * nl;
493
+ #else
494
+ vec3 h = normalize(l + s.view);
495
+ float nv = max(dot(s.normal, s.view), 0.0001), nh = max(dot(s.normal, h), 0.0), vh = max(dot(s.view, h), 0.0);
496
+ float a = s.roughness * s.roughness, a2 = a * a;
497
+ float d = nh * nh * (a2 - 1.0) + 1.0;
498
+ float distribution = a2 / (PI * d * d);
499
+ float visibility = 0.5 / max(nl * sqrt(nv * nv * (1.0 - a2) + a2) + nv * sqrt(nl * nl * (1.0 - a2) + a2), 0.0001);
500
+ vec3 fresnel = s.f0 + (1.0 - s.f0) * pow(1.0 - vh, 5.0);
501
+ vec3 diffuse = s.albedo * (1.0 - s.metallic) * (1.0 - fresnel);
502
+ // Light units are scaled by PI so a unit white light fully lights a white diffuse surface.
503
+ vec3 lit = diffuse + distribution * visibility * fresnel * PI;
504
+ if (uSheen.r + uSheen.g + uSheen.b > 0.0) {
505
+ // Cloth lobe: an inverted Gaussian that brightens toward grazing angles.
506
+ float inverse = 1.0 / max(uSheen.w, 0.07);
507
+ lit += uSheen.rgb * ((2.0 + inverse) * pow(max(1.0 - nh * nh, 0.0), inverse * 0.5) / (2.0 * PI)) / (4.0 * (nl + nv - nl * nv)) * PI;
508
+ }
509
+ if (uClearcoat.x > 0.0) {
510
+ // A second, dielectric lobe on top; the base layer loses what the coat reflects.
511
+ float ca = max(uClearcoat.y, 0.045); ca *= ca;
512
+ float ca2 = ca * ca, cd = nh * nh * (ca2 - 1.0) + 1.0;
513
+ float coatFresnel = (0.04 + 0.96 * pow(1.0 - vh, 5.0)) * uClearcoat.x;
514
+ lit = lit * (1.0 - coatFresnel) + ca2 / (PI * cd * cd) * (0.25 / max(vh * vh, 0.0001)) * coatFresnel * PI;
515
+ }
516
+ return lit * radiance * nl;
517
+ #endif
518
+ }
519
+
520
+ #if defined(CUSTOM_FRAGMENT) || defined(CUSTOM_NORMAL)
521
+ uniform vec4 uCustom[4];
522
+ #endif
523
+ #ifdef CUSTOM_FRAGMENT
524
+ /*CUSTOM_FRAGMENT*/
525
+ #endif
526
+ #ifdef CUSTOM_NORMAL
527
+ /*CUSTOM_NORMAL*/
528
+ #endif
529
+
530
+ vec3 toneMap(vec3 color) {
531
+ color *= uOutput.z;
532
+ if (uOutput.w > 1.5) {
533
+ // Filmic curve fit commonly used for ACES-like output.
534
+ color = clamp((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14), 0.0, 1.0);
535
+ } else if (uOutput.w > 0.5) color = color / (1.0 + color);
536
+ return color;
537
+ }
538
+ vec3 encodeSrgb(vec3 color) {
539
+ color = clamp(color, 0.0, 1.0);
540
+ return mix(color * 12.92, 1.055 * pow(color, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), color));
541
+ }
542
+ #endif
543
+
544
+ void main() {
545
+ #ifndef DEPTH_ONLY
546
+ for (int i = 0; i < int(uClipInfo.x); i++) if (dot(vWorldPosition, uClipPlanes[i].xyz) + uClipPlanes[i].w < 0.0) discard;
547
+ #endif
548
+ #ifndef DEPTH_ONLY
549
+ surfacePixel = gl_FragCoord.xy;
550
+ #endif
551
+ vec4 base = uColor * vColor;
552
+ #ifdef USE_MAP
553
+ vec4 mapColor = texture(uMap, vUv);
554
+ #ifdef MAP_FROM_TARGET
555
+ // Target pixels carry alpha-weighted RGB. Material shading uses straight color.
556
+ mapColor.rgb = mapColor.a > 0.0 ? mapColor.rgb / mapColor.a : vec3(0.0);
557
+ #endif
558
+ base *= mapColor;
559
+ #endif
560
+ #ifdef USE_SPLAT
561
+ {
562
+ // Ground layers, each weighted by its channel of the weight map.
563
+ vec4 share = texture(uSplatWeights, vUv);
564
+ float total = share.r + share.g + share.b + share.a;
565
+ share = total > 0.0001 ? share / total : vec4(1.0, 0.0, 0.0, 0.0);
566
+ base.rgb *= texture(uSplat0, vUv * uSplatRepeat.x).rgb * share.r + texture(uSplat1, vUv * uSplatRepeat.y).rgb * share.g
567
+ + texture(uSplat2, vUv * uSplatRepeat.z).rgb * share.b + texture(uSplat3, vUv * uSplatRepeat.w).rgb * share.a;
568
+ }
569
+ #endif
570
+ #ifdef USE_SOFT_DEPTH
571
+ {
572
+ // Fade out over the last stretch before the solid surface behind this pixel.
573
+ float stored = texelFetch(uSceneDepth, ivec2(gl_FragCoord.xy), 0).r * 2.0 - 1.0;
574
+ surfacePixel = vec2(gl_FragCoord.x, float(textureSize(uSceneDepth, 0).y) - gl_FragCoord.y);
575
+ sceneDistance = uLightCounts.w > 0.5 ? (uPointShadow.w - stored) / uPointShadow.z : uPointShadow.w / (stored + uPointShadow.z);
576
+ surfaceDistance = -(uView * vec4(vWorldPosition, 1.0)).z;
577
+ #ifndef USE_TRANSMISSION
578
+ base.a *= clamp((sceneDistance - surfaceDistance) / max(uSoftness, 0.0001), 0.0, 1.0);
579
+ #endif
580
+ }
581
+ #endif
582
+ #ifdef POINTS
583
+ if (length(gl_PointCoord - 0.5) > 0.5) discard;
584
+ #endif
585
+ #ifdef ALPHA_MASK
586
+ if (base.a < uAlphaCutoff) discard;
587
+ #endif
588
+ #ifdef DEPTH_ONLY
589
+ #ifdef ALPHA_BLEND
590
+ if (base.a < 0.5) discard;
591
+ #endif
592
+ outColor = vec4(1.0);
593
+ #else
594
+ vec3 color;
595
+ #ifdef SHADING_UNLIT
596
+ color = base.rgb;
597
+ #elif defined(SHADING_MATCAP)
598
+ vec3 viewNormal = normalize(mat3(uView) * surfaceNormal());
599
+ color = base.rgb * texture(uEmissiveMap, viewNormal.xy * 0.5 + 0.5).rgb;
600
+ #else
601
+ Surface s;
602
+ s.normal = surfaceNormal();
603
+ #ifdef CUSTOM_NORMAL
604
+ s.normal = normalize(customNormal(s.normal, vWorldPosition, vUv));
605
+ #endif
606
+ s.view = normalize(uCameraPosition.xyz - vWorldPosition);
607
+ s.albedo = base.rgb;
608
+ s.metallic = uSurface.x;
609
+ s.roughness = uSurface.y;
610
+ #ifdef USE_MR_MAP
611
+ vec4 mr = texture(uMetallicRoughnessMap, vUv);
612
+ s.metallic *= mr.b;
613
+ s.roughness *= mr.g;
614
+ #endif
615
+ s.roughness = clamp(s.roughness, 0.045, 1.0);
616
+ s.f0 = mix(vec3(0.04), s.albedo, s.metallic);
617
+ float occlusion = 1.0;
618
+ #ifdef USE_AO_MAP
619
+ #ifdef AO_UV1
620
+ occlusion = mix(1.0, texture(uOcclusionMap, vUv1).r, uSurface.w);
621
+ #else
622
+ occlusion = mix(1.0, texture(uOcclusionMap, vUv).r, uSurface.w);
623
+ #endif
624
+ #endif
625
+
626
+ #ifdef USE_TRANSMISSION
627
+ // Light that passes through replaces that share of the diffuse reflection.
628
+ // What the surface reflects at this angle does not pass through it.
629
+ float through = uExtra.y * (1.0 - s.metallic) * (1.0 - (0.04 + 0.96 * pow(1.0 - max(dot(s.normal, s.view), 0.0), 5.0)));
630
+ vec3 passed = vec3(0.0);
631
+ {
632
+ vec3 bent = refract(-s.view, s.normal, 1.0 / max(uRefraction.x, 1.0));
633
+ vec4 here = uViewProjection * vec4(vWorldPosition, 1.0), there = uViewProjection * vec4(vWorldPosition + bent * uRefraction.y, 1.0);
634
+ vec2 at = gl_FragCoord.xy / vec2(textureSize(uSceneColor, 0)) + (there.xy / max(there.w, 0.0001) - here.xy / here.w) * 0.5 * uClipInfo.zw;
635
+ // A rough surface scatters the view: average a spiral of taps that widens with roughness.
636
+ float spread = s.roughness * s.roughness * 0.25 / max(here.w, 1.0);
637
+ for (int i = 0; i < 12; i++) {
638
+ float turn = float(i) * 2.399963, reach = sqrt((float(i) + 0.5) / 12.0) * spread;
639
+ passed += texture(uSceneColor, clamp(at + vec2(cos(turn), sin(turn)) * reach, vec2(0.0), vec2(1.0))).rgb;
640
+ }
641
+ passed /= 12.0;
642
+ }
643
+ // Tint of the material, deepened by the distance travelled inside it.
644
+ vec3 tint = s.albedo;
645
+ float travelled = uRefraction.y;
646
+ #ifdef USE_SOFT_DEPTH
647
+ // With a depth image the light's path through the material is the real gap to what lies behind.
648
+ travelled = max(sceneDistance - surfaceDistance, 0.0);
649
+ #endif
650
+ if (uRefraction.z > 0.0) tint *= pow(max(uAttenuation, vec3(0.0001)), vec3(travelled / uRefraction.z));
651
+ s.albedo *= 1.0 - through;
652
+ float clear = 1.0;
653
+ #endif
654
+ #ifdef USE_REFLECTION_MAP
655
+ vec3 mirrored;
656
+ float mirrorClear = 1.0;
657
+ {
658
+ // The mirror camera sees the scene flipped left to right.
659
+ vec4 at = uViewProjection * vec4(vWorldPosition, 1.0);
660
+ vec2 where = at.xy / max(at.w, 0.0001) * 0.5 + 0.5;
661
+ where = vec2(1.0 - where.x, where.y) + s.normal.xz * uReflection.y;
662
+ float facing = max(dot(s.normal, s.view), 0.0);
663
+ mirrored = texture(uReflectionMap, clamp(where, vec2(0.002), vec2(0.998))).rgb * (s.f0 + (1.0 - s.f0) * pow(1.0 - facing, 5.0)) * uReflection.x;
664
+ }
665
+ #endif
666
+ // Indirect light: ambient, hemisphere and optional environment map.
667
+ vec3 diffuseAlbedo = s.albedo;
668
+ #ifdef SHADING_STANDARD
669
+ diffuseAlbedo *= 1.0 - s.metallic;
670
+ #endif
671
+ vec3 irradiance = uAmbient.rgb + mix(uHemisphereGround.rgb, uHemisphereSky.rgb, s.normal.y * 0.5 + 0.5);
672
+ #ifdef USE_ENVIRONMENT
673
+ irradiance += textureLod(uEnvironment, s.normal, uOutput.y).rgb * uOutput.x * uEnvironmentScale;
674
+ #endif
675
+ #ifdef USE_LIGHT_MAP
676
+ #ifdef LIGHT_UV1
677
+ irradiance += texture(uLightMap, vUv1).rgb * uExtra.x;
678
+ #else
679
+ irradiance += texture(uLightMap, vUv).rgb * uExtra.x;
680
+ #endif
681
+ #endif
682
+ color = diffuseAlbedo * irradiance * occlusion;
683
+ #if defined(USE_ENVIRONMENT) && defined(SHADING_STANDARD) && !defined(USE_REFLECTION_MAP)
684
+ {
685
+ vec3 reflected = reflect(-s.view, s.normal);
686
+ float nv = max(dot(s.normal, s.view), 0.0);
687
+ vec3 prefiltered = textureLod(uEnvironment, reflected, s.roughness * uOutput.y).rgb * uOutput.x * uEnvironmentScale;
688
+ // Analytic approximation of the split-sum environment BRDF.
689
+ vec4 r = s.roughness * vec4(-1.0, -0.0275, -0.572, 0.022) + vec4(1.0, 0.0425, 1.04, -0.04);
690
+ float a004 = min(r.x * r.x, exp2(-9.28 * nv)) * r.x + r.y;
691
+ vec2 scaleBias = vec2(-1.04, 1.04) * a004 + r.zw;
692
+ color += prefiltered * (s.f0 * scaleBias.x + scaleBias.y) * occlusion;
693
+ }
694
+ #endif
695
+
696
+ int directionalCount = int(uLightCounts.x), pointCount = int(uLightCounts.y), spotCount = int(uLightCounts.z);
697
+ for (int i = 0; i < directionalCount; i++) {
698
+ float visible = 1.0;
699
+ #ifdef RECEIVE_SHADOW
700
+ if (uDirectionalDirection[i].w >= 0.0) {
701
+ visible = float(i) == uCascadeInfo.x ? cascadedShadowFactor(int(uDirectionalDirection[i].w), vWorldPosition, s.normal) : shadowFactor(int(uDirectionalDirection[i].w), vWorldPosition, s.normal);
702
+ }
703
+ #endif
704
+ if (visible > 0.0) color += shade(s, -uDirectionalDirection[i].xyz, uDirectionalColor[i].rgb) * visible;
705
+ }
706
+ for (int i = 0; i < pointCount; i++) {
707
+ vec3 toLight = uPointPosition[i].xyz - vWorldPosition;
708
+ float dist = length(toLight);
709
+ float visible = 1.0;
710
+ #ifdef RECEIVE_SHADOW
711
+ if (float(i) == uPointShadow.x) visible = pointShadowFactor(int(uPointShadow.y), -toLight, vWorldPosition, s.normal);
712
+ #endif
713
+ color += shade(s, toLight / max(dist, 0.0001), uPointColor[i].rgb * rangeFalloff(dist, uPointPosition[i].w)) * visible;
714
+ }
715
+ // Point lights past the eight: only those whose range reaches this pixel's screen tile are visited.
716
+ if (uTileInfo.x > 0.5) {
717
+ ivec2 tileAt = clamp(ivec2((gl_FragCoord.xy - vec2(uTileGrid.w, uTileInfo.w)) / uTileGrid.z), ivec2(0), ivec2(uTileGrid.xy) - 1);
718
+ vec4 head = tiledTexel(int(uTileInfo.y) + tileAt.y * int(uTileGrid.x) + tileAt.x);
719
+ int first = int(head.x), tileCount = int(head.y);
720
+ for (int k = 0; k < 32; k++) {
721
+ if (k >= tileCount) break;
722
+ int slot = first + k;
723
+ int lightIndex = int(tiledTexel(int(uTileInfo.z) + slot / 4)[slot % 4]);
724
+ vec4 lightPosition = tiledTexel(lightIndex * 2), lightColor = tiledTexel(lightIndex * 2 + 1);
725
+ vec3 toLight = lightPosition.xyz - vWorldPosition;
726
+ float dist = length(toLight);
727
+ if (dist >= lightPosition.w) continue;
728
+ color += shade(s, toLight / max(dist, 0.0001), lightColor.rgb * rangeFalloff(dist, lightPosition.w));
729
+ }
730
+ }
731
+ for (int i = 0; i < spotCount; i++) {
732
+ vec3 toLight = uSpotPosition[i].xyz - vWorldPosition;
733
+ float dist = length(toLight);
734
+ vec3 l = toLight / max(dist, 0.0001);
735
+ float cone = smoothstep(uSpotCone[i].x, uSpotCone[i].y, dot(-l, uSpotDirection[i].xyz));
736
+ if (cone <= 0.0) continue;
737
+ float visible = 1.0;
738
+ #ifdef RECEIVE_SHADOW
739
+ if (uSpotDirection[i].w >= 0.0) visible = shadowFactor(int(uSpotDirection[i].w), vWorldPosition, s.normal);
740
+ #endif
741
+ color += shade(s, l, uSpotColor[i].rgb * rangeFalloff(dist, uSpotPosition[i].w) * cone) * visible;
742
+ }
743
+ #endif
744
+
745
+ #ifndef SHADING_MATCAP
746
+ vec3 emissive = uEmissive;
747
+ #ifdef USE_EMISSIVE_MAP
748
+ #ifdef EMISSIVE_UV1
749
+ emissive *= texture(uEmissiveMap, vUv1).rgb;
750
+ #else
751
+ emissive *= texture(uEmissiveMap, vUv).rgb;
752
+ #endif
753
+ #endif
754
+ color += emissive;
755
+ #endif
756
+
757
+ #ifdef CUSTOM_FRAGMENT
758
+ vec4 customized = customFragment(vec4(color, base.a), vWorldPosition, normalize(vNormal), vUv);
759
+ color = customized.rgb; base.a = customized.a;
760
+ #ifdef USE_TRANSMISSION
761
+ // On a see-through material the hook's alpha is how much still passes: 0 covers what lies behind.
762
+ through *= clamp(customized.a, 0.0, 1.0);
763
+ #endif
764
+ #endif
765
+ #ifdef USE_FOG
766
+ if (uFogParams.x > 0.5) {
767
+ float dist = length(uCameraPosition.xyz - vWorldPosition);
768
+ float fog = uFogParams.x > 1.5 ? 1.0 - exp(-uFogParams.y * uFogParams.y * dist * dist)
769
+ : smoothstep(uFogParams.y, uFogParams.z, dist);
770
+ color = mix(color, uFogColor.rgb, clamp(fog, 0.0, 1.0));
771
+ #ifdef USE_TRANSMISSION
772
+ clear = 1.0 - clamp(fog, 0.0, 1.0);
773
+ #endif
774
+ #ifdef USE_REFLECTION_MAP
775
+ mirrorClear = 1.0 - clamp(fog, 0.0, 1.0);
776
+ #endif
777
+ }
778
+ #endif
779
+ #ifdef TONE_MAPPED
780
+ color = toneMap(color);
781
+ #endif
782
+ #ifdef USE_TRANSMISSION
783
+ // The stored scene is display-ready, so it joins after tone mapping; the canvas holds it sRGB-encoded.
784
+ #ifndef LINEAR_OUTPUT
785
+ passed = mix(passed / 12.92, pow((passed + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), passed));
786
+ #endif
787
+ color += passed * tint * through * clear;
788
+ #endif
789
+ #ifdef USE_REFLECTION_MAP
790
+ // The mirror image is display-ready too.
791
+ color += mirrored * mirrorClear;
792
+ #endif
793
+ #ifdef LINEAR_OUTPUT
794
+ // sRGB render targets encode on write; hand them linear values. Fixed-point
795
+ // targets clamp by themselves, and half-float targets must keep values above 1.
796
+ color = max(color, vec3(0.0));
797
+ #else
798
+ color = encodeSrgb(color);
799
+ #endif
800
+ #ifdef ALPHA_BLEND
801
+ #ifdef PREMULTIPLIED_ALPHA
802
+ color *= base.a;
803
+ #endif
804
+ outColor = vec4(color, base.a);
805
+ #else
806
+ outColor = vec4(color, 1.0);
807
+ #endif
808
+ #endif
809
+ }
810
+ `;
811
+ /** Specialize the material shader pair with a list of preprocessor symbols. */
812
+ export function buildMaterialShader3D(defines, customFragment = '', customVertex = '', customNormal = '') {
813
+ const header = '#version 300 es\nprecision highp float;\nprecision highp int;\n' +
814
+ defines.map(name => '#define ' + name + '\n').join('');
815
+ return {
816
+ vertex: header + VERTEX_SOURCE.replace('/*CUSTOM_VERTEX*/', () => customVertex),
817
+ fragment: header +
818
+ FRAGMENT_SOURCE.replace('/*CUSTOM_FRAGMENT*/', () => customFragment).replace('/*CUSTOM_NORMAL*/', () => customNormal)
819
+ };
820
+ }
821
+ /** Full-screen triangle that samples a cube map along the view ray; drawn at the far plane. */
822
+ export const SKYBOX_SHADER_3D = Object.freeze({
823
+ vertex: /* glsl */ `#version 300 es
824
+ precision highp float;
825
+ uniform mat4 uInverseViewProjection;
826
+ out vec3 vDirection;
827
+ void main() {
828
+ vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)) * 2.0 - 1.0;
829
+ vec4 far = uInverseViewProjection * vec4(corner, 1.0, 1.0);
830
+ vec4 near = uInverseViewProjection * vec4(corner, -1.0, 1.0);
831
+ vDirection = far.xyz / far.w - near.xyz / near.w;
832
+ gl_Position = vec4(corner, 1.0, 1.0);
833
+ }
834
+ `,
835
+ fragment: /* glsl */ `#version 300 es
836
+ precision highp float;
837
+ uniform samplerCube uEnvironment;
838
+ uniform vec4 uOutput; // x: intensity, y: 1 keeps linear output, z: exposure, w: tone mapping
839
+ in vec3 vDirection;
840
+ out vec4 outColor;
841
+ void main() {
842
+ vec3 color = texture(uEnvironment, normalize(vDirection)).rgb * uOutput.x * uOutput.z;
843
+ if (uOutput.w > 1.5) color = clamp((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14), 0.0, 1.0);
844
+ else if (uOutput.w > 0.5) color = color / (1.0 + color);
845
+ color = clamp(color, 0.0, 1.0);
846
+ if (uOutput.y < 0.5) color = mix(color * 12.92, 1.055 * pow(color, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), color));
847
+ outColor = vec4(color, 1.0);
848
+ }
849
+ `
850
+ });
851
+ //# sourceMappingURL=shaders3D.js.map