FrameState.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. import SceneMode from "./SceneMode.js";
  2. /**
  3. * State information about the current frame. An instance of this class
  4. * is provided to update functions.
  5. *
  6. * @param {Context} context The rendering context
  7. * @param {CreditDisplay} creditDisplay Handles adding and removing credits from an HTML element
  8. * @param {JobScheduler} jobScheduler The job scheduler
  9. *
  10. * @alias FrameState
  11. * @constructor
  12. *
  13. * @private
  14. */
  15. function FrameState(context, creditDisplay, jobScheduler) {
  16. /**
  17. * The rendering context.
  18. *
  19. * @type {Context}
  20. */
  21. this.context = context;
  22. /**
  23. * An array of rendering commands.
  24. *
  25. * @type {DrawCommand[]}
  26. */
  27. this.commandList = [];
  28. /**
  29. * An array of shadow maps.
  30. * @type {ShadowMap[]}
  31. */
  32. this.shadowMaps = [];
  33. /**
  34. * The BRDF look up texture generator used for image-based lighting for PBR models
  35. * @type {BrdfLutGenerator}
  36. */
  37. this.brdfLutGenerator = undefined;
  38. /**
  39. * The environment map used for image-based lighting for PBR models
  40. * @type {CubeMap}
  41. */
  42. this.environmentMap = undefined;
  43. /**
  44. * The spherical harmonic coefficients used for image-based lighting for PBR models.
  45. * @type {Cartesian3[]}
  46. */
  47. this.sphericalHarmonicCoefficients = undefined;
  48. /**
  49. * The specular environment atlas used for image-based lighting for PBR models.
  50. * @type {Texture}
  51. */
  52. this.specularEnvironmentMaps = undefined;
  53. /**
  54. * The maximum level-of-detail of the specular environment atlas used for image-based lighting for PBR models.
  55. * @type {Number}
  56. */
  57. this.specularEnvironmentMapsMaximumLOD = undefined;
  58. /**
  59. * The current mode of the scene.
  60. *
  61. * @type {SceneMode}
  62. * @default {@link SceneMode.SCENE3D}
  63. */
  64. this.mode = SceneMode.SCENE3D;
  65. /**
  66. * The current morph transition time between 2D/Columbus View and 3D,
  67. * with 0.0 being 2D or Columbus View and 1.0 being 3D.
  68. *
  69. * @type {Number}
  70. */
  71. this.morphTime = SceneMode.getMorphTime(SceneMode.SCENE3D);
  72. /**
  73. * The current frame number.
  74. *
  75. * @type {Number}
  76. * @default 0
  77. */
  78. this.frameNumber = 0;
  79. /**
  80. * <code>true</code> if a new frame has been issued and the frame number has been updated.
  81. *
  82. * @type {Boolean}
  83. * @default false
  84. */
  85. this.newFrame = false;
  86. /**
  87. * The scene's current time.
  88. *
  89. * @type {JulianDate}
  90. * @default undefined
  91. */
  92. this.time = undefined;
  93. /**
  94. * The job scheduler.
  95. *
  96. * @type {JobScheduler}
  97. */
  98. this.jobScheduler = jobScheduler;
  99. /**
  100. * The map projection to use in 2D and Columbus View modes.
  101. *
  102. * @type {MapProjection}
  103. * @default undefined
  104. */
  105. this.mapProjection = undefined;
  106. /**
  107. * The current camera.
  108. *
  109. * @type {Camera}
  110. * @default undefined
  111. */
  112. this.camera = undefined;
  113. /**
  114. * Whether the camera is underground.
  115. *
  116. * @type {Boolean}
  117. * @default false
  118. */
  119. this.cameraUnderground = false;
  120. /**
  121. * The {@link GlobeTranslucencyState} object used by the scene.
  122. *
  123. * @type {GlobeTranslucencyState}
  124. * @default undefined
  125. */
  126. this.globeTranslucencyState = undefined;
  127. /**
  128. * The culling volume.
  129. *
  130. * @type {CullingVolume}
  131. * @default undefined
  132. */
  133. this.cullingVolume = undefined;
  134. /**
  135. * The current occluder.
  136. *
  137. * @type {Occluder}
  138. * @default undefined
  139. */
  140. this.occluder = undefined;
  141. /**
  142. * The maximum screen-space error used to drive level-of-detail refinement. Higher
  143. * values will provide better performance but lower visual quality.
  144. *
  145. * @type {Number}
  146. * @default 2
  147. */
  148. this.maximumScreenSpaceError = undefined;
  149. /**
  150. * Ratio between a pixel and a density-independent pixel. Provides a standard unit of
  151. * measure for real pixel measurements appropriate to a particular device.
  152. *
  153. * @type {Number}
  154. * @default 1.0
  155. */
  156. this.pixelRatio = 1.0;
  157. /**
  158. * @typedef FrameState.Passes
  159. * @type {Object}
  160. * @property {Boolean} render <code>true</code> if the primitive should update for a render pass, <code>false</code> otherwise.
  161. * @property {Boolean} pick <code>true</code> if the primitive should update for a picking pass, <code>false</code> otherwise.
  162. * @property {Boolean} depth <code>true</code> if the primitive should update for a depth only pass, <code>false</code> otherwise.
  163. * @property {Boolean} postProcess <code>true</code> if the primitive should update for a per-feature post-process pass, <code>false</code> otherwise.
  164. * @property {Boolean} offscreen <code>true</code> if the primitive should update for an offscreen pass, <code>false</code> otherwise.
  165. */
  166. /**
  167. * @type {FrameState.Passes}
  168. */
  169. this.passes = {
  170. /**
  171. * @default false
  172. */
  173. render: false,
  174. /**
  175. * @default false
  176. */
  177. pick: false,
  178. /**
  179. * @default false
  180. */
  181. depth: false,
  182. /**
  183. * @default false
  184. */
  185. postProcess: false,
  186. /**
  187. * @default false
  188. */
  189. offscreen: false,
  190. };
  191. /**
  192. * The credit display.
  193. *
  194. * @type {CreditDisplay}
  195. */
  196. this.creditDisplay = creditDisplay;
  197. /**
  198. * An array of functions to be called at the end of the frame. This array
  199. * will be cleared after each frame.
  200. * <p>
  201. * This allows queueing up events in <code>update</code> functions and
  202. * firing them at a time when the subscribers are free to change the
  203. * scene state, e.g., manipulate the camera, instead of firing events
  204. * directly in <code>update</code> functions.
  205. * </p>
  206. *
  207. * @type {FrameState.AfterRenderCallback[]}
  208. *
  209. * @example
  210. * frameState.afterRender.push(function() {
  211. * // take some action, raise an event, etc.
  212. * });
  213. */
  214. this.afterRender = [];
  215. /**
  216. * Gets whether or not to optimized for 3D only.
  217. *
  218. * @type {Boolean}
  219. * @default false
  220. */
  221. this.scene3DOnly = false;
  222. /**
  223. * @typedef FrameState.Fog
  224. * @type {Object}
  225. * @property {Boolean} enabled <code>true</code> if fog is enabled, <code>false</code> otherwise.
  226. * @property {Number} density A positive number used to mix the color and fog color based on camera distance.
  227. * @property {Number} sse A scalar used to modify the screen space error of geometry partially in fog.
  228. * @property {Number} minimumBrightness The minimum brightness of terrain with fog applied.
  229. */
  230. /**
  231. * @type {FrameState.Fog}
  232. */
  233. this.fog = {
  234. /**
  235. * @default false
  236. */
  237. enabled: false,
  238. density: undefined,
  239. sse: undefined,
  240. minimumBrightness: undefined,
  241. };
  242. /**
  243. * A scalar used to exaggerate the terrain.
  244. * @type {Number}
  245. * @default 1.0
  246. */
  247. this.terrainExaggeration = 1.0;
  248. /**
  249. * The height relative to which terrain is exaggerated.
  250. * @type {Number}
  251. * @default 0.0
  252. */
  253. this.terrainExaggerationRelativeHeight = 0.0;
  254. /**
  255. * @typedef FrameState.ShadowState
  256. * @type {Object}
  257. * @property {Boolean} shadowsEnabled Whether there are any active shadow maps this frame.
  258. * @property {Boolean} lightShadowsEnabled Whether there are any active shadow maps that originate from light sources. Does not include shadow maps that are used for analytical purposes.
  259. * @property {ShadowMap[]} shadowMaps All shadow maps that are enabled this frame.
  260. * @property {ShadowMap[]} lightShadowMaps Shadow maps that originate from light sources. Does not include shadow maps that are used for analytical purposes. Only these shadow maps will be used to generate receive shadows shaders.
  261. * @property {Number} nearPlane The near plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  262. * @property {Number} farPlane The far plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  263. * @property {Number} closestObjectSize The size of the bounding volume that is closest to the camera. This is used to place more shadow detail near the object.
  264. * @property {Number} lastDirtyTime The time when a shadow map was last dirty
  265. * @property {Boolean} outOfView Whether the shadows maps are out of view this frame
  266. */
  267. /**
  268. * @type {FrameState.ShadowState}
  269. */
  270. this.shadowState = {
  271. /**
  272. * @default true
  273. */
  274. shadowsEnabled: true,
  275. shadowMaps: [],
  276. lightShadowMaps: [],
  277. /**
  278. * @default 1.0
  279. */
  280. nearPlane: 1.0,
  281. /**
  282. * @default 5000.0
  283. */
  284. farPlane: 5000.0,
  285. /**
  286. * @default 1000.0
  287. */
  288. closestObjectSize: 1000.0,
  289. /**
  290. * @default 0
  291. */
  292. lastDirtyTime: 0,
  293. /**
  294. * @default true
  295. */
  296. outOfView: true,
  297. };
  298. /**
  299. * The position of the splitter to use when rendering different things on either side of a splitter.
  300. * This value should be between 0.0 and 1.0 with 0 being the far left of the viewport and 1 being the far right of the viewport.
  301. * @type {Number}
  302. * @default 0.0
  303. */
  304. this.splitPosition = 0.0;
  305. /**
  306. * Distances to the near and far planes of the camera frustums
  307. * @type {Number[]}
  308. * @default []
  309. */
  310. this.frustumSplits = [];
  311. /**
  312. * The current scene background color
  313. *
  314. * @type {Color}
  315. */
  316. this.backgroundColor = undefined;
  317. /**
  318. * The light used to shade the scene.
  319. *
  320. * @type {Light}
  321. */
  322. this.light = undefined;
  323. /**
  324. * The distance from the camera at which to disable the depth test of billboards, labels and points
  325. * to, for example, prevent clipping against terrain. When set to zero, the depth test should always
  326. * be applied. When less than zero, the depth test should never be applied.
  327. * @type {Number}
  328. */
  329. this.minimumDisableDepthTestDistance = undefined;
  330. /**
  331. * When <code>false</code>, 3D Tiles will render normally. When <code>true</code>, classified 3D Tile geometry will render normally and
  332. * unclassified 3D Tile geometry will render with the color multiplied with {@link FrameState#invertClassificationColor}.
  333. * @type {Boolean}
  334. * @default false
  335. */
  336. this.invertClassification = false;
  337. /**
  338. * The highlight color of unclassified 3D Tile geometry when {@link FrameState#invertClassification} is <code>true</code>.
  339. * @type {Color}
  340. */
  341. this.invertClassificationColor = undefined;
  342. /**
  343. * Whether or not the scene uses a logarithmic depth buffer.
  344. *
  345. * @type {Boolean}
  346. * @default false
  347. */
  348. this.useLogDepth = false;
  349. /**
  350. * Additional state used to update 3D Tilesets.
  351. *
  352. * @type {Cesium3DTilePassState}
  353. */
  354. this.tilesetPassState = undefined;
  355. /**
  356. * The minimum terrain height out of all rendered terrain tiles. Used to improve culling for objects underneath the ellipsoid but above terrain.
  357. *
  358. * @type {Number}
  359. * @default 0.0
  360. */
  361. this.minimumTerrainHeight = 0.0;
  362. }
  363. /**
  364. * A function that will be called at the end of the frame.
  365. *
  366. * @callback FrameState.AfterRenderCallback
  367. */
  368. export default FrameState;