FrameState.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. * The culling volume.
  115. *
  116. * @type {CullingVolume}
  117. * @default undefined
  118. */
  119. this.cullingVolume = undefined;
  120. /**
  121. * The current occluder.
  122. *
  123. * @type {Occluder}
  124. * @default undefined
  125. */
  126. this.occluder = undefined;
  127. /**
  128. * The maximum screen-space error used to drive level-of-detail refinement. Higher
  129. * values will provide better performance but lower visual quality.
  130. *
  131. * @type {Number}
  132. * @default 2
  133. */
  134. this.maximumScreenSpaceError = undefined;
  135. /**
  136. * Ratio between a pixel and a density-independent pixel. Provides a standard unit of
  137. * measure for real pixel measurements appropriate to a particular device.
  138. *
  139. * @type {Number}
  140. * @default 1.0
  141. */
  142. this.pixelRatio = 1.0;
  143. this.passes = {
  144. /**
  145. * <code>true</code> if the primitive should update for a render pass, <code>false</code> otherwise.
  146. *
  147. * @type {Boolean}
  148. * @default false
  149. */
  150. render : false,
  151. /**
  152. * <code>true</code> if the primitive should update for a picking pass, <code>false</code> otherwise.
  153. *
  154. * @type {Boolean}
  155. * @default false
  156. */
  157. pick : false,
  158. /**
  159. * <code>true</code> if the primitive should update for a depth only pass, <code>false</code> otherwise.
  160. * @type {Boolean}
  161. * @default false
  162. */
  163. depth : false,
  164. /**
  165. * <code>true</code> if the primitive should update for a per-feature post-process pass, <code>false</code> otherwise.
  166. * @type {Boolean}
  167. * @default false
  168. */
  169. postProcess : false,
  170. /**
  171. * <code>true</code> if the primitive should update for an offscreen pass, <code>false</code> otherwise.
  172. * @type {Boolean}
  173. * @default false
  174. */
  175. offscreen : false
  176. };
  177. /**
  178. * The credit display.
  179. *
  180. * @type {CreditDisplay}
  181. */
  182. this.creditDisplay = creditDisplay;
  183. /**
  184. * An array of functions to be called at the end of the frame. This array
  185. * will be cleared after each frame.
  186. * <p>
  187. * This allows queueing up events in <code>update</code> functions and
  188. * firing them at a time when the subscribers are free to change the
  189. * scene state, e.g., manipulate the camera, instead of firing events
  190. * directly in <code>update</code> functions.
  191. * </p>
  192. *
  193. * @type {FrameState~AfterRenderCallback[]}
  194. *
  195. * @example
  196. * frameState.afterRender.push(function() {
  197. * // take some action, raise an event, etc.
  198. * });
  199. */
  200. this.afterRender = [];
  201. /**
  202. * Gets whether or not to optimized for 3D only.
  203. *
  204. * @type {Boolean}
  205. * @default false
  206. */
  207. this.scene3DOnly = false;
  208. this.fog = {
  209. /**
  210. * <code>true</code> if fog is enabled, <code>false</code> otherwise.
  211. * @type {Boolean}
  212. * @default false
  213. */
  214. enabled : false,
  215. /**
  216. * A positive number used to mix the color and fog color based on camera distance.
  217. *
  218. * @type {Number}
  219. * @default undefined
  220. */
  221. density : undefined,
  222. /**
  223. * A scalar used to modify the screen space error of geometry partially in fog.
  224. *
  225. * @type {Number}
  226. * @default undefined
  227. */
  228. sse : undefined,
  229. /**
  230. * The minimum brightness of terrain with fog applied.
  231. *
  232. * @type {Number}
  233. * @default undefined
  234. */
  235. minimumBrightness : undefined
  236. };
  237. /**
  238. * A scalar used to exaggerate the terrain.
  239. * @type {Number}
  240. * @default 1.0
  241. */
  242. this.terrainExaggeration = 1.0;
  243. this.shadowState = {
  244. /**
  245. * Whether there are any active shadow maps this frame.
  246. * @type {Boolean}
  247. */
  248. shadowsEnabled : true,
  249. /**
  250. * Whether there are any active shadow maps that originate from light sources. Does not
  251. * include shadow maps that are used for analytical purposes.
  252. */
  253. lightShadowsEnabled : true,
  254. /**
  255. * All shadow maps that are enabled this frame.
  256. */
  257. shadowMaps : [],
  258. /**
  259. * Shadow maps that originate from light sources. Does not include shadow maps that are used for
  260. * analytical purposes. Only these shadow maps will be used to generate receive shadows shaders.
  261. */
  262. lightShadowMaps : [],
  263. /**
  264. * The near plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  265. * @type {Number}
  266. */
  267. nearPlane : 1.0,
  268. /**
  269. * The far plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  270. * @type {Number}
  271. */
  272. farPlane : 5000.0,
  273. /**
  274. * The size of the bounding volume that is closest to the camera. This is used to place more shadow detail near the object.
  275. * @type {Number}
  276. */
  277. closestObjectSize : 1000.0,
  278. /**
  279. * The time when a shadow map was last dirty
  280. * @type {Number}
  281. */
  282. lastDirtyTime : 0,
  283. /**
  284. * Whether the shadows maps are out of view this frame
  285. * @type {Boolean}
  286. */
  287. outOfView : true
  288. };
  289. /**
  290. * The position of the splitter to use when rendering imagery layers on either side of a splitter.
  291. * 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.
  292. * @type {Number}
  293. * @default 0.0
  294. */
  295. this.imagerySplitPosition = 0.0;
  296. /**
  297. * Distances to the near and far planes of the camera frustums
  298. * @type {Number[]}
  299. * @default []
  300. */
  301. this.frustumSplits = [];
  302. /**
  303. * The current scene background color
  304. *
  305. * @type {Color}
  306. */
  307. this.backgroundColor = undefined;
  308. /**
  309. * The color of the light emitted by the sun.
  310. *
  311. * @type {Color}
  312. */
  313. this.sunColor = undefined;
  314. /**
  315. * The distance from the camera at which to disable the depth test of billboards, labels and points
  316. * to, for example, prevent clipping against terrain. When set to zero, the depth test should always
  317. * be applied. When less than zero, the depth test should never be applied.
  318. * @type {Number}
  319. */
  320. this.minimumDisableDepthTestDistance = undefined;
  321. /**
  322. * When <code>false</code>, 3D Tiles will render normally. When <code>true</code>, classified 3D Tile geometry will render normally and
  323. * unclassified 3D Tile geometry will render with the color multiplied with {@link FrameState#invertClassificationColor}.
  324. * @type {Boolean}
  325. * @default false
  326. */
  327. this.invertClassification = false;
  328. /**
  329. * The highlight color of unclassified 3D Tile geometry when {@link FrameState#invertClassification} is <code>true</code>.
  330. * @type {Color}
  331. */
  332. this.invertClassificationColor = undefined;
  333. /**
  334. * Whether or not the scene uses a logarithmic depth buffer.
  335. *
  336. * @type {Boolean}
  337. * @default false
  338. */
  339. this.useLogDepth = false;
  340. /**
  341. * Additional state used to update 3D Tilesets.
  342. *
  343. * @type {Cesium3DTilePassState}
  344. */
  345. this.tilesetPassState = undefined;
  346. }
  347. /**
  348. * A function that will be called at the end of the frame.
  349. *
  350. * @callback FrameState~AfterRenderCallback
  351. */
  352. export default FrameState;