GlobeVS.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //This file is automatically rebuilt by the Cesium build process.
  2. /*global define*/
  3. define(function() {
  4. "use strict";
  5. return "attribute vec4 position3DAndHeight;\n\
  6. attribute vec4 textureCoordAndEncodedNormals;\n\
  7. \n\
  8. uniform vec3 u_center3D;\n\
  9. uniform mat4 u_modifiedModelView;\n\
  10. uniform vec4 u_tileRectangle;\n\
  11. \n\
  12. // Uniforms for 2D Mercator projection\n\
  13. uniform vec2 u_southAndNorthLatitude;\n\
  14. uniform vec3 u_southMercatorYLowAndHighAndOneOverHeight;\n\
  15. \n\
  16. varying vec3 v_positionMC;\n\
  17. varying vec3 v_positionEC;\n\
  18. \n\
  19. varying vec2 v_textureCoordinates;\n\
  20. varying vec3 v_normalMC;\n\
  21. varying vec3 v_normalEC;\n\
  22. \n\
  23. // These functions are generated at runtime.\n\
  24. vec4 getPosition(vec3 position3DWC);\n\
  25. float get2DYPositionFraction();\n\
  26. \n\
  27. vec4 getPosition3DMode(vec3 position3DWC)\n\
  28. {\n\
  29. return czm_projection * (u_modifiedModelView * vec4(position3DAndHeight.xyz, 1.0));\n\
  30. }\n\
  31. \n\
  32. float get2DMercatorYPositionFraction()\n\
  33. {\n\
  34. // The width of a tile at level 11, in radians and assuming a single root tile, is\n\
  35. // 2.0 * czm_pi / pow(2.0, 11.0)\n\
  36. // We want to just linearly interpolate the 2D position from the texture coordinates\n\
  37. // when we're at this level or higher. The constant below is the expression\n\
  38. // above evaluated and then rounded up at the 4th significant digit.\n\
  39. const float maxTileWidth = 0.003068;\n\
  40. float positionFraction = textureCoordAndEncodedNormals.y;\n\
  41. float southLatitude = u_southAndNorthLatitude.x;\n\
  42. float northLatitude = u_southAndNorthLatitude.y;\n\
  43. if (northLatitude - southLatitude > maxTileWidth)\n\
  44. {\n\
  45. float southMercatorYLow = u_southMercatorYLowAndHighAndOneOverHeight.x;\n\
  46. float southMercatorYHigh = u_southMercatorYLowAndHighAndOneOverHeight.y;\n\
  47. float oneOverMercatorHeight = u_southMercatorYLowAndHighAndOneOverHeight.z;\n\
  48. \n\
  49. float currentLatitude = mix(southLatitude, northLatitude, textureCoordAndEncodedNormals.y);\n\
  50. currentLatitude = clamp(currentLatitude, -czm_webMercatorMaxLatitude, czm_webMercatorMaxLatitude);\n\
  51. positionFraction = czm_latitudeToWebMercatorFraction(currentLatitude, southMercatorYLow, southMercatorYHigh, oneOverMercatorHeight);\n\
  52. } \n\
  53. return positionFraction;\n\
  54. }\n\
  55. \n\
  56. float get2DGeographicYPositionFraction()\n\
  57. {\n\
  58. return textureCoordAndEncodedNormals.y;\n\
  59. }\n\
  60. \n\
  61. vec4 getPositionPlanarEarth(vec3 position3DWC, float height2D)\n\
  62. {\n\
  63. float yPositionFraction = get2DYPositionFraction();\n\
  64. vec4 rtcPosition2D = vec4(height2D, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordAndEncodedNormals.x, yPositionFraction)), 1.0); \n\
  65. return czm_projection * (u_modifiedModelView * rtcPosition2D);\n\
  66. }\n\
  67. \n\
  68. vec4 getPosition2DMode(vec3 position3DWC)\n\
  69. {\n\
  70. return getPositionPlanarEarth(position3DWC, 0.0);\n\
  71. }\n\
  72. \n\
  73. vec4 getPositionColumbusViewMode(vec3 position3DWC)\n\
  74. {\n\
  75. return getPositionPlanarEarth(position3DWC, position3DAndHeight.w);\n\
  76. }\n\
  77. \n\
  78. vec4 getPositionMorphingMode(vec3 position3DWC)\n\
  79. {\n\
  80. // We do not do RTC while morphing, so there is potential for jitter.\n\
  81. // This is unlikely to be noticeable, though.\n\
  82. float yPositionFraction = get2DYPositionFraction();\n\
  83. vec4 position2DWC = vec4(0.0, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordAndEncodedNormals.x, yPositionFraction)), 1.0);\n\
  84. vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime);\n\
  85. return czm_modelViewProjection * morphPosition;\n\
  86. }\n\
  87. \n\
  88. void main() \n\
  89. {\n\
  90. vec3 position3DWC = position3DAndHeight.xyz + u_center3D;\n\
  91. \n\
  92. gl_Position = getPosition(position3DWC);\n\
  93. \n\
  94. #if defined(SHOW_REFLECTIVE_OCEAN) || defined(ENABLE_DAYNIGHT_SHADING)\n\
  95. v_positionEC = (czm_modelView3D * vec4(position3DWC, 1.0)).xyz;\n\
  96. v_positionMC = position3DWC; // position in model coordinates\n\
  97. #elif defined(ENABLE_VERTEX_LIGHTING)\n\
  98. v_positionEC = (czm_modelView3D * vec4(position3DWC, 1.0)).xyz;\n\
  99. v_positionMC = position3DWC; // position in model coordinates\n\
  100. float encodedNormal = textureCoordAndEncodedNormals.z;\n\
  101. v_normalMC = czm_octDecode(encodedNormal);\n\
  102. v_normalEC = czm_normal3D * v_normalMC;\n\
  103. #endif\n\
  104. \n\
  105. v_textureCoordinates = textureCoordAndEncodedNormals.xy;\n\
  106. }\n\
  107. ";
  108. });