AutomaticUniforms.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. /*global define*/
  2. define([
  3. '../Core/Cartesian3',
  4. '../Core/defineProperties',
  5. '../Core/Matrix4'
  6. ], function(
  7. Cartesian3,
  8. defineProperties,
  9. Matrix4) {
  10. "use strict";
  11. /*global WebGLRenderingContext*/
  12. var viewerPositionWCScratch = new Cartesian3();
  13. var AutomaticUniform = function(options) {
  14. this._size = options.size;
  15. this._datatype = options.datatype;
  16. this.getValue = options.getValue;
  17. };
  18. defineProperties(AutomaticUniform.prototype, {
  19. size: {
  20. get : function() {
  21. return this._size;
  22. }
  23. },
  24. datatype : {
  25. get : function() {
  26. return this._datatype;
  27. }
  28. }
  29. });
  30. // this check must use typeof, not defined, because defined doesn't work with undeclared variables.
  31. if (typeof WebGLRenderingContext === 'undefined') {
  32. return {};
  33. }
  34. var datatypeToGlsl = {};
  35. datatypeToGlsl[WebGLRenderingContext.FLOAT] = 'float';
  36. datatypeToGlsl[WebGLRenderingContext.FLOAT_VEC2] = 'vec2';
  37. datatypeToGlsl[WebGLRenderingContext.FLOAT_VEC3] = 'vec3';
  38. datatypeToGlsl[WebGLRenderingContext.FLOAT_VEC4] = 'vec4';
  39. datatypeToGlsl[WebGLRenderingContext.INT] = 'int';
  40. datatypeToGlsl[WebGLRenderingContext.INT_VEC2] = 'ivec2';
  41. datatypeToGlsl[WebGLRenderingContext.INT_VEC3] = 'ivec3';
  42. datatypeToGlsl[WebGLRenderingContext.INT_VEC4] = 'ivec4';
  43. datatypeToGlsl[WebGLRenderingContext.BOOL] = 'bool';
  44. datatypeToGlsl[WebGLRenderingContext.BOOL_VEC2] = 'bvec2';
  45. datatypeToGlsl[WebGLRenderingContext.BOOL_VEC3] = 'bvec3';
  46. datatypeToGlsl[WebGLRenderingContext.BOOL_VEC4] = 'bvec4';
  47. datatypeToGlsl[WebGLRenderingContext.FLOAT_MAT2] = 'mat2';
  48. datatypeToGlsl[WebGLRenderingContext.FLOAT_MAT3] = 'mat3';
  49. datatypeToGlsl[WebGLRenderingContext.FLOAT_MAT4] = 'mat4';
  50. datatypeToGlsl[WebGLRenderingContext.SAMPLER_2D] = 'sampler2D';
  51. datatypeToGlsl[WebGLRenderingContext.SAMPLER_CUBE] = 'samplerCube';
  52. AutomaticUniform.prototype.getDeclaration = function(name) {
  53. var declaration = 'uniform ' + datatypeToGlsl[this._datatype] + ' ' + name;
  54. var size = this._size;
  55. if (size === 1) {
  56. declaration += ';';
  57. } else {
  58. declaration += '[' + size.toString() + '];';
  59. }
  60. return declaration;
  61. };
  62. /**
  63. * @private
  64. */
  65. var AutomaticUniforms = {
  66. /**
  67. * An automatic GLSL uniform containing the viewport's <code>x</code>, <code>y</code>, <code>width</code>,
  68. * and <code>height</code> properties in an <code>vec4</code>'s <code>x</code>, <code>y</code>, <code>z</code>,
  69. * and <code>w</code> components, respectively.
  70. *
  71. * @alias czm_viewport
  72. * @glslUniform
  73. *
  74. * @see Context#getViewport
  75. *
  76. * @example
  77. * // GLSL declaration
  78. * uniform vec4 czm_viewport;
  79. *
  80. * // Scale the window coordinate components to [0, 1] by dividing
  81. * // by the viewport's width and height.
  82. * vec2 v = gl_FragCoord.xy / czm_viewport.zw;
  83. */
  84. czm_viewport : new AutomaticUniform({
  85. size : 1,
  86. datatype : WebGLRenderingContext.FLOAT_VEC4,
  87. getValue : function(uniformState) {
  88. return uniformState.viewportCartesian4;
  89. }
  90. }),
  91. /**
  92. * An automatic GLSL uniform representing a 4x4 orthographic projection matrix that
  93. * transforms window coordinates to clip coordinates. Clip coordinates is the
  94. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  95. * <br /><br />
  96. * This transform is useful when a vertex shader inputs or manipulates window coordinates
  97. * as done by {@link BillboardCollection}.
  98. * <br /><br />
  99. * Do not confuse {@link czm_viewportTransformation} with <code>czm_viewportOrthographic</code>.
  100. * The former transforms from normalized device coordinates to window coordinates; the later transforms
  101. * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
  102. *
  103. * @alias czm_viewportOrthographic
  104. * @glslUniform
  105. *
  106. * @see UniformState#viewportOrthographic
  107. * @see czm_viewport
  108. * @see czm_viewportTransformation
  109. * @see BillboardCollection
  110. *
  111. * @example
  112. * // GLSL declaration
  113. * uniform mat4 czm_viewportOrthographic;
  114. *
  115. * // Example
  116. * gl_Position = czm_viewportOrthographic * vec4(windowPosition, 0.0, 1.0);
  117. */
  118. czm_viewportOrthographic : new AutomaticUniform({
  119. size : 1,
  120. datatype : WebGLRenderingContext.FLOAT_MAT4,
  121. getValue : function(uniformState) {
  122. return uniformState.viewportOrthographic;
  123. }
  124. }),
  125. /**
  126. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  127. * transforms normalized device coordinates to window coordinates. The context's
  128. * full viewport is used, and the depth range is assumed to be <code>near = 0</code>
  129. * and <code>far = 1</code>.
  130. * <br /><br />
  131. * This transform is useful when there is a need to manipulate window coordinates
  132. * in a vertex shader as done by {@link BillboardCollection}. In many cases,
  133. * this matrix will not be used directly; instead, {@link czm_modelToWindowCoordinates}
  134. * will be used to transform directly from model to window coordinates.
  135. * <br /><br />
  136. * Do not confuse <code>czm_viewportTransformation</code> with {@link czm_viewportOrthographic}.
  137. * The former transforms from normalized device coordinates to window coordinates; the later transforms
  138. * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
  139. *
  140. * @alias czm_viewportTransformation
  141. * @glslUniform
  142. *
  143. * @see UniformState#viewportTransformation
  144. * @see czm_viewport
  145. * @see czm_viewportOrthographic
  146. * @see czm_modelToWindowCoordinates
  147. * @see BillboardCollection
  148. *
  149. * @example
  150. * // GLSL declaration
  151. * uniform mat4 czm_viewportTransformation;
  152. *
  153. * // Use czm_viewportTransformation as part of the
  154. * // transform from model to window coordinates.
  155. * vec4 q = czm_modelViewProjection * positionMC; // model to clip coordinates
  156. * q.xyz /= q.w; // clip to normalized device coordinates (ndc)
  157. * q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // ndc to window coordinates
  158. */
  159. czm_viewportTransformation : new AutomaticUniform({
  160. size : 1,
  161. datatype : WebGLRenderingContext.FLOAT_MAT4,
  162. getValue : function(uniformState) {
  163. return uniformState.viewportTransformation;
  164. }
  165. }),
  166. /**
  167. * An automatic GLSL uniform representing a 4x4 model transformation matrix that
  168. * transforms model coordinates to world coordinates.
  169. *
  170. * @alias czm_model
  171. * @glslUniform
  172. *
  173. * @see UniformState#model
  174. * @see czm_inverseModel
  175. * @see czm_modelView
  176. * @see czm_modelViewProjection
  177. *
  178. * @example
  179. * // GLSL declaration
  180. * uniform mat4 czm_model;
  181. *
  182. * // Example
  183. * vec4 worldPosition = czm_model * modelPosition;
  184. */
  185. czm_model : new AutomaticUniform({
  186. size : 1,
  187. datatype : WebGLRenderingContext.FLOAT_MAT4,
  188. getValue : function(uniformState) {
  189. return uniformState.model;
  190. }
  191. }),
  192. /**
  193. * An automatic GLSL uniform representing a 4x4 model transformation matrix that
  194. * transforms world coordinates to model coordinates.
  195. *
  196. * @alias czm_inverseModel
  197. * @glslUniform
  198. *
  199. * @see UniformState#inverseModel
  200. * @see czm_model
  201. * @see czm_inverseModelView
  202. *
  203. * @example
  204. * // GLSL declaration
  205. * uniform mat4 czm_inverseModel;
  206. *
  207. * // Example
  208. * vec4 modelPosition = czm_inverseModel * worldPosition;
  209. */
  210. czm_inverseModel : new AutomaticUniform({
  211. size : 1,
  212. datatype : WebGLRenderingContext.FLOAT_MAT4,
  213. getValue : function(uniformState) {
  214. return uniformState.inverseModel;
  215. }
  216. }),
  217. /**
  218. * An automatic GLSL uniform representing a 4x4 view transformation matrix that
  219. * transforms world coordinates to eye coordinates.
  220. *
  221. * @alias czm_view
  222. * @glslUniform
  223. *
  224. * @see UniformState#view
  225. * @see czm_viewRotation
  226. * @see czm_modelView
  227. * @see czm_viewProjection
  228. * @see czm_modelViewProjection
  229. * @see czm_inverseView
  230. *
  231. * @example
  232. * // GLSL declaration
  233. * uniform mat4 czm_view;
  234. *
  235. * // Example
  236. * vec4 eyePosition = czm_view * worldPosition;
  237. */
  238. czm_view : new AutomaticUniform({
  239. size : 1,
  240. datatype : WebGLRenderingContext.FLOAT_MAT4,
  241. getValue : function(uniformState) {
  242. return uniformState.view;
  243. }
  244. }),
  245. /**
  246. * An automatic GLSL uniform representing a 4x4 view transformation matrix that
  247. * transforms 3D world coordinates to eye coordinates. In 3D mode, this is identical to
  248. * {@link czm_view}, but in 2D and Columbus View it represents the view matrix
  249. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  250. * 2D and Columbus View in the same way that 3D is lit.
  251. *
  252. * @alias czm_view3D
  253. * @glslUniform
  254. *
  255. * @see UniformState#view3D
  256. * @see czm_view
  257. *
  258. * @example
  259. * // GLSL declaration
  260. * uniform mat4 czm_view3D;
  261. *
  262. * // Example
  263. * vec4 eyePosition3D = czm_view3D * worldPosition3D;
  264. */
  265. czm_view3D : new AutomaticUniform({
  266. size : 1,
  267. datatype : WebGLRenderingContext.FLOAT_MAT4,
  268. getValue : function(uniformState) {
  269. return uniformState.view3D;
  270. }
  271. }),
  272. /**
  273. * An automatic GLSL uniform representing a 3x3 view rotation matrix that
  274. * transforms vectors in world coordinates to eye coordinates.
  275. *
  276. * @alias czm_viewRotation
  277. * @glslUniform
  278. *
  279. * @see UniformState#viewRotation
  280. * @see czm_view
  281. * @see czm_inverseView
  282. * @see czm_inverseViewRotation
  283. *
  284. * @example
  285. * // GLSL declaration
  286. * uniform mat3 czm_viewRotation;
  287. *
  288. * // Example
  289. * vec3 eyeVector = czm_viewRotation * worldVector;
  290. */
  291. czm_viewRotation : new AutomaticUniform({
  292. size : 1,
  293. datatype : WebGLRenderingContext.FLOAT_MAT3,
  294. getValue : function(uniformState) {
  295. return uniformState.viewRotation;
  296. }
  297. }),
  298. /**
  299. * An automatic GLSL uniform representing a 3x3 view rotation matrix that
  300. * transforms vectors in 3D world coordinates to eye coordinates. In 3D mode, this is identical to
  301. * {@link czm_viewRotation}, but in 2D and Columbus View it represents the view matrix
  302. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  303. * 2D and Columbus View in the same way that 3D is lit.
  304. *
  305. * @alias czm_viewRotation3D
  306. * @glslUniform
  307. *
  308. * @see UniformState#viewRotation3D
  309. * @see czm_viewRotation
  310. *
  311. * @example
  312. * // GLSL declaration
  313. * uniform mat3 czm_viewRotation3D;
  314. *
  315. * // Example
  316. * vec3 eyeVector = czm_viewRotation3D * worldVector;
  317. */
  318. czm_viewRotation3D : new AutomaticUniform({
  319. size : 1,
  320. datatype : WebGLRenderingContext.FLOAT_MAT3,
  321. getValue : function(uniformState) {
  322. return uniformState.viewRotation3D;
  323. }
  324. }),
  325. /**
  326. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  327. * transforms from eye coordinates to world coordinates.
  328. *
  329. * @alias czm_inverseView
  330. * @glslUniform
  331. *
  332. * @see UniformState#inverseView
  333. * @see czm_view
  334. * @see czm_inverseNormal
  335. *
  336. * @example
  337. * // GLSL declaration
  338. * uniform mat4 czm_inverseView;
  339. *
  340. * // Example
  341. * vec4 worldPosition = czm_inverseView * eyePosition;
  342. */
  343. czm_inverseView : new AutomaticUniform({
  344. size : 1,
  345. datatype : WebGLRenderingContext.FLOAT_MAT4,
  346. getValue : function(uniformState) {
  347. return uniformState.inverseView;
  348. }
  349. }),
  350. /**
  351. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  352. * transforms from 3D eye coordinates to world coordinates. In 3D mode, this is identical to
  353. * {@link czm_inverseView}, but in 2D and Columbus View it represents the inverse view matrix
  354. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  355. * 2D and Columbus View in the same way that 3D is lit.
  356. *
  357. * @alias czm_inverseView3D
  358. * @glslUniform
  359. *
  360. * @see UniformState#inverseView3D
  361. * @see czm_inverseView
  362. *
  363. * @example
  364. * // GLSL declaration
  365. * uniform mat4 czm_inverseView3D;
  366. *
  367. * // Example
  368. * vec4 worldPosition = czm_inverseView3D * eyePosition;
  369. */
  370. czm_inverseView3D : new AutomaticUniform({
  371. size : 1,
  372. datatype : WebGLRenderingContext.FLOAT_MAT4,
  373. getValue : function(uniformState) {
  374. return uniformState.inverseView3D;
  375. }
  376. }),
  377. /**
  378. * An automatic GLSL uniform representing a 3x3 rotation matrix that
  379. * transforms vectors from eye coordinates to world coordinates.
  380. *
  381. * @alias czm_inverseViewRotation
  382. * @glslUniform
  383. *
  384. * @see UniformState#inverseView
  385. * @see czm_view
  386. * @see czm_viewRotation
  387. * @see czm_inverseViewRotation
  388. *
  389. * @example
  390. * // GLSL declaration
  391. * uniform mat3 czm_inverseViewRotation;
  392. *
  393. * // Example
  394. * vec4 worldVector = czm_inverseViewRotation * eyeVector;
  395. */
  396. czm_inverseViewRotation : new AutomaticUniform({
  397. size : 1,
  398. datatype : WebGLRenderingContext.FLOAT_MAT3,
  399. getValue : function(uniformState) {
  400. return uniformState.inverseViewRotation;
  401. }
  402. }),
  403. /**
  404. * An automatic GLSL uniform representing a 3x3 rotation matrix that
  405. * transforms vectors from 3D eye coordinates to world coordinates. In 3D mode, this is identical to
  406. * {@link czm_inverseViewRotation}, but in 2D and Columbus View it represents the inverse view matrix
  407. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  408. * 2D and Columbus View in the same way that 3D is lit.
  409. *
  410. * @alias czm_inverseViewRotation3D
  411. * @glslUniform
  412. *
  413. * @see UniformState#inverseView3D
  414. * @see czm_inverseViewRotation
  415. *
  416. * @example
  417. * // GLSL declaration
  418. * uniform mat3 czm_inverseViewRotation3D;
  419. *
  420. * // Example
  421. * vec4 worldVector = czm_inverseViewRotation3D * eyeVector;
  422. */
  423. czm_inverseViewRotation3D : new AutomaticUniform({
  424. size : 1,
  425. datatype : WebGLRenderingContext.FLOAT_MAT3,
  426. getValue : function(uniformState) {
  427. return uniformState.inverseViewRotation3D;
  428. }
  429. }),
  430. /**
  431. * An automatic GLSL uniform representing a 4x4 projection transformation matrix that
  432. * transforms eye coordinates to clip coordinates. Clip coordinates is the
  433. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  434. *
  435. * @alias czm_projection
  436. * @glslUniform
  437. *
  438. * @see UniformState#projection
  439. * @see czm_viewProjection
  440. * @see czm_modelViewProjection
  441. * @see czm_infiniteProjection
  442. *
  443. * @example
  444. * // GLSL declaration
  445. * uniform mat4 czm_projection;
  446. *
  447. * // Example
  448. * gl_Position = czm_projection * eyePosition;
  449. */
  450. czm_projection : new AutomaticUniform({
  451. size : 1,
  452. datatype : WebGLRenderingContext.FLOAT_MAT4,
  453. getValue : function(uniformState) {
  454. return uniformState.projection;
  455. }
  456. }),
  457. /**
  458. * An automatic GLSL uniform representing a 4x4 inverse projection transformation matrix that
  459. * transforms from clip coordinates to eye coordinates. Clip coordinates is the
  460. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  461. *
  462. * @alias czm_inverseProjection
  463. * @glslUniform
  464. *
  465. * @see UniformState#inverseProjection
  466. * @see czm_projection
  467. *
  468. * @example
  469. * // GLSL declaration
  470. * uniform mat4 czm_inverseProjection;
  471. *
  472. * // Example
  473. * vec4 eyePosition = czm_inverseProjection * clipPosition;
  474. */
  475. czm_inverseProjection : new AutomaticUniform({
  476. size : 1,
  477. datatype : WebGLRenderingContext.FLOAT_MAT4,
  478. getValue : function(uniformState) {
  479. return uniformState.inverseProjection;
  480. }
  481. }),
  482. /**
  483. * @private
  484. */
  485. czm_inverseProjectionOIT : new AutomaticUniform({
  486. size : 1,
  487. datatype : WebGLRenderingContext.FLOAT_MAT4,
  488. getValue : function(uniformState) {
  489. return uniformState.inverseProjectionOIT;
  490. }
  491. }),
  492. /**
  493. * An automatic GLSL uniform representing a 4x4 projection transformation matrix with the far plane at infinity,
  494. * that transforms eye coordinates to clip coordinates. Clip coordinates is the
  495. * coordinate system for a vertex shader's <code>gl_Position</code> output. An infinite far plane is used
  496. * in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles
  497. * are not clipped by the far plane.
  498. *
  499. * @alias czm_infiniteProjection
  500. * @glslUniform
  501. *
  502. * @see UniformState#infiniteProjection
  503. * @see czm_projection
  504. * @see czm_modelViewInfiniteProjection
  505. *
  506. * @example
  507. * // GLSL declaration
  508. * uniform mat4 czm_infiniteProjection;
  509. *
  510. * // Example
  511. * gl_Position = czm_infiniteProjection * eyePosition;
  512. */
  513. czm_infiniteProjection : new AutomaticUniform({
  514. size : 1,
  515. datatype : WebGLRenderingContext.FLOAT_MAT4,
  516. getValue : function(uniformState) {
  517. return uniformState.infiniteProjection;
  518. }
  519. }),
  520. /**
  521. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  522. * transforms model coordinates to eye coordinates.
  523. * <br /><br />
  524. * Positions should be transformed to eye coordinates using <code>czm_modelView</code> and
  525. * normals should be transformed using {@link czm_normal}.
  526. *
  527. * @alias czm_modelView
  528. * @glslUniform
  529. *
  530. * @see UniformState#modelView
  531. * @see czm_model
  532. * @see czm_view
  533. * @see czm_modelViewProjection
  534. * @see czm_normal
  535. *
  536. * @example
  537. * // GLSL declaration
  538. * uniform mat4 czm_modelView;
  539. *
  540. * // Example
  541. * vec4 eyePosition = czm_modelView * modelPosition;
  542. *
  543. * // The above is equivalent to, but more efficient than:
  544. * vec4 eyePosition = czm_view * czm_model * modelPosition;
  545. */
  546. czm_modelView : new AutomaticUniform({
  547. size : 1,
  548. datatype : WebGLRenderingContext.FLOAT_MAT4,
  549. getValue : function(uniformState) {
  550. return uniformState.modelView;
  551. }
  552. }),
  553. /**
  554. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  555. * transforms 3D model coordinates to eye coordinates. In 3D mode, this is identical to
  556. * {@link czm_modelView}, but in 2D and Columbus View it represents the model-view matrix
  557. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  558. * 2D and Columbus View in the same way that 3D is lit.
  559. * <br /><br />
  560. * Positions should be transformed to eye coordinates using <code>czm_modelView3D</code> and
  561. * normals should be transformed using {@link czm_normal3D}.
  562. *
  563. * @alias czm_modelView3D
  564. * @glslUniform
  565. *
  566. * @see UniformState#modelView3D
  567. * @see czm_modelView
  568. *
  569. * @example
  570. * // GLSL declaration
  571. * uniform mat4 czm_modelView3D;
  572. *
  573. * // Example
  574. * vec4 eyePosition = czm_modelView3D * modelPosition;
  575. *
  576. * // The above is equivalent to, but more efficient than:
  577. * vec4 eyePosition = czm_view3D * czm_model * modelPosition;
  578. */
  579. czm_modelView3D : new AutomaticUniform({
  580. size : 1,
  581. datatype : WebGLRenderingContext.FLOAT_MAT4,
  582. getValue : function(uniformState) {
  583. return uniformState.modelView3D;
  584. }
  585. }),
  586. /**
  587. * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
  588. * transforms model coordinates, relative to the eye, to eye coordinates. This is used
  589. * in conjunction with {@link czm_translateRelativeToEye}.
  590. *
  591. * @alias czm_modelViewRelativeToEye
  592. * @glslUniform
  593. *
  594. * @example
  595. * // GLSL declaration
  596. * uniform mat4 czm_modelViewRelativeToEye;
  597. *
  598. * // Example
  599. * attribute vec3 positionHigh;
  600. * attribute vec3 positionLow;
  601. *
  602. * void main()
  603. * {
  604. * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  605. * gl_Position = czm_projection * (czm_modelViewRelativeToEye * p);
  606. * }
  607. *
  608. * @see czm_modelViewProjectionRelativeToEye
  609. * @see czm_translateRelativeToEye
  610. * @see EncodedCartesian3
  611. */
  612. czm_modelViewRelativeToEye : new AutomaticUniform({
  613. size : 1,
  614. datatype : WebGLRenderingContext.FLOAT_MAT4,
  615. getValue : function(uniformState) {
  616. return uniformState.modelViewRelativeToEye;
  617. }
  618. }),
  619. /**
  620. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  621. * transforms from eye coordinates to model coordinates.
  622. *
  623. * @alias czm_inverseModelView
  624. * @glslUniform
  625. *
  626. * @see UniformState#inverseModelView
  627. * @see czm_modelView
  628. *
  629. * @example
  630. * // GLSL declaration
  631. * uniform mat4 czm_inverseModelView;
  632. *
  633. * // Example
  634. * vec4 modelPosition = czm_inverseModelView * eyePosition;
  635. */
  636. czm_inverseModelView : new AutomaticUniform({
  637. size : 1,
  638. datatype : WebGLRenderingContext.FLOAT_MAT4,
  639. getValue : function(uniformState) {
  640. return uniformState.inverseModelView;
  641. }
  642. }),
  643. /**
  644. * An automatic GLSL uniform representing a 4x4 transformation matrix that
  645. * transforms from eye coordinates to 3D model coordinates. In 3D mode, this is identical to
  646. * {@link czm_inverseModelView}, but in 2D and Columbus View it represents the inverse model-view matrix
  647. * as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  648. * 2D and Columbus View in the same way that 3D is lit.
  649. *
  650. * @alias czm_inverseModelView3D
  651. * @glslUniform
  652. *
  653. * @see UniformState#inverseModelView
  654. * @see czm_inverseModelView
  655. * @see czm_modelView3D
  656. *
  657. * @example
  658. * // GLSL declaration
  659. * uniform mat4 czm_inverseModelView3D;
  660. *
  661. * // Example
  662. * vec4 modelPosition = czm_inverseModelView3D * eyePosition;
  663. */
  664. czm_inverseModelView3D : new AutomaticUniform({
  665. size : 1,
  666. datatype : WebGLRenderingContext.FLOAT_MAT4,
  667. getValue : function(uniformState) {
  668. return uniformState.inverseModelView3D;
  669. }
  670. }),
  671. /**
  672. * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that
  673. * transforms world coordinates to clip coordinates. Clip coordinates is the
  674. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  675. *
  676. * @alias czm_viewProjection
  677. * @glslUniform
  678. *
  679. * @see UniformState#viewProjection
  680. * @see czm_view
  681. * @see czm_projection
  682. * @see czm_modelViewProjection
  683. * @see czm_inverseViewProjection
  684. *
  685. * @example
  686. * // GLSL declaration
  687. * uniform mat4 czm_viewProjection;
  688. *
  689. * // Example
  690. * vec4 gl_Position = czm_viewProjection * czm_model * modelPosition;
  691. *
  692. * // The above is equivalent to, but more efficient than:
  693. * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
  694. */
  695. czm_viewProjection : new AutomaticUniform({
  696. size : 1,
  697. datatype : WebGLRenderingContext.FLOAT_MAT4,
  698. getValue : function(uniformState) {
  699. return uniformState.viewProjection;
  700. }
  701. }),
  702. /**
  703. * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that
  704. * transforms clip coordinates to world coordinates. Clip coordinates is the
  705. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  706. *
  707. * @alias czm_inverseViewProjection
  708. * @glslUniform
  709. *
  710. * @see UniformState#inverseViewProjection
  711. * @see czm_viewProjection
  712. *
  713. * @example
  714. * // GLSL declaration
  715. * uniform mat4 czm_inverseViewProjection;
  716. *
  717. * // Example
  718. * vec4 worldPosition = czm_inverseViewProjection * clipPosition;
  719. */
  720. czm_inverseViewProjection : new AutomaticUniform({
  721. size : 1,
  722. datatype : WebGLRenderingContext.FLOAT_MAT4,
  723. getValue : function(uniformState) {
  724. return uniformState.inverseViewProjection;
  725. }
  726. }),
  727. /**
  728. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  729. * transforms model coordinates to clip coordinates. Clip coordinates is the
  730. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  731. *
  732. * @alias czm_modelViewProjection
  733. * @glslUniform
  734. *
  735. * @see UniformState#modelViewProjection
  736. * @see czm_model
  737. * @see czm_view
  738. * @see czm_projection
  739. * @see czm_modelView
  740. * @see czm_viewProjection
  741. * @see czm_modelViewInfiniteProjection
  742. * @see czm_inverseModelViewProjection
  743. *
  744. * @example
  745. * // GLSL declaration
  746. * uniform mat4 czm_modelViewProjection;
  747. *
  748. * // Example
  749. * vec4 gl_Position = czm_modelViewProjection * modelPosition;
  750. *
  751. * // The above is equivalent to, but more efficient than:
  752. * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
  753. */
  754. czm_modelViewProjection : new AutomaticUniform({
  755. size : 1,
  756. datatype : WebGLRenderingContext.FLOAT_MAT4,
  757. getValue : function(uniformState) {
  758. return uniformState.modelViewProjection;
  759. }
  760. }),
  761. /**
  762. * An automatic GLSL uniform representing a 4x4 inverse model-view-projection transformation matrix that
  763. * transforms clip coordinates to model coordinates. Clip coordinates is the
  764. * coordinate system for a vertex shader's <code>gl_Position</code> output.
  765. *
  766. * @alias czm_inverseModelViewProjection
  767. * @glslUniform
  768. *
  769. * @see UniformState#modelViewProjection
  770. * @see czm_modelViewProjection
  771. *
  772. * @example
  773. * // GLSL declaration
  774. * uniform mat4 czm_inverseModelViewProjection;
  775. *
  776. * // Example
  777. * vec4 modelPosition = czm_inverseModelViewProjection * clipPosition;
  778. */
  779. czm_inverseModelViewProjection : new AutomaticUniform({
  780. size : 1,
  781. datatype : WebGLRenderingContext.FLOAT_MAT4,
  782. getValue : function(uniformState) {
  783. return uniformState.inverseModelViewProjection;
  784. }
  785. }),
  786. /**
  787. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  788. * transforms model coordinates, relative to the eye, to clip coordinates. Clip coordinates is the
  789. * coordinate system for a vertex shader's <code>gl_Position</code> output. This is used in
  790. * conjunction with {@link czm_translateRelativeToEye}.
  791. *
  792. * @alias czm_modelViewProjectionRelativeToEye
  793. * @glslUniform
  794. *
  795. * @example
  796. * // GLSL declaration
  797. * uniform mat4 czm_modelViewProjectionRelativeToEye;
  798. *
  799. * // Example
  800. * attribute vec3 positionHigh;
  801. * attribute vec3 positionLow;
  802. *
  803. * void main()
  804. * {
  805. * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  806. * gl_Position = czm_modelViewProjectionRelativeToEye * p;
  807. * }
  808. *
  809. * @see czm_modelViewRelativeToEye
  810. * @see czm_translateRelativeToEye
  811. * @see EncodedCartesian3
  812. */
  813. czm_modelViewProjectionRelativeToEye : new AutomaticUniform({
  814. size : 1,
  815. datatype : WebGLRenderingContext.FLOAT_MAT4,
  816. getValue : function(uniformState) {
  817. return uniformState.modelViewProjectionRelativeToEye;
  818. }
  819. }),
  820. /**
  821. * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
  822. * transforms model coordinates to clip coordinates. Clip coordinates is the
  823. * coordinate system for a vertex shader's <code>gl_Position</code> output. The projection matrix places
  824. * the far plane at infinity. This is useful in algorithms like shadow volumes and GPU ray casting with
  825. * proxy geometry to ensure that triangles are not clipped by the far plane.
  826. *
  827. * @alias czm_modelViewInfiniteProjection
  828. * @glslUniform
  829. *
  830. * @see UniformState#modelViewInfiniteProjection
  831. * @see czm_model
  832. * @see czm_view
  833. * @see czm_infiniteProjection
  834. * @see czm_modelViewProjection
  835. *
  836. * @example
  837. * // GLSL declaration
  838. * uniform mat4 czm_modelViewInfiniteProjection;
  839. *
  840. * // Example
  841. * vec4 gl_Position = czm_modelViewInfiniteProjection * modelPosition;
  842. *
  843. * // The above is equivalent to, but more efficient than:
  844. * gl_Position = czm_infiniteProjection * czm_view * czm_model * modelPosition;
  845. */
  846. czm_modelViewInfiniteProjection : new AutomaticUniform({
  847. size : 1,
  848. datatype : WebGLRenderingContext.FLOAT_MAT4,
  849. getValue : function(uniformState) {
  850. return uniformState.modelViewInfiniteProjection;
  851. }
  852. }),
  853. /**
  854. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  855. * transforms normal vectors in model coordinates to eye coordinates.
  856. * <br /><br />
  857. * Positions should be transformed to eye coordinates using {@link czm_modelView} and
  858. * normals should be transformed using <code>czm_normal</code>.
  859. *
  860. * @alias czm_normal
  861. * @glslUniform
  862. *
  863. * @see UniformState#normal
  864. * @see czm_inverseNormal
  865. * @see czm_modelView
  866. *
  867. * @example
  868. * // GLSL declaration
  869. * uniform mat3 czm_normal;
  870. *
  871. * // Example
  872. * vec3 eyeNormal = czm_normal * normal;
  873. */
  874. czm_normal : new AutomaticUniform({
  875. size : 1,
  876. datatype : WebGLRenderingContext.FLOAT_MAT3,
  877. getValue : function(uniformState) {
  878. return uniformState.normal;
  879. }
  880. }),
  881. /**
  882. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  883. * transforms normal vectors in 3D model coordinates to eye coordinates.
  884. * In 3D mode, this is identical to
  885. * {@link czm_normal}, but in 2D and Columbus View it represents the normal transformation
  886. * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  887. * 2D and Columbus View in the same way that 3D is lit.
  888. * <br /><br />
  889. * Positions should be transformed to eye coordinates using {@link czm_modelView3D} and
  890. * normals should be transformed using <code>czm_normal3D</code>.
  891. *
  892. * @alias czm_normal3D
  893. * @glslUniform
  894. *
  895. * @see UniformState#normal3D
  896. * @see czm_normal
  897. *
  898. * @example
  899. * // GLSL declaration
  900. * uniform mat3 czm_normal3D;
  901. *
  902. * // Example
  903. * vec3 eyeNormal = czm_normal3D * normal;
  904. */
  905. czm_normal3D : new AutomaticUniform({
  906. size : 1,
  907. datatype : WebGLRenderingContext.FLOAT_MAT3,
  908. getValue : function(uniformState) {
  909. return uniformState.normal3D;
  910. }
  911. }),
  912. /**
  913. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  914. * transforms normal vectors in eye coordinates to model coordinates. This is
  915. * the opposite of the transform provided by {@link czm_normal}.
  916. *
  917. * @alias czm_inverseNormal
  918. * @glslUniform
  919. *
  920. * @see UniformState#inverseNormal
  921. * @see czm_normal
  922. * @see czm_modelView
  923. * @see czm_inverseView
  924. *
  925. * @example
  926. * // GLSL declaration
  927. * uniform mat3 czm_inverseNormal;
  928. *
  929. * // Example
  930. * vec3 normalMC = czm_inverseNormal * normalEC;
  931. */
  932. czm_inverseNormal : new AutomaticUniform({
  933. size : 1,
  934. datatype : WebGLRenderingContext.FLOAT_MAT3,
  935. getValue : function(uniformState) {
  936. return uniformState.inverseNormal;
  937. }
  938. }),
  939. /**
  940. * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
  941. * transforms normal vectors in eye coordinates to 3D model coordinates. This is
  942. * the opposite of the transform provided by {@link czm_normal}.
  943. * In 3D mode, this is identical to
  944. * {@link czm_inverseNormal}, but in 2D and Columbus View it represents the inverse normal transformation
  945. * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting
  946. * 2D and Columbus View in the same way that 3D is lit.
  947. *
  948. * @alias czm_inverseNormal3D
  949. * @glslUniform
  950. *
  951. * @see UniformState#inverseNormal3D
  952. * @see czm_inverseNormal
  953. *
  954. * @example
  955. * // GLSL declaration
  956. * uniform mat3 czm_inverseNormal3D;
  957. *
  958. * // Example
  959. * vec3 normalMC = czm_inverseNormal3D * normalEC;
  960. */
  961. czm_inverseNormal3D : new AutomaticUniform({
  962. size : 1,
  963. datatype : WebGLRenderingContext.FLOAT_MAT3,
  964. getValue : function(uniformState) {
  965. return uniformState.inverseNormal3D;
  966. }
  967. }),
  968. /**
  969. * An automatic GLSL uniform containing height (<code>x</code>) and height squared (<code>y</code>)
  970. * of the eye (camera) in the 2D scene in meters.
  971. *
  972. * @alias czm_eyeHeight2D
  973. * @glslUniform
  974. *
  975. * @see UniformState#eyeHeight2D
  976. */
  977. czm_eyeHeight2D : new AutomaticUniform({
  978. size : 1,
  979. datatype : WebGLRenderingContext.FLOAT_VEC2,
  980. getValue : function(uniformState) {
  981. return uniformState.eyeHeight2D;
  982. }
  983. }),
  984. /**
  985. * An automatic GLSL uniform containing the near distance (<code>x</code>) and the far distance (<code>y</code>)
  986. * of the frustum defined by the camera. This is the largest possible frustum, not an individual
  987. * frustum used for multi-frustum rendering.
  988. *
  989. * @alias czm_entireFrustum
  990. * @glslUniform
  991. *
  992. * @see UniformState#entireFrustum
  993. * @see czm_currentFrustum
  994. *
  995. * @example
  996. * // GLSL declaration
  997. * uniform vec2 czm_entireFrustum;
  998. *
  999. * // Example
  1000. * float frustumLength = czm_entireFrustum.y - czm_entireFrustum.x;
  1001. */
  1002. czm_entireFrustum : new AutomaticUniform({
  1003. size : 1,
  1004. datatype : WebGLRenderingContext.FLOAT_VEC2,
  1005. getValue : function(uniformState) {
  1006. return uniformState.entireFrustum;
  1007. }
  1008. }),
  1009. /**
  1010. * An automatic GLSL uniform containing the near distance (<code>x</code>) and the far distance (<code>y</code>)
  1011. * of the frustum defined by the camera. This is the individual
  1012. * frustum used for multi-frustum rendering.
  1013. *
  1014. * @alias czm_currentFrustum
  1015. * @glslUniform
  1016. *
  1017. * @see UniformState#currentFrustum
  1018. * @see czm_entireFrustum
  1019. *
  1020. * @example
  1021. * // GLSL declaration
  1022. * uniform vec2 czm_currentFrustum;
  1023. *
  1024. * // Example
  1025. * float frustumLength = czm_currentFrustum.y - czm_currentFrustum.x;
  1026. */
  1027. czm_currentFrustum : new AutomaticUniform({
  1028. size : 1,
  1029. datatype : WebGLRenderingContext.FLOAT_VEC2,
  1030. getValue : function(uniformState) {
  1031. return uniformState.currentFrustum;
  1032. }
  1033. }),
  1034. /**
  1035. * An automatic GLSL uniform representing the sun position in world coordinates.
  1036. *
  1037. * @alias czm_sunPositionWC
  1038. * @glslUniform
  1039. *
  1040. * @see UniformState#sunPositionWC
  1041. * @see czm_sunPositionColumbusView
  1042. * @see czm_sunDirectionWC
  1043. *
  1044. * @example
  1045. * // GLSL declaration
  1046. * uniform vec3 czm_sunPositionWC;
  1047. */
  1048. czm_sunPositionWC : new AutomaticUniform({
  1049. size : 1,
  1050. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1051. getValue : function(uniformState) {
  1052. return uniformState.sunPositionWC;
  1053. }
  1054. }),
  1055. /**
  1056. * An automatic GLSL uniform representing the sun position in Columbus view world coordinates.
  1057. *
  1058. * @alias czm_sunPositionColumbusView
  1059. * @glslUniform
  1060. *
  1061. * @see UniformState#sunPositionColumbusView
  1062. * @see czm_sunPositionWC
  1063. *
  1064. * @example
  1065. * // GLSL declaration
  1066. * uniform vec3 czm_sunPositionColumbusView;
  1067. */
  1068. czm_sunPositionColumbusView : new AutomaticUniform({
  1069. size : 1,
  1070. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1071. getValue : function(uniformState) {
  1072. return uniformState.sunPositionColumbusView;
  1073. }
  1074. }),
  1075. /**
  1076. * An automatic GLSL uniform representing the normalized direction to the sun in eye coordinates.
  1077. * This is commonly used for directional lighting computations.
  1078. *
  1079. * @alias czm_sunDirectionEC
  1080. * @glslUniform
  1081. *
  1082. * @see UniformState#sunDirectionEC
  1083. * @see czm_moonDirectionEC
  1084. * @see czm_sunDirectionWC
  1085. *
  1086. * @example
  1087. * // GLSL declaration
  1088. * uniform vec3 czm_sunDirectionEC;
  1089. *
  1090. * // Example
  1091. * float diffuse = max(dot(czm_sunDirectionEC, normalEC), 0.0);
  1092. */
  1093. czm_sunDirectionEC : new AutomaticUniform({
  1094. size : 1,
  1095. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1096. getValue : function(uniformState) {
  1097. return uniformState.sunDirectionEC;
  1098. }
  1099. }),
  1100. /**
  1101. * An automatic GLSL uniform representing the normalized direction to the sun in world coordinates.
  1102. * This is commonly used for directional lighting computations.
  1103. *
  1104. * @alias czm_sunDirectionWC
  1105. * @glslUniform
  1106. *
  1107. * @see UniformState#sunDirectionWC
  1108. * @see czm_sunPositionWC
  1109. * @see czm_sunDirectionEC
  1110. *
  1111. * @example
  1112. * // GLSL declaration
  1113. * uniform vec3 czm_sunDirectionWC;
  1114. */
  1115. czm_sunDirectionWC : new AutomaticUniform({
  1116. size : 1,
  1117. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1118. getValue : function(uniformState) {
  1119. return uniformState.sunDirectionWC;
  1120. }
  1121. }),
  1122. /**
  1123. * An automatic GLSL uniform representing the normalized direction to the moon in eye coordinates.
  1124. * This is commonly used for directional lighting computations.
  1125. *
  1126. * @alias czm_moonDirectionEC
  1127. * @glslUniform
  1128. *
  1129. * @see UniformState#moonDirectionEC
  1130. * @see czm_sunDirectionEC
  1131. *
  1132. * @example
  1133. * // GLSL declaration
  1134. * uniform vec3 czm_moonDirectionEC;
  1135. *
  1136. * // Example
  1137. * float diffuse = max(dot(czm_moonDirectionEC, normalEC), 0.0);
  1138. */
  1139. czm_moonDirectionEC : new AutomaticUniform({
  1140. size : 1,
  1141. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1142. getValue : function(uniformState) {
  1143. return uniformState.moonDirectionEC;
  1144. }
  1145. }),
  1146. /**
  1147. * An automatic GLSL uniform representing the high bits of the camera position in model
  1148. * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
  1149. * as described in {@link http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/|Precisions, Precisions}.
  1150. *
  1151. * @alias czm_encodedCameraPositionMCHigh
  1152. * @glslUniform
  1153. *
  1154. * @see czm_encodedCameraPositionMCLow
  1155. * @see czm_modelViewRelativeToEye
  1156. * @see czm_modelViewProjectionRelativeToEye
  1157. *
  1158. * @example
  1159. * // GLSL declaration
  1160. * uniform vec3 czm_encodedCameraPositionMCHigh;
  1161. */
  1162. czm_encodedCameraPositionMCHigh : new AutomaticUniform({
  1163. size : 1,
  1164. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1165. getValue : function(uniformState) {
  1166. return uniformState.encodedCameraPositionMCHigh;
  1167. }
  1168. }),
  1169. /**
  1170. * An automatic GLSL uniform representing the low bits of the camera position in model
  1171. * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
  1172. * as described in {@link http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/|Precisions, Precisions}.
  1173. *
  1174. * @alias czm_encodedCameraPositionMCLow
  1175. * @glslUniform
  1176. *
  1177. * @see czm_encodedCameraPositionMCHigh
  1178. * @see czm_modelViewRelativeToEye
  1179. * @see czm_modelViewProjectionRelativeToEye
  1180. *
  1181. * @example
  1182. * // GLSL declaration
  1183. * uniform vec3 czm_encodedCameraPositionMCLow;
  1184. */
  1185. czm_encodedCameraPositionMCLow : new AutomaticUniform({
  1186. size : 1,
  1187. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1188. getValue : function(uniformState) {
  1189. return uniformState.encodedCameraPositionMCLow;
  1190. }
  1191. }),
  1192. /**
  1193. * An automatic GLSL uniform representing the position of the viewer (camera) in world coordinates.
  1194. *
  1195. * @alias czm_viewerPositionWC
  1196. * @glslUniform
  1197. *
  1198. * @example
  1199. * // GLSL declaration
  1200. * uniform vec3 czm_viewerPositionWC;
  1201. */
  1202. czm_viewerPositionWC : new AutomaticUniform({
  1203. size : 1,
  1204. datatype : WebGLRenderingContext.FLOAT_VEC3,
  1205. getValue : function(uniformState) {
  1206. return Matrix4.getTranslation(uniformState.inverseView, viewerPositionWCScratch);
  1207. }
  1208. }),
  1209. /**
  1210. * An automatic GLSL uniform representing the frame number. This uniform is automatically incremented
  1211. * every frame.
  1212. *
  1213. * @alias czm_frameNumber
  1214. * @glslUniform
  1215. *
  1216. * @example
  1217. * // GLSL declaration
  1218. * uniform float czm_frameNumber;
  1219. */
  1220. czm_frameNumber : new AutomaticUniform({
  1221. size : 1,
  1222. datatype : WebGLRenderingContext.FLOAT,
  1223. getValue : function(uniformState) {
  1224. return uniformState.frameState.frameNumber;
  1225. }
  1226. }),
  1227. /**
  1228. * An automatic GLSL uniform representing the current morph transition time between
  1229. * 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.
  1230. *
  1231. * @alias czm_morphTime
  1232. * @glslUniform
  1233. *
  1234. * @example
  1235. * // GLSL declaration
  1236. * uniform float czm_morphTime;
  1237. *
  1238. * // Example
  1239. * vec4 p = czm_columbusViewMorph(position2D, position3D, czm_morphTime);
  1240. */
  1241. czm_morphTime : new AutomaticUniform({
  1242. size : 1,
  1243. datatype : WebGLRenderingContext.FLOAT,
  1244. getValue : function(uniformState) {
  1245. return uniformState.frameState.morphTime;
  1246. }
  1247. }),
  1248. /**
  1249. * An automatic GLSL uniform representing the current {@link SceneMode}, expressed
  1250. * as a float.
  1251. *
  1252. * @alias czm_sceneMode
  1253. * @glslUniform
  1254. *
  1255. * @see czm_sceneMode2D
  1256. * @see czm_sceneModeColumbusView
  1257. * @see czm_sceneMode3D
  1258. * @see czm_sceneModeMorphing
  1259. *
  1260. * @example
  1261. * // GLSL declaration
  1262. * uniform float czm_sceneMode;
  1263. *
  1264. * // Example
  1265. * if (czm_sceneMode == czm_sceneMode2D)
  1266. * {
  1267. * eyeHeightSq = czm_eyeHeight2D.y;
  1268. * }
  1269. */
  1270. czm_sceneMode : new AutomaticUniform({
  1271. size : 1,
  1272. datatype : WebGLRenderingContext.FLOAT,
  1273. getValue : function(uniformState) {
  1274. return uniformState.frameState.mode;
  1275. }
  1276. }),
  1277. /**
  1278. * An automatic GLSL uniform representing a 3x3 rotation matrix that transforms
  1279. * from True Equator Mean Equinox (TEME) axes to the pseudo-fixed axes at the current scene time.
  1280. *
  1281. * @alias czm_temeToPseudoFixed
  1282. * @glslUniform
  1283. *
  1284. * @see UniformState#temeToPseudoFixedMatrix
  1285. * @see Transforms.computeTemeToPseudoFixedMatrix
  1286. *
  1287. * @example
  1288. * // GLSL declaration
  1289. * uniform mat3 czm_temeToPseudoFixed;
  1290. *
  1291. * // Example
  1292. * vec3 pseudoFixed = czm_temeToPseudoFixed * teme;
  1293. */
  1294. czm_temeToPseudoFixed : new AutomaticUniform({
  1295. size : 1,
  1296. datatype : WebGLRenderingContext.FLOAT_MAT3,
  1297. getValue : function(uniformState) {
  1298. return uniformState.temeToPseudoFixedMatrix;
  1299. }
  1300. }),
  1301. /**
  1302. * An automatic GLSL uniform representing the ratio of canvas coordinate space to canvas pixel space.
  1303. *
  1304. * @alias czm_resolutionScale
  1305. * @glslUniform
  1306. *
  1307. * @example
  1308. * uniform float czm_resolutionScale;
  1309. */
  1310. czm_resolutionScale : new AutomaticUniform({
  1311. size : 1,
  1312. datatype : WebGLRenderingContext.FLOAT,
  1313. getValue : function(uniformState) {
  1314. return uniformState.resolutionScale;
  1315. }
  1316. })
  1317. };
  1318. return AutomaticUniforms;
  1319. });