AutomaticUniforms.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Matrix4 from "../Core/Matrix4.js";
  3. import WebGLConstants from "../Core/WebGLConstants.js";
  4. const viewerPositionWCScratch = new Cartesian3();
  5. function AutomaticUniform(options) {
  6. this._size = options.size;
  7. this._datatype = options.datatype;
  8. this.getValue = options.getValue;
  9. }
  10. const datatypeToGlsl = {};
  11. datatypeToGlsl[WebGLConstants.FLOAT] = "float";
  12. datatypeToGlsl[WebGLConstants.FLOAT_VEC2] = "vec2";
  13. datatypeToGlsl[WebGLConstants.FLOAT_VEC3] = "vec3";
  14. datatypeToGlsl[WebGLConstants.FLOAT_VEC4] = "vec4";
  15. datatypeToGlsl[WebGLConstants.INT] = "int";
  16. datatypeToGlsl[WebGLConstants.INT_VEC2] = "ivec2";
  17. datatypeToGlsl[WebGLConstants.INT_VEC3] = "ivec3";
  18. datatypeToGlsl[WebGLConstants.INT_VEC4] = "ivec4";
  19. datatypeToGlsl[WebGLConstants.BOOL] = "bool";
  20. datatypeToGlsl[WebGLConstants.BOOL_VEC2] = "bvec2";
  21. datatypeToGlsl[WebGLConstants.BOOL_VEC3] = "bvec3";
  22. datatypeToGlsl[WebGLConstants.BOOL_VEC4] = "bvec4";
  23. datatypeToGlsl[WebGLConstants.FLOAT_MAT2] = "mat2";
  24. datatypeToGlsl[WebGLConstants.FLOAT_MAT3] = "mat3";
  25. datatypeToGlsl[WebGLConstants.FLOAT_MAT4] = "mat4";
  26. datatypeToGlsl[WebGLConstants.SAMPLER_2D] = "sampler2D";
  27. datatypeToGlsl[WebGLConstants.SAMPLER_CUBE] = "samplerCube";
  28. AutomaticUniform.prototype.getDeclaration = function (name) {
  29. let declaration = `uniform ${datatypeToGlsl[this._datatype]} ${name}`;
  30. const size = this._size;
  31. if (size === 1) {
  32. declaration += ";";
  33. } else {
  34. declaration += `[${size.toString()}];`;
  35. }
  36. return declaration;
  37. };
  38. /**
  39. * @private
  40. */
  41. const AutomaticUniforms = {
  42. /**
  43. * An automatic GLSL uniform containing the viewport's <code>x</code>, <code>y</code>, <code>width</code>,
  44. * and <code>height</code> properties in an <code>vec4</code>'s <code>x</code>, <code>y</code>, <code>z</code>,
  45. * and <code>w</code> components, respectively.
  46. *
  47. * @example
  48. * // GLSL declaration
  49. * uniform vec4 czm_viewport;
  50. *
  51. * // Scale the window coordinate components to [0, 1] by dividing
  52. * // by the viewport's width and height.
  53. * vec2 v = gl_FragCoord.xy / czm_viewport.zw;
  54. *
  55. * @see Context#getViewport
  56. */
  57. czm_viewport: new AutomaticUniform({
  58. size: 1,
  59. datatype: WebGLConstants.FLOAT_VEC4,
  60. getValue: function (uniformState) {
  61. return uniformState.viewportCartesian4;
  62. },
  63. }),
  64. /**
  65. * An automatic GLSL uniform representing a 4x4 orthographic projection matrix that
  66. * transforms window coordinates to clip coordinates. Clip coordinates is the
  67. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  68. * <br /><br />
  69. * This transform is useful when a vertex shader inputs or manipulates window coordinates
  70. * as done by {@link BillboardCollection}.
  71. * <br /><br />
  72. * Do not confuse {@link czm_viewportTransformation} with <code>czm_viewportOrthographic</code>.
  73. * The former transforms from normalized device coordinates to window coordinates; the later transforms
  74. * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
  75. *
  76. * @example
  77. * // GLSL declaration
  78. * uniform mat4 czm_viewportOrthographic;
  79. *
  80. * // Example
  81. * gl_Position = czm_viewportOrthographic * vec4(windowPosition, 0.0, 1.0);
  82. *
  83. * @see UniformState#viewportOrthographic
  84. * @see czm_viewport
  85. * @see czm_viewportTransformation
  86. * @see BillboardCollection
  87. */
  88. czm_viewportOrthographic: new AutomaticUniform({
  89. size: 1,
  90. datatype: WebGLConstants.FLOAT_MAT4,
  91. getValue: function (uniformState) {
  92. return uniformState.viewportOrthographic;
  93. },
  94. }),
  95. /**
  96. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  97. * transforms normalized device coordinates to window coordinates. The context's
  98. * full viewport is used, and the depth range is assumed to be <code>near = 0</code>
  99. * and <code>far = 1</code>.
  100. * <br /><br />
  101. * This transform is useful when there is a need to manipulate window coordinates
  102. * in a vertex shader as done by {@link BillboardCollection}. In many cases,
  103. * this matrix will not be used directly; instead, {@link czm_modelToWindowCoordinates}
  104. * will be used to transform directly from model to window coordinates.
  105. * <br /><br />
  106. * Do not confuse <code>czm_viewportTransformation</code> with {@link czm_viewportOrthographic}.
  107. * The former transforms from normalized device coordinates to window coordinates; the later transforms
  108. * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
  109. *
  110. * @example
  111. * // GLSL declaration
  112. * uniform mat4 czm_viewportTransformation;
  113. *
  114. * // Use czm_viewportTransformation as part of the
  115. * // transform from model to window coordinates.
  116. * vec4 q = czm_modelViewProjection * positionMC; // model to clip coordinates
  117. * q.xyz /= q.w; // clip to normalized device coordinates (ndc)
  118. * q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // ndc to window coordinates
  119. *
  120. * @see UniformState#viewportTransformation
  121. * @see czm_viewport
  122. * @see czm_viewportOrthographic
  123. * @see czm_modelToWindowCoordinates
  124. * @see BillboardCollection
  125. */
  126. czm_viewportTransformation: new AutomaticUniform({
  127. size: 1,
  128. datatype: WebGLConstants.FLOAT_MAT4,
  129. getValue: function (uniformState) {
  130. return uniformState.viewportTransformation;
  131. },
  132. }),
  133. /**
  134. * An automatic GLSL uniform representing the depth of the scene
  135. * after the globe pass and then updated after the 3D Tiles pass.
  136. * The depth is packed into an RGBA texture.
  137. *
  138. * @example
  139. * // GLSL declaration
  140. * uniform sampler2D czm_globeDepthTexture;
  141. *
  142. * // Get the depth at the current fragment
  143. * vec2 coords = gl_FragCoord.xy / czm_viewport.zw;
  144. * float depth = czm_unpackDepth(texture2D(czm_globeDepthTexture, coords));
  145. */
  146. czm_globeDepthTexture: new AutomaticUniform({
  147. size: 1,
  148. datatype: WebGLConstants.SAMPLER_2D,
  149. getValue: function (uniformState) {
  150. return uniformState.globeDepthTexture;
  151. },
  152. }),
  153. /**
  154. * An automatic GLSL uniform representing a 4x4 model transformation matrix that
  155. * transforms model coordinates to world coordinates.
  156. *
  157. * @example
  158. * // GLSL declaration
  159. * uniform mat4 czm_model;
  160. *
  161. * // Example
  162. * vec4 worldPosition = czm_model * modelPosition;
  163. *
  164. * @see UniformState#model
  165. * @see czm_inverseModel
  166. * @see czm_modelView
  167. * @see czm_modelViewProjection
  168. */
  169. czm_model: new AutomaticUniform({
  170. size: 1,
  171. datatype: WebGLConstants.FLOAT_MAT4,
  172. getValue: function (uniformState) {
  173. return uniformState.model;
  174. },
  175. }),
  176. /**
  177. * An automatic GLSL uniform representing a 4x4 model transformation matrix that
  178. * transforms world coordinates to model coordinates.
  179. *
  180. * @example
  181. * // GLSL declaration
  182. * uniform mat4 czm_inverseModel;
  183. *
  184. * // Example
  185. * vec4 modelPosition = czm_inverseModel * worldPosition;
  186. *
  187. * @see UniformState#inverseModel
  188. * @see czm_model
  189. * @see czm_inverseModelView
  190. */
  191. czm_inverseModel: new AutomaticUniform({
  192. size: 1,
  193. datatype: WebGLConstants.FLOAT_MAT4,
  194. getValue: function (uniformState) {
  195. return uniformState.inverseModel;
  196. },
  197. }),
  198. /**
  199. * An automatic GLSL uniform representing a 4x4 view transformation matrix that
  200. * transforms world coordinates to eye coordinates.
  201. *
  202. * @example
  203. * // GLSL declaration
  204. * uniform mat4 czm_view;
  205. *
  206. * // Example
  207. * vec4 eyePosition = czm_view * worldPosition;
  208. *
  209. * @see UniformState#view
  210. * @see czm_viewRotation
  211. * @see czm_modelView
  212. * @see czm_viewProjection
  213. * @see czm_modelViewProjection
  214. * @see czm_inverseView
  215. */
  216. czm_view: new AutomaticUniform({
  217. size: 1,
  218. datatype: WebGLConstants.FLOAT_MAT4,
  219. getValue: function (uniformState) {
  220. return uniformState.view;
  221. },
  222. }),
  223. /**
  224. * An automatic GLSL uniform representing a 4x4 view transformation matrix that
  225. * transforms 3D world coordinates to eye coordinates. In 3D mode, this is identical to
  226. * {@link czm_view}, but in 2D and Columbus View it represents the view matrix
  227. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  228. * 2D and Columbus View in the same way that 3D is lit.
  229. *
  230. * @example
  231. * // GLSL declaration
  232. * uniform mat4 czm_view3D;
  233. *
  234. * // Example
  235. * vec4 eyePosition3D = czm_view3D * worldPosition3D;
  236. *
  237. * @see UniformState#view3D
  238. * @see czm_view
  239. */
  240. czm_view3D: new AutomaticUniform({
  241. size: 1,
  242. datatype: WebGLConstants.FLOAT_MAT4,
  243. getValue: function (uniformState) {
  244. return uniformState.view3D;
  245. },
  246. }),
  247. /**
  248. * An automatic GLSL uniform representing a 3x3 view rotation matrix that
  249. * transforms vectors in world coordinates to eye coordinates.
  250. *
  251. * @example
  252. * // GLSL declaration
  253. * uniform mat3 czm_viewRotation;
  254. *
  255. * // Example
  256. * vec3 eyeVector = czm_viewRotation * worldVector;
  257. *
  258. * @see UniformState#viewRotation
  259. * @see czm_view
  260. * @see czm_inverseView
  261. * @see czm_inverseViewRotation
  262. */
  263. czm_viewRotation: new AutomaticUniform({
  264. size: 1,
  265. datatype: WebGLConstants.FLOAT_MAT3,
  266. getValue: function (uniformState) {
  267. return uniformState.viewRotation;
  268. },
  269. }),
  270. /**
  271. * An automatic GLSL uniform representing a 3x3 view rotation matrix that
  272. * transforms vectors in 3D world coordinates to eye coordinates. In 3D mode, this is identical to
  273. * {@link czm_viewRotation}, but in 2D and Columbus View it represents the view matrix
  274. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  275. * 2D and Columbus View in the same way that 3D is lit.
  276. *
  277. * @example
  278. * // GLSL declaration
  279. * uniform mat3 czm_viewRotation3D;
  280. *
  281. * // Example
  282. * vec3 eyeVector = czm_viewRotation3D * worldVector;
  283. *
  284. * @see UniformState#viewRotation3D
  285. * @see czm_viewRotation
  286. */
  287. czm_viewRotation3D: new AutomaticUniform({
  288. size: 1,
  289. datatype: WebGLConstants.FLOAT_MAT3,
  290. getValue: function (uniformState) {
  291. return uniformState.viewRotation3D;
  292. },
  293. }),
  294. /**
  295. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  296. * transforms from eye coordinates to world coordinates.
  297. *
  298. * @example
  299. * // GLSL declaration
  300. * uniform mat4 czm_inverseView;
  301. *
  302. * // Example
  303. * vec4 worldPosition = czm_inverseView * eyePosition;
  304. *
  305. * @see UniformState#inverseView
  306. * @see czm_view
  307. * @see czm_inverseNormal
  308. */
  309. czm_inverseView: new AutomaticUniform({
  310. size: 1,
  311. datatype: WebGLConstants.FLOAT_MAT4,
  312. getValue: function (uniformState) {
  313. return uniformState.inverseView;
  314. },
  315. }),
  316. /**
  317. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  318. * transforms from 3D eye coordinates to world coordinates. In 3D mode, this is identical to
  319. * {@link czm_inverseView}, but in 2D and Columbus View it represents the inverse view matrix
  320. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  321. * 2D and Columbus View in the same way that 3D is lit.
  322. *
  323. * @example
  324. * // GLSL declaration
  325. * uniform mat4 czm_inverseView3D;
  326. *
  327. * // Example
  328. * vec4 worldPosition = czm_inverseView3D * eyePosition;
  329. *
  330. * @see UniformState#inverseView3D
  331. * @see czm_inverseView
  332. */
  333. czm_inverseView3D: new AutomaticUniform({
  334. size: 1,
  335. datatype: WebGLConstants.FLOAT_MAT4,
  336. getValue: function (uniformState) {
  337. return uniformState.inverseView3D;
  338. },
  339. }),
  340. /**
  341. * An automatic GLSL uniform representing a 3x3 rotation matrix that
  342. * transforms vectors from eye coordinates to world coordinates.
  343. *
  344. * @example
  345. * // GLSL declaration
  346. * uniform mat3 czm_inverseViewRotation;
  347. *
  348. * // Example
  349. * vec4 worldVector = czm_inverseViewRotation * eyeVector;
  350. *
  351. * @see UniformState#inverseView
  352. * @see czm_view
  353. * @see czm_viewRotation
  354. * @see czm_inverseViewRotation
  355. */
  356. czm_inverseViewRotation: new AutomaticUniform({
  357. size: 1,
  358. datatype: WebGLConstants.FLOAT_MAT3,
  359. getValue: function (uniformState) {
  360. return uniformState.inverseViewRotation;
  361. },
  362. }),
  363. /**
  364. * An automatic GLSL uniform representing a 3x3 rotation matrix that
  365. * transforms vectors from 3D eye coordinates to world coordinates. In 3D mode, this is identical to
  366. * {@link czm_inverseViewRotation}, but in 2D and Columbus View it represents the inverse view matrix
  367. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  368. * 2D and Columbus View in the same way that 3D is lit.
  369. *
  370. * @example
  371. * // GLSL declaration
  372. * uniform mat3 czm_inverseViewRotation3D;
  373. *
  374. * // Example
  375. * vec4 worldVector = czm_inverseViewRotation3D * eyeVector;
  376. *
  377. * @see UniformState#inverseView3D
  378. * @see czm_inverseViewRotation
  379. */
  380. czm_inverseViewRotation3D: new AutomaticUniform({
  381. size: 1,
  382. datatype: WebGLConstants.FLOAT_MAT3,
  383. getValue: function (uniformState) {
  384. return uniformState.inverseViewRotation3D;
  385. },
  386. }),
  387. /**
  388. * An automatic GLSL uniform representing a 4x4 projection transformation matrix that
  389. * transforms eye coordinates to clip coordinates. Clip coordinates is the
  390. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  391. *
  392. * @example
  393. * // GLSL declaration
  394. * uniform mat4 czm_projection;
  395. *
  396. * // Example
  397. * gl_Position = czm_projection * eyePosition;
  398. *
  399. * @see UniformState#projection
  400. * @see czm_viewProjection
  401. * @see czm_modelViewProjection
  402. * @see czm_infiniteProjection
  403. */
  404. czm_projection: new AutomaticUniform({
  405. size: 1,
  406. datatype: WebGLConstants.FLOAT_MAT4,
  407. getValue: function (uniformState) {
  408. return uniformState.projection;
  409. },
  410. }),
  411. /**
  412. * An automatic GLSL uniform representing a 4x4 inverse projection transformation matrix that
  413. * transforms from clip coordinates to eye coordinates. Clip coordinates is the
  414. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  415. *
  416. * @example
  417. * // GLSL declaration
  418. * uniform mat4 czm_inverseProjection;
  419. *
  420. * // Example
  421. * vec4 eyePosition = czm_inverseProjection * clipPosition;
  422. *
  423. * @see UniformState#inverseProjection
  424. * @see czm_projection
  425. */
  426. czm_inverseProjection: new AutomaticUniform({
  427. size: 1,
  428. datatype: WebGLConstants.FLOAT_MAT4,
  429. getValue: function (uniformState) {
  430. return uniformState.inverseProjection;
  431. },
  432. }),
  433. /**
  434. * An automatic GLSL uniform representing a 4x4 projection transformation matrix with the far plane at infinity,
  435. * that transforms eye coordinates to clip coordinates. Clip coordinates is the
  436. * coordinate system for a vertex shader's <code>gl_Position</code> output. An infinite far plane is used
  437. * in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles
  438. * are not clipped by the far plane.
  439. *
  440. * @example
  441. * // GLSL declaration
  442. * uniform mat4 czm_infiniteProjection;
  443. *
  444. * // Example
  445. * gl_Position = czm_infiniteProjection * eyePosition;
  446. *
  447. * @see UniformState#infiniteProjection
  448. * @see czm_projection
  449. * @see czm_modelViewInfiniteProjection
  450. */
  451. czm_infiniteProjection: new AutomaticUniform({
  452. size: 1,
  453. datatype: WebGLConstants.FLOAT_MAT4,
  454. getValue: function (uniformState) {
  455. return uniformState.infiniteProjection;
  456. },
  457. }),
  458. /**
  459. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  460. * transforms model coordinates to eye coordinates.
  461. * <br /><br />
  462. * Positions should be transformed to eye coordinates using <code>czm_modelView</code> and
  463. * normals should be transformed using {@link czm_normal}.
  464. *
  465. * @example
  466. * // GLSL declaration
  467. * uniform mat4 czm_modelView;
  468. *
  469. * // Example
  470. * vec4 eyePosition = czm_modelView * modelPosition;
  471. *
  472. * // The above is equivalent to, but more efficient than:
  473. * vec4 eyePosition = czm_view * czm_model * modelPosition;
  474. *
  475. * @see UniformState#modelView
  476. * @see czm_model
  477. * @see czm_view
  478. * @see czm_modelViewProjection
  479. * @see czm_normal
  480. */
  481. czm_modelView: new AutomaticUniform({
  482. size: 1,
  483. datatype: WebGLConstants.FLOAT_MAT4,
  484. getValue: function (uniformState) {
  485. return uniformState.modelView;
  486. },
  487. }),
  488. /**
  489. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  490. * transforms 3D model coordinates to eye coordinates. In 3D mode, this is identical to
  491. * {@link czm_modelView}, but in 2D and Columbus View it represents the model-view matrix
  492. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  493. * 2D and Columbus View in the same way that 3D is lit.
  494. * <br /><br />
  495. * Positions should be transformed to eye coordinates using <code>czm_modelView3D</code> and
  496. * normals should be transformed using {@link czm_normal3D}.
  497. *
  498. * @example
  499. * // GLSL declaration
  500. * uniform mat4 czm_modelView3D;
  501. *
  502. * // Example
  503. * vec4 eyePosition = czm_modelView3D * modelPosition;
  504. *
  505. * // The above is equivalent to, but more efficient than:
  506. * vec4 eyePosition = czm_view3D * czm_model * modelPosition;
  507. *
  508. * @see UniformState#modelView3D
  509. * @see czm_modelView
  510. */
  511. czm_modelView3D: new AutomaticUniform({
  512. size: 1,
  513. datatype: WebGLConstants.FLOAT_MAT4,
  514. getValue: function (uniformState) {
  515. return uniformState.modelView3D;
  516. },
  517. }),
  518. /**
  519. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  520. * transforms model coordinates, relative to the eye, to eye coordinates. This is used
  521. * in conjunction with {@link czm_translateRelativeToEye}.
  522. *
  523. * @example
  524. * // GLSL declaration
  525. * uniform mat4 czm_modelViewRelativeToEye;
  526. *
  527. * // Example
  528. * attribute vec3 positionHigh;
  529. * attribute vec3 positionLow;
  530. *
  531. * void main()
  532. * {
  533. * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  534. * gl_Position = czm_projection * (czm_modelViewRelativeToEye * p);
  535. * }
  536. *
  537. * @see czm_modelViewProjectionRelativeToEye
  538. * @see czm_translateRelativeToEye
  539. * @see EncodedCartesian3
  540. */
  541. czm_modelViewRelativeToEye: new AutomaticUniform({
  542. size: 1,
  543. datatype: WebGLConstants.FLOAT_MAT4,
  544. getValue: function (uniformState) {
  545. return uniformState.modelViewRelativeToEye;
  546. },
  547. }),
  548. /**
  549. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  550. * transforms from eye coordinates to model coordinates.
  551. *
  552. * @example
  553. * // GLSL declaration
  554. * uniform mat4 czm_inverseModelView;
  555. *
  556. * // Example
  557. * vec4 modelPosition = czm_inverseModelView * eyePosition;
  558. *
  559. * @see UniformState#inverseModelView
  560. * @see czm_modelView
  561. */
  562. czm_inverseModelView: new AutomaticUniform({
  563. size: 1,
  564. datatype: WebGLConstants.FLOAT_MAT4,
  565. getValue: function (uniformState) {
  566. return uniformState.inverseModelView;
  567. },
  568. }),
  569. /**
  570. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  571. * transforms from eye coordinates to 3D model coordinates. In 3D mode, this is identical to
  572. * {@link czm_inverseModelView}, but in 2D and Columbus View it represents the inverse model-view matrix
  573. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  574. * 2D and Columbus View in the same way that 3D is lit.
  575. *
  576. * @example
  577. * // GLSL declaration
  578. * uniform mat4 czm_inverseModelView3D;
  579. *
  580. * // Example
  581. * vec4 modelPosition = czm_inverseModelView3D * eyePosition;
  582. *
  583. * @see UniformState#inverseModelView
  584. * @see czm_inverseModelView
  585. * @see czm_modelView3D
  586. */
  587. czm_inverseModelView3D: new AutomaticUniform({
  588. size: 1,
  589. datatype: WebGLConstants.FLOAT_MAT4,
  590. getValue: function (uniformState) {
  591. return uniformState.inverseModelView3D;
  592. },
  593. }),
  594. /**
  595. * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that
  596. * transforms world coordinates to clip coordinates. Clip coordinates is the
  597. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  598. *
  599. * @example
  600. * // GLSL declaration
  601. * uniform mat4 czm_viewProjection;
  602. *
  603. * // Example
  604. * vec4 gl_Position = czm_viewProjection * czm_model * modelPosition;
  605. *
  606. * // The above is equivalent to, but more efficient than:
  607. * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
  608. *
  609. * @see UniformState#viewProjection
  610. * @see czm_view
  611. * @see czm_projection
  612. * @see czm_modelViewProjection
  613. * @see czm_inverseViewProjection
  614. */
  615. czm_viewProjection: new AutomaticUniform({
  616. size: 1,
  617. datatype: WebGLConstants.FLOAT_MAT4,
  618. getValue: function (uniformState) {
  619. return uniformState.viewProjection;
  620. },
  621. }),
  622. /**
  623. * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that
  624. * transforms clip coordinates to world coordinates. Clip coordinates is the
  625. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  626. *
  627. * @example
  628. * // GLSL declaration
  629. * uniform mat4 czm_inverseViewProjection;
  630. *
  631. * // Example
  632. * vec4 worldPosition = czm_inverseViewProjection * clipPosition;
  633. *
  634. * @see UniformState#inverseViewProjection
  635. * @see czm_viewProjection
  636. */
  637. czm_inverseViewProjection: new AutomaticUniform({
  638. size: 1,
  639. datatype: WebGLConstants.FLOAT_MAT4,
  640. getValue: function (uniformState) {
  641. return uniformState.inverseViewProjection;
  642. },
  643. }),
  644. /**
  645. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  646. * transforms model coordinates to clip coordinates. Clip coordinates is the
  647. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  648. *
  649. * @example
  650. * // GLSL declaration
  651. * uniform mat4 czm_modelViewProjection;
  652. *
  653. * // Example
  654. * vec4 gl_Position = czm_modelViewProjection * modelPosition;
  655. *
  656. * // The above is equivalent to, but more efficient than:
  657. * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
  658. *
  659. * @see UniformState#modelViewProjection
  660. * @see czm_model
  661. * @see czm_view
  662. * @see czm_projection
  663. * @see czm_modelView
  664. * @see czm_viewProjection
  665. * @see czm_modelViewInfiniteProjection
  666. * @see czm_inverseModelViewProjection
  667. */
  668. czm_modelViewProjection: new AutomaticUniform({
  669. size: 1,
  670. datatype: WebGLConstants.FLOAT_MAT4,
  671. getValue: function (uniformState) {
  672. return uniformState.modelViewProjection;
  673. },
  674. }),
  675. /**
  676. * An automatic GLSL uniform representing a 4x4 inverse model-view-projection transformation matrix that
  677. * transforms clip coordinates to model coordinates. Clip coordinates is the
  678. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  679. *
  680. * @example
  681. * // GLSL declaration
  682. * uniform mat4 czm_inverseModelViewProjection;
  683. *
  684. * // Example
  685. * vec4 modelPosition = czm_inverseModelViewProjection * clipPosition;
  686. *
  687. * @see UniformState#modelViewProjection
  688. * @see czm_modelViewProjection
  689. */
  690. czm_inverseModelViewProjection: new AutomaticUniform({
  691. size: 1,
  692. datatype: WebGLConstants.FLOAT_MAT4,
  693. getValue: function (uniformState) {
  694. return uniformState.inverseModelViewProjection;
  695. },
  696. }),
  697. /**
  698. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  699. * transforms model coordinates, relative to the eye, to clip coordinates. Clip coordinates is the
  700. * coordinate system for a vertex shader's <code>gl_Position</code> output. This is used in
  701. * conjunction with {@link czm_translateRelativeToEye}.
  702. *
  703. * @example
  704. * // GLSL declaration
  705. * uniform mat4 czm_modelViewProjectionRelativeToEye;
  706. *
  707. * // Example
  708. * attribute vec3 positionHigh;
  709. * attribute vec3 positionLow;
  710. *
  711. * void main()
  712. * {
  713. * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  714. * gl_Position = czm_modelViewProjectionRelativeToEye * p;
  715. * }
  716. *
  717. * @see czm_modelViewRelativeToEye
  718. * @see czm_translateRelativeToEye
  719. * @see EncodedCartesian3
  720. */
  721. czm_modelViewProjectionRelativeToEye: new AutomaticUniform({
  722. size: 1,
  723. datatype: WebGLConstants.FLOAT_MAT4,
  724. getValue: function (uniformState) {
  725. return uniformState.modelViewProjectionRelativeToEye;
  726. },
  727. }),
  728. /**
  729. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  730. * transforms model coordinates to clip coordinates. Clip coordinates is the
  731. * coordinate system for a vertex shader's <code>gl_Position</code> output. The projection matrix places
  732. * the far plane at infinity. This is useful in algorithms like shadow volumes and GPU ray casting with
  733. * proxy geometry to ensure that triangles are not clipped by the far plane.
  734. *
  735. * @example
  736. * // GLSL declaration
  737. * uniform mat4 czm_modelViewInfiniteProjection;
  738. *
  739. * // Example
  740. * vec4 gl_Position = czm_modelViewInfiniteProjection * modelPosition;
  741. *
  742. * // The above is equivalent to, but more efficient than:
  743. * gl_Position = czm_infiniteProjection * czm_view * czm_model * modelPosition;
  744. *
  745. * @see UniformState#modelViewInfiniteProjection
  746. * @see czm_model
  747. * @see czm_view
  748. * @see czm_infiniteProjection
  749. * @see czm_modelViewProjection
  750. */
  751. czm_modelViewInfiniteProjection: new AutomaticUniform({
  752. size: 1,
  753. datatype: WebGLConstants.FLOAT_MAT4,
  754. getValue: function (uniformState) {
  755. return uniformState.modelViewInfiniteProjection;
  756. },
  757. }),
  758. /**
  759. * An automatic GLSL uniform that indicates if the current camera is orthographic in 3D.
  760. *
  761. * @see UniformState#orthographicIn3D
  762. */
  763. czm_orthographicIn3D: new AutomaticUniform({
  764. size: 1,
  765. datatype: WebGLConstants.FLOAT,
  766. getValue: function (uniformState) {
  767. return uniformState.orthographicIn3D ? 1 : 0;
  768. },
  769. }),
  770. /**
  771. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  772. * transforms normal vectors in model coordinates to eye coordinates.
  773. * <br /><br />
  774. * Positions should be transformed to eye coordinates using {@link czm_modelView} and
  775. * normals should be transformed using <code>czm_normal</code>.
  776. *
  777. * @example
  778. * // GLSL declaration
  779. * uniform mat3 czm_normal;
  780. *
  781. * // Example
  782. * vec3 eyeNormal = czm_normal * normal;
  783. *
  784. * @see UniformState#normal
  785. * @see czm_inverseNormal
  786. * @see czm_modelView
  787. */
  788. czm_normal: new AutomaticUniform({
  789. size: 1,
  790. datatype: WebGLConstants.FLOAT_MAT3,
  791. getValue: function (uniformState) {
  792. return uniformState.normal;
  793. },
  794. }),
  795. /**
  796. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  797. * transforms normal vectors in 3D model coordinates to eye coordinates.
  798. * In 3D mode, this is identical to
  799. * {@link czm_normal}, but in 2D and Columbus View it represents the normal transformation
  800. * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  801. * 2D and Columbus View in the same way that 3D is lit.
  802. * <br /><br />
  803. * Positions should be transformed to eye coordinates using {@link czm_modelView3D} and
  804. * normals should be transformed using <code>czm_normal3D</code>.
  805. *
  806. * @example
  807. * // GLSL declaration
  808. * uniform mat3 czm_normal3D;
  809. *
  810. * // Example
  811. * vec3 eyeNormal = czm_normal3D * normal;
  812. *
  813. * @see UniformState#normal3D
  814. * @see czm_normal
  815. */
  816. czm_normal3D: new AutomaticUniform({
  817. size: 1,
  818. datatype: WebGLConstants.FLOAT_MAT3,
  819. getValue: function (uniformState) {
  820. return uniformState.normal3D;
  821. },
  822. }),
  823. /**
  824. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  825. * transforms normal vectors in eye coordinates to model coordinates. This is
  826. * the opposite of the transform provided by {@link czm_normal}.
  827. *
  828. * @example
  829. * // GLSL declaration
  830. * uniform mat3 czm_inverseNormal;
  831. *
  832. * // Example
  833. * vec3 normalMC = czm_inverseNormal * normalEC;
  834. *
  835. * @see UniformState#inverseNormal
  836. * @see czm_normal
  837. * @see czm_modelView
  838. * @see czm_inverseView
  839. */
  840. czm_inverseNormal: new AutomaticUniform({
  841. size: 1,
  842. datatype: WebGLConstants.FLOAT_MAT3,
  843. getValue: function (uniformState) {
  844. return uniformState.inverseNormal;
  845. },
  846. }),
  847. /**
  848. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  849. * transforms normal vectors in eye coordinates to 3D model coordinates. This is
  850. * the opposite of the transform provided by {@link czm_normal}.
  851. * In 3D mode, this is identical to
  852. * {@link czm_inverseNormal}, but in 2D and Columbus View it represents the inverse normal transformation
  853. * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  854. * 2D and Columbus View in the same way that 3D is lit.
  855. *
  856. * @example
  857. * // GLSL declaration
  858. * uniform mat3 czm_inverseNormal3D;
  859. *
  860. * // Example
  861. * vec3 normalMC = czm_inverseNormal3D * normalEC;
  862. *
  863. * @see UniformState#inverseNormal3D
  864. * @see czm_inverseNormal
  865. */
  866. czm_inverseNormal3D: new AutomaticUniform({
  867. size: 1,
  868. datatype: WebGLConstants.FLOAT_MAT3,
  869. getValue: function (uniformState) {
  870. return uniformState.inverseNormal3D;
  871. },
  872. }),
  873. /**
  874. * An automatic GLSL uniform containing the height in meters of the
  875. * eye (camera) above or below the ellipsoid.
  876. *
  877. * @see UniformState#eyeHeight
  878. */
  879. czm_eyeHeight: new AutomaticUniform({
  880. size: 1,
  881. datatype: WebGLConstants.FLOAT,
  882. getValue: function (uniformState) {
  883. return uniformState.eyeHeight;
  884. },
  885. }),
  886. /**
  887. * An automatic GLSL uniform containing height (<code>x</code>) and height squared (<code>y</code>)
  888. * in meters of the eye (camera) above the 2D world plane. This uniform is only valid
  889. * when the {@link SceneMode} is <code>SCENE2D</code>.
  890. *
  891. * @see UniformState#eyeHeight2D
  892. */
  893. czm_eyeHeight2D: new AutomaticUniform({
  894. size: 1,
  895. datatype: WebGLConstants.FLOAT_VEC2,
  896. getValue: function (uniformState) {
  897. return uniformState.eyeHeight2D;
  898. },
  899. }),
  900. /**
  901. * An automatic GLSL uniform containing the near distance (<code>x</code>) and the far distance (<code>y</code>)
  902. * of the frustum defined by the camera. This is the largest possible frustum, not an individual
  903. * frustum used for multi-frustum rendering.
  904. *
  905. * @example
  906. * // GLSL declaration
  907. * uniform vec2 czm_entireFrustum;
  908. *
  909. * // Example
  910. * float frustumLength = czm_entireFrustum.y - czm_entireFrustum.x;
  911. *
  912. * @see UniformState#entireFrustum
  913. * @see czm_currentFrustum
  914. */
  915. czm_entireFrustum: new AutomaticUniform({
  916. size: 1,
  917. datatype: WebGLConstants.FLOAT_VEC2,
  918. getValue: function (uniformState) {
  919. return uniformState.entireFrustum;
  920. },
  921. }),
  922. /**
  923. * An automatic GLSL uniform containing the near distance (<code>x</code>) and the far distance (<code>y</code>)
  924. * of the frustum defined by the camera. This is the individual
  925. * frustum used for multi-frustum rendering.
  926. *
  927. * @example
  928. * // GLSL declaration
  929. * uniform vec2 czm_currentFrustum;
  930. *
  931. * // Example
  932. * float frustumLength = czm_currentFrustum.y - czm_currentFrustum.x;
  933. *
  934. * @see UniformState#currentFrustum
  935. * @see czm_entireFrustum
  936. */
  937. czm_currentFrustum: new AutomaticUniform({
  938. size: 1,
  939. datatype: WebGLConstants.FLOAT_VEC2,
  940. getValue: function (uniformState) {
  941. return uniformState.currentFrustum;
  942. },
  943. }),
  944. /**
  945. * The distances to the frustum planes. The top, bottom, left and right distances are
  946. * the x, y, z, and w components, respectively.
  947. */
  948. czm_frustumPlanes: new AutomaticUniform({
  949. size: 1,
  950. datatype: WebGLConstants.FLOAT_VEC4,
  951. getValue: function (uniformState) {
  952. return uniformState.frustumPlanes;
  953. },
  954. }),
  955. /**
  956. * Gets the far plane's distance from the near plane, plus 1.0.
  957. */
  958. czm_farDepthFromNearPlusOne: new AutomaticUniform({
  959. size: 1,
  960. datatype: WebGLConstants.FLOAT,
  961. getValue: function (uniformState) {
  962. return uniformState.farDepthFromNearPlusOne;
  963. },
  964. }),
  965. /**
  966. * Gets the log2 of {@link AutomaticUniforms#czm_farDepthFromNearPlusOne}.
  967. */
  968. czm_log2FarDepthFromNearPlusOne: new AutomaticUniform({
  969. size: 1,
  970. datatype: WebGLConstants.FLOAT,
  971. getValue: function (uniformState) {
  972. return uniformState.log2FarDepthFromNearPlusOne;
  973. },
  974. }),
  975. /**
  976. * Gets 1.0 divided by {@link AutomaticUniforms#czm_log2FarDepthFromNearPlusOne}.
  977. */
  978. czm_oneOverLog2FarDepthFromNearPlusOne: new AutomaticUniform({
  979. size: 1,
  980. datatype: WebGLConstants.FLOAT,
  981. getValue: function (uniformState) {
  982. return uniformState.oneOverLog2FarDepthFromNearPlusOne;
  983. },
  984. }),
  985. /**
  986. * An automatic GLSL uniform representing the sun position in world coordinates.
  987. *
  988. * @example
  989. * // GLSL declaration
  990. * uniform vec3 czm_sunPositionWC;
  991. *
  992. * @see UniformState#sunPositionWC
  993. * @see czm_sunPositionColumbusView
  994. * @see czm_sunDirectionWC
  995. */
  996. czm_sunPositionWC: new AutomaticUniform({
  997. size: 1,
  998. datatype: WebGLConstants.FLOAT_VEC3,
  999. getValue: function (uniformState) {
  1000. return uniformState.sunPositionWC;
  1001. },
  1002. }),
  1003. /**
  1004. * An automatic GLSL uniform representing the sun position in Columbus view world coordinates.
  1005. *
  1006. * @example
  1007. * // GLSL declaration
  1008. * uniform vec3 czm_sunPositionColumbusView;
  1009. *
  1010. * @see UniformState#sunPositionColumbusView
  1011. * @see czm_sunPositionWC
  1012. */
  1013. czm_sunPositionColumbusView: new AutomaticUniform({
  1014. size: 1,
  1015. datatype: WebGLConstants.FLOAT_VEC3,
  1016. getValue: function (uniformState) {
  1017. return uniformState.sunPositionColumbusView;
  1018. },
  1019. }),
  1020. /**
  1021. * An automatic GLSL uniform representing the normalized direction to the sun in eye coordinates.
  1022. *
  1023. * @example
  1024. * // GLSL declaration
  1025. * uniform vec3 czm_sunDirectionEC;
  1026. *
  1027. * // Example
  1028. * float diffuse = max(dot(czm_sunDirectionEC, normalEC), 0.0);
  1029. *
  1030. * @see UniformState#sunDirectionEC
  1031. * @see czm_moonDirectionEC
  1032. * @see czm_sunDirectionWC
  1033. */
  1034. czm_sunDirectionEC: new AutomaticUniform({
  1035. size: 1,
  1036. datatype: WebGLConstants.FLOAT_VEC3,
  1037. getValue: function (uniformState) {
  1038. return uniformState.sunDirectionEC;
  1039. },
  1040. }),
  1041. /**
  1042. * An automatic GLSL uniform representing the normalized direction to the sun in world coordinates.
  1043. *
  1044. * @example
  1045. * // GLSL declaration
  1046. * uniform vec3 czm_sunDirectionWC;
  1047. *
  1048. * // Example
  1049. * float diffuse = max(dot(czm_sunDirectionWC, normalWC), 0.0);
  1050. *
  1051. * @see UniformState#sunDirectionWC
  1052. * @see czm_sunPositionWC
  1053. * @see czm_sunDirectionEC
  1054. */
  1055. czm_sunDirectionWC: new AutomaticUniform({
  1056. size: 1,
  1057. datatype: WebGLConstants.FLOAT_VEC3,
  1058. getValue: function (uniformState) {
  1059. return uniformState.sunDirectionWC;
  1060. },
  1061. }),
  1062. /**
  1063. * An automatic GLSL uniform representing the normalized direction to the moon in eye coordinates.
  1064. *
  1065. * @example
  1066. * // GLSL declaration
  1067. * uniform vec3 czm_moonDirectionEC;
  1068. *
  1069. * // Example
  1070. * float diffuse = max(dot(czm_moonDirectionEC, normalEC), 0.0);
  1071. *
  1072. * @see UniformState#moonDirectionEC
  1073. * @see czm_sunDirectionEC
  1074. */
  1075. czm_moonDirectionEC: new AutomaticUniform({
  1076. size: 1,
  1077. datatype: WebGLConstants.FLOAT_VEC3,
  1078. getValue: function (uniformState) {
  1079. return uniformState.moonDirectionEC;
  1080. },
  1081. }),
  1082. /**
  1083. * An automatic GLSL uniform representing the normalized direction to the scene's light source in eye coordinates.
  1084. * This is commonly used for directional lighting computations.
  1085. *
  1086. * @example
  1087. * // GLSL declaration
  1088. * uniform vec3 czm_lightDirectionEC;
  1089. *
  1090. * // Example
  1091. * float diffuse = max(dot(czm_lightDirectionEC, normalEC), 0.0);
  1092. *
  1093. * @see UniformState#lightDirectionEC
  1094. * @see czm_lightDirectionWC
  1095. */
  1096. czm_lightDirectionEC: new AutomaticUniform({
  1097. size: 1,
  1098. datatype: WebGLConstants.FLOAT_VEC3,
  1099. getValue: function (uniformState) {
  1100. return uniformState.lightDirectionEC;
  1101. },
  1102. }),
  1103. /**
  1104. * An automatic GLSL uniform representing the normalized direction to the scene's light source in world coordinates.
  1105. * This is commonly used for directional lighting computations.
  1106. *
  1107. * @example
  1108. * // GLSL declaration
  1109. * uniform vec3 czm_lightDirectionWC;
  1110. *
  1111. * // Example
  1112. * float diffuse = max(dot(czm_lightDirectionWC, normalWC), 0.0);
  1113. *
  1114. * @see UniformState#lightDirectionWC
  1115. * @see czm_lightDirectionEC
  1116. */
  1117. czm_lightDirectionWC: new AutomaticUniform({
  1118. size: 1,
  1119. datatype: WebGLConstants.FLOAT_VEC3,
  1120. getValue: function (uniformState) {
  1121. return uniformState.lightDirectionWC;
  1122. },
  1123. }),
  1124. /**
  1125. * An automatic GLSL uniform that represents the color of light emitted by the scene's light source. This
  1126. * is equivalent to the light color multiplied by the light intensity limited to a maximum luminance of 1.0
  1127. * suitable for non-HDR lighting.
  1128. *
  1129. * @example
  1130. * // GLSL declaration
  1131. * uniform vec3 czm_lightColor;
  1132. *
  1133. * // Example
  1134. * vec3 diffuseColor = czm_lightColor * max(dot(czm_lightDirectionWC, normalWC), 0.0);
  1135. *
  1136. * @see UniformState#lightColor
  1137. * @see czm_lightColorHdr
  1138. */
  1139. czm_lightColor: new AutomaticUniform({
  1140. size: 1,
  1141. datatype: WebGLConstants.FLOAT_VEC3,
  1142. getValue: function (uniformState) {
  1143. return uniformState.lightColor;
  1144. },
  1145. }),
  1146. /**
  1147. * An automatic GLSL uniform that represents the high dynamic range color of light emitted by the scene's light
  1148. * source. This is equivalent to the light color multiplied by the light intensity suitable for HDR lighting.
  1149. *
  1150. * @example
  1151. * // GLSL declaration
  1152. * uniform vec3 czm_lightColorHdr;
  1153. *
  1154. * // Example
  1155. * vec3 diffuseColor = czm_lightColorHdr * max(dot(czm_lightDirectionWC, normalWC), 0.0);
  1156. *
  1157. * @see UniformState#lightColorHdr
  1158. * @see czm_lightColor
  1159. */
  1160. czm_lightColorHdr: new AutomaticUniform({
  1161. size: 1,
  1162. datatype: WebGLConstants.FLOAT_VEC3,
  1163. getValue: function (uniformState) {
  1164. return uniformState.lightColorHdr;
  1165. },
  1166. }),
  1167. /**
  1168. * An automatic GLSL uniform representing the high bits of the camera position in model
  1169. * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
  1170. * as described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.
  1171. *
  1172. * @example
  1173. * // GLSL declaration
  1174. * uniform vec3 czm_encodedCameraPositionMCHigh;
  1175. *
  1176. * @see czm_encodedCameraPositionMCLow
  1177. * @see czm_modelViewRelativeToEye
  1178. * @see czm_modelViewProjectionRelativeToEye
  1179. */
  1180. czm_encodedCameraPositionMCHigh: new AutomaticUniform({
  1181. size: 1,
  1182. datatype: WebGLConstants.FLOAT_VEC3,
  1183. getValue: function (uniformState) {
  1184. return uniformState.encodedCameraPositionMCHigh;
  1185. },
  1186. }),
  1187. /**
  1188. * An automatic GLSL uniform representing the low bits of the camera position in model
  1189. * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
  1190. * as described in {@linkhttp://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.
  1191. *
  1192. * @example
  1193. * // GLSL declaration
  1194. * uniform vec3 czm_encodedCameraPositionMCLow;
  1195. *
  1196. * @see czm_encodedCameraPositionMCHigh
  1197. * @see czm_modelViewRelativeToEye
  1198. * @see czm_modelViewProjectionRelativeToEye
  1199. */
  1200. czm_encodedCameraPositionMCLow: new AutomaticUniform({
  1201. size: 1,
  1202. datatype: WebGLConstants.FLOAT_VEC3,
  1203. getValue: function (uniformState) {
  1204. return uniformState.encodedCameraPositionMCLow;
  1205. },
  1206. }),
  1207. /**
  1208. * An automatic GLSL uniform representing the position of the viewer (camera) in world coordinates.
  1209. *
  1210. * @example
  1211. * // GLSL declaration
  1212. * uniform vec3 czm_viewerPositionWC;
  1213. */
  1214. czm_viewerPositionWC: new AutomaticUniform({
  1215. size: 1,
  1216. datatype: WebGLConstants.FLOAT_VEC3,
  1217. getValue: function (uniformState) {
  1218. return Matrix4.getTranslation(
  1219. uniformState.inverseView,
  1220. viewerPositionWCScratch
  1221. );
  1222. },
  1223. }),
  1224. /**
  1225. * An automatic GLSL uniform representing the frame number. This uniform is automatically incremented
  1226. * every frame.
  1227. *
  1228. * @example
  1229. * // GLSL declaration
  1230. * uniform float czm_frameNumber;
  1231. */
  1232. czm_frameNumber: new AutomaticUniform({
  1233. size: 1,
  1234. datatype: WebGLConstants.FLOAT,
  1235. getValue: function (uniformState) {
  1236. return uniformState.frameState.frameNumber;
  1237. },
  1238. }),
  1239. /**
  1240. * An automatic GLSL uniform representing the current morph transition time between
  1241. * 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.
  1242. *
  1243. * @example
  1244. * // GLSL declaration
  1245. * uniform float czm_morphTime;
  1246. *
  1247. * // Example
  1248. * vec4 p = czm_columbusViewMorph(position2D, position3D, czm_morphTime);
  1249. */
  1250. czm_morphTime: new AutomaticUniform({
  1251. size: 1,
  1252. datatype: WebGLConstants.FLOAT,
  1253. getValue: function (uniformState) {
  1254. return uniformState.frameState.morphTime;
  1255. },
  1256. }),
  1257. /**
  1258. * An automatic GLSL uniform representing the current {@link SceneMode}, expressed
  1259. * as a float.
  1260. *
  1261. * @example
  1262. * // GLSL declaration
  1263. * uniform float czm_sceneMode;
  1264. *
  1265. * // Example
  1266. * if (czm_sceneMode == czm_sceneMode2D)
  1267. * {
  1268. * eyeHeightSq = czm_eyeHeight2D.y;
  1269. * }
  1270. *
  1271. * @see czm_sceneMode2D
  1272. * @see czm_sceneModeColumbusView
  1273. * @see czm_sceneMode3D
  1274. * @see czm_sceneModeMorphing
  1275. */
  1276. czm_sceneMode: new AutomaticUniform({
  1277. size: 1,
  1278. datatype: WebGLConstants.FLOAT,
  1279. getValue: function (uniformState) {
  1280. return uniformState.frameState.mode;
  1281. },
  1282. }),
  1283. /**
  1284. * An automatic GLSL uniform representing the current rendering pass.
  1285. *
  1286. * @example
  1287. * // GLSL declaration
  1288. * uniform float czm_pass;
  1289. *
  1290. * // Example
  1291. * if ((czm_pass == czm_passTranslucent) && isOpaque())
  1292. * {
  1293. * gl_Position *= 0.0; // Cull opaque geometry in the translucent pass
  1294. * }
  1295. */
  1296. czm_pass: new AutomaticUniform({
  1297. size: 1,
  1298. datatype: WebGLConstants.FLOAT,
  1299. getValue: function (uniformState) {
  1300. return uniformState.pass;
  1301. },
  1302. }),
  1303. /**
  1304. * An automatic GLSL uniform representing the current scene background color.
  1305. *
  1306. * @example
  1307. * // GLSL declaration
  1308. * uniform vec4 czm_backgroundColor;
  1309. *
  1310. * // Example: If the given color's RGB matches the background color, invert it.
  1311. * vec4 adjustColorForContrast(vec4 color)
  1312. * {
  1313. * if (czm_backgroundColor.rgb == color.rgb)
  1314. * {
  1315. * color.rgb = vec3(1.0) - color.rgb;
  1316. * }
  1317. *
  1318. * return color;
  1319. * }
  1320. */
  1321. czm_backgroundColor: new AutomaticUniform({
  1322. size: 1,
  1323. datatype: WebGLConstants.FLOAT_VEC4,
  1324. getValue: function (uniformState) {
  1325. return uniformState.backgroundColor;
  1326. },
  1327. }),
  1328. /**
  1329. * An automatic GLSL uniform containing the BRDF look up texture used for image-based lighting computations.
  1330. *
  1331. * @example
  1332. * // GLSL declaration
  1333. * uniform sampler2D czm_brdfLut;
  1334. *
  1335. * // Example: For a given roughness and NdotV value, find the material's BRDF information in the red and green channels
  1336. * float roughness = 0.5;
  1337. * float NdotV = dot(normal, view);
  1338. * vec2 brdfLut = texture2D(czm_brdfLut, vec2(NdotV, 1.0 - roughness)).rg;
  1339. */
  1340. czm_brdfLut: new AutomaticUniform({
  1341. size: 1,
  1342. datatype: WebGLConstants.SAMPLER_2D,
  1343. getValue: function (uniformState) {
  1344. return uniformState.brdfLut;
  1345. },
  1346. }),
  1347. /**
  1348. * An automatic GLSL uniform containing the environment map used within the scene.
  1349. *
  1350. * @example
  1351. * // GLSL declaration
  1352. * uniform samplerCube czm_environmentMap;
  1353. *
  1354. * // Example: Create a perfect reflection of the environment map on a model
  1355. * float reflected = reflect(view, normal);
  1356. * vec4 reflectedColor = textureCube(czm_environmentMap, reflected);
  1357. */
  1358. czm_environmentMap: new AutomaticUniform({
  1359. size: 1,
  1360. datatype: WebGLConstants.SAMPLER_CUBE,
  1361. getValue: function (uniformState) {
  1362. return uniformState.environmentMap;
  1363. },
  1364. }),
  1365. /**
  1366. * An automatic GLSL uniform containing the specular environment map atlas used within the scene.
  1367. *
  1368. * @example
  1369. * // GLSL declaration
  1370. * uniform sampler2D czm_specularEnvironmentMaps;
  1371. */
  1372. czm_specularEnvironmentMaps: new AutomaticUniform({
  1373. size: 1,
  1374. datatype: WebGLConstants.SAMPLER_2D,
  1375. getValue: function (uniformState) {
  1376. return uniformState.specularEnvironmentMaps;
  1377. },
  1378. }),
  1379. /**
  1380. * An automatic GLSL uniform containing the size of the specular environment map atlas used within the scene.
  1381. *
  1382. * @example
  1383. * // GLSL declaration
  1384. * uniform vec2 czm_specularEnvironmentMapSize;
  1385. */
  1386. czm_specularEnvironmentMapSize: new AutomaticUniform({
  1387. size: 1,
  1388. datatype: WebGLConstants.FLOAT_VEC2,
  1389. getValue: function (uniformState) {
  1390. return uniformState.specularEnvironmentMapsDimensions;
  1391. },
  1392. }),
  1393. /**
  1394. * An automatic GLSL uniform containing the maximum level-of-detail of the specular environment map atlas used within the scene.
  1395. *
  1396. * @example
  1397. * // GLSL declaration
  1398. * uniform float czm_specularEnvironmentMapsMaximumLOD;
  1399. */
  1400. czm_specularEnvironmentMapsMaximumLOD: new AutomaticUniform({
  1401. size: 1,
  1402. datatype: WebGLConstants.FLOAT,
  1403. getValue: function (uniformState) {
  1404. return uniformState.specularEnvironmentMapsMaximumLOD;
  1405. },
  1406. }),
  1407. /**
  1408. * An automatic GLSL uniform containing the spherical harmonic coefficients used within the scene.
  1409. *
  1410. * @example
  1411. * // GLSL declaration
  1412. * uniform vec3[9] czm_sphericalHarmonicCoefficients;
  1413. */
  1414. czm_sphericalHarmonicCoefficients: new AutomaticUniform({
  1415. size: 9,
  1416. datatype: WebGLConstants.FLOAT_VEC3,
  1417. getValue: function (uniformState) {
  1418. return uniformState.sphericalHarmonicCoefficients;
  1419. },
  1420. }),
  1421. /**
  1422. * An automatic GLSL uniform representing a 3x3 rotation matrix that transforms
  1423. * from True Equator Mean Equinox (TEME) axes to the pseudo-fixed axes at the current scene time.
  1424. *
  1425. * @example
  1426. * // GLSL declaration
  1427. * uniform mat3 czm_temeToPseudoFixed;
  1428. *
  1429. * // Example
  1430. * vec3 pseudoFixed = czm_temeToPseudoFixed * teme;
  1431. *
  1432. * @see UniformState#temeToPseudoFixedMatrix
  1433. * @see Transforms.computeTemeToPseudoFixedMatrix
  1434. */
  1435. czm_temeToPseudoFixed: new AutomaticUniform({
  1436. size: 1,
  1437. datatype: WebGLConstants.FLOAT_MAT3,
  1438. getValue: function (uniformState) {
  1439. return uniformState.temeToPseudoFixedMatrix;
  1440. },
  1441. }),
  1442. /**
  1443. * An automatic GLSL uniform representing the ratio of canvas coordinate space to canvas pixel space.
  1444. *
  1445. * @example
  1446. * uniform float czm_pixelRatio;
  1447. */
  1448. czm_pixelRatio: new AutomaticUniform({
  1449. size: 1,
  1450. datatype: WebGLConstants.FLOAT,
  1451. getValue: function (uniformState) {
  1452. return uniformState.pixelRatio;
  1453. },
  1454. }),
  1455. /**
  1456. * An automatic GLSL uniform scalar used to mix a color with the fog color based on the distance to the camera.
  1457. *
  1458. * @see czm_fog
  1459. */
  1460. czm_fogDensity: new AutomaticUniform({
  1461. size: 1,
  1462. datatype: WebGLConstants.FLOAT,
  1463. getValue: function (uniformState) {
  1464. return uniformState.fogDensity;
  1465. },
  1466. }),
  1467. /**
  1468. * An automatic GLSL uniform representing the splitter position to use when rendering with a splitter.
  1469. * This will be in pixel coordinates relative to the canvas.
  1470. *
  1471. * @example
  1472. * // GLSL declaration
  1473. * uniform float czm_splitPosition;
  1474. */
  1475. czm_splitPosition: new AutomaticUniform({
  1476. size: 1,
  1477. datatype: WebGLConstants.FLOAT,
  1478. getValue: function (uniformState) {
  1479. return uniformState.splitPosition;
  1480. },
  1481. }),
  1482. /**
  1483. * An automatic GLSL uniform representing the splitter position to use when rendering imagery layers with a splitter.
  1484. * This will be in pixel coordinates relative to the canvas.
  1485. *
  1486. * @deprecated Use czm_splitPosition instead.
  1487. *
  1488. * @example
  1489. * // GLSL declaration
  1490. * uniform float czm_imagerySplitPosition;
  1491. */
  1492. czm_imagerySplitPosition: new AutomaticUniform({
  1493. size: 1,
  1494. datatype: WebGLConstants.FLOAT,
  1495. getValue: function (uniformState) {
  1496. return uniformState.imagerySplitPosition;
  1497. },
  1498. }),
  1499. /**
  1500. * An automatic GLSL uniform scalar representing the geometric tolerance per meter
  1501. */
  1502. czm_geometricToleranceOverMeter: new AutomaticUniform({
  1503. size: 1,
  1504. datatype: WebGLConstants.FLOAT,
  1505. getValue: function (uniformState) {
  1506. return uniformState.geometricToleranceOverMeter;
  1507. },
  1508. }),
  1509. /**
  1510. * An automatic GLSL uniform representing the distance from the camera at which to disable the depth test of billboards, labels and points
  1511. * to, for example, prevent clipping against terrain. When set to zero, the depth test should always be applied. When less than zero,
  1512. * the depth test should never be applied.
  1513. */
  1514. czm_minimumDisableDepthTestDistance: new AutomaticUniform({
  1515. size: 1,
  1516. datatype: WebGLConstants.FLOAT,
  1517. getValue: function (uniformState) {
  1518. return uniformState.minimumDisableDepthTestDistance;
  1519. },
  1520. }),
  1521. /**
  1522. * An automatic GLSL uniform that will be the highlight color of unclassified 3D Tiles.
  1523. */
  1524. czm_invertClassificationColor: new AutomaticUniform({
  1525. size: 1,
  1526. datatype: WebGLConstants.FLOAT_VEC4,
  1527. getValue: function (uniformState) {
  1528. return uniformState.invertClassificationColor;
  1529. },
  1530. }),
  1531. /**
  1532. * An automatic GLSL uniform that is used for gamma correction.
  1533. */
  1534. czm_gamma: new AutomaticUniform({
  1535. size: 1,
  1536. datatype: WebGLConstants.FLOAT,
  1537. getValue: function (uniformState) {
  1538. return uniformState.gamma;
  1539. },
  1540. }),
  1541. /**
  1542. * An automatic GLSL uniform that stores the ellipsoid radii.
  1543. */
  1544. czm_ellipsoidRadii: new AutomaticUniform({
  1545. size: 1,
  1546. datatype: WebGLConstants.FLOAT_VEC3,
  1547. getValue: function (uniformState) {
  1548. return uniformState.ellipsoid.radii;
  1549. },
  1550. }),
  1551. /**
  1552. * An automatic GLSL uniform that stores the ellipsoid inverse radii.
  1553. */
  1554. czm_ellipsoidInverseRadii: new AutomaticUniform({
  1555. size: 1,
  1556. datatype: WebGLConstants.FLOAT_VEC3,
  1557. getValue: function (uniformState) {
  1558. return uniformState.ellipsoid.oneOverRadii;
  1559. },
  1560. }),
  1561. };
  1562. export default AutomaticUniforms;