GlobeVS.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef QUANTIZATION_BITS12\n\
  3. attribute vec4 compressed0;\n\
  4. attribute float compressed1;\n\
  5. #else\n\
  6. attribute vec4 position3DAndHeight;\n\
  7. attribute vec4 textureCoordAndEncodedNormals;\n\
  8. #endif\n\
  9. \n\
  10. uniform vec3 u_center3D;\n\
  11. uniform mat4 u_modifiedModelView;\n\
  12. uniform mat4 u_modifiedModelViewProjection;\n\
  13. uniform vec4 u_tileRectangle;\n\
  14. \n\
  15. // Uniforms for 2D Mercator projection\n\
  16. uniform vec2 u_southAndNorthLatitude;\n\
  17. uniform vec2 u_southMercatorYAndOneOverHeight;\n\
  18. \n\
  19. varying vec3 v_positionMC;\n\
  20. varying vec3 v_positionEC;\n\
  21. \n\
  22. varying vec3 v_textureCoordinates;\n\
  23. varying vec3 v_normalMC;\n\
  24. varying vec3 v_normalEC;\n\
  25. \n\
  26. #ifdef APPLY_MATERIAL\n\
  27. varying float v_slope;\n\
  28. varying float v_aspect;\n\
  29. varying float v_height;\n\
  30. #endif\n\
  31. \n\
  32. #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT)\n\
  33. varying float v_distance;\n\
  34. #endif\n\
  35. \n\
  36. #if defined(FOG) || defined(GROUND_ATMOSPHERE)\n\
  37. varying vec3 v_fogMieColor;\n\
  38. varying vec3 v_fogRayleighColor;\n\
  39. #endif\n\
  40. \n\
  41. // These functions are generated at runtime.\n\
  42. vec4 getPosition(vec3 position, float height, vec2 textureCoordinates);\n\
  43. float get2DYPositionFraction(vec2 textureCoordinates);\n\
  44. \n\
  45. vec4 getPosition3DMode(vec3 position, float height, vec2 textureCoordinates)\n\
  46. {\n\
  47. return u_modifiedModelViewProjection * vec4(position, 1.0);\n\
  48. }\n\
  49. \n\
  50. float get2DMercatorYPositionFraction(vec2 textureCoordinates)\n\
  51. {\n\
  52. // The width of a tile at level 11, in radians and assuming a single root tile, is\n\
  53. // 2.0 * czm_pi / pow(2.0, 11.0)\n\
  54. // We want to just linearly interpolate the 2D position from the texture coordinates\n\
  55. // when we're at this level or higher. The constant below is the expression\n\
  56. // above evaluated and then rounded up at the 4th significant digit.\n\
  57. const float maxTileWidth = 0.003068;\n\
  58. float positionFraction = textureCoordinates.y;\n\
  59. float southLatitude = u_southAndNorthLatitude.x;\n\
  60. float northLatitude = u_southAndNorthLatitude.y;\n\
  61. if (northLatitude - southLatitude > maxTileWidth)\n\
  62. {\n\
  63. float southMercatorY = u_southMercatorYAndOneOverHeight.x;\n\
  64. float oneOverMercatorHeight = u_southMercatorYAndOneOverHeight.y;\n\
  65. \n\
  66. float currentLatitude = mix(southLatitude, northLatitude, textureCoordinates.y);\n\
  67. currentLatitude = clamp(currentLatitude, -czm_webMercatorMaxLatitude, czm_webMercatorMaxLatitude);\n\
  68. positionFraction = czm_latitudeToWebMercatorFraction(currentLatitude, southMercatorY, oneOverMercatorHeight);\n\
  69. }\n\
  70. return positionFraction;\n\
  71. }\n\
  72. \n\
  73. float get2DGeographicYPositionFraction(vec2 textureCoordinates)\n\
  74. {\n\
  75. return textureCoordinates.y;\n\
  76. }\n\
  77. \n\
  78. vec4 getPositionPlanarEarth(vec3 position, float height, vec2 textureCoordinates)\n\
  79. {\n\
  80. float yPositionFraction = get2DYPositionFraction(textureCoordinates);\n\
  81. vec4 rtcPosition2D = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);\n\
  82. return u_modifiedModelViewProjection * rtcPosition2D;\n\
  83. }\n\
  84. \n\
  85. vec4 getPosition2DMode(vec3 position, float height, vec2 textureCoordinates)\n\
  86. {\n\
  87. return getPositionPlanarEarth(position, 0.0, textureCoordinates);\n\
  88. }\n\
  89. \n\
  90. vec4 getPositionColumbusViewMode(vec3 position, float height, vec2 textureCoordinates)\n\
  91. {\n\
  92. return getPositionPlanarEarth(position, height, textureCoordinates);\n\
  93. }\n\
  94. \n\
  95. vec4 getPositionMorphingMode(vec3 position, float height, vec2 textureCoordinates)\n\
  96. {\n\
  97. // We do not do RTC while morphing, so there is potential for jitter.\n\
  98. // This is unlikely to be noticeable, though.\n\
  99. vec3 position3DWC = position + u_center3D;\n\
  100. float yPositionFraction = get2DYPositionFraction(textureCoordinates);\n\
  101. vec4 position2DWC = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);\n\
  102. vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime);\n\
  103. return czm_modelViewProjection * morphPosition;\n\
  104. }\n\
  105. \n\
  106. #ifdef QUANTIZATION_BITS12\n\
  107. uniform vec2 u_minMaxHeight;\n\
  108. uniform mat4 u_scaleAndBias;\n\
  109. #endif\n\
  110. \n\
  111. void main()\n\
  112. {\n\
  113. #ifdef QUANTIZATION_BITS12\n\
  114. vec2 xy = czm_decompressTextureCoordinates(compressed0.x);\n\
  115. vec2 zh = czm_decompressTextureCoordinates(compressed0.y);\n\
  116. vec3 position = vec3(xy, zh.x);\n\
  117. float height = zh.y;\n\
  118. vec2 textureCoordinates = czm_decompressTextureCoordinates(compressed0.z);\n\
  119. \n\
  120. height = height * (u_minMaxHeight.y - u_minMaxHeight.x) + u_minMaxHeight.x;\n\
  121. position = (u_scaleAndBias * vec4(position, 1.0)).xyz;\n\
  122. \n\
  123. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y)\n\
  124. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;\n\
  125. float encodedNormal = compressed1;\n\
  126. #elif defined(INCLUDE_WEB_MERCATOR_Y)\n\
  127. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;\n\
  128. float encodedNormal = 0.0;\n\
  129. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)\n\
  130. float webMercatorT = textureCoordinates.y;\n\
  131. float encodedNormal = compressed0.w;\n\
  132. #else\n\
  133. float webMercatorT = textureCoordinates.y;\n\
  134. float encodedNormal = 0.0;\n\
  135. #endif\n\
  136. \n\
  137. #else\n\
  138. // A single float per element\n\
  139. vec3 position = position3DAndHeight.xyz;\n\
  140. float height = position3DAndHeight.w;\n\
  141. vec2 textureCoordinates = textureCoordAndEncodedNormals.xy;\n\
  142. \n\
  143. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)) && defined(INCLUDE_WEB_MERCATOR_Y)\n\
  144. float webMercatorT = textureCoordAndEncodedNormals.z;\n\
  145. float encodedNormal = textureCoordAndEncodedNormals.w;\n\
  146. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)\n\
  147. float webMercatorT = textureCoordinates.y;\n\
  148. float encodedNormal = textureCoordAndEncodedNormals.z;\n\
  149. #elif defined(INCLUDE_WEB_MERCATOR_Y)\n\
  150. float webMercatorT = textureCoordAndEncodedNormals.z;\n\
  151. float encodedNormal = 0.0;\n\
  152. #else\n\
  153. float webMercatorT = textureCoordinates.y;\n\
  154. float encodedNormal = 0.0;\n\
  155. #endif\n\
  156. \n\
  157. #endif\n\
  158. \n\
  159. vec3 position3DWC = position + u_center3D;\n\
  160. gl_Position = getPosition(position, height, textureCoordinates);\n\
  161. \n\
  162. v_textureCoordinates = vec3(textureCoordinates, webMercatorT);\n\
  163. \n\
  164. #if defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)\n\
  165. v_positionEC = (u_modifiedModelView * vec4(position, 1.0)).xyz;\n\
  166. v_positionMC = position3DWC; // position in model coordinates\n\
  167. vec3 normalMC = czm_octDecode(encodedNormal);\n\
  168. v_normalMC = normalMC;\n\
  169. v_normalEC = czm_normal3D * v_normalMC;\n\
  170. #elif defined(SHOW_REFLECTIVE_OCEAN) || defined(ENABLE_DAYNIGHT_SHADING) || defined(GENERATE_POSITION) || defined(HDR)\n\
  171. v_positionEC = (u_modifiedModelView * vec4(position, 1.0)).xyz;\n\
  172. v_positionMC = position3DWC; // position in model coordinates\n\
  173. #endif\n\
  174. \n\
  175. #if defined(FOG) || defined(GROUND_ATMOSPHERE)\n\
  176. AtmosphereColor atmosFogColor = computeGroundAtmosphereFromSpace(position3DWC, false, vec3(0.0));\n\
  177. v_fogMieColor = atmosFogColor.mie;\n\
  178. v_fogRayleighColor = atmosFogColor.rayleigh;\n\
  179. #endif\n\
  180. \n\
  181. #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT)\n\
  182. v_distance = length((czm_modelView3D * vec4(position3DWC, 1.0)).xyz);\n\
  183. #endif\n\
  184. \n\
  185. #ifdef APPLY_MATERIAL\n\
  186. float northPoleZ = czm_ellipsoidRadii.z;\n\
  187. vec3 northPolePositionMC = vec3(0.0, 0.0, northPoleZ);\n\
  188. vec3 ellipsoidNormal = normalize(v_positionMC); // For a sphere this is correct, but not generally for an ellipsoid.\n\
  189. vec3 vectorEastMC = normalize(cross(northPolePositionMC - v_positionMC, ellipsoidNormal));\n\
  190. float dotProd = abs(dot(ellipsoidNormal, v_normalMC));\n\
  191. v_slope = acos(dotProd);\n\
  192. vec3 normalRejected = ellipsoidNormal * dotProd;\n\
  193. vec3 normalProjected = v_normalMC - normalRejected;\n\
  194. vec3 aspectVector = normalize(normalProjected);\n\
  195. v_aspect = acos(dot(aspectVector, vectorEastMC));\n\
  196. float determ = dot(cross(vectorEastMC, aspectVector), ellipsoidNormal);\n\
  197. v_aspect = czm_branchFreeTernary(determ < 0.0, 2.0 * czm_pi - v_aspect, v_aspect);\n\
  198. v_height = height;\n\
  199. #endif\n\
  200. }\n\
  201. ";