AutomaticUniforms.js 61 KB

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