GlobeVS.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. uniform vec3 u_center3D;\n\
  10. uniform mat4 u_modifiedModelView;\n\
  11. uniform mat4 u_modifiedModelViewProjection;\n\
  12. uniform vec4 u_tileRectangle;\n\
  13. uniform vec2 u_southAndNorthLatitude;\n\
  14. uniform vec2 u_southMercatorYAndOneOverHeight;\n\
  15. varying vec3 v_positionMC;\n\
  16. varying vec3 v_positionEC;\n\
  17. varying vec3 v_textureCoordinates;\n\
  18. varying vec3 v_normalMC;\n\
  19. varying vec3 v_normalEC;\n\
  20. #ifdef APPLY_MATERIAL\n\
  21. varying float v_slope;\n\
  22. varying float v_aspect;\n\
  23. varying float v_height;\n\
  24. #endif\n\
  25. #if defined(FOG) || defined(GROUND_ATMOSPHERE)\n\
  26. varying float v_distance;\n\
  27. varying vec3 v_fogMieColor;\n\
  28. varying vec3 v_fogRayleighColor;\n\
  29. #endif\n\
  30. vec4 getPosition(vec3 position, float height, vec2 textureCoordinates);\n\
  31. float get2DYPositionFraction(vec2 textureCoordinates);\n\
  32. vec4 getPosition3DMode(vec3 position, float height, vec2 textureCoordinates)\n\
  33. {\n\
  34. return u_modifiedModelViewProjection * vec4(position, 1.0);\n\
  35. }\n\
  36. float get2DMercatorYPositionFraction(vec2 textureCoordinates)\n\
  37. {\n\
  38. const float maxTileWidth = 0.003068;\n\
  39. float positionFraction = textureCoordinates.y;\n\
  40. float southLatitude = u_southAndNorthLatitude.x;\n\
  41. float northLatitude = u_southAndNorthLatitude.y;\n\
  42. if (northLatitude - southLatitude > maxTileWidth)\n\
  43. {\n\
  44. float southMercatorY = u_southMercatorYAndOneOverHeight.x;\n\
  45. float oneOverMercatorHeight = u_southMercatorYAndOneOverHeight.y;\n\
  46. float currentLatitude = mix(southLatitude, northLatitude, textureCoordinates.y);\n\
  47. currentLatitude = clamp(currentLatitude, -czm_webMercatorMaxLatitude, czm_webMercatorMaxLatitude);\n\
  48. positionFraction = czm_latitudeToWebMercatorFraction(currentLatitude, southMercatorY, oneOverMercatorHeight);\n\
  49. }\n\
  50. return positionFraction;\n\
  51. }\n\
  52. float get2DGeographicYPositionFraction(vec2 textureCoordinates)\n\
  53. {\n\
  54. return textureCoordinates.y;\n\
  55. }\n\
  56. vec4 getPositionPlanarEarth(vec3 position, float height, vec2 textureCoordinates)\n\
  57. {\n\
  58. float yPositionFraction = get2DYPositionFraction(textureCoordinates);\n\
  59. vec4 rtcPosition2D = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);\n\
  60. return u_modifiedModelViewProjection * rtcPosition2D;\n\
  61. }\n\
  62. vec4 getPosition2DMode(vec3 position, float height, vec2 textureCoordinates)\n\
  63. {\n\
  64. return getPositionPlanarEarth(position, 0.0, textureCoordinates);\n\
  65. }\n\
  66. vec4 getPositionColumbusViewMode(vec3 position, float height, vec2 textureCoordinates)\n\
  67. {\n\
  68. return getPositionPlanarEarth(position, height, textureCoordinates);\n\
  69. }\n\
  70. vec4 getPositionMorphingMode(vec3 position, float height, vec2 textureCoordinates)\n\
  71. {\n\
  72. vec3 position3DWC = position + u_center3D;\n\
  73. float yPositionFraction = get2DYPositionFraction(textureCoordinates);\n\
  74. vec4 position2DWC = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);\n\
  75. vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime);\n\
  76. return czm_modelViewProjection * morphPosition;\n\
  77. }\n\
  78. #ifdef QUANTIZATION_BITS12\n\
  79. uniform vec2 u_minMaxHeight;\n\
  80. uniform mat4 u_scaleAndBias;\n\
  81. #endif\n\
  82. void main()\n\
  83. {\n\
  84. #ifdef QUANTIZATION_BITS12\n\
  85. vec2 xy = czm_decompressTextureCoordinates(compressed0.x);\n\
  86. vec2 zh = czm_decompressTextureCoordinates(compressed0.y);\n\
  87. vec3 position = vec3(xy, zh.x);\n\
  88. float height = zh.y;\n\
  89. vec2 textureCoordinates = czm_decompressTextureCoordinates(compressed0.z);\n\
  90. height = height * (u_minMaxHeight.y - u_minMaxHeight.x) + u_minMaxHeight.x;\n\
  91. position = (u_scaleAndBias * vec4(position, 1.0)).xyz;\n\
  92. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y)\n\
  93. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;\n\
  94. float encodedNormal = compressed1;\n\
  95. #elif defined(INCLUDE_WEB_MERCATOR_Y)\n\
  96. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;\n\
  97. float encodedNormal = 0.0;\n\
  98. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)\n\
  99. float webMercatorT = textureCoordinates.y;\n\
  100. float encodedNormal = compressed0.w;\n\
  101. #else\n\
  102. float webMercatorT = textureCoordinates.y;\n\
  103. float encodedNormal = 0.0;\n\
  104. #endif\n\
  105. #else\n\
  106. vec3 position = position3DAndHeight.xyz;\n\
  107. float height = position3DAndHeight.w;\n\
  108. vec2 textureCoordinates = textureCoordAndEncodedNormals.xy;\n\
  109. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)) && defined(INCLUDE_WEB_MERCATOR_Y)\n\
  110. float webMercatorT = textureCoordAndEncodedNormals.z;\n\
  111. float encodedNormal = textureCoordAndEncodedNormals.w;\n\
  112. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)\n\
  113. float webMercatorT = textureCoordinates.y;\n\
  114. float encodedNormal = textureCoordAndEncodedNormals.z;\n\
  115. #elif defined(INCLUDE_WEB_MERCATOR_Y)\n\
  116. float webMercatorT = textureCoordAndEncodedNormals.z;\n\
  117. float encodedNormal = 0.0;\n\
  118. #else\n\
  119. float webMercatorT = textureCoordinates.y;\n\
  120. float encodedNormal = 0.0;\n\
  121. #endif\n\
  122. #endif\n\
  123. vec3 position3DWC = position + u_center3D;\n\
  124. gl_Position = getPosition(position, height, textureCoordinates);\n\
  125. v_textureCoordinates = vec3(textureCoordinates, webMercatorT);\n\
  126. #if defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)\n\
  127. v_positionEC = (u_modifiedModelView * vec4(position, 1.0)).xyz;\n\
  128. v_positionMC = position3DWC;\n\
  129. vec3 normalMC = czm_octDecode(encodedNormal);\n\
  130. v_normalMC = normalMC;\n\
  131. v_normalEC = czm_normal3D * v_normalMC;\n\
  132. #elif defined(SHOW_REFLECTIVE_OCEAN) || defined(ENABLE_DAYNIGHT_SHADING) || defined(GENERATE_POSITION) || defined(HDR)\n\
  133. v_positionEC = (u_modifiedModelView * vec4(position, 1.0)).xyz;\n\
  134. v_positionMC = position3DWC;\n\
  135. #endif\n\
  136. #if defined(FOG) || defined(GROUND_ATMOSPHERE)\n\
  137. AtmosphereColor atmosFogColor = computeGroundAtmosphereFromSpace(position3DWC, false);\n\
  138. v_fogMieColor = atmosFogColor.mie;\n\
  139. v_fogRayleighColor = atmosFogColor.rayleigh;\n\
  140. v_distance = length((czm_modelView3D * vec4(position3DWC, 1.0)).xyz);\n\
  141. #endif\n\
  142. #ifdef APPLY_MATERIAL\n\
  143. float northPoleZ = czm_ellipsoidRadii.z;\n\
  144. vec3 northPolePositionMC = vec3(0.0, 0.0, northPoleZ);\n\
  145. vec3 ellipsoidNormal = normalize(v_positionMC);\n\
  146. vec3 vectorEastMC = normalize(cross(northPolePositionMC - v_positionMC, ellipsoidNormal));\n\
  147. float dotProd = abs(dot(ellipsoidNormal, v_normalMC));\n\
  148. v_slope = acos(dotProd);\n\
  149. vec3 normalRejected = ellipsoidNormal * dotProd;\n\
  150. vec3 normalProjected = v_normalMC - normalRejected;\n\
  151. vec3 aspectVector = normalize(normalProjected);\n\
  152. v_aspect = acos(dot(aspectVector, vectorEastMC));\n\
  153. float determ = dot(cross(vectorEastMC, aspectVector), ellipsoidNormal);\n\
  154. v_aspect = czm_branchFreeTernary(determ < 0.0, 2.0 * czm_pi - v_aspect, v_aspect);\n\
  155. v_height = height;\n\
  156. #endif\n\
  157. }\n\
  158. ";